Class TrackingMap<K,V>

java.lang.Object
com.cedarsoftware.util.TrackingMap<K,V>
Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
All Implemented Interfaces:
Map<K,V>

public class TrackingMap<K,V> extends Object implements Map<K,V>
A wrapper around a Map that tracks which keys have been accessed via get or containsKey methods. This is useful for scenarios where it's necessary to monitor usage patterns of keys in a map, such as identifying unused entries or optimizing memory usage by expunging rarely accessed keys.

Usage Example:


 Map<String, Integer> originalMap = new HashMap<>();
 originalMap.put("apple", 1);
 originalMap.put("banana", 2);
 originalMap.put("cherry", 3);

 TrackingMap<String, Integer> trackingMap = new TrackingMap<>(originalMap);

 // Access some keys
 trackingMap.get("apple");
 trackingMap.containsKey("banana");

 // Expunge unused keys
 trackingMap.expungeUnused();

 // Now, "cherry" has been removed as it was not accessed
 LOG.info(trackingMap.keySet()); // Outputs: [apple, banana]
 

Thread Safety: This class is thread-safe when wrapping concurrent map implementations (ConcurrentMap, ConcurrentNavigableMap). The thread safety is provided by using a concurrent tracking set and delegating all operations to the underlying concurrent map. When wrapping non-concurrent maps, external synchronization is required.

Concurrent Operations: When wrapping a ConcurrentMap or ConcurrentNavigableMap, this class provides additional methods that leverage the concurrent semantics of the backing map: putIfAbsent(), replace(), compute*(), merge(), and navigation methods. These operations maintain both the concurrent guarantees and the access tracking functionality.

Note: The expungeUnused() method removes all entries that have not been accessed via get(Object) or containsKey(Object) since the map was created or since the last call to expungeUnused().

Author:
Sean Kellner - original version John DeRegnaucourt - correct ConcurrentMap and ConcurrentNavigableMap support when wrapped.
Copyright (c) Cedar Software LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

