Package com.zybooks.dsaj.map
Class AbstractSortedMap<K,V>
java.lang.Object
com.zybooks.dsaj.map.AbstractMap<K,V>
com.zybooks.dsaj.map.AbstractSortedMap<K,V>
- Type Parameters:
K
- The key type (keys must be unique and comparable)V
- The value type
- Direct Known Subclasses:
SortedTableMap
,TreeMap
An abstract base class to ease the implementation of the SortedMap interface.
The base class provides the following 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 perform key-key, entry-entry,
or key-entry comparisons using the comparator.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.zybooks.dsaj.map.AbstractMap
AbstractMap.MapEntry<K,
V> -
Constructor Summary
ModifierConstructorDescriptionprotected
Initializes the map with a default comparator.protected
Initializes the comparator for the map. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Compares two entries according to their keys.protected int
Compares an entry's key and a raw keyprotected int
Compares a raw key and an entry's key.protected int
Compares two raw keysMethods inherited from class com.zybooks.dsaj.map.AbstractMap
isEmpty, keySet, values
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.zybooks.dsaj.map.Map
entrySet, get, isEmpty, keySet, put, remove, size, values
Methods inherited from interface com.zybooks.dsaj.map.SortedMap
ceilingEntry, firstEntry, floorEntry, higherEntry, lastEntry, lowerEntry, subMap
-
Constructor Details
-
AbstractSortedMap
Initializes the comparator for the map.- Parameters:
c
- comparator defining the order of keys in the map
-
AbstractSortedMap
protected AbstractSortedMap()Initializes the map with a default comparator.
-
-
Method Details
-
compare
Compares two entries according to their keys.- Parameters:
a
- the first entry to be comparedb
- the second entry to be compared- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
-
compare
Compares a raw key and an entry's key.- Parameters:
a
- the key to be comparedb
- the entry whose key should be compared- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the key of the second argument.
-
compare
Compares an entry's key and a raw key- Parameters:
a
- the entry whose key should be comparedb
- the key to be compared- Returns:
- a negative integer, zero, or a positive integer as the first argument's key is less than, equal to, or greater than the second argument.
-
compare
Compares two raw keys- Parameters:
a
- the first key to be comparedb
- the second key to be compared- Returns:
- a negative integer, zero, or a positive integer as the first key is less than, equal to, or greater than the second key.
-