blob: 9badb1b92e3ecb359d506d13bf8a855ad8eec79f [file] [log] [blame]
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -07001package net.onrc.onos.core.util;
2
3import static com.google.common.base.Preconditions.checkNotNull;
4import static com.google.common.base.Preconditions.checkArgument;
5
Yuta HIGUCHI6d7ee9f2014-08-22 09:56:50 -07006import javax.annotation.concurrent.Immutable;
7
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -07008/**
9 * The class representing an ONOS Instance ID.
10 *
11 * This class is immutable.
12 */
Yuta HIGUCHI6d7ee9f2014-08-22 09:56:50 -070013@Immutable
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070014public final class OnosInstanceId {
15 private final String id;
16
17 /**
Yuta HIGUCHI630216e2014-07-30 09:09:34 -070018 * Default constructor for serializer.
19 */
20 @Deprecated
21 protected OnosInstanceId() {
22 id = "(should never see this)";
23 }
24
25 /**
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070026 * 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}