blob: 502eee124da5c6ff365961824a34b27f203e00d4 [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) {
46 if (obj instanceof ClusterId) {
47 final ClusterId other = (ClusterId) obj;
48 return Objects.equals(this.id, other.id);
49 }
50 return false;
51 }
52
53 @Override
54 public String toString() {
55 return toStringHelper(this).add("id", id).toString();
56 }
57
58}