Class DualTreeBidiMap<K,​V>

  • Type Parameters:
    K - the type of the keys in this map
    V - the type of the values in this map
    All Implemented Interfaces:, java.util.Map<K,​V>, java.util.SortedMap<K,​V>, BidiMap<K,​V>, Get<K,​V>, IterableGet<K,​V>, IterableMap<K,​V>, OrderedBidiMap<K,​V>, OrderedMap<K,​V>, Put<K,​V>, SortedBidiMap<K,​V>

    public class DualTreeBidiMap<K,​V>
    extends AbstractDualBidiMap<K,​V>
    implements SortedBidiMap<K,​V>,
    Implementation of BidiMap that uses two TreeMap instances.

    The setValue() method on iterators will succeed only if the new value being set is not already in the bidimap.

    When considering whether to use this class, the TreeBidiMap class should also be considered. It implements the interface using a dedicated design, and does not store each object twice, which can save on memory use.

    NOTE: From Commons Collections 3.1, all subclasses will use TreeMap and the flawed createMap method is ignored.

    See Also:
    Serialized Form
    • Constructor Detail

      • DualTreeBidiMap

        public DualTreeBidiMap()
        Creates an empty DualTreeBidiMap
      • DualTreeBidiMap

        public DualTreeBidiMap​(java.util.Map<? extends K,​? extends V> map)
        Constructs a DualTreeBidiMap and copies the mappings from specified Map.
        map - the map whose mappings are to be placed in this map
      • DualTreeBidiMap

        public DualTreeBidiMap​(java.util.Comparator<? super K> keyComparator,
                               java.util.Comparator<? super V> valueComparator)
        Constructs a DualTreeBidiMap using the specified Comparator.
        keyComparator - the comparator
        valueComparator - the values comparator to use
    • Method Detail

      • comparator

        public java.util.Comparator<? super K> comparator()
        Specified by:
        comparator in interface java.util.SortedMap<K,​V>
      • valueComparator

        public java.util.Comparator<? super V> valueComparator()
        Description copied from interface: SortedBidiMap
        Get the comparator used for the values in the value-to-key map aspect.
        Specified by:
        valueComparator in interface SortedBidiMap<K,​V>
        Comparator<? super V>
      • firstKey

        public K firstKey()
        Description copied from interface: OrderedMap
        Gets the first key currently in this map.
        Specified by:
        firstKey in interface OrderedMap<K,​V>
        Specified by:
        firstKey in interface java.util.SortedMap<K,​V>
        the first key currently in this map
      • lastKey

        public K lastKey()
        Description copied from interface: OrderedMap
        Gets the last key currently in this map.
        Specified by:
        lastKey in interface OrderedMap<K,​V>
        Specified by:
        lastKey in interface java.util.SortedMap<K,​V>
        the last key currently in this map
      • nextKey

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

        public K previousKey​(K key)
        Description copied from interface: OrderedMap
        Gets the previous key before the one specified.
        Specified by:
        previousKey in interface OrderedMap<K,​V>
        key - the key to search for previous from
        the previous key, null if no match or at start
      • inverseSortedBidiMap

        public SortedBidiMap<V,​K> inverseSortedBidiMap()
      • headMap

        public java.util.SortedMap<K,​V> headMap​(K toKey)
        Specified by:
        headMap in interface java.util.SortedMap<K,​V>
      • tailMap

        public java.util.SortedMap<K,​V> tailMap​(K fromKey)
        Specified by:
        tailMap in interface java.util.SortedMap<K,​V>
      • subMap

        public java.util.SortedMap<K,​V> subMap​(K fromKey,
                                                     K toKey)
        Specified by:
        subMap in interface java.util.SortedMap<K,​V>
      • inverseBidiMap

        public SortedBidiMap<V,​K> inverseBidiMap()
        Description copied from interface: BidiMap
        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 as a Map.

        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:
        inverseBidiMap in interface BidiMap<K,​V>
        Specified by:
        inverseBidiMap in interface OrderedBidiMap<K,​V>
        Specified by:
        inverseBidiMap in interface SortedBidiMap<K,​V>
        inverseBidiMap in class AbstractDualBidiMap<K,​V>
        an inverted bidirectional map