tom | 9ccd781 | 2014-08-25 22:43:19 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.of.controller.impl.registry; |
alshabib | 1f44e8e | 2014-08-14 15:19:57 -0700 | [diff] [blame] | 2 | |
| 3 | |
| 4 | |
| 5 | public class ControllerRegistryEntry implements Comparable<ControllerRegistryEntry> { |
| 6 | // |
| 7 | // TODO: Refactor the implementation and decide whether controllerId |
| 8 | // is needed. If "yes", we might need to consider it inside the |
| 9 | // compareTo(), equals() and hashCode() implementations. |
| 10 | // |
| 11 | private final String controllerId; |
| 12 | private final int sequenceNumber; |
| 13 | |
| 14 | public ControllerRegistryEntry(String controllerId, int sequenceNumber) { |
| 15 | this.controllerId = controllerId; |
| 16 | this.sequenceNumber = sequenceNumber; |
| 17 | } |
| 18 | |
| 19 | public String getControllerId() { |
| 20 | return controllerId; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Compares this object with the specified object for order. |
| 25 | * NOTE: the test is based on ControllerRegistryEntry sequence numbers, |
| 26 | * and doesn't include the controllerId. |
| 27 | * |
| 28 | * @param o the object to be compared. |
| 29 | * @return a negative integer, zero, or a positive integer as this object |
| 30 | * is less than, equal to, or greater than the specified object. |
| 31 | */ |
| 32 | @Override |
| 33 | public int compareTo(ControllerRegistryEntry o) { |
| 34 | return this.sequenceNumber - o.sequenceNumber; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Test whether some other object is "equal to" this one. |
| 39 | * NOTE: the test is based on ControllerRegistryEntry sequence numbers, |
| 40 | * and doesn't include the controllerId. |
| 41 | * |
| 42 | * @param obj the reference object with which to compare. |
| 43 | * @return true if this object is the same as the obj argument; false |
| 44 | * otherwise. |
| 45 | */ |
| 46 | @Override |
| 47 | public boolean equals(Object obj) { |
| 48 | if (obj instanceof ControllerRegistryEntry) { |
| 49 | ControllerRegistryEntry other = (ControllerRegistryEntry) obj; |
| 50 | return this.sequenceNumber == other.sequenceNumber; |
| 51 | } |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Get the hash code for the object. |
| 57 | * NOTE: the computation is based on ControllerRegistryEntry sequence |
| 58 | * numbers, and doesn't include the controller ID. |
| 59 | * |
| 60 | * @return a hash code value for this object. |
| 61 | */ |
| 62 | @Override |
| 63 | public int hashCode() { |
| 64 | return Integer.valueOf(this.sequenceNumber).hashCode(); |
| 65 | } |
| 66 | } |