Interface Selection<T>

Type Parameters:
T - element type
All Superinterfaces:
Collection<T>, Iterable<T>
All Known Subinterfaces:
Selection.ComparableSelection<T>, Selection.DoubleSelection, Selection.IntSelection, Selection.LongSelection, Selection.NumberSelection<T>, TypedValueSelection
All Known Implementing Classes:
SelectionImpl, TypedValueSelectionImpl

public interface Selection<T> extends Collection<T>
Read only, random accessible heap of typed values. Values can be iterated over, and fetched by index. Negative indexes reference values from the end of the heap; get(-1) returns the last entry, etc.

Selections form a middle ground between Java Collection and List. They lack the mutability of Lists, but do support indexed random addressing.

Selections support access to the first and last elements, arbitrary index elements access, etc.

All of the mutation functions throw UnsupportedOperationException.

  • Method Details

    • get

      Optional<T> get(int index)
      Fetch a value at a specific index in the Selection. If the resolved index is outside the bounds of 0...size(), Optional.empty() will be returned. It supports negative indexes to allow for easy retrieval of tail values.
      Parameters:
      index - 0..size()-1, returns the value at the index. If < 0, returns the value at size()-index (so -1 returns the last, -2 returns 1 from the last, etc).
      Returns:
      Optional of value.
    • getOrElse

      default T getOrElse(int index, T other)
      Fetch a value at a specific index in the Selection. If the resolved index is outside the bounds of 0...size(), the supplied value is returned. It supports negative indexes to allow for easy retrieval of tail values.
      Parameters:
      index - 0..size()-1, returns the value at the index. If < 0, returns the value at size()-index (so -1 returns the last, -2 returns 1 from the last, etc).
      other - alternate value to be returned if not found
      Returns:
      value
    • getOrFail

      default T getOrFail(int index)
      Fetch a value at a specific index in the Selection. If the resolved index is outside the bounds of 0...size(), a NoSuchValueException is thrown. It supports negative indexes to allow for easy retrieval of tail values.
      Parameters:
      index - 0..size()-1, returns the value at the index. If < 0, returns the value at size()-index (so -1 returns the last, -2 returns 1 from the last, etc).
      Returns:
      value.
    • sole

      default T sole()
      Fetch the single value in this Selection, throwing an exception if size()!=1;
      Returns:
      value
    • soleOrElse

      default T soleOrElse(T other)
      Fetch the single value is the size()==1, return the alternative if size()=0, throw an exception is size()>1.
      Parameters:
      other - alt value
      Returns:
      value or other value
    • first

      default Optional<T> first()
      Alias for get(int) where index=0;
      Returns:
      Optional of T
    • firstOrElse

      default T firstOrElse(T other)
      Alias for getOrElse(int, Object) where index=0.
      Returns:
      T
    • firstOrFail

      default T firstOrFail()
      Alias for getOrFail(int) where index=0.
      Returns:
      T
    • last

      default Optional<T> last()
      Alias for get(int) where index = size()-1;
      Returns:
      Optional of T
    • lastOrElse

      default T lastOrElse(T other)
      Alias for getOrElse(int, Object) where index = size()-1.
      Returns:
      T
    • lastOrFail

      default T lastOrFail()
      Alias for getOrFail(int) where index = size()-1.
      Returns:
      T
    • add

      default boolean add(T t)
      Specified by:
      add in interface Collection<T>
    • remove

      default boolean remove(Object o)
      Specified by:
      remove in interface Collection<T>
    • removeAll

      default boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<T>
    • retainAll

      default boolean retainAll(Collection<?> c)
      Specified by:
      retainAll in interface Collection<T>
    • clear

      default void clear()
      Specified by:
      clear in interface Collection<T>
    • removeIf

      default boolean removeIf(Predicate<? super T> filter)
      Specified by:
      removeIf in interface Collection<T>