blob: c6d730d23a6d0207e97c375e49f58c46ff97bce9 [file] [log] [blame]
Jonathan Hartdeda0ba2014-04-03 11:14:12 -07001package net.onrc.onos.core.registry;
Jonathan Hart3d7730a2013-02-22 11:51:17 -08002
3import org.codehaus.jackson.annotate.JsonProperty;
4
Jonathan Hart3d7730a2013-02-22 11:51:17 -08005public class ControllerRegistryEntry implements Comparable<ControllerRegistryEntry> {
Pavlin Radoslavov60c9b8f2014-04-09 16:25:01 -07006 //
7 // TODO: Refactor the implementation and decide whether controllerId
8 // is needed. If "yes", we might need to consider it inside the
Jonathan Hart12a26aa2014-06-04 14:33:09 -07009 // compareTo(), equals() and hashCode() implementations.
Pavlin Radoslavov60c9b8f2014-04-09 16:25:01 -070010 //
Jonathan Hart12a26aa2014-06-04 14:33:09 -070011 private final String controllerId;
12 private final int sequenceNumber;
Jonathan Hart3d7730a2013-02-22 11:51:17 -080013
Ray Milkey269ffb92014-04-03 14:43:30 -070014 public ControllerRegistryEntry(String controllerId, int sequenceNumber) {
15 this.controllerId = controllerId;
16 this.sequenceNumber = sequenceNumber;
17 }
18
19 @JsonProperty("controllerId")
20 public String getControllerId() {
21 return controllerId;
22 }
23
Pavlin Radoslavov60c9b8f2014-04-09 16:25:01 -070024 /**
25 * Compares this object with the specified object for order.
26 * NOTE: the test is based on ControllerRegistryEntry sequence numbers,
27 * and doesn't include the controllerId.
28 *
29 * @param o the object to be compared.
30 * @return a negative integer, zero, or a positive integer as this object
31 * is less than, equal to, or greater than the specified object.
32 */
Ray Milkey269ffb92014-04-03 14:43:30 -070033 @Override
34 public int compareTo(ControllerRegistryEntry o) {
Pavlin Radoslavov60c9b8f2014-04-09 16:25:01 -070035 return this.sequenceNumber - o.sequenceNumber;
Ray Milkey269ffb92014-04-03 14:43:30 -070036 }
Jonathan Hart3d7730a2013-02-22 11:51:17 -080037
Pavlin Radoslavov60c9b8f2014-04-09 16:25:01 -070038 /**
39 * Test whether some other object is "equal to" this one.
40 * NOTE: the test is based on ControllerRegistryEntry sequence numbers,
41 * and doesn't include the controllerId.
42 *
43 * @param obj the reference object with which to compare.
44 * @return true if this object is the same as the obj argument; false
45 * otherwise.
46 */
47 @Override
48 public boolean equals(Object obj) {
49 if (obj instanceof ControllerRegistryEntry) {
50 ControllerRegistryEntry other = (ControllerRegistryEntry) obj;
51 return this.sequenceNumber == other.sequenceNumber;
52 }
53 return false;
54 }
55
56 /**
57 * Get the hash code for the object.
58 * NOTE: the computation is based on ControllerRegistryEntry sequence
59 * numbers, and doesn't include the controller ID.
60 *
61 * @return a hash code value for this object.
62 */
63 @Override
64 public int hashCode() {
65 return Integer.valueOf(this.sequenceNumber).hashCode();
66 }
Jonathan Hart3d7730a2013-02-22 11:51:17 -080067}