Class TreeMultiMap<K,V>

java.lang.Object
com.github.tadukoo.util.map.MultiMap<K,V>
com.github.tadukoo.util.map.TreeMultiMap<K,V>

public class TreeMultiMap<K,V> extends MultiMap<K,V>
A MultiMap class that uses TreeMap as the backing Map class.
Since:
Alpha v.0.1
Version:
Alpha v.0.2
Author:
Logan Ferree (Tadukoo)
  • Constructor Details

    • TreeMultiMap

      public TreeMultiMap()
      Creates a new TreeMultiMap where the backing TreeMap uses the natural ordering of its keys.
    • TreeMultiMap

      public TreeMultiMap(Comparator<? super K> comparator)
      Creates a new TreeMultiMap where the backing TreeMap uses the given Comparator to determine the ordering of its keys.
      Parameters:
      comparator - The Comparator to use in ordering the keys
    • TreeMultiMap

      @SafeVarargs public TreeMultiMap(Pair<K,V>... entries)
      Creates a new TreeMultiMap where the given Pairs are loaded into the map right away.
      Parameters:
      entries - The Pairs to be placed in this MultiMap
    • TreeMultiMap

      public TreeMultiMap(Map<K,V> map)
      Creates a new TreeMultiMap where the backing TreeMap is constructed with the same mappings as the specified Map. The backing TreeMap uses the natural ordering of its keys.
      Parameters:
      map - The Map whose mappings are to be placed in the backing TreeMap
    • TreeMultiMap

      public TreeMultiMap(SortedMap<K,V> map)
      Creates a new TreeMultiMap where the backing TreeMap is constructed with the same mappings as the specified SortedMap. The backing TreeMap also uses the Comparator used by the given SortedMap.
      Parameters:
      map - The SortedMap whose mappings are to be placed in the backing TreeMap
    • TreeMultiMap

      public TreeMultiMap(MultiMap<K,V> multiMap)
      Creates a new TreeMultiMap where the backing TreeMap uses the given Comparator to determine the ordering of its keys.
      The MultiMap is then populated with the values present in the specified MultiMap.
      Parameters:
      multiMap - The MultiMap whose mappings are to be placed in this MultiMap
    • TreeMultiMap

      public TreeMultiMap(TreeMultiMap<K,V> treeMultiMap)
      Creates a new TreeMultiMap where the backing TreeMap uses the Comparator present in the given TreeMultiMap to determine the ordering of its keys.
      The MultiMap is then populated with the values present in the specified TreeMultiMap.
      Parameters:
      treeMultiMap - The TreeMultiMap whose mappings are to be placed in this MultiMap
  • Method Details

    • asMap

      public TreeMap<K,List<V>> asMap()
      Returns the underlying TreeMap of this TreeMultiMap.
      Overrides:
      asMap in class MultiMap<K,V>
      Returns:
      The underlying TreeMap
    • comparator

      public Comparator<? super K> comparator()
      Returns:
      The Comparator used by this TreeMultiMap
    • firstKey

      public K firstKey()
      Returns:
      The first (lowest) key in this multiMap
    • lastKey

      public K lastKey()
      Returns:
      The last (highest) key in this multiMap
    • firstEntry

      public Map.Entry<K,List<V>> firstEntry()
      Returns:
      A key-value mapping associated with the least key in this multiMap, or null if the multiMap is empty
    • lastEntry

      public Map.Entry<K,List<V>> lastEntry()
      Returns:
      A key-value mapping associated with the greatest key in this map, or null if the multiMap is empty
    • pollFirstEntry

      public Map.Entry<K,List<V>> pollFirstEntry()
      Removes and returns a key-value mapping associated with the least key in this multiMap, or null if the multiMap is empty.
      Returns:
      The removed first entry of this multiMap, or null if it's empty
    • pollLastEntry

      public Map.Entry<K,List<V>> pollLastEntry()
      Removes and returns a key-value mapping associated with the greatest key in this multiMap, or null if the multiMap is empty.
      Returns:
      The removed last entry of this multiMap, or null if it's empty
    • lowerKey

      public K lowerKey(K key)
      Returns the greatest key strictly less than the given key, or null if there is no such key.
      Parameters:
      key - The key
      Returns:
      The greatest key less than key, or null if there is no such key
    • higherKey

      public K higherKey(K key)
      Returns the least key strictly greater than the given key, or null if there is no such key.
      Parameters:
      key - The key
      Returns:
      The least key greater than key, or null if there is no such key
    • lowerEntry

      public Map.Entry<K,List<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.
      Parameters:
      key - The key
      Returns:
      An entry with the greatest key less than key, or null if there is no such key
    • higherEntry

      public Map.Entry<K,List<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.
      Parameters:
      key - The key
      Returns:
      An entry with the least key greater than key, or null if there is no such key
    • floorKey

      public K floorKey(K key)
      Returns the greatest key less than or equal to the given key, or null if there is no such key.
      Parameters:
      key - The key
      Returns:
      The greatest key less than or equal to key, or null if there is no such key
    • ceilingKey

      public K ceilingKey(K key)
      Returns the least key greater than or equal to the given key, or null if there is no such key.
      Parameters:
      key - The key
      Returns:
      The least key greater than or equal to key, or null if there is no such key
    • floorEntry

      public Map.Entry<K,List<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.
      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
    • ceilingEntry

      public Map.Entry<K,List<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.
      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
    • descendingKeySet

      public NavigableSet<K> descendingKeySet()
      Returns:
      A reverse order navigable set view of the keys in this multiMap
      See Also:
    • descendingMap

      public NavigableMap<K,List<V>> descendingMap()
      Returns:
      A reverse order view of this multiMap
      See Also:
    • subMap

      public SortedMap<K,List<V>> subMap(K fromKey, K toKey)
      Parameters:
      fromKey - low end point (inclusive) of the keys in the returned map
      toKey - high end point (exclusive) of the keys in the returned map
      Returns:
      A view of the portion of this multiMap whose keys range from fromKey, inclusive, to toKey, exclusive
      See Also:
    • subMap

      public NavigableMap<K,List<V>> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
      Parameters:
      fromKey - low end point of the keys in the returned map
      fromInclusive - true if the low end point is to be included in the returned view
      toKey - high end point of the keys in the returned map
      toInclusive - true if the high end point is to be included in the returned view
      Returns:
      A view of the portion of this map whose keys range from fromKey to toKey
      See Also:
    • headMap

      public SortedMap<K,List<V>> headMap(K toKey)
      Parameters:
      toKey - high end point (exclusive) of the keys in the returned map
      Returns:
      A view of the portion of this multiMap whose keys are strictly less than toKey
      See Also:
    • headMap

      public NavigableMap<K,List<V>> headMap(K toKey, boolean inclusive)
      Parameters:
      toKey - high end point of the keys in the returned map
      inclusive - true if the high end point is to be included in the returned view
      Returns:
      A view of the portion of this multiMap whose keys are less than (or equal to, if inclusive is true) toKey
      See Also:
    • tailMap

      public SortedMap<K,List<V>> tailMap(K fromKey)
      Parameters:
      fromKey - low end point (inclusive) of the keys in the returned map
      Returns:
      A view of the portion of this multiMap whose keys are greater than or equal to fromKey
      See Also:
    • tailMap

      public NavigableMap<K,List<V>> tailMap(K fromKey, boolean inclusive)
      Parameters:
      fromKey - low end point of the keys in the returned map
      inclusive - true if the low end point is to be included in the returned view
      Returns:
      A view of the portion of this multiMap whose keys are greater than (or equal to, if inclusive is true) fromKey
      See Also: