Class TreeMap<K,V>
java.lang.Object
com.github.andrewoma.dexx.collection.internal.base.AbstractTraversable<Pair<K,V>>
com.github.andrewoma.dexx.collection.internal.base.AbstractIterable<Pair<K,V>>
com.github.andrewoma.dexx.collection.internal.base.AbstractMap<K,V>
com.github.andrewoma.dexx.collection.internal.base.AbstractSortedMap<K,V>
com.github.andrewoma.dexx.collection.TreeMap<K,V>
- All Implemented Interfaces:
Iterable<Pair<K,
,V>> Map<K,
,V> SortedMap<K,
,V> Traversable<Pair<K,
,V>> Iterable<Pair<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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionTreeMap()
private
TreeMap
(Comparator<? super K> ordering, KeyFunction<K, V> keyFunction) -
Method Summary
Modifier and TypeMethodDescriptionComparator
<? super K> Returns the comparator associated with this map, ornull
if the default ordering is used.boolean
containsKey
(K key) Returns true if this map contains the specified key.drop
(int number) Returns a map containing all elements in this map, excluding the firstnumber
of elements.static <K,
V> @NotNull BuilderFactory <Pair<K, V>, TreeMap<K, V>> factory
(Comparator<? super K> ordering, KeyFunction<K, V> keyFunction) first()
Returns the first entry in the map ornull
if the map is empty.<U> void
All collection methods can be built upon thisforEach
definition.Returns the bottom of the map starting from the key specified.Returns the value associated with the key ornull
if the no value exists with the key specified.boolean
isEmpty()
Returns true if this collection is empty.iterator()
keys()
Returns the keys for this map.last()
Returns the last entry in the map ornull
if the map is empty.Returns a map with the value specified associated to the key specified.Returns a subset of the map between thefrom
andto
keys specified.Returns a map with the value associated with the key removed if it exists.int
size()
Returns the size of the collection.slice
(int from, int until) take
(int number) Returns a list containing the firstnumber
of elements from this list.Returns the top of the map up until the key specified.values()
Returns the values for this map.Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractSortedMap
asSortedMap
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractMap
asMap, equals, hashCode
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractTraversable
makeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface com.github.andrewoma.dexx.collection.Traversable
makeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet
-
Field Details
-
tree
-
redBlackTree
-
-
Constructor Details
-
TreeMap
public TreeMap() -
TreeMap
-
TreeMap
-
-
Method Details
-
factory
@NotNull public static <K,V> @NotNull BuilderFactory<Pair<K,V>, factoryTreeMap<K, V>> (Comparator<? super K> ordering, KeyFunction<K, V> keyFunction) -
comparator
Description copied from interface:SortedMap
Returns the comparator associated with this map, ornull
if the default ordering is used. -
containsKey
Description copied from interface:Map
Returns true if this map contains the specified key. -
put
Description copied from interface:Map
Returns a map with the value specified associated to the key specified.If value already exists for the key, it will be replaced.
-
get
Description copied from interface:Map
Returns the value associated with the key ornull
if the no value exists with the key specified. -
size
public int size()Description copied from interface:Traversable
Returns the size of the collection.Warning: infinite collections are possible, as are collections that require traversal to calculate the size.
- Specified by:
size
in interfaceTraversable<K>
- Overrides:
size
in classAbstractTraversable<Pair<K,
V>>
-
isEmpty
public boolean isEmpty()Description copied from interface:Traversable
Returns true if this collection is empty.- Specified by:
isEmpty
in interfaceTraversable<K>
- Overrides:
isEmpty
in classAbstractTraversable<Pair<K,
V>>
-
remove
Description copied from interface:Map
Returns a map with the value associated with the key removed if it exists. -
iterator
-
forEach
Description copied from interface:Traversable
All collection methods can be built upon thisforEach
definition.- Specified by:
forEach
in interfaceTraversable<K>
- Overrides:
forEach
in classAbstractIterable<Pair<K,
V>>
-
first
Description copied from interface:SortedMap
Returns the first entry in the map ornull
if the map is empty. -
toPair
-
last
Description copied from interface:SortedMap
Returns the last entry in the map ornull
if the map is empty. -
drop
Description copied from interface:SortedMap
Returns a map containing all elements in this map, excluding the firstnumber
of elements. -
take
Description copied from interface:SortedMap
Returns a list containing the firstnumber
of elements from this list. -
from
Description copied from interface:SortedMap
Returns the bottom of the map starting from the key specified. -
to
Description copied from interface:SortedMap
Returns the top of the map up until the key specified. -
range
@NotNull public @NotNull SortedMap<K,V> range(@NotNull K from, boolean fromInclusive, @NotNull K to, boolean toInclusive) Description copied from interface:SortedMap
Returns a subset of the map between thefrom
andto
keys specified.- Parameters:
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
-
keys
Description copied from interface:Map
Returns the keys for this map. -
values
Description copied from interface:Map
Returns the values for this map. -
slice
-