Interface SortedMap<K,V>

Type Parameters:
K - The key type (keys must be unique and comparable)
V - The value type
All Superinterfaces:
Map<K,V>
All Known Implementing Classes:
AbstractSortedMap, AVLTreeMap, RBTreeMap, SortedTableMap, SplayTreeMap, TreeMap

public interface SortedMap<K,V> extends Map<K,V>
A map with additional support for keys from a total ordering. The total ordering is the natural ordering of keys, by default, or it can be defined by providing an optional Comparator. All iterations will be in sorted order relative to the keys, and additional methods provide for non-exact searches. This interface is a simple variant that blends features of java.util.SortedMap and java.util.NavigableMap.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the entry with least key greater than or equal to given key (or null if no such key exists).
    Returns the entry having the least key (or null if map is empty).
    Returns the entry with greatest key less than or equal to given key (or null if no such key exists).
    Returns the entry with least key strictly greater than given key (or null if no such key exists).
    Returns the entry having the greatest key (or null if map is empty).
    Returns the entry with greatest key strictly less than given key (or null if no such key exists).
    subMap(K fromKey, K toKey)
    Returns an iterable containing all keys in the range from fromKey inclusive to toKey exclusive.

    Methods inherited from interface com.zybooks.dsaj.map.Map

    entrySet, get, isEmpty, keySet, put, remove, size, values
  • Method Details

    • firstEntry

      Entry<K,V> firstEntry()
      Returns the entry having the least key (or null if map is empty).
      Returns:
      entry with least key (or null if map is empty)
    • lastEntry

      Entry<K,V> lastEntry()
      Returns the entry having the greatest key (or null if map is empty).
      Returns:
      entry with greatest key (or null if map is empty)
    • ceilingEntry

      Entry<K,V> ceilingEntry(K key) throws IllegalArgumentException
      Returns the entry with least key greater than or equal to given key (or null if no such key exists).
      Parameters:
      key - the target key
      Returns:
      entry with least key greater than or equal to given (or null if no such entry)
      Throws:
      IllegalArgumentException - if the key is not compatible with the map
    • floorEntry

      Entry<K,V> floorEntry(K key) throws IllegalArgumentException
      Returns the entry with greatest key less than or equal to given key (or null if no such key exists).
      Parameters:
      key - the target key
      Returns:
      entry with greatest key less than or equal to given (or null if no such entry)
      Throws:
      IllegalArgumentException - if the key is not compatible with the map
    • lowerEntry

      Entry<K,V> lowerEntry(K key) throws IllegalArgumentException
      Returns the entry with greatest key strictly less than given key (or null if no such key exists).
      Parameters:
      key - the target key
      Returns:
      entry with greatest key strictly less than given (or null if no such entry)
      Throws:
      IllegalArgumentException - if the key is not compatible with the map
    • higherEntry

      Entry<K,V> higherEntry(K key) throws IllegalArgumentException
      Returns the entry with least key strictly greater than given key (or null if no such key exists).
      Parameters:
      key - the target key
      Returns:
      entry with least key strictly greater than given (or null if no such entry)
      Throws:
      IllegalArgumentException - if the key is not compatible with the map
    • subMap

      Iterable<Entry<K,V>> subMap(K fromKey, K toKey) throws IllegalArgumentException
      Returns an iterable containing all keys in the range from fromKey inclusive to toKey exclusive.
      Parameters:
      fromKey - the lowest key allowed in the desired range
      toKey - the highest key allowed in the desired range
      Returns:
      iterable with keys in desired range
      Throws:
      IllegalArgumentException - if fromKey or toKey is not compatible with the map