Package eu.bandm.tools.util.nonnull
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
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 Summary
Modifier and TypeMethodDescriptionasSorted()Returns a sorted, unmodifiable view if the backing peer is a sorted set.static <T> NonNullSet<T> Creates an unmodifiable snapshot copy containing all elements in the prototype.static <T> NonNullSet<T> Creates an independent instance, initialized to contain all elements in the prototype.static <E1> NonNullSet<E1> Creates a new instance and uses aHashSetas its peer.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.static <T1> NonNullSet<T1> singleton(T1 x) Return an unmodifiable singleton set with the given data.Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Method Details
-
newInstance
Creates a new instance and uses aHashSetas its peer.- Type Parameters:
E1- the type of the set elements- Returns:
- a new and empty instance
-
newInstance
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 inHashSet::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
Creates an independent instance, initialized to contain all elements in the prototype. The selection of the implementation is done byCollections.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
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
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
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.
-