This commit is contained in:
zzz
2011-01-01 20:07:34 +00:00
parent 08a3165c44
commit 0eebfbacd7

View File

@ -9,7 +9,7 @@ import net.i2p.data.Hash;
* Help sort Hashes in relation to a base key using the XOR metric
*
*/
class XORComparator implements Comparator {
class XORComparator implements Comparator<Hash> {
private Hash _base;
/**
* @param target key to compare distances with
@ -17,15 +17,11 @@ class XORComparator implements Comparator {
public XORComparator(Hash target) {
_base = target;
}
public int compare(Object lhs, Object rhs) {
public int compare(Hash lhs, Hash rhs) {
if (lhs == null) throw new NullPointerException("LHS is null");
if (rhs == null) throw new NullPointerException("RHS is null");
if ( (lhs instanceof Hash) && (rhs instanceof Hash) ) {
byte lhsDelta[] = DataHelper.xor(((Hash)lhs).getData(), _base.getData());
byte rhsDelta[] = DataHelper.xor(((Hash)rhs).getData(), _base.getData());
return DataHelper.compareTo(lhsDelta, rhsDelta);
} else {
throw new ClassCastException(lhs.getClass().getName() + " / " + rhs.getClass().getName());
}
byte lhsDelta[] = DataHelper.xor(lhs.getData(), _base.getData());
byte rhsDelta[] = DataHelper.xor(rhs.getData(), _base.getData());
return DataHelper.compareTo(lhsDelta, rhsDelta);
}
}