xapi.collect.impl.HashComparator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xapi-core-collect Show documentation
Show all versions of xapi-core-collect Show documentation
Core interfaces for our collections api.
package xapi.collect.impl;
import java.util.Comparator;
public final class HashComparator implements Comparator {
public int compare(T o1, T o2) {
if (o1 == o2)
return 0;
if (o1 == null) {
return 1;
} else if (o2 == null) {
return -1;
}
int delta = o1.hashCode() - o2.hashCode();
if (delta == 0) {
if (o1.equals(o2)) {
return 0;
} else {
throw new RuntimeException("Hash collision for inequal objects: "+o1+" && "+o2);
}
}
return delta > 0 ? 1 : -1;
};
}