Interface NonNullKeyMap<K,V>

Type Parameters:
K - the type of the keys
V - the type of the values
All Superinterfaces:
Map<K,V>
All Known Subinterfaces:
NonNullMap<K,V>
All Known Implementing Classes:
NonNullEnumMap, NonNullKeyProxy, NonNullProxy

public interface NonNullKeyMap<K,V> extends Map<K,V>
Implements a map which is strict in all keys. Values may be null. 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 <K1, V1> NonNullKeyMap<K1,V1> newInstance()
      Creates a new instance and uses a HashMap as its peer.
      Type Parameters:
      K1 - the type of the keys
      V1 - the type of the values
      Returns:
      a new and empty instance
    • newInstance

      static <K1, V1> NonNullKeyMap<K1,V1> newInstance(Supplier<Map<K1,V1>> supplier)
      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 in HashMap::new, not to a free lambda expression.
      Type Parameters:
      K1 - the type of the keys
      V1 - 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

      static <K1, V1> NonNullKeyMap<K1,V1> duplicate(Map<K1,V1> 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:
      K1 - the type of the keys
      V1 - 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

      static <K1, V1> NonNullKeyMap<K1,V1> copyOf(Map<? extends K1,? extends V1> proto)
      Creates an unmodifiable snapshot copy containing all elements in the prototype.
      Type Parameters:
      K1 - the type of the keys
      V1 - 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

      SortedMap<K,V> 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.