blob: 1e6780facdff2764b9e1cf7a421d95fc263161ed [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.topology;
tomcfde0622014-09-09 11:02:42 -070017
18import java.util.Objects;
19
20import static com.google.common.base.MoreObjects.toStringHelper;
21
22/**
23 * Representation of the topology cluster identity.
24 */
25public final class ClusterId {
26
27 private final int id;
28
29 // Public construction is prohibit
30 private ClusterId(int id) {
31 this.id = id;
32 }
33
34 /**
35 * Returns the cluster identifier, represented by the specified integer
36 * serial number.
37 *
38 * @param id integer serial number
39 * @return cluster identifier
40 */
41 public static ClusterId clusterId(int id) {
42 return new ClusterId(id);
43 }
44
tom97937552014-09-11 10:48:42 -070045 /**
46 * Returns the backing integer index.
47 *
48 * @return backing integer index
49 */
50 public int index() {
51 return id;
52 }
53
tomcfde0622014-09-09 11:02:42 -070054 @Override
55 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070056 return id;
tomcfde0622014-09-09 11:02:42 -070057 }
58
59 @Override
60 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -070061 if (this == obj) {
62 return true;
63 }
tomcfde0622014-09-09 11:02:42 -070064 if (obj instanceof ClusterId) {
65 final ClusterId other = (ClusterId) obj;
66 return Objects.equals(this.id, other.id);
67 }
68 return false;
69 }
70
71 @Override
72 public String toString() {
73 return toStringHelper(this).add("id", id).toString();
74 }
75
76}