Class OneToManyHashMap<K,​V>

  • All Implemented Interfaces:
    java.util.Map<K,​java.util.Set<V>>, OneToManyMap<K,​V>

    public class OneToManyHashMap<K,​V>
    extends java.lang.Object
    implements java.util.Map<K,​java.util.Set<V>>, OneToManyMap<K,​V>
    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 Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      boolean containsKey​(java.lang.Object key)  
      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.
      boolean containsValue​(java.lang.Object value)  
      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.Set<java.util.Map.Entry<K,​java.util.Set<V>>> entrySet()  
      java.util.Collection<V> flatValues()
      Returns a Collection of all the values in the map.
      java.util.Set<V> get​(java.lang.Object key)  
      boolean isEmpty()  
      java.util.Set<K> keySet()  
      java.util.Set<V> put​(K key, java.util.Set<V> value)  
      void putAll​(java.util.Map<? extends K,​? extends java.util.Set<V>> m)  
      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.
      java.util.Set<V> remove​(java.lang.Object key)  
      int size()  
      java.util.Collection<java.util.Set<V>> values()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Constructor Detail

      • OneToManyHashMap

        public OneToManyHashMap()
    • Method Detail

      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<K,​V>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<K,​V>
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<K,​V>
      • containsSingleValue

        public boolean containsSingleValue​(V value)
        Description copied from interface: OneToManyMap
        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.
        Specified by:
        containsSingleValue in interface OneToManyMap<K,​V>
        Parameters:
        value - The value being searched for.
        Returns:
        Returns true if any of the value sets contains a matching value, otherwise returns false
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​java.util.Set<V>>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K,​V>
      • entries

        public java.util.Set<java.util.Map.Entry<K,​V>> entries()
        Description copied from interface: OneToManyMap
        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).
        Specified by:
        entries in interface OneToManyMap<K,​V>
        Returns:
        The Set<Entry<K, V>> representing all the key-value pairs in the ManyToOneMap.
      • get

        public java.util.Set<V> get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K,​V>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<K,​V>
      • keySet

        public java.util.Set<K> keySet()
        Specified by:
        keySet in interface java.util.Map<K,​V>
      • put

        public java.util.Set<V> put​(K key,
                                    java.util.Set<V> value)
        Specified by:
        put in interface java.util.Map<K,​V>
      • putSingleValue

        public V putSingleValue​(K key,
                                V value)
        Description copied from interface: OneToManyMap
        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.
        Specified by:
        putSingleValue in interface OneToManyMap<K,​V>
        Returns:
        returns the newly added value.
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends java.util.Set<V>> m)
        Specified by:
        putAll in interface java.util.Map<K,​V>
      • putAllSingleValues

        public void putAllSingleValues​(java.util.Map<? extends K,​? extends V> m)
        Description copied from interface: OneToManyMap
        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.
        Specified by:
        putAllSingleValues in interface OneToManyMap<K,​V>
        Parameters:
        m - A map containing the key-value mappings to be added to the ManyToOneMap.
      • remove

        public java.util.Set<V> remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<K,​V>
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<K,​V>
      • values

        public java.util.Collection<java.util.Set<V>> values()
        Specified by:
        values in interface java.util.Map<K,​V>
      • flatValues

        public java.util.Collection<V> flatValues()
        Description copied from interface: OneToManyMap
        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>>.
        Specified by:
        flatValues in interface OneToManyMap<K,​V>
        Returns:
        All the values in the map as a flattened Collection.