public class RBTreeMap<K,V> extends AbstractMap<K,V> implements SortedMap<K,V>, Cloneable, Serializable
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
RBTreeMap()
Constructs a new, empty map, sorted according to the keys' natural
order.
|
RBTreeMap(Comparator<? super K> c)
Constructs a new, empty map, sorted according to the given comparator.
|
RBTreeMap(Map<? extends K,? extends V> m)
Constructs a new map containing the same mappings as the given map,
sorted according to the keys' natural order.
|
RBTreeMap(SortedMap<K,? extends V> m)
Constructs a new map containing the same mappings as the given
SortedMap, sorted according to the same ordering.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all mappings from this RBTreeMap.
|
Object |
clone()
Returns a shallow copy of this RBTreeMap instance.
|
Comparator<? super K> |
comparator()
Returns the comparator used to order this map, or null if this
map uses its keys' natural order.
|
boolean |
containsKey(Object key)
Returns true if this map contains a mapping for the specified
key.
|
boolean |
containsValue(Object value)
Returns true if this map maps one or more keys to the
specified value.
|
Set<Map.Entry<K,V>> |
entrySet()
Returns a set view of the mappings contained in this map.
|
K |
firstKey()
Returns the first (lowest) key currently in this sorted map.
|
V |
get(Object key)
Returns the value to which this map maps the specified key.
|
V[] |
getClosestMatch(K key)
Returns a pair of values: (glb,lub).
|
V |
getNextOf(K key)
Returns the value associated to the next key in the map if an exact match
doesn't exist.
|
SortedMap<K,V> |
headMap(K toKey)
Returns a view of the portion of this map whose keys are strictly less
than toKey.
|
Set<K> |
keySet()
Returns a Set view of the keys contained in this map.
|
K |
lastKey()
Returns the last (highest) key currently in this sorted map.
|
V |
put(K key,
V value)
Associates the specified value with the specified key in this map.
|
void |
putAll(Map<? extends K,? extends V> map)
Copies all of the mappings from the specified map to this map.
|
V |
remove(Object key)
Removes the mapping for this key from this RBTreeMap if present.
|
int |
size()
Returns the number of key-value mappings in this map.
|
SortedMap<K,V> |
subMap(Object fromKey,
Object toKey)
Returns a view of the portion of this map whose keys range from
fromKey, inclusive, to toKey, exclusive.
|
SortedMap<K,V> |
tailMap(K fromKey)
Returns a view of the portion of this map whose keys are greater than
or equal to fromKey.
|
Collection<V> |
values()
Returns a collection view of the values contained in this map.
|
equals, hashCode, isEmpty, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll
public RBTreeMap()
Comparable
public RBTreeMap(Comparator<? super K> c)
public RBTreeMap(Map<? extends K,? extends V> m)
ClassCastException
- the keys in t are not Comparable, or
are not mutually comparable.public int size()
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
containsKey
in class AbstractMap<K,V>
key
- key whose presence in this map is to be tested.ClassCastException
- if the key cannot be compared with the keys
currently in the map.NullPointerException
- key is null and this map uses
natural ordering, or its comparator does not tolerate
null keys.public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
containsValue
in class AbstractMap<K,V>
value
- value whose presence in this Map is to be tested.public V[] getClosestMatch(K key)
public V getNextOf(K key)
key
- the key for wich the look-up will be done.public V get(Object key)
get
in interface Map<K,V>
get
in class AbstractMap<K,V>
key
- key whose associated value is to be returned.ClassCastException
- key cannot be compared with the keys
currently in the map.NullPointerException
- key is null and this map uses
natural ordering, or its comparator does not tolerate
null keys.containsKey(Object)
public Comparator<? super K> comparator()
comparator
in interface SortedMap<K,V>
public K firstKey()
firstKey
in interface SortedMap<K,V>
NoSuchElementException
- Map is empty.public K lastKey()
lastKey
in interface SortedMap<K,V>
NoSuchElementException
- Map is empty.public void putAll(Map<? extends K,? extends V> map)
putAll
in interface Map<K,V>
putAll
in class AbstractMap<K,V>
map
- Mappings to be stored in this map.ClassCastException
- class of a key or value in the specified
map prevents it from being stored in this map.NullPointerException
- this map does not permit null
keys and a specified key is null.public V put(K key, V value)
put
in interface Map<K,V>
put
in class AbstractMap<K,V>
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.ClassCastException
- key cannot be compared with the keys
currently in the map.NullPointerException
- key is null and this map uses
natural order, or its comparator does not tolerate
null keys.public V remove(Object key)
remove
in interface Map<K,V>
remove
in class AbstractMap<K,V>
ClassCastException
- key cannot be compared with the keys
currently in the map.NullPointerException
- key is null and this map uses
natural order, or its comparator does not tolerate
null keys.public void clear()
public Object clone()
clone
in class AbstractMap<K,V>
public Set<K> keySet()
public Collection<V> values()
public Set<Map.Entry<K,V>> entrySet()
public SortedMap<K,V> subMap(Object fromKey, Object toKey)
The sorted map returned by this method will throw an IllegalArgumentException if the user attempts to insert a key less than fromKey or greater than or equal to toKey.
Note: this method always returns a half-open range (which includes its low endpoint but not its high endpoint). If you need a closed range (which includes both endpoints), and the key type allows for calculation of the successor a given key, merely request the subrange from lowEndpoint to successor(highEndpoint). For example, suppose that m is a sorted map whose keys are strings. The following idiom obtains a view containing all of the key-value mappings in m whose keys are between low and high, inclusive:
SortedMap sub = m.submap(low, high+"\0");A similar technique can be used to generate an open range (which contains neither endpoint). The following idiom obtains a view containing all of the key-value mappings in m whose keys are between low and high, exclusive:
SortedMap sub = m.subMap(low+"\0", high);
subMap
in interface SortedMap<K,V>
fromKey
- low endpoint (inclusive) of the subMap.toKey
- high endpoint (exclusive) of the subMap.NullPointerException
- if fromKey or toKey is
null and this map uses natural order, or its
comparator does not tolerate null keys.IllegalArgumentException
- if fromKey is greater than
toKey.public SortedMap<K,V> headMap(K toKey)
The sorted map returned by this method will throw an IllegalArgumentException if the user attempts to insert a key greater than or equal to toKey.
Note: this method always returns a view that does not contain its (high) endpoint. If you need a view that does contain this endpoint, and the key type allows for calculation of the successor a given key, merely request a headMap bounded by successor(highEndpoint). For example, suppose that suppose that m is a sorted map whose keys are strings. The following idiom obtains a view containing all of the key-value mappings in m whose keys are less than or equal to high:
SortedMap head = m.headMap(high+"\0");
headMap
in interface SortedMap<K,V>
toKey
- high endpoint (exclusive) of the headMap.NullPointerException
- if toKey is null and
this map uses natural order, or its comparator does * not
tolerate null keys.public SortedMap<K,V> tailMap(K fromKey)
The sorted map returned by this method will throw an IllegalArgumentException if the user attempts to insert a key less than fromKey.
Note: this method always returns a view that contains its (low) endpoint. If you need a view that does not contain this endpoint, and the element type allows for calculation of the successor a given value, merely request a tailMap bounded by successor(lowEndpoint). For For example, suppose that suppose that m is a sorted map whose keys are strings. The following idiom obtains a view containing all of the key-value mappings in m whose keys are strictly greater than low:
SortedMap tail = m.tailMap(low+"\0");
tailMap
in interface SortedMap<K,V>
fromKey
- low endpoint (inclusive) of the tailMap.NullPointerException
- fromKey is null and this
map uses natural ordering, or its comparator does
not tolerate null keys.Copyright © 2024 GATE. All rights reserved.