Interface OneToManyMap<K,​V>

  • All Superinterfaces:
    java.util.Map<K,​java.util.Set<V>>
    All Known Subinterfaces:
    OneToManyBiMap<K,​V>
    All Known Implementing Classes:
    OneToManyHashBiMap, OneToManyHashMap

    public interface OneToManyMap<K,​V>
    extends java.util.Map<K,​java.util.Set<V>>
    An extension of java.util.Map that represents a mapping from a key to a set of values. In addition to the standard java.util.Map methods this interface also provides several useful methods for directly accessing the values rather than having to access values via a java.util.Set
    Author:
    Nick Smith
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean containsSingleValue​(V value)
      This method returns true if any of the value sets in the OneToManyMap contains an equivalent object to the value parameter, where equivalence is determined using the equals(Object) method.
      java.util.Set<java.util.Map.Entry<K,​V>> entries()
      This method is similar to the java.util.Map.entrySet() method, however the entries returned map from a key to a value, rather than from a key(K) to a value(V) rather than froma key(K) to a set of values(Set<V>).
      java.util.Collection<V> flatValues()
      Returns a Collection of all the values in the map.
      void putAllSingleValues​(java.util.Map<? extends K,​? extends V> m)
      This method is similar to java.utilMap.putAll(Map m), however the map specified is from keys to values instead of keys to sets of values.
      V putSingleValue​(K key, V value)
      This method is similar to the method java.util.Map.put(K, V) , however it allows the user to add a single value to the map rather than adding a java.util.Set containing one or more values.
      • 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 Detail

      • containsSingleValue

        boolean containsSingleValue​(V value)
        This method returns true if any of the value sets in the OneToManyMap contains an equivalent object to the value parameter, where equivalence is determined using the equals(Object) method.
        Parameters:
        value - The value being searched for.
        Returns:
        Returns true if any of the value sets contains a matching value, otherwise returns false
      • entries

        java.util.Set<java.util.Map.Entry<K,​V>> entries()
        This method is similar to the java.util.Map.entrySet() method, however the entries returned map from a key to a value, rather than from a key(K) to a value(V) rather than froma key(K) to a set of values(Set<V>).
        Note that the entries returned by this method do not support the method java.util.Map.Entry.setValue(V).
        Returns:
        The Set<Entry<K, V>> representing all the key-value pairs in the ManyToOneMap.
      • putSingleValue

        V putSingleValue​(K key,
                         V value)
        This method is similar to the method java.util.Map.put(K, V) , however it allows the user to add a single value to the map rather than adding a java.util.Set containing one or more values. If the specified key already has a set of values associated with it then the new value is added to this set. Otherwise a new set is created and the new value is added to that.
        Parameters:
        key -
        value -
        Returns:
        returns the newly added value.
      • putAllSingleValues

        void putAllSingleValues​(java.util.Map<? extends K,​? extends V> m)
        This method is similar to java.utilMap.putAll(Map m), however the map specified is from keys to values instead of keys to sets of values.
        Parameters:
        m - A map containing the key-value mappings to be added to the ManyToOneMap.
      • flatValues

        java.util.Collection<V> flatValues()
        Returns a Collection of all the values in the map. Unlike values() the values are in a single flattened Collection<V> rather than a Collection<Set<V>>.
        Returns:
        All the values in the map as a flattened Collection.