Interface RangeMap<K extends Comparable<? super K>,​V>

  • Type Parameters:
    K - the type of keys in this tree
    V - the type of values in this tree
    All Known Implementing Classes:
    LLRBRangeTree, SynchronizedRangeMap

    public interface RangeMap<K extends Comparable<? super K>,​V>
    An object that maps ranges of keys to values. Cannot contain duplicate keys or overlapping ranges.

    The interface offers a subset of the operations of Map with the write operations having instead two keys denoting the inclusive upper and lower bounds of a range.

    See Also:
    Map, Range tree
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void clear()
      Removes all mappings from this object.
      V computeIfAbsent​(K key, Function<? super K,​Map.Entry<Range<? extends K>,​? extends V>> mappingFunction)
      Looks up a value associated with a key.
      V get​(K key)
      Returns the value associated with a key.
      void put​(K low, K high, V value)
      Associates a range of keys with a value.
      V putIfAbsent​(K low, K high, V value)
      Associates a range of keys with a value only if no existing mapping exists.
    • Method Detail

      • clear

        void clear()
        Removes all mappings from this object.
        See Also:
        Map.clear()
      • get

        V get​(K key)
        Returns the value associated with a key.
        Parameters:
        key - the key for which to look up a value, not null
        Returns:
        the value associated with key or null if not found
        Throws:
        NullPointerException - if key is null
        See Also:
        Map.get(Object)
      • computeIfAbsent

        V computeIfAbsent​(K key,
                          Function<? super K,​Map.Entry<Range<? extends K>,​? extends V>> mappingFunction)
        Looks up a value associated with a key. If none is found the mapping function is applied. If the mapping produces a not null value then the mapping is created.
        Parameters:
        key - the key for which to look up a value, not null
        mappingFunction - the mapping function to apply if no value has been found, not null
        Returns:
        the value associated with key or null if not found
        Throws:
        NullPointerException - if key is null
        NullPointerException - if key is mappingFunction
        See Also:
        Map.computeIfAbsent(Object, Function), AbstractMap.SimpleImmutableEntry
      • put

        void put​(K low,
                 K high,
                 V value)
        Associates a range of keys with a value.
        Parameters:
        low - the lower end of the range, inclusive, not null
        high - the upper end of the range, inclusive, not null
        value - the value to associate, possibly null
        Throws:
        IllegalArgumentException - if a mapping for a part or the whole range already exists
        IllegalArgumentException - if low is not less than high
        NullPointerException - if low or high are null
        See Also:
        Map.put(Object, Object)
      • putIfAbsent

        V putIfAbsent​(K low,
                      K high,
                      V value)
        Associates a range of keys with a value only if no existing mapping exists.
        Parameters:
        low - the lower end of the range, inclusive, not null
        high - the upper end of the range, inclusive, not null
        value - the value to associate, possibly null
        Returns:
        the value mapped to the key range before this method was called
        Throws:
        IllegalArgumentException - if low is not less than high
        NullPointerException - if low or high are null
        See Also:
        Map.putIfAbsent(Object, Object)