License

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  • Nested Class Summary

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

    Map.Entry<K extends Object,V extends Object>
  • Constructor Summary

    Constructors
    Constructor
    Description
    Wraps the provided Map with a TrackingMap.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    Returns the least key greater than or equal to the given key, or null if no such key.
    void
    Removes all the mappings from this map.
    Comparator<? super K>
    Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.
    compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
    Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).
    computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
    If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unless null.
    computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
    If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.
    boolean
    Returns true if this map contains a mapping for the specified key.
    boolean
    Returns true if this map maps one or more keys to the specified value.
    Returns a reverse order NavigableSet view of the keys contained in this map.
     
    boolean
    equals(Object other)
    Compares the specified object with this map for equality.
    void
    Remove the entries from the Map that have not been accessed by .get() or .containsKey().
    Returns a key-value mapping associated with the least key in this map, or null if the map is empty.
    Returns the first (lowest) key currently in this map.
    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.
    floorKey(K key)
    Returns the greatest key less than or equal to the given key, or null if no such key.
    void
    forEach(BiConsumer<? super K,? super V> action)
    Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.
    get(Object key)
    Retrieves the value associated with the specified key and marks the key as accessed.
    getOrDefault(Object key, V defaultValue)
    Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
    Returns the underlying Map that this TrackingMap wraps.
    int
     
    headMap(K toKey)
    Returns a view of the portion of this map whose keys are strictly less than toKey.
    headMap(K toKey, boolean inclusive)
    Returns a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey.
    Returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key.
    higherKey(K key)
    Returns the least key strictly greater than the given key, or null if no such key.
    void
    Add the used keys from the passed in TrackingMap to this TrackingMap's keysUsed.
    void
    Adds the accessed keys from another TrackingMap to this map's set of accessed keys.
    boolean
     
     
    Returns an unmodifiable view of the keys that have been accessed via get() or containsKey().
    Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.
    Returns the last (highest) key currently in this map.
    Returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key.
    lowerKey(K key)
    Returns the greatest key strictly less than the given key, or null if no such key.
    merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
    If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value.
    Returns a NavigableSet view of the keys contained in this map.
    Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty.
    Removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.
    put(K key, V value)
    Associates the specified value with the specified key in this map.
    void
    putAll(Map<? extends K,? extends V> m)
    Copies all the mappings from the specified map to this map.
    putIfAbsent(K key, V value)
    If the specified key is not already associated with a value, associate it with the given value.
    Removes the mapping for a key from this map if it is present.
    boolean
    remove(Object key, Object value)
    Removes the entry for a key only if currently mapped to a given value.
    replace(K key, V value)
    Replaces the entry for a key only if currently mapped to some value.
    boolean
    replace(K key, V oldValue, V newValue)
    Replaces the entry for a key only if currently mapped to a given value.
    void
    replaceAll(BiFunction<? super K,? super V,? extends V> function)
    Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.
    void
    Replace all contents of the wrapped map with those from the provided map.
    void
    Deprecated.
    int
     
    subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
    Returns a view of the portion of this map whose keys range from fromKey to toKey.
    subMap(K fromKey, K toKey)
    Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive.
    tailMap(K fromKey)
    Returns a view of the portion of this map whose keys are greater than or equal to fromKey.
    tailMap(K fromKey, boolean inclusive)
    Returns a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey.
     
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • TrackingMap

      public TrackingMap(Map<K,V> map)
      Wraps the provided Map with a TrackingMap.
      Parameters:
      map - the Map to be wrapped and tracked
      Throws:
      IllegalArgumentException - if the provided map is null
  • Method Details

    • get

      public V get(Object key)
      Retrieves the value associated with the specified key and marks the key as accessed.
      Specified by:
      get in interface Map<K,V>
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value associated with the specified key, or null if no mapping exists
    • put

      public V put(K key, V value)
      Associates the specified value with the specified key in this map.
      Specified by:
      put in interface Map<K,V>
      Parameters:
      key - key with which the specified value is to be associated
      value - value to be associated with the specified key
      Returns:
      the previous value associated with key, or null if there was no mapping
    • containsKey

      public boolean containsKey(Object key)
      Returns true if this map contains a mapping for the specified key. Marks the key as accessed.
      Specified by:
      containsKey in interface Map<K,V>
      Parameters:
      key - key whose presence in this map is to be tested
      Returns:
      true if this map contains a mapping for the specified key
    • putAll

      public void putAll(Map<? extends K,? extends V> m)
      Copies all the mappings from the specified map to this map.
      Specified by:
      putAll in interface Map<K,V>
      Parameters:
      m - mappings to be stored in this map
      Throws:
      NullPointerException - if the specified map is null
    • remove

      public V remove(Object key)
      Removes the mapping for a key from this map if it is present. Also removes the key from the set of accessed keys.
      Specified by:
      remove in interface Map<K,V>
      Parameters:
      key - key whose mapping is to be removed from the map
      Returns:
      the previous value associated with key, or null if there was no mapping
    • size

      public int size()
      Specified by:
      size in interface Map<K,V>
      Returns:
      the number of key-value mappings in this map
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
      Returns:
      true if this map contains no key-value mappings
    • equals

      public boolean equals(Object other)
      Compares the specified object with this map for equality.
      Specified by:
      equals in interface Map<K,V>
      Overrides:
      equals in class Object
      Parameters:
      other - object to be compared for equality with this map
      Returns:
      true if the specified object is equal to this map
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<K,V>
      Overrides:
      hashCode in class Object
      Returns:
      the hash code value for this map
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      a string representation of this map
    • clear

      public void clear()
      Removes all the mappings from this map. The map will be empty after this call returns. Also clears the set of accessed keys.
      Specified by:
      clear in interface Map<K,V>
    • containsValue

      public boolean containsValue(Object value)
      Returns true if this map maps one or more keys to the specified value.
      Specified by:
      containsValue in interface Map<K,V>
      Parameters:
      value - value whose presence in this map is to be tested
      Returns:
      true if this map maps one or more keys to the specified value
    • values

      public Collection<V> values()
      Specified by:
      values in interface Map<K,V>
      Returns:
      a Collection view of the values contained in this map
    • keySet

      public Set<K> keySet()
      Specified by:
      keySet in interface Map<K,V>
      Returns:
      a Set view of the keys contained in this map
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      Specified by:
      entrySet in interface Map<K,V>
      Returns:
      a Set view of the mappings contained in this map
    • expungeUnused

      public void expungeUnused()
      Remove the entries from the Map that have not been accessed by .get() or .containsKey().
    • informAdditionalUsage

      public void informAdditionalUsage(Collection<K> additional)
      Adds the accessed keys from another TrackingMap to this map's set of accessed keys. This can be useful when merging usage information from multiple tracking maps.
      Parameters:
      additional - another TrackingMap whose accessed keys are to be added
    • informAdditionalUsage

      public void informAdditionalUsage(TrackingMap<K,V> additional)
      Add the used keys from the passed in TrackingMap to this TrackingMap's keysUsed. This can cause the readKeys to include entries that are not in wrapped Maps keys.
      Parameters:
      additional - TrackingMap whose used keys are to be added to this map's used keys.
    • keysUsed

      public Set<Object> keysUsed()
      Returns an unmodifiable view of the keys that have been accessed via get() or containsKey().

      The returned set may contain objects that are not of type K if callers queried the map using keys of a different type.

      Returns:
      unmodifiable set of accessed keys
    • getWrappedMap

      public Map<K,V> getWrappedMap()
      Returns the underlying Map that this TrackingMap wraps.
      Returns:
      the wrapped Map
    • replaceContents

      public void replaceContents(Map<K,V> map)
      Replace all contents of the wrapped map with those from the provided map. The underlying map instance remains the same.
      Parameters:
      map - map providing new contents; must not be null
    • setWrappedMap

      @Deprecated public void setWrappedMap(Map<K,V> map)
      Deprecated.
      Use replaceContents(Map) instead. This method merely replaces the contents of the wrapped map and does not change the underlying instance.
    • putIfAbsent

      public V putIfAbsent(K key, V value)
      If the specified key is not already associated with a value, associate it with the given value.

      Does not mark the key as accessed since this is a write operation. Available when the backing map is a ConcurrentMap.

      Specified by:
      putIfAbsent in interface Map<K,V>
      Parameters:
      key - key with which the specified value is to be associated
      value - value to be associated with the specified key
      Returns:
      the previous value associated with the specified key, or null if there was no mapping for the key
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support ConcurrentMap operations
    • remove

      public boolean remove(Object key, Object value)
      Removes the entry for a key only if currently mapped to a given value. Also removes the key from the set of accessed keys if removal succeeds. Available when the backing map is a ConcurrentMap.
      Specified by:
      remove in interface Map<K,V>
      Parameters:
      key - key with which the specified value is associated
      value - value expected to be associated with the specified key
      Returns:
      true if the value was removed
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support ConcurrentMap operations
    • replace

      public boolean replace(K key, V oldValue, V newValue)
      Replaces the entry for a key only if currently mapped to a given value. Available when the backing map is a ConcurrentMap.
      Specified by:
      replace in interface Map<K,V>
      Parameters:
      key - key with which the specified value is associated
      oldValue - value expected to be associated with the specified key
      newValue - value to be associated with the specified key
      Returns:
      true if the value was replaced
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support ConcurrentMap operations
    • replace

      public V replace(K key, V value)
      Replaces the entry for a key only if currently mapped to some value. Available when the backing map is a ConcurrentMap.
      Specified by:
      replace in interface Map<K,V>
      Parameters:
      key - key with which the specified value is associated
      value - value to be associated with the specified key
      Returns:
      the previous value associated with the specified key, or null if there was no mapping for the key
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support ConcurrentMap operations
    • computeIfAbsent

      public V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
      If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unless null. Marks the key as accessed since this involves reading the current value.
      Specified by:
      computeIfAbsent in interface Map<K,V>
      Parameters:
      key - key with which the specified value is to be associated
      mappingFunction - the function to compute a value
      Returns:
      the current (existing or computed) value associated with the specified key, or null if the computed value is null
    • computeIfPresent

      public V computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
      If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value. Marks the key as accessed since this involves reading the current value.
      Specified by:
      computeIfPresent in interface Map<K,V>
      Parameters:
      key - key with which the specified value is to be associated
      remappingFunction - the function to compute a value
      Returns:
      the new value associated with the specified key, or null if none
    • compute

      public V compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
      Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping). Marks the key as accessed since this involves reading the current value.
      Specified by:
      compute in interface Map<K,V>
      Parameters:
      key - key with which the specified value is to be associated
      remappingFunction - the function to compute a value
      Returns:
      the new value associated with the specified key, or null if none
    • merge

      public V merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
      If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is null. Marks the key as accessed since this involves reading the current value.
      Specified by:
      merge in interface Map<K,V>
      Parameters:
      key - key with which the resulting value is to be associated
      value - the non-null value to be merged with the existing value
      remappingFunction - the function to recompute a value if present
      Returns:
      the new value associated with the specified key, or null if no value is associated with the key
    • getOrDefault

      public V getOrDefault(Object key, V defaultValue)
      Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key. Marks the key as accessed.
      Specified by:
      getOrDefault in interface Map<K,V>
      Parameters:
      key - the key whose associated value is to be returned
      defaultValue - the default mapping of the key
      Returns:
      the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key
    • forEach

      public void forEach(BiConsumer<? super K,? super V> action)
      Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.
      Specified by:
      forEach in interface Map<K,V>
      Parameters:
      action - The action to be performed for each entry
    • replaceAll

      public void replaceAll(BiFunction<? super K,? super V,? extends V> function)
      Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.
      Specified by:
      replaceAll in interface Map<K,V>
      Parameters:
      function - the function to apply to each entry
    • lowerEntry

      public Map.Entry<K,V> lowerEntry(K key)
      Returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key. Marks the returned key as accessed if present. Available when the backing map is a NavigableMap.
      Parameters:
      key - the key
      Returns:
      an entry with the greatest key less than key, or null if no such key
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • lowerKey

      public K lowerKey(K key)
      Returns the greatest key strictly less than the given key, or null if no such key. Marks the returned key as accessed if present. Available when the backing map is a NavigableMap.
      Parameters:
      key - the key
      Returns:
      the greatest key less than key, or null if no such key
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • floorEntry

      public Map.Entry<K,V> floorEntry(K key)
      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. Marks the returned key as accessed if present. Available when the backing map is a NavigableMap.
      Parameters:
      key - the key
      Returns:
      an entry with the greatest key less than or equal to key, or null if no such key
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • floorKey

      public K floorKey(K key)
      Returns the greatest key less than or equal to the given key, or null if no such key. Marks the returned key as accessed if present. Available when the backing map is a NavigableMap.
      Parameters:
      key - the key
      Returns:
      the greatest key less than or equal to key, or null if no such key
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • ceilingEntry

      public Map.Entry<K,V> ceilingEntry(K key)
      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. Marks the returned key as accessed if present. Available when the backing map is a NavigableMap.
      Parameters:
      key - the key
      Returns:
      an entry with the least key greater than or equal to key, or null if no such key
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • ceilingKey

      public K ceilingKey(K key)
      Returns the least key greater than or equal to the given key, or null if no such key. Marks the returned key as accessed if present. Available when the backing map is a NavigableMap.
      Parameters:
      key - the key
      Returns:
      the least key greater than or equal to key, or null if no such key
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • higherEntry

      public Map.Entry<K,V> higherEntry(K key)
      Returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key. Marks the returned key as accessed if present. Available when the backing map is a NavigableMap.
      Parameters:
      key - the key
      Returns:
      an entry with the least key greater than key, or null if no such key
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • higherKey

      public K higherKey(K key)
      Returns the least key strictly greater than the given key, or null if no such key. Marks the returned key as accessed if present. Available when the backing map is a NavigableMap.
      Parameters:
      key - the key
      Returns:
      the least key greater than key, or null if no such key
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • firstEntry

      public Map.Entry<K,V> firstEntry()
      Returns a key-value mapping associated with the least key in this map, or null if the map is empty. Marks the returned key as accessed if present. Available when the backing map is a NavigableMap.
      Returns:
      an entry with the least key, or null if this map is empty
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • lastEntry

      public Map.Entry<K,V> lastEntry()
      Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty. Marks the returned key as accessed if present. Available when the backing map is a NavigableMap.
      Returns:
      an entry with the greatest key, or null if this map is empty
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • pollFirstEntry

      public Map.Entry<K,V> pollFirstEntry()
      Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty. Removes the key from tracked keys if present. Available when the backing map is a NavigableMap.
      Returns:
      the removed first entry of this map, or null if this map is empty
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • pollLastEntry

      public Map.Entry<K,V> pollLastEntry()
      Removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty. Removes the key from tracked keys if present. Available when the backing map is a NavigableMap.
      Returns:
      the removed last entry of this map, or null if this map is empty
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • descendingKeySet

      public NavigableSet<K> descendingKeySet()
      Returns a reverse order NavigableSet view of the keys contained in this map. Available when the backing map is a NavigableMap.
      Returns:
      a reverse order navigable set view of the keys in this map
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • subMap

      public TrackingMap<K,V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
      Returns a view of the portion of this map whose keys range from fromKey to toKey. Available when the backing map is a ConcurrentNavigableMap.
      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
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support ConcurrentNavigableMap operations
    • headMap

      public TrackingMap<K,V> headMap(K toKey, boolean inclusive)
      Returns a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey. Available when the backing map is a NavigableMap.
      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 toKey
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • tailMap

      public TrackingMap<K,V> tailMap(K fromKey, boolean inclusive)
      Returns a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey. Available when the backing map is a NavigableMap.
      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 fromKey
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • comparator

      public Comparator<? super K> comparator()
      Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys. Available when the backing map is a SortedMap.
      Returns:
      the comparator used to order the keys in this map, or null
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support SortedMap operations
    • subMap

      public TrackingMap<K,V> subMap(K fromKey, K toKey)
      Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive. Available when the backing map is a NavigableMap.
      Parameters:
      fromKey - low endpoint (inclusive) of the keys in the returned map
      toKey - high endpoint (exclusive) of the keys in the returned map
      Returns:
      a view of the portion of this map whose keys range from fromKey to toKey
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • headMap

      public TrackingMap<K,V> headMap(K toKey)
      Returns a view of the portion of this map whose keys are strictly less than toKey. Available when the backing map is a NavigableMap.
      Parameters:
      toKey - high endpoint (exclusive) of the keys in the returned map
      Returns:
      a view of the portion of this map whose keys are less than toKey
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • tailMap

      public TrackingMap<K,V> tailMap(K fromKey)
      Returns a view of the portion of this map whose keys are greater than or equal to fromKey. Available when the backing map is a NavigableMap.
      Parameters:
      fromKey - low endpoint (inclusive) of the keys in the returned map
      Returns:
      a view of the portion of this map whose keys are greater than or equal to fromKey
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support NavigableMap operations
    • firstKey

      public K firstKey()
      Returns the first (lowest) key currently in this map. Marks the returned key as accessed. Available when the backing map is a SortedMap.
      Returns:
      the first (lowest) key currently in this map
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support SortedMap operations
    • lastKey

      public K lastKey()
      Returns the last (highest) key currently in this map. Marks the returned key as accessed. Available when the backing map is a SortedMap.
      Returns:
      the last (highest) key currently in this map
      Throws:
      UnsupportedOperationException - if the wrapped map doesn't support SortedMap operations