Skip to content

Commit

Permalink
Merge pull request redis#103 from malomalo/set-compare
Browse files Browse the repository at this point in the history
Tuple compare
  • Loading branch information
xetorthio committed May 12, 2011
2 parents 6ff9683 + 9dd1cff commit f25d709
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/java/redis/clients/jedis/Tuple.java
Expand Up @@ -4,7 +4,7 @@

import redis.clients.util.SafeEncoder;

public class Tuple {
public class Tuple implements Comparable {
private byte[] element;
private Double score;

Expand Down Expand Up @@ -38,12 +38,22 @@ public boolean equals(Object obj) {
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);
Expand Down

0 comments on commit f25d709

Please sign in to comment.