Simon Hunt
Committed by Gerrit Code Review

Fix for ONOS-3220 : Implement Comparable on intent Key.

Change-Id: Ibba4a972d2e3a82b5bf9256893a82501236021cb
...@@ -28,7 +28,7 @@ import java.util.Objects; ...@@ -28,7 +28,7 @@ import java.util.Objects;
28 */ 28 */
29 // TODO maybe pull this up to utils 29 // TODO maybe pull this up to utils
30 @Beta 30 @Beta
31 -public abstract class Key { 31 +public abstract class Key implements Comparable<Key> {
32 32
33 //TODO consider making this a HashCode object (worry about performance) 33 //TODO consider making this a HashCode object (worry about performance)
34 private final long hash; 34 private final long hash;
...@@ -117,6 +117,12 @@ public abstract class Key { ...@@ -117,6 +117,12 @@ public abstract class Key {
117 Objects.equals(this.appId, other.appId) && 117 Objects.equals(this.appId, other.appId) &&
118 Objects.equals(this.key, other.key); 118 Objects.equals(this.key, other.key);
119 } 119 }
120 +
121 + @Override
122 + public int compareTo(Key o) {
123 + StringKey sk = (StringKey) o;
124 + return this.key.compareTo(sk.key);
125 + }
120 } 126 }
121 127
122 private static final class LongKey extends Key { 128 private static final class LongKey extends Key {
...@@ -157,6 +163,13 @@ public abstract class Key { ...@@ -157,6 +163,13 @@ public abstract class Key {
157 this.key == other.key && 163 this.key == other.key &&
158 Objects.equals(this.appId, other.appId); 164 Objects.equals(this.appId, other.appId);
159 } 165 }
166 +
167 + @Override
168 + public int compareTo(Key o) {
169 + Long myKey = key;
170 + Long otherKey = ((LongKey) o).key;
171 + return myKey.compareTo(otherKey);
172 + }
160 } 173 }
161 } 174 }
162 175
......
...@@ -325,5 +325,11 @@ public class PartitionManagerTest { ...@@ -325,5 +325,11 @@ public class PartitionManagerTest {
325 325
326 return Objects.equals(this.hash(), that.hash()); 326 return Objects.equals(this.hash(), that.hash());
327 } 327 }
328 +
329 + @Override
330 + public int compareTo(Key o) {
331 + Long thisHash = hash();
332 + return thisHash.compareTo(o.hash());
333 + }
328 } 334 }
329 } 335 }
......