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