DATAREDIS-74
+ add equals/hashCode/compareTo to Tuples
This commit is contained in:
@@ -54,4 +54,29 @@ public class DefaultStringTuple extends DefaultTuple implements StringTuple {
|
||||
public String getValueAsString() {
|
||||
return valueAsString;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((valueAsString == null) ? 0 : valueAsString.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (super.equals(obj)) {
|
||||
if (!(obj instanceof DefaultStringTuple))
|
||||
return false;
|
||||
DefaultStringTuple other = (DefaultStringTuple) obj;
|
||||
if (valueAsString == null) {
|
||||
if (other.valueAsString != null)
|
||||
return false;
|
||||
}
|
||||
else if (!valueAsString.equals(other.valueAsString))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
|
||||
/**
|
||||
@@ -48,4 +50,40 @@ public class DefaultTuple implements Tuple {
|
||||
public byte[] getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (!(obj instanceof DefaultTuple))
|
||||
return false;
|
||||
DefaultTuple other = (DefaultTuple) obj;
|
||||
if (score == null) {
|
||||
if (other.score != null)
|
||||
return false;
|
||||
}
|
||||
else if (!score.equals(other.score))
|
||||
return false;
|
||||
if (!Arrays.equals(value, other.value))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((score == null) ? 0 : score.hashCode());
|
||||
result = prime * result + Arrays.hashCode(value);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Double o) {
|
||||
Double d = (score == null ? Double.valueOf(0.0d) : score);
|
||||
Double a = (o == null ? Double.valueOf(0.0d) : o);
|
||||
return d.compareTo(a);
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public interface RedisZSetCommands {
|
||||
/**
|
||||
* ZSet tuple.
|
||||
*/
|
||||
public interface Tuple {
|
||||
public interface Tuple extends Comparable<Double> {
|
||||
byte[] getValue();
|
||||
|
||||
Double getScore();
|
||||
|
||||
@@ -47,4 +47,44 @@ class DefaultTypedTuple<V> implements TypedTuple<V> {
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((score == null) ? 0 : score.hashCode());
|
||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (!(obj instanceof DefaultTypedTuple))
|
||||
return false;
|
||||
DefaultTypedTuple other = (DefaultTypedTuple) obj;
|
||||
if (score == null) {
|
||||
if (other.score != null)
|
||||
return false;
|
||||
}
|
||||
else if (!score.equals(other.score))
|
||||
return false;
|
||||
if (value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
||||
}
|
||||
else if (!value.equals(other.value))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Double o) {
|
||||
Double d = (score == null ? Double.valueOf(0) : score);
|
||||
Double a = (o == null ? Double.valueOf(0) : o);
|
||||
return d.compareTo(a);
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public interface ZSetOperations<K, V> {
|
||||
/**
|
||||
* Typed ZSet tuple.
|
||||
*/
|
||||
public interface TypedTuple<V> {
|
||||
public interface TypedTuple<V> extends Comparable<Double> {
|
||||
V getValue();
|
||||
|
||||
Double getScore();
|
||||
|
||||
Reference in New Issue
Block a user