java - CompareTo may return 0, alternative to TreeSet/TreeMap -
I need a set of objects and currently using TreeSet
. My problem is that will often return
0
to compare objects, which means that the order of those two objects should be left unchanged. TreeMap
(used by TreeSet
by default) will then be treated as a single object, which is not true.
Which option for TreeMap
can I use?
Use the case: I have a set of disposable objects I want to sort them with Y coordination, so that they can be provided in the right order. Of course, there can be the same Y coordination in two objects.
You're defining a criteria to compare, but you need to add additional criteria.
You say:
I have a set of displayable objects I want to sort them with y coordination so that they are provided in the correct order. Could. Of course, there can be the same Y coordination in two objects.
So, if two elements have the same Y coordination, then what do you put first? What will be the other criteria?
It may be time to create, it may be X coordination, you have to define it:
Maps & lt; String, Thing & gt; Map = new trendmark & lt; String, Thing & gt; (New Comparative () {Comparison of Public Entry (Cheung One, Thing Two) {int result = one.y - two.y; if (result == 0) {// same y coordinate second Use the result of the criteria = A. X - two X; if (result == 0) {// is still the same? Try other parameters (time may be back in the creation time. CreationTime)} return results;}};
You have to define when a thing
is higher / less / same / other thing
Comments
Post a Comment