tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net; |
2 | |||||
3 | import java.net.URI; | ||||
4 | import java.util.Objects; | ||||
5 | |||||
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 6 | /** |
7 | * Immutable representation of a network element identity. | ||||
8 | */ | ||||
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 9 | public abstract class ElementId { |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 10 | |
11 | private final URI uri; | ||||
12 | |||||
Yuta HIGUCHI | 24a086b | 2014-09-21 23:28:41 -0700 | [diff] [blame] | 13 | // Default constructor for serialization |
14 | protected ElementId() { | ||||
15 | this.uri = null; | ||||
16 | } | ||||
17 | |||||
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 18 | /** |
19 | * Creates an element identifier using the supplied URI. | ||||
20 | * | ||||
21 | * @param uri backing URI | ||||
22 | */ | ||||
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 23 | protected ElementId(URI uri) { |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 24 | 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) { | ||||
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 43 | if (this == obj) { |
44 | return true; | ||||
45 | } | ||||
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 46 | if (obj instanceof ElementId) { |
47 | final ElementId that = (ElementId) obj; | ||||
48 | return this.getClass() == that.getClass() && | ||||
49 | Objects.equals(this.uri, that.uri); | ||||
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 50 | } |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 51 | return false; |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 52 | } |
53 | |||||
54 | @Override | ||||
55 | public String toString() { | ||||
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 56 | return uri.toString(); |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 57 | } |
58 | |||||
59 | } |