blob: 569a922a427d17ed5b6905511c6d3649c07d589f [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
5
6public class ControllerRegistryEntry implements Comparable<ControllerRegistryEntry> {
Pavlin Radoslavov60c9b8f2014-04-09 16:25:01 -07007 //
8 // TODO: Refactor the implementation and decide whether controllerId
9 // is needed. If "yes", we might need to consider it inside the
10 // compareTo(), equals() and hashCode() impmenetations.
11 //
Ray Milkey269ffb92014-04-03 14:43:30 -070012 private String controllerId;
13 private int sequenceNumber;
Jonathan Hart3d7730a2013-02-22 11:51:17 -080014
Ray Milkey269ffb92014-04-03 14:43:30 -070015 public ControllerRegistryEntry(String controllerId, int sequenceNumber) {
16 this.controllerId = controllerId;
17 this.sequenceNumber = sequenceNumber;
18 }
19
20 @JsonProperty("controllerId")
21 public String getControllerId() {
22 return controllerId;
23 }
24
Pavlin Radoslavov60c9b8f2014-04-09 16:25:01 -070025 /**
26 * Compares this object with the specified object for order.
27 * NOTE: the test is based on ControllerRegistryEntry sequence numbers,
28 * and doesn't include the controllerId.
29 *
30 * @param o the object to be compared.
31 * @return a negative integer, zero, or a positive integer as this object
32 * is less than, equal to, or greater than the specified object.
33 */
Ray Milkey269ffb92014-04-03 14:43:30 -070034 @Override
35 public int compareTo(ControllerRegistryEntry o) {
Pavlin Radoslavov60c9b8f2014-04-09 16:25:01 -070036 return this.sequenceNumber - o.sequenceNumber;
Ray Milkey269ffb92014-04-03 14:43:30 -070037 }
Jonathan Hart3d7730a2013-02-22 11:51:17 -080038
Pavlin Radoslavov60c9b8f2014-04-09 16:25:01 -070039 /**
40 * Test whether some other object is "equal to" this one.
41 * NOTE: the test is based on ControllerRegistryEntry sequence numbers,
42 * and doesn't include the controllerId.
43 *
44 * @param obj the reference object with which to compare.
45 * @return true if this object is the same as the obj argument; false
46 * otherwise.
47 */
48 @Override
49 public boolean equals(Object obj) {
50 if (obj instanceof ControllerRegistryEntry) {
51 ControllerRegistryEntry other = (ControllerRegistryEntry) obj;
52 return this.sequenceNumber == other.sequenceNumber;
53 }
54 return false;
55 }
56
57 /**
58 * Get the hash code for the object.
59 * NOTE: the computation is based on ControllerRegistryEntry sequence
60 * numbers, and doesn't include the controller ID.
61 *
62 * @return a hash code value for this object.
63 */
64 @Override
65 public int hashCode() {
66 return Integer.valueOf(this.sequenceNumber).hashCode();
67 }
Jonathan Hart3d7730a2013-02-22 11:51:17 -080068}