JDK-6278287 : (coll) EnumSet/EnumMap should implement NavigableX or SequencedX interfaces
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 5.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2005-05-31
  • Updated: 2023-07-31
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
EnumSet implements Set. We can't take full advantage of the order in an enum unless EnumSet implements SortedSet.

JUSTIFICATION :
enums have a defined order. EnumSet should take advantage of this to implement SortedSet efficiently.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I'd like to see EnumSet provide all the API for SortedSet.
ACTUAL -
EnumSet only supports the Set API.

---------- BEGIN SOURCE ----------
EnumSet.allOf(SomeEnumSet).headSet(SomeEnumSet.SOMEMEMBER);

won't compile.
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Current plan is to reimplement EnumSet correctly. I'll look into posting the fix after I've done it.
###@###.### 2005-05-31 17:13:49 GMT

Comments
An alternative is to have EnumSet implement SequencedSet and EnumMap implement SequencedMap. Having the ordering semantics conveyed by the type is a significant benefit. This would allow EnumSet/EnumMap to participate with classes that pass around collections of type SequencedX, in order to convey ordering semantics, which isn't possible today with EnumSet and EnumMap. The operations on the SequencedX interfaces (operate on ends, iterate in reverse) are perhaps secondary, though they'd come along for the ride. Having EnumSet/Map implement the NavigableX interfaces is significantly more difficult because of the larger number of operations on those interfaces. While it would be logically consistent to implement the NavigableX interfaces, it's not clear the effort of adding those operations is worthwhile. A bit of discussion is here: https://mail.openjdk.org/pipermail/core-libs-dev/2023-May/106211.html A couple folks seem to concur that the ordering semantics of the interface is more important than the actual operations.
31-07-2023

Similar analysis applies to EnumMap and NavigableMap.
05-07-2019

EVALUATION The fact that "Yesterday" is a more popular song title than "Tomorrow" suggests that EnumSet should even implement the bi-directional NavigableSet. Hopefully the finality of enums will make this possible in a compatible way. ###@###.### 2005-06-03 16:49:12 GMT EnumSet is designed as a replacement for int-based "bit flags". Additional requirements are likely to impact how efficiently the main use case of "bit flags" can be implemented. ###@###.### 2005-06-03 18:36:13 GMT
03-06-2005