public class TreeMap<K,V> extends AbstractSortedMap<K,V>
TreeMap is an implementation of SortedMap based on a
red-black tree.
TreeMaps can be constructed with a KeyFunction
to provide modest memory saving per node. See DerivedKeyHashMap
for an example of using a key function.
| Constructor and Description |
|---|
TreeMap() |
TreeMap(java.util.Comparator<? super K> ordering,
KeyFunction<K,V> keyFunction) |
| Modifier and Type | Method and Description |
|---|---|
java.util.Comparator<? super K> |
comparator()
Returns the comparator associated with this map, or
null if the default ordering is used. |
boolean |
containsKey(K key)
Returns true if this map contains the specified key.
|
SortedMap<K,V> |
drop(int number)
Returns a map containing all elements in this map, excluding the first
number of elements. |
static <K,V> BuilderFactory<Pair<K,V>,TreeMap<K,V>> |
factory(java.util.Comparator<? super K> ordering,
KeyFunction<K,V> keyFunction) |
Pair<K,V> |
first()
Returns the first entry in the map or
null if the map is empty. |
<U> void |
forEach(Function<Pair<K,V>,U> f)
All collection methods can be built upon this
forEach definition. |
SortedMap<K,V> |
from(K key,
boolean inclusive)
Returns the bottom of the map starting from the key specified.
|
V |
get(K key)
Returns the value associated with the key or
null if the no value exists with the key specified. |
boolean |
isEmpty()
Returns true if this collection is empty.
|
java.util.Iterator<Pair<K,V>> |
iterator() |
Iterable<K> |
keys()
Returns the keys for this map.
|
Pair<K,V> |
last()
Returns the last entry in the map or
null if the map is empty. |
TreeMap<K,V> |
put(K key,
V value)
Returns a map with the value specified associated to the key specified.
|
SortedMap<K,V> |
range(K from,
boolean fromInclusive,
K to,
boolean toInclusive)
Returns a subset of the map between the
from and to keys specified. |
TreeMap<K,V> |
remove(K key)
Returns a map with the value associated with the key removed if it exists.
|
int |
size()
Returns the size of the collection.
|
protected TreeMap<K,V> |
slice(int from,
int until) |
SortedMap<K,V> |
take(int number)
Returns a list containing the first
number of elements from this list. |
SortedMap<K,V> |
to(K key,
boolean inclusive)
Returns the top of the map up until the key specified.
|
Iterable<V> |
values()
Returns the values for this map.
|
asSortedMapasMap, equals, hashCodemakeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitmakeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSetpublic TreeMap()
public TreeMap(java.util.Comparator<? super K> ordering, KeyFunction<K,V> keyFunction)
@NotNull public static <K,V> BuilderFactory<Pair<K,V>,TreeMap<K,V>> factory(java.util.Comparator<? super K> ordering, KeyFunction<K,V> keyFunction)
public java.util.Comparator<? super K> comparator()
SortedMapnull if the default ordering is used.public boolean containsKey(@NotNull
K key)
Map@NotNull public TreeMap<K,V> put(@NotNull K key, V value)
MapIf value already exists for the key, it will be replaced.
public V get(@NotNull K key)
Mapnull if the no value exists with the key specified.public int size()
TraversableWarning: infinite collections are possible, as are collections that require traversal to calculate the size.
size in interface Traversable<Pair<K,V>>size in class AbstractTraversable<Pair<K,V>>public boolean isEmpty()
TraversableisEmpty in interface Traversable<Pair<K,V>>isEmpty in class AbstractTraversable<Pair<K,V>>@NotNull public TreeMap<K,V> remove(@NotNull K key)
Mappublic <U> void forEach(@NotNull
Function<Pair<K,V>,U> f)
TraversableforEach definition.forEach in interface Traversable<Pair<K,V>>forEach in class AbstractIterable<Pair<K,V>>@Nullable public Pair<K,V> first()
SortedMapnull if the map is empty.@Nullable public Pair<K,V> last()
SortedMapnull if the map is empty.@NotNull public SortedMap<K,V> drop(int number)
SortedMapnumber of elements.@NotNull public SortedMap<K,V> take(int number)
SortedMapnumber of elements from this list.@NotNull public SortedMap<K,V> from(@NotNull K key, boolean inclusive)
SortedMap@NotNull public SortedMap<K,V> to(@NotNull K key, boolean inclusive)
SortedMap@NotNull public SortedMap<K,V> range(@NotNull K from, boolean fromInclusive, @NotNull K to, boolean toInclusive)
SortedMapfrom and to keys specified.fromInclusive - if true, the key will be included in the result, otherwise it will be excludedtoInclusive - if true, the key will be included in the result, otherwise it will be excluded@NotNull public Iterable<K> keys()
Map@NotNull public Iterable<V> values()
Map