Class TreeBidiMap.Inverse

    • 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>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Set entrySet
      Store the entrySet once created.
      private java.util.Set keySet
      Store the keySet once created.
      private TreeBidiMap main
      The parent map.
      private java.util.Set valuesSet
      Store the valuesSet once created.
    • Constructor Summary

      Constructors 
      Constructor Description
      Inverse​(TreeBidiMap main)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      boolean containsKey​(java.lang.Object key)  
      boolean containsValue​(java.lang.Object value)  
      java.util.Set entrySet()  
      boolean equals​(java.lang.Object obj)  
      java.lang.Object firstKey()
      Gets the first key currently in this map.
      java.lang.Object get​(java.lang.Object key)  
      java.lang.Object getKey​(java.lang.Object value)
      Gets the key that is currently mapped to the specified value.
      int hashCode()  
      BidiMap inverseBidiMap()
      Gets a view of this map where the keys and values are reversed.
      OrderedBidiMap inverseOrderedBidiMap()
      Gets a view of this map where the keys and values are reversed.
      boolean isEmpty()  
      java.util.Set keySet()  
      java.lang.Object lastKey()
      Gets the last key currently in this map.
      MapIterator mapIterator()
      Obtains a MapIterator over the map.
      java.lang.Object nextKey​(java.lang.Object key)
      Gets the next key after the one specified.
      OrderedMapIterator orderedMapIterator()
      Obtains an OrderedMapIterator over the map.
      java.lang.Object previousKey​(java.lang.Object key)
      Gets the previous key before the one specified.
      java.lang.Object put​(java.lang.Object key, java.lang.Object value)
      Puts the key-value pair into the map, replacing any previous pair.
      void putAll​(java.util.Map map)  
      java.lang.Object remove​(java.lang.Object key)  
      java.lang.Object removeValue​(java.lang.Object value)
      Removes the key-value pair that is currently mapped to the specified value (optional operation).
      int size()  
      java.lang.String toString()  
      java.util.Collection values()  
      • Methods inherited from class java.lang.Object

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

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • keySet

        private java.util.Set keySet
        Store the keySet once created.
      • valuesSet

        private java.util.Set valuesSet
        Store the valuesSet once created.
      • entrySet

        private java.util.Set entrySet
        Store the entrySet once created.
    • Constructor Detail

      • Inverse

        Inverse​(TreeBidiMap main)
        Constructor.
        Parameters:
        main - the main map
    • Method Detail

      • size

        public int size()
        Specified by:
        size in interface java.util.Map
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map
      • get

        public java.lang.Object get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map
      • getKey

        public java.lang.Object getKey​(java.lang.Object value)
        Description copied from interface: BidiMap
        Gets the key that is currently mapped to the specified value.

        If the value is not contained in the map, null is returned.

        Implementations should seek to make this method perform equally as well as get(Object).

        Specified by:
        getKey in interface BidiMap
        Parameters:
        value - the value to find the key for
        Returns:
        the mapped key, or null if not found
      • containsKey

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

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map
      • firstKey

        public java.lang.Object firstKey()
        Description copied from interface: OrderedMap
        Gets the first key currently in this map.
        Specified by:
        firstKey in interface OrderedMap
        Returns:
        the first key currently in this map
      • lastKey

        public java.lang.Object lastKey()
        Description copied from interface: OrderedMap
        Gets the last key currently in this map.
        Specified by:
        lastKey in interface OrderedMap
        Returns:
        the last key currently in this map
      • nextKey

        public java.lang.Object nextKey​(java.lang.Object key)
        Description copied from interface: OrderedMap
        Gets the next key after the one specified.
        Specified by:
        nextKey in interface OrderedMap
        Parameters:
        key - the key to search for next from
        Returns:
        the next key, null if no match or at end
      • previousKey

        public java.lang.Object previousKey​(java.lang.Object key)
        Description copied from interface: OrderedMap
        Gets the previous key before the one specified.
        Specified by:
        previousKey in interface OrderedMap
        Parameters:
        key - the key to search for previous from
        Returns:
        the previous key, null if no match or at start
      • put

        public java.lang.Object put​(java.lang.Object key,
                                    java.lang.Object value)
        Description copied from interface: BidiMap
        Puts the key-value pair into the map, replacing any previous pair.

        When adding a key-value pair, the value may already exist in the map against a different key. That mapping is removed, to ensure that the value only occurs once in the inverse map.

          BidiMap map1 = new DualHashBidiMap();
          map.put("A","B");  // contains A mapped to B, as per Map
          map.put("A","C");  // contains A mapped to C, as per Map
         
          BidiMap map2 = new DualHashBidiMap();
          map.put("A","B");  // contains A mapped to B, as per Map
          map.put("C","B");  // contains C mapped to B, key A is removed
         
        Specified by:
        put in interface BidiMap
        Specified by:
        put in interface java.util.Map
        Parameters:
        key - the key to store
        value - the value to store
        Returns:
        the previous value mapped to this key
      • putAll

        public void putAll​(java.util.Map map)
        Specified by:
        putAll in interface java.util.Map
      • remove

        public java.lang.Object remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map
      • removeValue

        public java.lang.Object removeValue​(java.lang.Object value)
        Description copied from interface: BidiMap
        Removes the key-value pair that is currently mapped to the specified value (optional operation).

        If the value is not contained in the map, null is returned.

        Implementations should seek to make this method perform equally as well as remove(Object).

        Specified by:
        removeValue in interface BidiMap
        Parameters:
        value - the value to find the key-value pair for
        Returns:
        the key that was removed, null if nothing removed
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map
      • keySet

        public java.util.Set keySet()
        Specified by:
        keySet in interface java.util.Map
      • values

        public java.util.Collection values()
        Specified by:
        values in interface java.util.Map
      • entrySet

        public java.util.Set entrySet()
        Specified by:
        entrySet in interface java.util.Map
      • mapIterator

        public MapIterator mapIterator()
        Description copied from interface: BidiMap
        Obtains a MapIterator over the map.

        A map iterator is an efficient way of iterating over maps. It does not require that the map is stored using Map Entry objects which can increase performance.

         BidiMap map = new DualHashBidiMap();
         MapIterator it = map.mapIterator();
         while (it.hasNext()) {
           Object key = it.next();
           Object value = it.getValue();
           it.setValue("newValue");
         }
         
        Specified by:
        mapIterator in interface BidiMap
        Specified by:
        mapIterator in interface IterableMap
        Returns:
        a map iterator
      • orderedMapIterator

        public OrderedMapIterator orderedMapIterator()
        Description copied from interface: OrderedMap
        Obtains an OrderedMapIterator over the map.

        A ordered map iterator is an efficient way of iterating over maps in both directions.

         BidiMap map = new TreeBidiMap();
         MapIterator it = map.mapIterator();
         while (it.hasNext()) {
           Object key = it.next();
           Object value = it.getValue();
           it.setValue("newValue");
           Object previousKey = it.previous();
         }
         
        Specified by:
        orderedMapIterator in interface OrderedMap
        Returns:
        a map iterator
      • inverseBidiMap

        public BidiMap inverseBidiMap()
        Description copied from interface: OrderedBidiMap
        Gets a view of this map where the keys and values are reversed.

        Changes to one map will be visible in the other and vice versa. This enables both directions of the map to be accessed equally.

        Implementations should seek to avoid creating a new object every time this method is called. See AbstractMap.values() etc. Calling this method on the inverse map should return the original.

        Implementations must return an OrderedBidiMap instance, usually by forwarding to inverseOrderedBidiMap().

        Specified by:
        inverseBidiMap in interface BidiMap
        Specified by:
        inverseBidiMap in interface OrderedBidiMap
        Returns:
        an inverted bidirectional map
      • inverseOrderedBidiMap

        public OrderedBidiMap inverseOrderedBidiMap()
        Description copied from interface: OrderedBidiMap
        Gets a view of this map where the keys and values are reversed.

        Changes to one map will be visible in the other and vice versa. This enables both directions of the map to be accessed equally.

        Implementations should seek to avoid creating a new object every time this method is called. See AbstractMap.values() etc. Calling this method on the inverse map should return the original.

        Specified by:
        inverseOrderedBidiMap in interface OrderedBidiMap
        Returns:
        an inverted bidirectional map
      • equals

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Map
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object