Class AbstractSortedMap<K,V>

  • All Implemented Interfaces:
    Map<K,V>
    Direct Known Subclasses:
    SortedTableMap, TreeMap


    public abstract class AbstractSortedMap<K,V>
    extends AbstractMap<K,V>
    An abstract base class to ease the implementation of the SortedMap interface. The base class provides four means of support: 1) It defines a PQEntry class as a concrete implementation of the entry interface 2) It provides an instance variable for a general Comparator and protected methods, compare(a, b), that can compare either two entries or two keys using the comparator. 3) It provides a boolean checkKey method that verifies that a given key is appropriate for use with the comparator
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      private java.util.Comparator<K> comp
      The comparator defining the ordering of keys in the map.
    • Constructor Summary

      Constructors 
      Modifier Constructor and Description
      protected AbstractSortedMap()
      Initializes the map with a default comparator.
      protected AbstractSortedMap(java.util.Comparator<K> c)
      Initializes the comparator for the map.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      protected boolean checkKey(K key)
      Determines whether a key is valid.
      protected int compare(Entry<K,V> a, Entry<K,V> b)
      Method for comparing two entries according to key
      protected int compare(Entry<K,V> a, K b)
      Method for comparing a key and an entry's key
      protected int compare(K a, Entry<K,V> b)
      Method for comparing a key and an entry's key
      protected int compare(K a, K b)
      Method for comparing two keys
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • comp

        private java.util.Comparator<K> comp
        The comparator defining the ordering of keys in the map.
    • Constructor Detail

      • AbstractSortedMap

        protected AbstractSortedMap()
        Initializes the map with a default comparator.
      • AbstractSortedMap

        protected AbstractSortedMap(java.util.Comparator<K> c)
        Initializes the comparator for the map.
        Parameters:
        c - comparator defining the order of keys in the map
    • Method Detail

      • compare

        protected int compare(Entry<K,V> a,
                              Entry<K,V> b)
        Method for comparing two entries according to key
      • compare

        protected int compare(K a,
                              Entry<K,V> b)
        Method for comparing a key and an entry's key
      • compare

        protected int compare(Entry<K,V> a,
                              K b)
        Method for comparing a key and an entry's key
      • compare

        protected int compare(K a,
                              K b)
        Method for comparing two keys
      • checkKey

        protected boolean checkKey(K key)
                            throws java.lang.IllegalArgumentException
        Determines whether a key is valid.
        Throws:
        java.lang.IllegalArgumentException