forked from I2P_Developers/i2p.i2p
generics
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user