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 | /** |
Yuta HIGUCHI | 630216e | 2014-07-30 09:09:34 -0700 | [diff] [blame] | 15 | * Default constructor for serializer. |
| 16 | */ |
| 17 | @Deprecated |
| 18 | protected OnosInstanceId() { |
| 19 | id = "(should never see this)"; |
| 20 | } |
| 21 | |
| 22 | /** |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame] | 23 | * Constructor from a string value. |
| 24 | * |
| 25 | * @param id the value to use. |
| 26 | */ |
| 27 | public OnosInstanceId(String id) { |
| 28 | this.id = checkNotNull(id); |
| 29 | checkArgument(!id.isEmpty(), "Empty ONOS Instance ID"); |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public int hashCode() { |
| 34 | return id.hashCode(); |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public boolean equals(Object obj) { |
| 39 | if (obj == this) { |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | if (!(obj instanceof OnosInstanceId)) { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | OnosInstanceId that = (OnosInstanceId) obj; |
| 48 | return this.id.equals(that.id); |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public String toString() { |
| 53 | return id; |
| 54 | } |
| 55 | } |