blob: d2cd398e8074ae0421e3c1835b6f48520acc3e39 [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) {
tomfc9a4ff2014-09-22 18:22:47 -070043 if (this == obj) {
44 return true;
45 }
tomca20e0c2014-09-03 23:22:24 -070046 if (obj instanceof ElementId) {
47 final ElementId that = (ElementId) obj;
48 return this.getClass() == that.getClass() &&
49 Objects.equals(this.uri, that.uri);
tomb36046e2014-08-27 00:22:24 -070050 }
tomca20e0c2014-09-03 23:22:24 -070051 return false;
tomb36046e2014-08-27 00:22:24 -070052 }
53
54 @Override
55 public String toString() {
tomff7eb7c2014-09-08 12:49:03 -070056 return uri.toString();
tomb36046e2014-08-27 00:22:24 -070057 }
58
59}