blob: 9f0e20b46135141bce13d51070dac9f7a2d01d15 [file] [log] [blame]
tomcfde0622014-09-09 11:02:42 -07001package org.onlab.onos.net.topology;
2
3import java.util.Objects;
4
5import static com.google.common.base.MoreObjects.toStringHelper;
6
7/**
8 * Representation of the topology cluster identity.
9 */
10public final class ClusterId {
11
12 private final int id;
13
14 // Public construction is prohibit
15 private ClusterId(int id) {
16 this.id = id;
17 }
18
19 /**
20 * Returns the cluster identifier, represented by the specified integer
21 * serial number.
22 *
23 * @param id integer serial number
24 * @return cluster identifier
25 */
26 public static ClusterId clusterId(int id) {
27 return new ClusterId(id);
28 }
29
tom97937552014-09-11 10:48:42 -070030 /**
31 * Returns the backing integer index.
32 *
33 * @return backing integer index
34 */
35 public int index() {
36 return id;
37 }
38
tomcfde0622014-09-09 11:02:42 -070039 @Override
40 public int hashCode() {
41 return Objects.hash(id);
42 }
43
44 @Override
45 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -070046 if (this == obj) {
47 return true;
48 }
tomcfde0622014-09-09 11:02:42 -070049 if (obj instanceof ClusterId) {
50 final ClusterId other = (ClusterId) obj;
51 return Objects.equals(this.id, other.id);
52 }
53 return false;
54 }
55
56 @Override
57 public String toString() {
58 return toStringHelper(this).add("id", id).toString();
59 }
60
61}