Interface NonNullSet<E>

Type Parameters:
E - the type of the set elements
All Superinterfaces:
Collection<E>, Iterable<E>, Nullfree, Set<E>
All Known Implementing Classes:
SetProxy

public interface NonNullSet<E> extends Set<E>, Nullfree
Implements a set which is strict in all its elements. The implementation is done by delegation to some peer object from a predefined Java runtime class. Optional operations are supported whenever the peer object supports them.
  • Method Details

    • newInstance

      static <E1> NonNullSet<E1> newInstance()
      Creates a new instance and uses a HashSet as its peer.
      Type Parameters:
      E1 - the type of the set elements
      Returns:
      a new and empty instance
    • newInstance

      static <E1> NonNullSet<E1> newInstance(Supplier<Set<E1>> supplier)
      Creates a new instance and uses a set 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 HashSet::new, not to a free lambda expression.
      Type Parameters:
      E1 - the type of the set 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.
    • duplicate

      static <T> NonNullSet<T> duplicate(Set<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).
      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 the data contains null values.
      See Also:
    • copyOf

      static <T> NonNullSet<T> copyOf(Set<? extends T> proto)
      Creates an unmodifiable snapshot copy containing all elements in the prototype.
      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 the data contains null values.
      See Also:
    • asSorted

      SortedSet<E> asSorted()
      Returns a sorted, unmodifiable view if the backing peer is a sorted set.
      Returns:
      a sorted, unmodifiable view if the backing peer is a sorted set.
      Throws:
      UnsupportedOperationException - if the backing peer does not offer a sorted view.
    • singleton

      static <T1> NonNullSet<T1> singleton(T1 x)
      Return an unmodifiable singleton set with the given data.
      Type Parameters:
      T1 - the type of the set elements
      Parameters:
      x - the single value in the set
      Returns:
      an unmodifiabel singelton set with the given data.
      Throws:
      NullPointerException - if the given data is null.