Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.topology; |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 21 | |
| 22 | /** |
| 23 | * Representation of the topology cluster identity. |
| 24 | */ |
| 25 | public 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 | |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 45 | /** |
| 46 | * Returns the backing integer index. |
| 47 | * |
| 48 | * @return backing integer index |
| 49 | */ |
| 50 | public int index() { |
| 51 | return id; |
| 52 | } |
| 53 | |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 54 | @Override |
| 55 | public int hashCode() { |
| 56 | return Objects.hash(id); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public boolean equals(Object obj) { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 61 | if (this == obj) { |
| 62 | return true; |
| 63 | } |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 64 | 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 | } |