Package eu.bandm.tools.util.nonnull
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
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.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classAuxiliary class, not accessible by the user, which intercepts all modification to guarantee nullfree.static classAuxiliary class, not accessible by the user, which intercepts all modification to guarantee nullfree. -
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic <T> NonNullList<T> Creates an unmodifiable snapshot copy containing all elements in the prototype.static <T> NonNullList<T> Creates an independent instance, initialized to contain all elements in the prototype.static <T> NonNullList<T> Creates a new instance with an ArrayList as implementaiton.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.static <T> NonNullList<T> singleton(T x) Creates a new unmodifiable instance which contains the given element.Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
add, add, addAll, addAll, addFirst, addLast, clear, contains, containsAll, equals, get, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, set, size, sort, spliterator, subList, toArray, toArray
-
Method Details
-
newInstance
Creates a new instance with an ArrayList as implementaiton.- Type Parameters:
T- the types of the elements.- Returns:
- a new empty instance
-
newInstance
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 inLinkedList::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
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
Creates an independent instance, initialized to contain all elements in the prototype. The selection of the implementation is done byCollections.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
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:
-