On Fri, 16 Apr 2021 at 18:41, Stuart Marks <stuart.ma...@oracle.com> wrote: > This is a proposal to add a ReversibleCollection interface to the Collections > Framework. I'm looking for comments on overall design before I work on > detailed > specifications and tests. Please send such comments as replies on this email > thread.
I think this could be an interesting addition to the framework. > # Ordering and Reversibility Reading this section, it seems like ordering is a more significant quality than reversibility. Yet the API is named "reversible". That seems odd, esepcially given the stream characteristic. > SortedSet::addFirst and addLast throw UnsupportedOperationException. This is > because > SortedSet's ordering is determined by the comparison method and cannot be > controlled > explicitly. This seems undesirable. Maybe SortedSet should not implement reversible/ordered? Maybe they should add to the set but validate whether they would be in first/last position? Simply allowing users to get a new instance with a different (eg. reversed) comparator would meet much of the use case. Also, SortedSet uses first() and last(), yet the proposed interface uses getFirst() and getLast(). Stephen