blob: 796299b81c71f1713498e94d48796ef5935ef846 [file] [log] [blame]
Jordan Halterman28183ee2017-10-17 17:29:10 -07001/*
2 * Copyright 2017-present Open Networking Foundation
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 */
16package org.onosproject.cluster;
17
18import java.util.Objects;
19
20import org.onosproject.core.Version;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23import static com.google.common.base.Preconditions.checkNotNull;
24
25/**
26 * Controller member identity.
27 */
28public final class Member {
29
30 private final NodeId nodeId;
31 private final Version version;
32
33 /**
34 * Creates a new cluster member identifier from the specified string.
35 *
36 * @param nodeId node identifier
37 * @param version node version
38 */
39 public Member(NodeId nodeId, Version version) {
40 this.nodeId = checkNotNull(nodeId);
41 this.version = version;
42 }
43
44 /**
45 * Returns the node identifier.
46 *
47 * @return the node identifier
48 */
49 public NodeId nodeId() {
50 return nodeId;
51 }
52
53 /**
54 * Returns the node version.
55 *
56 * @return the node version
57 */
58 public Version version() {
59 return version;
60 }
61
62 @Override
63 public int hashCode() {
64 return Objects.hash(nodeId, version);
65 }
66
67 @Override
68 public boolean equals(Object object) {
69 if (object instanceof Member) {
70 Member member = (Member) object;
71 return member.nodeId.equals(nodeId) && Objects.equals(member.version, version);
72 }
73 return false;
74 }
75
76 @Override
77 public String toString() {
78 return toStringHelper(this)
79 .add("nodeId", nodeId)
80 .add("version", version)
81 .toString();
82 }
83}