Class IntervalTree<K,​V>

  • Type Parameters:
    K - the key type
    V - the value type
    All Implemented Interfaces:
    IntervalMap<K,​V>

    public class IntervalTree<K,​V>
    extends Object
    implements IntervalMap<K,​V>
    Tree implementation of IntervalMap.
    • Constructor Detail

      • IntervalTree

        public IntervalTree​(Comparator<? super K> comparator)
        Creates a new IntervalTree.
        Parameters:
        comparator - the comparator to compare keys
      • IntervalTree

        public IntervalTree()
        Creates a new IntervalTree that uses the natural order of the keys.
    • Method Detail

      • add

        public void add​(K min,
                        K max,
                        V value)
                 throws IllegalArgumentException
        Adds a new element to the interval tree
        Parameters:
        min - the lower bound of the interval
        max - the upper bound of the interval
        value - the associated value
        Throws:
        IllegalArgumentException - if min > max
      • add

        public void add​(K key,
                        V value)
        Adds a new element to the interval tree
        Parameters:
        key - the lower and upper bound of the interval
        value - the associated value
      • search

        public Set<V> search​(K lower,
                             K upper)
        Description copied from interface: IntervalMap
        Get all values falling into the specified interval.
        Specified by:
        search in interface IntervalMap<K,​V>
        Parameters:
        lower - the upper bound
        upper - the lower bound
        Returns:
        the values
      • get

        public Optional<V> get​(K lower,
                               K upper)
        Description copied from interface: IntervalMap
        Get the first value falling into the interval.
        Specified by:
        get in interface IntervalMap<K,​V>
        Parameters:
        lower - the lower bound
        upper - the upper bound
        Returns:
        the value