blob: a75f11ede24a748b3be0a002a7c734c5998b3dc8 [file] [log] [blame]
tomb36046e2014-08-27 00:22:24 -07001package org.onlab.onos.net;
2
3import java.net.URI;
4import java.util.Objects;
5
tomb36046e2014-08-27 00:22:24 -07006/**
7 * Immutable representation of a network element identity.
8 */
tomca20e0c2014-09-03 23:22:24 -07009public abstract class ElementId {
tomb36046e2014-08-27 00:22:24 -070010
11 private final URI uri;
12
Yuta HIGUCHI24a086b2014-09-21 23:28:41 -070013 // Default constructor for serialization
14 protected ElementId() {
15 this.uri = null;
16 }
17
tomb36046e2014-08-27 00:22:24 -070018 /**
19 * Creates an element identifier using the supplied URI.
20 *
21 * @param uri backing URI
22 */
tomca20e0c2014-09-03 23:22:24 -070023 protected ElementId(URI uri) {
tomb36046e2014-08-27 00:22:24 -070024 this.uri = uri;
25 }
26
27 /**
28 * Returns the backing URI.
29 *
30 * @return backing URI
31 */
32 public URI uri() {
33 return uri;
34 }
35
36 @Override
37 public int hashCode() {
38 return Objects.hash(uri);
39 }
40
41 @Override
42 public boolean equals(Object obj) {
tomca20e0c2014-09-03 23:22:24 -070043 if (obj instanceof ElementId) {
44 final ElementId that = (ElementId) obj;
45 return this.getClass() == that.getClass() &&
46 Objects.equals(this.uri, that.uri);
tomb36046e2014-08-27 00:22:24 -070047 }
tomca20e0c2014-09-03 23:22:24 -070048 return false;
tomb36046e2014-08-27 00:22:24 -070049 }
50
51 @Override
52 public String toString() {
tomff7eb7c2014-09-08 12:49:03 -070053 return uri.toString();
tomb36046e2014-08-27 00:22:24 -070054 }
55
56}