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 | |
| 13 | /** |
| 14 | * Creates an element identifier using the supplied URI. |
| 15 | * |
| 16 | * @param uri backing URI |
| 17 | */ |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 18 | protected ElementId(URI uri) { |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 19 | 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) { |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 38 | if (obj instanceof ElementId) { |
| 39 | final ElementId that = (ElementId) obj; |
| 40 | return this.getClass() == that.getClass() && |
| 41 | Objects.equals(this.uri, that.uri); |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 42 | } |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 43 | return false; |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public String toString() { |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 48 | return uri.toString(); |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | } |