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 | |
| 6 | import static com.google.common.base.Objects.toStringHelper; |
| 7 | |
| 8 | /** |
| 9 | * Immutable representation of a network element identity. |
| 10 | */ |
| 11 | public class ElementId { |
| 12 | |
| 13 | private final URI uri; |
| 14 | |
| 15 | /** |
| 16 | * Creates an element identifier using the supplied URI. |
| 17 | * |
| 18 | * @param uri backing URI |
| 19 | */ |
| 20 | public ElementId(URI uri) { |
| 21 | this.uri = uri; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Returns the backing URI. |
| 26 | * |
| 27 | * @return backing URI |
| 28 | */ |
| 29 | public URI uri() { |
| 30 | return uri; |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public int hashCode() { |
| 35 | return Objects.hash(uri); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public boolean equals(Object obj) { |
| 40 | if (this == obj) { |
| 41 | return true; |
| 42 | } |
| 43 | if (obj == null || getClass() != obj.getClass()) { |
| 44 | return false; |
| 45 | } |
| 46 | final ElementId other = (ElementId) obj; |
| 47 | return Objects.equals(this.uri, other.uri); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public String toString() { |
| 52 | return toStringHelper(this).add("uri", uri).toString(); |
| 53 | } |
| 54 | |
| 55 | } |