tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.topology; |
| 2 | |
| 3 | import java.util.Objects; |
| 4 | |
| 5 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 6 | |
| 7 | /** |
| 8 | * Representation of the topology cluster identity. |
| 9 | */ |
| 10 | public 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 | |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Returns the backing integer index. |
| 32 | * |
| 33 | * @return backing integer index |
| 34 | */ |
| 35 | public int index() { |
| 36 | return id; |
| 37 | } |
| 38 | |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 39 | @Override |
| 40 | public int hashCode() { |
| 41 | return Objects.hash(id); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public boolean equals(Object obj) { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 46 | if (this == obj) { |
| 47 | return true; |
| 48 | } |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 49 | 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 | } |