Accname
2D-Graphics enthusiast
- Reaction score
- 1,462
Hi guys.
I am desperate. This piece of shit is driving me CRAZY.
I have a TreeSet with this custom comparator:
And then I have this:
Guess what the outcome is...
By the way, the equals method is NOT changed at all for these classes. Its still the default equals from Object.
Heres the official documentation from oracle.
http://docs.oracle.com/javase/7/docs/api/java/util/TreeSet.html#contains(java.lang.Object)
I am desperate. This piece of shit is driving me CRAZY.
I have a TreeSet with this custom comparator:
Code:
TreeSet<Layer> layers = new TreeSet<>(new Comparator<Layer>() {
public int compare(Layer o1, Layer o2) {
if (o1.equals(o2)) {
return 0;
}
if (o1.get_z() >= o2.get_z()) {
return 1;
}
return -1;
}
});
Code:
public void containTest(Layer obj) {
for (Layer a : layers) {
if (a.equals(obj)) {
System.out.println(obj+" is contained.");
}
}
System.out.println("Contains "+obj+" = "+layers.contains(obj));
}
Layer(0) is contained.
Contains Layer(0) = false
By the way, the equals method is NOT changed at all for these classes. Its still the default equals from Object.
Heres the official documentation from oracle.
http://docs.oracle.com/javase/7/docs/api/java/util/TreeSet.html#contains(java.lang.Object)