blob: 61b0751e2aaa7f49249ce4d4c322f462b9115b64 [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
6/**
7 * The class representing an ONOS Instance ID.
8 *
9 * This class is immutable.
10 */
11public final class OnosInstanceId {
12 private final String id;
13
14 /**
Yuta HIGUCHI630216e2014-07-30 09:09:34 -070015 * Default constructor for serializer.
16 */
17 @Deprecated
18 protected OnosInstanceId() {
19 id = "(should never see this)";
20 }
21
22 /**
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070023 * 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}