I have a set of objects which I cannot modify by overriding their equals or hashCode functions (which don’t behave as I would like), but for which I do have a comparator that behaves as I would like. Is there a Set I could use that leverages the comparator to not allow duplicates, but when iterated iterates over insertion order?
Essentially I am looking for a cross between the TreeSet and LinkedHashSet. Something like a LinkedTreeSet!
Have you considered creating a class that wraps the objects and implements an equals/hashCode function that behaves as you expect? A bit of a hassle but you seem to have heavy constraints.
Also, if you do end up doing this or finding something more suitable, make sure to comment it properly, or the next guy will make the wrong assumptions about equals/hashCode methods!
PS: a TreeSet still uses equals to rule out duplicates