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.cluster; |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 17 | |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 18 | import java.util.Objects; |
| 19 | |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 20 | /** |
| 21 | * Controller cluster identity. |
| 22 | */ |
David K. Bainbridge | e676dab | 2015-10-23 16:13:07 -0700 | [diff] [blame] | 23 | public class NodeId implements Comparable<NodeId> { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 24 | |
| 25 | private final String id; |
| 26 | |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 27 | /** |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 28 | * Creates a new cluster node identifier from the specified string. |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 29 | * |
| 30 | * @param id string identifier |
| 31 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 32 | public NodeId(String id) { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 33 | this.id = id; |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public int hashCode() { |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 38 | return id.hashCode(); |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public boolean equals(Object obj) { |
| 43 | if (this == obj) { |
| 44 | return true; |
| 45 | } |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 46 | if (obj instanceof NodeId) { |
| 47 | final NodeId other = (NodeId) obj; |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 48 | return Objects.equals(this.id, other.id); |
| 49 | } |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public String toString() { |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 55 | return id; |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 56 | } |
| 57 | |
David K. Bainbridge | e676dab | 2015-10-23 16:13:07 -0700 | [diff] [blame] | 58 | @Override |
| 59 | public int compareTo(NodeId that) { |
| 60 | return this.id.compareTo(that.id); |
| 61 | } |
| 62 | |
tom | 73d6d1e | 2014-09-17 20:08:01 -0700 | [diff] [blame] | 63 | } |