Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame^] | 1 | package net.onrc.onos.core.util; |
| 2 | |
| 3 | import static com.google.common.base.Preconditions.checkNotNull; |
| 4 | import static com.google.common.base.Preconditions.checkArgument; |
| 5 | |
| 6 | /** |
| 7 | * The class representing an ONOS Instance ID. |
| 8 | * |
| 9 | * This class is immutable. |
| 10 | */ |
| 11 | public final class OnosInstanceId { |
| 12 | private final String id; |
| 13 | |
| 14 | /** |
| 15 | * Constructor from a string value. |
| 16 | * |
| 17 | * @param id the value to use. |
| 18 | */ |
| 19 | public OnosInstanceId(String id) { |
| 20 | this.id = checkNotNull(id); |
| 21 | checkArgument(!id.isEmpty(), "Empty ONOS Instance ID"); |
| 22 | } |
| 23 | |
| 24 | @Override |
| 25 | public int hashCode() { |
| 26 | return id.hashCode(); |
| 27 | } |
| 28 | |
| 29 | @Override |
| 30 | public boolean equals(Object obj) { |
| 31 | if (obj == this) { |
| 32 | return true; |
| 33 | } |
| 34 | |
| 35 | if (!(obj instanceof OnosInstanceId)) { |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | OnosInstanceId that = (OnosInstanceId) obj; |
| 40 | return this.id.equals(that.id); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public String toString() { |
| 45 | return id; |
| 46 | } |
| 47 | } |