The idea of EnumSet implementing SortedSet or NavigableSet has been around for a
long time; see
https://bugs.openjdk.org/browse/JDK-6278287
But yes, EnumSet could also implement SequencedSet. Similarly, EnumMap could
implement SequencedMap, SortedMap, or NavigableMap.
Implementing NavigableSet/Map is somewhat onerous, given that there's no
AbstractNavigableSet/Map, and there are a lot of methods and variations of views to
be implemented.
I'm a bit skeptical about the usefulness of retrofitting EnumSet/Map this way,
though. My hunch is that EnumSet is usually treated as a bag of named booleans used
as a set of boolean options. The EnumSet is passed around as an aggregate, with
individual enum instances tested at specific points in the code to adjust the logic.
It doesn't seem like the members of an EnumSet would be iterated frequently, or that
it would be useful to have specific subsets of an EnumSet (which is what
NavigableSet would provide). Maybe similar analysis applies to EnumMap.
I could be convinced otherwise with use cases, though.
s'marks
On 5/23/23 2:57 AM, Tagir Valeev wrote:
Hello!
Looks like this was overlooked. On the other hand, it could even implement
SortedSet or Navigable set, as it's essentially not just ordered but sorted,
according to the enum natural order. Same for EnumMap.
With best regards,
Tagir Valeev
On Tue, May 23, 2023, 11:46 Andrey Turbanov <turban...@gmail.com> wrote:
Hello.
I've noticed that EnumSet unfortunately doesn't implement the newly
introduced interface SequencedSet.
From the first look it fits into it.
Is there a reason for that? Sorry if it was already discussed.
Andrey Turbanov