Interface Selectable<C,T>

Type Parameters:
C - the type of criteria
T - the type of the elements
All Known Implementing Classes:
Beans
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Selectable<C,T>
A notional list of elements from which sublists may be selected according to some criteria.
Author:
Laird Nelson
  • Method Details

    • select

      List<T> select(C criteria)
      Selects and returns an immutable List representing a sublist of this Selectable's elements, as mediated by the supplied criteria.

      Implementations of this method must be idempotent and must return a determinate value.

      Implementations of this method must not return null.

      Implementations of this method should not call list(), since that method is typically implemented in terms of this one.

      Parameters:
      criteria - the criteria to use; may be null
      Returns:
      an immutable sublist of this Selectable's elements; never null
      See Also:
    • list

      default List<T> list()
      Returns an immutable List of all of this Selectable's elements.

      Implementations of this method must be idempotent and must return a determinate value.

      Implementations of this method must not return null.

      The default implementation of this method calls the select(Object) method with null as the sole argument.

      Returns:
      an immutable List of all of this Selectable's elements; never null
      See Also:
    • of

      static <C, E> Selectable<C,E> of(Collection<? extends E> collection, BiFunction<? super E,? super C,? extends Boolean> f)
      Returns a Selectable using the supplied Collection as its elements, and the supplied BiFunction as its selector function.

      There is no guarantee that this method will return new Selectable instances.

      The Selectable instances returned by this method may or may not cache their selections.

      The selector function must select a sublist from the supplied Collection as mediated by the supplied criteria. The selector function must additionally be idempotent and must produce a determinate value when given the same arguments.

      No validation of these semantics of the selector function is performed.

      Type Parameters:
      C - the type of criteria
      E - the type of the elements
      Parameters:
      collection - a Collection of elements from which sublists may be selected; must not be null
      f - the selector function; must not be null
      Returns:
      a Selectable; never null
      Throws:
      NullPointerException - if either collection or f is null
    • of

      static <C, E> Selectable<C,E> of()
      Returns a Selectable whose select(Object) method always returns an empty List.
      Type Parameters:
      C - the type of criteria
      E - the type of the elements
      Returns:
      a Selectable whose select(Object) method always returns an empty List; never null
    • ofCaching

      static <C, E> Selectable<C,E> ofCaching(Collection<? extends E> collection, BiFunction<? super E,? super C,? extends Boolean> f)
      Returns a Selectable using the supplied Collection as its elements, and the supplied BiFunction as its selector function.

      There is no guarantee that this method will return new Selectable instances.

      The Selectable instances returned by this method will cache their selections.

      The selector function must select a sublist from the supplied Collection as mediated by the supplied criteria. The selector function must additionally be idempotent and must produce a determinate value when given the same arguments.

      No validation of these semantics of the selector function is performed.

      Type Parameters:
      C - the type of criteria
      E - the type of the elements
      Parameters:
      collection - a Collection of elements from which sublists may be selected; must not be null
      f - the selector function; must not be null
      Returns:
      a Selectable; never null
      Throws:
      NullPointerException - if either collection or f is null