According to the docs, SortedSet expects to function based on either
natural order (if the elements implement Comparable) or in accordance
with whatever Comparator is provided.  The only functional difference
between the SortedSet contract and EnumSet API are all the methods in
SortedSet dealing with subsets (first, subSet, etc.).  Still doesn't
seem to be any good reason why EnumSet doesn't implement SortedSet.

On Aug 4, 3:28 pm, drd <[email protected]> wrote:
> I know Mr. Bloch himself did the implementation and probably had a
> reason to not implement it. However in effective java he does not
> state anything about ordering or why it is not ordered.
>
> I also want to stress that SortedSet says that there has to be a
> natural ordering. This ordering is provided by Enumset as stated in
> the javadoc. By using this information the implementation of the
> comparator should be very easy and should not hurt performance (the
> enumset is sorted per se and the comparable interface should not be
> created for sorting).
>
> My colleagues and me had a discussion about this because we wanted to
> pass a sorted collection of enums. As we were not able to pass a
> EnumSet (thank you struts), we were forced to use a Set. However a
> colleague argued that when we passed it as a Set we could not enforce
> the contract that we had a sorted collection. This made us use a List
> in which we could enforce the ordering, but cannot enforce the
> uniqueness.
>
> But my question then remains, who can answer my question?
>
> Mr. Bloch????
>
> On Jul 31, 3:49 pm, JodaStephen <[email protected]> wrote:
>
> > Making Enum implement Comparable by default was a mistake in the
> > original design process, which has had negative consequences (you
> > should have had to write "implements Comparable" if you wanted it).
>
> > But, since all Enums do implement Comparable, then I would agree that
> > EnumSet should probably implement SortedSet. One reason why not, is
> > that users might expect to be able to supply their own comparator, and
> > that isn't possible given the internal implementation of EnumSet.
>
> > Stephen
>
> > On Jul 30, 10:56 am, drd <[email protected]> wrote:
>
> > > I was wondering: why is an EnumSet not a SortedSet.
>
> > > Javadoc of EnumSet says : ... the iterator returns the elements in
> > > their natural order ...
>
> > > Javadoc of SortedSet says: A Set that further provides a total
> > > ordering on its elements. The elements are ordered using their natural
> > > ordering, or by a Comparator typically provided at sorted set creation
> > > time...
>
> > > Why is then the EnumSet not a SortedSet?
>
> > > I hope somebody will be able to clarify my mind.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to