blob: e205bb61159b7615756a89b93f4f32c2d47faf4f [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
13 /**
14 * Creates an element identifier using the supplied URI.
15 *
16 * @param uri backing URI
17 */
tomca20e0c2014-09-03 23:22:24 -070018 protected ElementId(URI uri) {
tomb36046e2014-08-27 00:22:24 -070019 this.uri = uri;
20 }
21
22 /**
23 * Returns the backing URI.
24 *
25 * @return backing URI
26 */
27 public URI uri() {
28 return uri;
29 }
30
31 @Override
32 public int hashCode() {
33 return Objects.hash(uri);
34 }
35
36 @Override
37 public boolean equals(Object obj) {
tomca20e0c2014-09-03 23:22:24 -070038 if (obj instanceof ElementId) {
39 final ElementId that = (ElementId) obj;
40 return this.getClass() == that.getClass() &&
41 Objects.equals(this.uri, that.uri);
tomb36046e2014-08-27 00:22:24 -070042 }
tomca20e0c2014-09-03 23:22:24 -070043 return false;
tomb36046e2014-08-27 00:22:24 -070044 }
45
46 @Override
47 public String toString() {
tomff7eb7c2014-09-08 12:49:03 -070048 return uri.toString();
tomb36046e2014-08-27 00:22:24 -070049 }
50
51}