Interface NonNullList<T>

Type Parameters:
T - the types of the elements.
All Superinterfaces:
Collection<T>, Iterable<T>, List<T>, Nullfree, SequencedCollection<T>
All Known Implementing Classes:
NonNullList.ListProxy

public interface NonNullList<T> extends List<T>, Nullfree
Implements a list which is strict in all its elements. The implementation is done by delegation to some peer object from a predefined Java runtime class.
  • Method Details

    • newInstance

      static <T> NonNullList<T> newInstance()
      Creates a new instance with an ArrayList as implementaiton.
      Type Parameters:
      T - the types of the elements.
      Returns:
      a new empty instance
    • newInstance

      static <T> NonNullList<T> newInstance(Supplier<List<T>> supplier)
      Creates a new instance and uses a list returned by the given supplier as its peer. This supplier should deliver a fresh and empty instance, and no further reference to this result should be kept anywhere, because by this the non-null contract can be broken. The supplier argument is thus meant to be set to a constructor, as in LinkedList::new, not to a free lambda expression.
      Type Parameters:
      T - the types of the elements.
      Parameters:
      supplier - must deliver an empty instance of the intended peer class.
      Returns:
      a new and empty instance
      Throws:
      IllegalArgumentException - if the delivered peer is not empty.
    • singleton

      static <T> NonNullList<T> singleton(T x)
      Creates a new unmodifiable instance which contains the given element.
      Type Parameters:
      T - the types of the elements.
      Parameters:
      x - the only member of tghe new instance
      Returns:
      a new instance with the given member
      Throws:
      NullPointerException - if the argument is null
    • duplicate

      static <T> NonNullList<T> duplicate(List<T> proto)
      Creates an independent instance, initialized to contain all elements in the prototype. The selection of the implementation is done by Collections.duplicate(List), which tries to come the behaviour of the prototype as close as possible.
      Type Parameters:
      T - the type of the set elements
      Parameters:
      proto - the data for the new set
      Returns:
      a new instance with the given data
      Throws:
      NullPointerException - if proto contains null values
      See Also:
    • copyOf

      static <T> NonNullList<T> copyOf(List<? extends T> proto)
      Creates an unmodifiable snapshot copy containing all elements in the prototype.
      Type Parameters:
      T - the type of the list elements
      Parameters:
      proto - the data for the new list
      Returns:
      a new instance with the given data
      Throws:
      NullPointerException - if the data contains null values.
      See Also: