Logical inconsistence between Set and SortedSet interfaces

Andrej Hollmann andrej.hollmann at gmx.de
Sun Jan 27 10:30:05 UTC 2013


Hello,

I want to add few products to the SortedSet and sort them by price. I 
add four different elements to TreeSet:
["salt",0.5$], ["milk", 1$], ["bread", 1$], ["bananas", 2$]

But at the end my TreeSet contains only three elements:
["salt",0.5$], ["bread", 1$], ["bananas", 2$]

The "bread" replaced the "milk" because it has the same price. I think 
ordering and equity are different aspects and should be separated. A 
logically correct SortedSet implementation should contain all four 
elements in ordered style. In that way SortedSet would be downward 
compatible to inherited Set interface.

To test my thinks I wrote my own SortedSet, which is based on TreeList 
from apache-collection and achieved desired results.

PS: With new SortedSet I can sort products by date, or supplier, ... . I 
just need to implement my own comparator and can be sure that added 
products will be not replaced by others because elements are the same 
during comparison.

Best Regards
Andrej




More information about the core-libs-dev mailing list