Interface OrderStatisticMap<K,V extends @Nullable Object>
- Type Parameters:
K- the type of the keys of this mapV- the type of the values of this map
- All Superinterfaces:
Map<K,,V> NavigableMap<K,,V> SortedMap<K,V>
NavigableMap that allows two additional operations: receiving (and deleting) an entry
by its rank, and getting the rank of an entry.
Implementations should adhere to all contracts of the NavigableMap interface.
Implementing classes should provide two means for comparing elements:
- Using the natural ordering over the keys. In this case, all keys of the map have to
implement the
Comparableinterface. - Using a
Comparatorto create an order over the keys of the map.
In both cases, the used compare-method should be consistent with equals, i.e.,
compare(k, l) == 0 => k.equals(l), so that the Map
interface is correctly implemented. If the used compare-method is not consistent with
equals, the Map contract is not fulfilled (See the SortedMap
interface for a more detailed description).
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> OrderStatisticMap<K, V> create()Creates a new empty OrderStatisticMap using natural ordering.static <K,V> OrderStatisticMap<K, V> create(Comparator<? super K> pComparator) Creates a new empty OrderStatisticMap using the given comparator over its keys.static <K,V> OrderStatisticMap<K, V> createWithNaturalOrder(Map<? extends K, ? extends V> pMap) Creates a new OrderStatisticSet containing the same entries as the given map, using natural ordering over its keys.static <K,V> OrderStatisticMap<K, V> createWithSameOrder(SortedMap<K, ? extends V> pSortedMap) Creates a new OrderStatisticMap containing the same entries and using the same order over keys as the givenSortedMap.getEntryByRank(int pIndex) Returns the entry of this map with the given rank.default KgetKeyByRank(int pIndex) Returns the key of this map with the given rank.intReturn the rank of the entry with the given key in this map.removeByRank(int pIndex) Remove the entry of this map with the given rank and return its key.Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, get, getOrDefault, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, sizeMethods inherited from interface java.util.NavigableMap
ceilingEntry, ceilingKey, firstEntry, floorEntry, floorKey, higherEntry, higherKey, lastEntry, lowerEntry, lowerKey, pollFirstEntry, pollLastEntry
-
Method Details
-
getKeyByRank
Returns the key of this map with the given rank. The lowest key in the map has rank == 0, the largest key in the set has rank == size - 1.If this OrderStatisticMap is a view on some backing OrderStatisticMap (as created, e.g., by
descendingMap()orheadMap(Object)), the returned rank is in relation to the keys in the view, not in relation to the keys in the backing set. Thus, one can always expect that key of rank 0 is the first key in this map, and key of rankis the last.Map.size()- 1- Parameters:
pIndex- the rank of the key to return- Returns:
- the key of this map with the given rank
- Throws:
IndexOutOfBoundsException- if the given rank is out of the range of this map (i.e., pRank < 0 || pRank >= size)
-
getEntryByRank
Returns the entry of this map with the given rank. The lowest entry in the set has rank == 0, the largest entry in the set has rank == size - 1.If this OrderStatisticMap is a view on some backing OrderStatisticMap (as created, e.g., by
descendingMap()orheadMap(Object)), the returned rank is in relation to the entries in the view, not in relation to the entries in the backing set. Thus, one can always expect that entry of rank 0 is the first entry in this map, and entry of rankis the last.Map.size()- 1- Parameters:
pIndex- the rank of the entry to return- Returns:
- the entry of this map with the given rank
- Throws:
IndexOutOfBoundsException- if the given rank is out of the range of this map (i.e., pRank < 0 || pRank >= size)
-
removeByRank
Remove the entry of this map with the given rank and return its key.The lowest entry in the map has rank == 0, the largest entry in the map has rank == size - 1.
If this OrderStatisticMap is a view on some backing OrderStatisticMap (as created, e.g., by
descendingMap()orheadMap(Object)), the returned rank is in relation to the entries in the view, not in relation to the entries in the backing set. Thus, one can always expect that entry of rank 0 is the first entry in this map, and entry of rankis the last.Map.size()- 1- Parameters:
pIndex- the rank of the element to remove- Returns:
- the removed element
- Throws:
IndexOutOfBoundsException- if the given rank is out of the range of this set (i.e., pRank < 0 || pRank >= size)- See Also:
-
rankOf
Return the rank of the entry with the given key in this map. Returns -1 if the key does not exist in the map.The lowest entry in the set has rank == 0, the largest entry in the set has rank == size - 1.
If this OrderStatisticMap is a view on some backing OrderStatisticMap (as created, e.g., by
descendingMap()orheadMap(Object)), the returned rank is in relation to the entries in the view, not in relation to the entries in the backing set. Thus, one can always expect that key of rank 0 is the first key in this map, and key of rankis the last.Map.size()- 1- Parameters:
pObj- the key of the entry to return the rank for- Returns:
- the rank of the entry with the given key in the map, or -1 if the key is not in the set
- Throws:
NullPointerException- if the given key isnull
-
descendingMap
OrderStatisticMap<K,V> descendingMap()- Specified by:
descendingMapin interfaceNavigableMap<K,V extends @Nullable Object>
-
descendingKeySet
OrderStatisticSet<K> descendingKeySet()- Specified by:
descendingKeySetin interfaceNavigableMap<K,V extends @Nullable Object>
-
subMap
- Specified by:
subMapin interfaceNavigableMap<K,V extends @Nullable Object>
-
headMap
- Specified by:
headMapin interfaceNavigableMap<K,V extends @Nullable Object>
-
tailMap
- Specified by:
tailMapin interfaceNavigableMap<K,V extends @Nullable Object>
-
subMap
-
headMap
-
tailMap
-
create
Creates a new empty OrderStatisticMap using natural ordering. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticMap interface. -
create
Creates a new empty OrderStatisticMap using the given comparator over its keys. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticMap interface. -
createWithNaturalOrder
Creates a new OrderStatisticSet containing the same entries as the given map, using natural ordering over its keys. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticMap interface. -
createWithSameOrder
Creates a new OrderStatisticMap containing the same entries and using the same order over keys as the givenSortedMap. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticMap interface.- Type Parameters:
K- type of the keys of the given and new mapV- type of the values of the given and new map- Parameters:
pSortedMap- map to use entries and ordering of- Returns:
- a new OrderStatisticMap containing the same entries and using the same order over keys as the given map
-