Package eu.bandm.tools.util.nonnull
Interface NonNullMap<K,V>
- Type Parameters:
K- the type of the keysV- the type of the values
- All Superinterfaces:
Map<K,,V> NonNullKeyMap<K,,V> NonNullValueMap<K,,V> Nullfree
- All Known Implementing Classes:
NonNullEnumMap,NonNullProxy
public interface NonNullMap<K,V>
extends Map<K,V>, NonNullKeyMap<K,V>, NonNullValueMap<K,V>, Nullfree
Implements a map which is strict in all keys and values.
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.
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionasSorted()Returns a sorted, unmodifiable view if the backing peer is a sorted set.static <K1,V1> NonNullMap <K1, V1> Creates an unmodifiable snapshot copy containing all elements in the prototype.static <K1,V1> NonNullMap <K1, V1> Creates an independent instance, initialized to contain all elements in the prototype.static <K1,V1> NonNullMap <K1, V1> Creates a new instance and uses aHashMapas its peer.static <K1,V1> NonNullMap <K1, V1> newInstance(Supplier<Map<K1, V1>> supplier) Creates a new instance and uses a map returned by the given supplier as its peer.Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Method Details
-
newInstance
Creates a new instance and uses aHashMapas its peer.- Type Parameters:
K1- the type of the keysV1- the type of the values- Returns:
- a new and empty instance
-
newInstance
Creates a new instance and uses a map 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 inTreeMap::new, not to a free lambda expression.- Type Parameters:
K1- the type of the keysV1- the type of the values- 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:
K1- the type of the keysV1- the type of the values- Parameters:
proto- the data for the new map- Returns:
- a new instance with the given data
- Throws:
NullPointerException- if keys or values contains null values.- See Also:
-
copyOf
Creates an unmodifiable snapshot copy containing all elements in the prototype.- Type Parameters:
K1- the type of the keysV1- the type of the values- Parameters:
proto- the data for the new map- Returns:
- a new instance with the given data
- Throws:
NullPointerException- if the data contains null.- See Also:
-
asSorted
Returns a sorted, unmodifiable view if the backing peer is a sorted set.- Specified by:
asSortedin interfaceNonNullKeyMap<K,V> - Specified by:
asSortedin interfaceNonNullValueMap<K,V> - 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.
-