ReversibleCollection proposal
Peter Levart
peter.levart at gmail.com
Sun Apr 18 07:57:34 UTC 2021
On 4/18/21 9:51 AM, Peter Levart wrote:
> public interface Collection<E> .... {
> default Collection<E> reversed() { return this; }
> default void addFirst(E e) { throw new
> UnsupportedOperationException(); }
> default void addLast(E e) { throw new
> UnsupportedOperationException(); }
For unordered collections this could as well be:
default void addFirst(E e) { return add(e); }
default void addLast(E e) { return add(e); }
As the iteration of such modified unordered collection would not
guarantee any order. SortedSet would of course override them with
throwing methods.
> default E getFirst() { return iterator().next(); }
> default E getLast() { return iterator().next(); }
> default E removeFirst() { var i = iterator(); i.next();
> i.remove(); }
> default E removeLast() { var i = iterator(); i.next();
> i.remove(); }
> }
More information about the core-libs-dev
mailing list