Interface TwoKeyMultiMap<K1,K2,V>

Type Parameters:
K1 - type of first keys in this map
K2 - type of second keys in this map
V - type of values in this map
All Known Implementing Classes:
AbstractTwoKeyMultiMap, MapMultiMapTwoKeyMultiMap

public interface TwoKeyMultiMap<K1,K2,V>
A collection that maps two-key pairs to values, similar to TwoKeyMap, but in which each two-key pair may be associated with multiple values. The values associated with the same two-key pair contain no duplicates. You can visualize the contents of a two-key multimap either as a map from keys to multimaps as values:
  • k1 -> { k2 -> [v1, v2], k3 -> [v3] }
  • k2 -> { k4 -> [v1, v4] }

... or as a single "flattened" collection of key1-key2-value triples:

  • k1, k2 -> v1
  • k1, k2 -> v2
  • k1, k3 -> v3
  • k2, k4 -> v1
  • k2, k4 -> v4

Note that both null keys and values are not permitted in this map.

  • Method Details

    • contains

      boolean contains(K1 key1, K2 key2, V value)
      Returns:
      true if given key1-key2-value mapping is contained in this two-key multimap.
    • containsKey

      boolean containsKey(K1 key1, K2 key2)
      Returns:
      true if this two-key multimap contains the mapping with key1 as the first key and key2 as the second key.
    • containsKey

      boolean containsKey(K1 key1)
      Returns:
      true if this two-key multimap contains at least one mapping with key1 as the first key.
    • containsValue

      boolean containsValue(V value)
      Returns:
      true if this two-key multimap contains at least one mapping with value as the value. Note that this operation may be slow compared to containsKey(Object).
    • get

      Set<V> get(K1 key1, K2 key2)
      Returns:
      an unmodifiable view of the values associated with given keys in this multimap, if the two-key pair is absent; otherwise, returns an empty set.
    • get

      MultiMap<K2,V> get(K1 key1)
      Returns:
      an unmodifiable view of the values associated with given key in this two-key multimap, if the key is absent; otherwise, returns an empty multimap.
    • put

      boolean put(@Nonnull K1 key1, @Nonnull K2 key2, @Nonnull V value)
      Stores a key1-key2-value triple in this two-key multimap.
      Returns:
      true if this two-key multimap changed.
    • remove

      boolean remove(K1 key1, K2 key2, V value)
      Removes a single key1-key2-value triple from this two-key multimap, if it exists.
      Returns:
      true if the two-key multimap changed
    • removeAll

      boolean removeAll(K1 key1, K2 key2)
      Removes all values associated with the two-key pair.
      Returns:
      true if the multimap changed.
    • twoKeySet

      Set<Pair<K1,K2>> twoKeySet()
      Returns:
      an unmodifiable view of all distinct two-key pairs contained in this two-key multimap. Note that the result contains a two-key pair if and only if this map maps that key pair to at least one non-null value.
    • entrySet

      Set<TwoKeyMap.Entry<K1,K2,V>> entrySet()
      Returns:
      an unmodifiable view of all key1-key2-value triples contained in this two-key multimap, as TwoKeyMap.Entry instances.
    • forEach

      default void forEach(@Nonnull TriConsumer<K1,K2,V> action)
      Performs the given action for all key1-key2-value triples contained in this map.
    • clear

      void clear()
      Removes all the mappings from this map. The map will be empty after this call returns.
    • isEmpty

      boolean isEmpty()
      Returns:
      true if this map contains no key1-key2-value mappings.
    • size

      int size()
      Returns:
      the number of key1-key2-value mappings in this map.