Comparator for TreeMap<Integer[], Double>
Hi all,
I'm trying to write a compartor for a TreeMap<Integer[], Double>. The Integer[] has always two entries and [x,y] should be equal to [y,x].
This is my code:
TreeMap<Integer[], Double> t =new TreeMap<Integer[], Double>(new Comparator(){
publicint compare(Object o1, Object o2){
Integer[] i1 = (Integer[]) o1;
Integer[] i2 = (Integer[]) o2;
if (i1[0].equals(i2[0]) && i1[1].equals(i2[1]))
return 0;
if (!i1[0].equals(i2[0]))
return i1[0].compareTo(i2[0]);
return i1[1].compareTo(i2[1]);
}
});
However, after inserting two elements like
t.put(new Integer[]{1,2}, 0.1);
t.put(new Integer[]{2,1}, 0.2);
, the TreeMap contains these two elements instead of just one.
Is there an error in my Comparator?
Regards,
Andreas

