Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.registry; |
Jonathan Hart | 3d7730a | 2013-02-22 11:51:17 -0800 | [diff] [blame] | 2 | |
| 3 | import org.codehaus.jackson.annotate.JsonProperty; |
| 4 | |
| 5 | |
| 6 | public class ControllerRegistryEntry implements Comparable<ControllerRegistryEntry> { |
Pavlin Radoslavov | 60c9b8f | 2014-04-09 16:25:01 -0700 | [diff] [blame] | 7 | // |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 12 | private String controllerId; |
| 13 | private int sequenceNumber; |
Jonathan Hart | 3d7730a | 2013-02-22 11:51:17 -0800 | [diff] [blame] | 14 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 15 | 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 Radoslavov | 60c9b8f | 2014-04-09 16:25:01 -0700 | [diff] [blame] | 25 | /** |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 34 | @Override |
| 35 | public int compareTo(ControllerRegistryEntry o) { |
Pavlin Radoslavov | 60c9b8f | 2014-04-09 16:25:01 -0700 | [diff] [blame] | 36 | return this.sequenceNumber - o.sequenceNumber; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 37 | } |
Jonathan Hart | 3d7730a | 2013-02-22 11:51:17 -0800 | [diff] [blame] | 38 | |
Pavlin Radoslavov | 60c9b8f | 2014-04-09 16:25:01 -0700 | [diff] [blame] | 39 | /** |
| 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 Hart | 3d7730a | 2013-02-22 11:51:17 -0800 | [diff] [blame] | 68 | } |