Created
March 8, 2011 21:49
-
-
Save malomalo/861155 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main/java/redis/clients/jedis/Tuple.java b/src/main/java/redis/clients/jedis/Tuple.java | |
index 6df12d2..dd698e0 100644 | |
--- a/src/main/java/redis/clients/jedis/Tuple.java | |
+++ b/src/main/java/redis/clients/jedis/Tuple.java | |
@@ -4,7 +4,7 @@ import java.util.Arrays; | |
import redis.clients.util.SafeEncoder; | |
-public class Tuple { | |
+public class Tuple implements Comparable { | |
private byte[] element; | |
private Double score; | |
@@ -38,12 +38,22 @@ public class Tuple { | |
return false; | |
} else if (!Arrays.equals(element, other.element)) | |
return false; | |
- if (Double.doubleToLongBits(score) != Double | |
- .doubleToLongBits(other.score)) | |
- return false; | |
return true; | |
} | |
+ public int compareTo(Tuple other) { | |
+ if (Arrays.equals(this.element, other.element)) | |
+ return 0; | |
+ else | |
+ return this.score < other.getScore() ? -1 : 1; | |
+ } | |
+ public int compareTo(Object obj) { | |
+ if (getClass() != obj.getClass()) | |
+ throw new ClassCastException(); | |
+ return compareTo((Tuple) obj); | |
+ } | |
+ | |
+ | |
public Tuple(String element, Double score) { | |
super(); | |
this.element = SafeEncoder.encode(element); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment