JDK-5087829 : (coll) SortedSet needs to be able to use another .equals method
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-08-17
  • Updated: 2012-10-08
  • Resolved: 2004-08-17
Related Reports
Duplicate :  
Relates :  
Description

Name: js151677			Date: 08/17/2004


A DESCRIPTION OF THE REQUEST :
If you are trying to create a SortedSet of, say, case insensitive Strings (so Hello and hello are equivelent) you can pass in a Comparator to handle the comparison but because of the fact that SortedSet is going to call the .equals method on (in this case) String it is impossible to get the correct behaviour.

A solution would be to create a new interface (java.lang.Equalitator or something) that describes the .equals method (possible that Object would implement this new interface - but by no means required - but probably a good idea) and allow SortedSet and presumably SOrtedMap to additionally provide the Equalitator.  The SortedSet would then use the .equals method of the Equalitator rather than the .equals method of the specific class.

JUSTIFICATION :
  To avoid having to wrap objects that are going into a SortedSet.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Without this enhancement people will have to come up with their own unique way of solving this issue, either by creating their own SortedSet or by wrapping each object in another class to facilitate the .equals change.
ACTUAL -
You cannot create a SOrtedSet of case insensitve Strings (for example)

CUSTOMER SUBMITTED WORKAROUND :
Wrap each object in another class that provides a different .equals method.
(Incident Review ID: 297188) 
======================================================================