Class ForwardingNavigableMap<K,V>

  • All Implemented Interfaces:
    Map<K,V>, NavigableMap<K,V>, SortedMap<K,V>

    @GwtIncompatible
    public abstract class ForwardingNavigableMap<K,V>
    extends ForwardingSortedMap<K,V>
    implements NavigableMap<K,V>
    A navigable map which forwards all its method calls to another navigable map. Subclasses should override one or more methods to modify the behavior of the backing map as desired per the decorator pattern.

    Warning: The methods of ForwardingNavigableMap forward indiscriminately to the methods of the delegate. For example, overriding ForwardingMap.put(K, V) alone will not change the behavior of ForwardingMap.putAll(java.util.Map<? extends K, ? extends V>), which can lead to unexpected behavior. In this case, you should override putAll as well, either providing your own implementation, or delegating to the provided standardPutAll method.

    default method warning: This class does not forward calls to default methods. Instead, it inherits their default implementations. When those implementations invoke methods, they invoke methods on the ForwardingNavigableMap.

    Each of the standard methods uses the map's comparator (or the natural ordering of the elements, if there is no comparator) to test element equality. As a result, if the comparator is not consistent with equals, some of the standard implementations may violate the Map contract.

    The standard methods and the collection views they return are not guaranteed to be thread-safe, even when all of the methods that they depend on are thread-safe.

    Since:
    12.0
    Author:
    Louis Wasserman
    • Method Detail

      • delegate

        protected abstract NavigableMap<K,Vdelegate()
        Description copied from class: ForwardingObject
        Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.
        Specified by:
        delegate in class ForwardingSortedMap<K,V>
      • lowerEntry

        public Map.Entry<K,VlowerEntry(K key)
        Description copied from interface: java.util.NavigableMap
        Returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key.
        Specified by:
        lowerEntry in interface NavigableMap<K,V>
        Parameters:
        key - the key
        Returns:
        an entry with the greatest key less than key, or null if there is no such key
      • lowerKey

        public K lowerKey(K key)
        Description copied from interface: java.util.NavigableMap
        Returns the greatest key strictly less than the given key, or null if there is no such key.
        Specified by:
        lowerKey in interface NavigableMap<K,V>
        Parameters:
        key - the key
        Returns:
        the greatest key less than key, or null if there is no such key
      • standardLowerKey

        protected K standardLowerKey(K key)
        A sensible definition of lowerKey(K) in terms of lowerEntry. If you override lowerEntry(K), you may wish to override lowerKey to forward to this implementation.
      • floorEntry

        public Map.Entry<K,VfloorEntry(K key)
        Description copied from interface: java.util.NavigableMap
        Returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key.
        Specified by:
        floorEntry in interface NavigableMap<K,V>
        Parameters:
        key - the key
        Returns:
        an entry with the greatest key less than or equal to key, or null if there is no such key
      • floorKey

        public K floorKey(K key)
        Description copied from interface: java.util.NavigableMap
        Returns the greatest key less than or equal to the given key, or null if there is no such key.
        Specified by:
        floorKey in interface NavigableMap<K,V>
        Parameters:
        key - the key
        Returns:
        the greatest key less than or equal to key, or null if there is no such key
      • standardFloorKey

        protected K standardFloorKey(K key)
        A sensible definition of floorKey(K) in terms of floorEntry. If you override floorEntry, you may wish to override floorKey to forward to this implementation.
      • ceilingEntry

        public Map.Entry<K,VceilingEntry(K key)
        Description copied from interface: java.util.NavigableMap
        Returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such key.
        Specified by:
        ceilingEntry in interface NavigableMap<K,V>
        Parameters:
        key - the key
        Returns:
        an entry with the least key greater than or equal to key, or null if there is no such key
      • ceilingKey

        public K ceilingKey(K key)
        Description copied from interface: java.util.NavigableMap
        Returns the least key greater than or equal to the given key, or null if there is no such key.
        Specified by:
        ceilingKey in interface NavigableMap<K,V>
        Parameters:
        key - the key
        Returns:
        the least key greater than or equal to key, or null if there is no such key
      • standardCeilingKey

        protected K standardCeilingKey(K key)
        A sensible definition of ceilingKey(K) in terms of ceilingEntry. If you override ceilingEntry, you may wish to override ceilingKey to forward to this implementation.
      • higherEntry

        public Map.Entry<K,VhigherEntry(K key)
        Description copied from interface: java.util.NavigableMap
        Returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key.
        Specified by:
        higherEntry in interface NavigableMap<K,V>
        Parameters:
        key - the key
        Returns:
        an entry with the least key greater than key, or null if there is no such key
      • higherKey

        public K higherKey(K key)
        Description copied from interface: java.util.NavigableMap
        Returns the least key strictly greater than the given key, or null if there is no such key.
        Specified by:
        higherKey in interface NavigableMap<K,V>
        Parameters:
        key - the key
        Returns:
        the least key greater than key, or null if there is no such key
      • standardHigherKey

        protected K standardHigherKey(K key)
        A sensible definition of higherKey(K) in terms of higherEntry. If you override higherEntry, you may wish to override higherKey to forward to this implementation.
      • lastEntry

        public Map.Entry<K,VlastEntry()
        Description copied from interface: java.util.NavigableMap
        Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.
        Specified by:
        lastEntry in interface NavigableMap<K,V>
        Returns:
        an entry with the greatest key, or null if this map is empty
      • standardPollFirstEntry

        protected Map.Entry<K,VstandardPollFirstEntry()
        A sensible definition of pollFirstEntry() in terms of the iterator of entrySet. If you override entrySet, you may wish to override pollFirstEntry to forward to this implementation.
      • standardPollLastEntry

        protected Map.Entry<K,VstandardPollLastEntry()
        A sensible definition of pollFirstEntry() in terms of the iterator of the entrySet of descendingMap. If you override descendingMap, you may wish to override pollFirstEntry to forward to this implementation.
      • descendingMap

        public NavigableMap<K,VdescendingMap()
        Description copied from interface: java.util.NavigableMap
        Returns a reverse order view of the mappings contained in this map. The descending map is backed by this map, so changes to the map are reflected in the descending map, and vice-versa. If either map is modified while an iteration over a collection view of either map is in progress (except through the iterator's own remove operation), the results of the iteration are undefined.

        The returned map has an ordering equivalent to Collections.reverseOrder(comparator()). The expression m.descendingMap().descendingMap() returns a view of m essentially equivalent to m.

        Specified by:
        descendingMap in interface NavigableMap<K,V>
        Returns:
        a reverse order view of this map
      • navigableKeySet

        public NavigableSet<KnavigableKeySet()
        Description copied from interface: java.util.NavigableMap
        Returns a NavigableSet view of the keys contained in this map. The set's iterator returns the keys in ascending order. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
        Specified by:
        navigableKeySet in interface NavigableMap<K,V>
        Returns:
        a navigable set view of the keys in this map
      • descendingKeySet

        public NavigableSet<KdescendingKeySet()
        Description copied from interface: java.util.NavigableMap
        Returns a reverse order NavigableSet view of the keys contained in this map. The set's iterator returns the keys in descending order. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
        Specified by:
        descendingKeySet in interface NavigableMap<K,V>
        Returns:
        a reverse order navigable set view of the keys in this map
      • subMap

        public NavigableMap<K,VsubMap(K fromKey,
                                              boolean fromInclusive,
                                              K toKey,
                                              boolean toInclusive)
        Description copied from interface: java.util.NavigableMap
        Returns a view of the portion of this map whose keys range from fromKey to toKey. If fromKey and toKey are equal, the returned map is empty unless fromInclusive and toInclusive are both true. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

        The returned map will throw an IllegalArgumentException on an attempt to insert a key outside of its range, or to construct a submap either of whose endpoints lie outside its range.

        Specified by:
        subMap in interface NavigableMap<K,V>
        Parameters:
        fromKey - low endpoint of the keys in the returned map
        fromInclusive - true if the low endpoint is to be included in the returned view
        toKey - high endpoint of the keys in the returned map
        toInclusive - true if the high endpoint is to be included in the returned view
        Returns:
        a view of the portion of this map whose keys range from fromKey to toKey
      • headMap

        public NavigableMap<K,VheadMap(K toKey,
                                               boolean inclusive)
        Description copied from interface: java.util.NavigableMap
        Returns a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

        The returned map will throw an IllegalArgumentException on an attempt to insert a key outside its range.

        Specified by:
        headMap in interface NavigableMap<K,V>
        Parameters:
        toKey - high endpoint of the keys in the returned map
        inclusive - true if the high endpoint is to be included in the returned view
        Returns:
        a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey
      • tailMap

        public NavigableMap<K,VtailMap(K fromKey,
                                               boolean inclusive)
        Description copied from interface: java.util.NavigableMap
        Returns a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

        The returned map will throw an IllegalArgumentException on an attempt to insert a key outside its range.

        Specified by:
        tailMap in interface NavigableMap<K,V>
        Parameters:
        fromKey - low endpoint of the keys in the returned map
        inclusive - true if the low endpoint is to be included in the returned view
        Returns:
        a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey