blob: 91e38681020d9926314874f6ae58632f14f01f57 [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 */
Yuta HIGUCHI80912e62014-10-12 00:15:47 -070016package org.onlab.onos.mastership;
Yuta HIGUCHI080d7842014-09-25 13:53:15 -070017
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070018import java.util.Objects;
19
Yuta HIGUCHI80912e62014-10-12 00:15:47 -070020import org.onlab.onos.cluster.NodeId;
21
Yuta HIGUCHIa9700c72014-10-24 22:12:03 -070022import com.google.common.base.MoreObjects;
23
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070024public final class MastershipTerm {
25
26 private final NodeId master;
Yuta HIGUCHI22e0f2f2014-09-26 16:30:53 -070027 private final int termNumber;
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070028
29 private MastershipTerm(NodeId master, int term) {
30 this.master = master;
31 this.termNumber = term;
32 }
33
34 public static MastershipTerm of(NodeId master, int term) {
35 return new MastershipTerm(master, term);
36 }
37
38 public NodeId master() {
39 return master;
40 }
41
42 public int termNumber() {
43 return termNumber;
44 }
45
46 @Override
47 public int hashCode() {
48 return Objects.hash(master, termNumber);
49 }
50
51 @Override
52 public boolean equals(Object other) {
Ayaka Koshibe48239b02014-09-25 17:12:31 -070053 if (this == other) {
54 return true;
55 }
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070056 if (other instanceof MastershipTerm) {
57 MastershipTerm that = (MastershipTerm) other;
58 if (!this.master.equals(that.master)) {
59 return false;
60 }
61 if (this.termNumber != that.termNumber) {
62 return false;
63 }
64 return true;
65 }
66 return false;
67 }
Yuta HIGUCHIa9700c72014-10-24 22:12:03 -070068
69 @Override
70 public String toString() {
71 return MoreObjects.toStringHelper(getClass())
72 .add("master", this.master)
73 .add("termNumber", this.termNumber)
74 .toString();
75 }
Yuta HIGUCHI080d7842014-09-25 13:53:15 -070076}