Yuta HIGUCHI | 80912e6 | 2014-10-12 00:15:47 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.mastership; |
Yuta HIGUCHI | 080d784 | 2014-09-25 13:53:15 -0700 | [diff] [blame] | 2 | |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 3 | import java.util.Objects; |
| 4 | |
Yuta HIGUCHI | 80912e6 | 2014-10-12 00:15:47 -0700 | [diff] [blame^] | 5 | import org.onlab.onos.cluster.NodeId; |
| 6 | |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 7 | public final class MastershipTerm { |
| 8 | |
| 9 | private final NodeId master; |
Yuta HIGUCHI | 22e0f2f | 2014-09-26 16:30:53 -0700 | [diff] [blame] | 10 | private final int termNumber; |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 11 | |
| 12 | private MastershipTerm(NodeId master, int term) { |
| 13 | this.master = master; |
| 14 | this.termNumber = term; |
| 15 | } |
| 16 | |
| 17 | public static MastershipTerm of(NodeId master, int term) { |
| 18 | return new MastershipTerm(master, term); |
| 19 | } |
| 20 | |
| 21 | public NodeId master() { |
| 22 | return master; |
| 23 | } |
| 24 | |
| 25 | public int termNumber() { |
| 26 | return termNumber; |
| 27 | } |
| 28 | |
| 29 | @Override |
| 30 | public int hashCode() { |
| 31 | return Objects.hash(master, termNumber); |
| 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public boolean equals(Object other) { |
Ayaka Koshibe | 48239b0 | 2014-09-25 17:12:31 -0700 | [diff] [blame] | 36 | if (this == other) { |
| 37 | return true; |
| 38 | } |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 39 | if (other instanceof MastershipTerm) { |
| 40 | MastershipTerm that = (MastershipTerm) other; |
| 41 | if (!this.master.equals(that.master)) { |
| 42 | return false; |
| 43 | } |
| 44 | if (this.termNumber != that.termNumber) { |
| 45 | return false; |
| 46 | } |
| 47 | return true; |
| 48 | } |
| 49 | return false; |
| 50 | } |
Yuta HIGUCHI | 080d784 | 2014-09-25 13:53:15 -0700 | [diff] [blame] | 51 | } |