Class TreeMap<K,V>
- java.lang.Object
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractTraversable<E>
-
- 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>>,java.lang.Iterable<Pair<K,V>>
public class TreeMap<K,V> extends AbstractSortedMap<K,V>
TreeMapis an implementation ofSortedMapbased on a red-black tree.TreeMapscan be constructed with aKeyFunctionto provide modest memory saving per node. SeeDerivedKeyHashMapfor an example of using a key function.
-
-
Field Summary
Fields Modifier and Type Field Description private RedBlackTree<K,V>redBlackTreeprivate Tree<K,V>tree
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Comparator<? super K>comparator()Returns the comparator associated with this map, ornullif the default ordering is used.booleancontainsKey(K key)Returns true if this map contains the specified key.@NotNull SortedMap<K,V>drop(int number)Returns a map containing all elements in this map, excluding the firstnumberof elements.static <K,V>
@NotNull BuilderFactory<Pair<K,V>,TreeMap<K,V>>factory(java.util.Comparator<? super K> ordering, KeyFunction<K,V> keyFunction)@Nullable Pair<K,V>first()Returns the first entry in the map ornullif the map is empty.<U> voidforEach(@NotNull Function<Pair<K,V>,U> f)All collection methods can be built upon thisforEachdefinition.@NotNull SortedMap<K,V>from(K key, boolean inclusive)Returns the bottom of the map starting from the key specified.Vget(K key)Returns the value associated with the key ornullif the no value exists with the key specified.booleanisEmpty()Returns true if this collection is empty.@NotNull java.util.Iterator<Pair<K,V>>iterator()@NotNull Iterable<K>keys()Returns the keys for this map.@Nullable Pair<K,V>last()Returns the last entry in the map ornullif the map is empty.@NotNull TreeMap<K,V>put(K key, V value)Returns a map with the value specified associated to the key specified.@NotNull SortedMap<K,V>range(K from, boolean fromInclusive, K to, boolean toInclusive)Returns a subset of the map between thefromandtokeys specified.@NotNull TreeMap<K,V>remove(K key)Returns a map with the value associated with the key removed if it exists.intsize()Returns the size of the collection.protected @NotNull TreeMap<K,V>slice(int from, int until)@NotNull SortedMap<K,V>take(int number)Returns a list containing the firstnumberof elements from this list.@NotNull SortedMap<K,V>to(K key, boolean inclusive)Returns the top of the map up until the key specified.private Pair<K,V>toPair(Tree<K,V> tree)@NotNull Iterable<V>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 com.github.andrewoma.dexx.collection.Traversable
makeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet
-
-
-
-
Constructor Detail
-
TreeMap
public TreeMap()
-
TreeMap
public TreeMap(java.util.Comparator<? super K> ordering, KeyFunction<K,V> keyFunction)
-
-
Method Detail
-
factory
@NotNull public static <K,V> @NotNull BuilderFactory<Pair<K,V>,TreeMap<K,V>> factory(java.util.Comparator<? super K> ordering, KeyFunction<K,V> keyFunction)
-
comparator
public java.util.Comparator<? super K> comparator()
Description copied from interface:SortedMapReturns the comparator associated with this map, ornullif the default ordering is used.
-
containsKey
public boolean containsKey(@NotNull K key)Description copied from interface:MapReturns true if this map contains the specified key.
-
put
@NotNull public @NotNull TreeMap<K,V> put(@NotNull K key, V value)
Description copied from interface:MapReturns a map with the value specified associated to the key specified.If value already exists for the key, it will be replaced.
-
get
public V get(@NotNull K key)
Description copied from interface:MapReturns the value associated with the key ornullif the no value exists with the key specified.
-
size
public int size()
Description copied from interface:TraversableReturns the size of the collection.Warning: infinite collections are possible, as are collections that require traversal to calculate the size.
- Specified by:
sizein interfaceTraversable<K>- Overrides:
sizein classAbstractTraversable<Pair<K,V>>
-
isEmpty
public boolean isEmpty()
Description copied from interface:TraversableReturns true if this collection is empty.- Specified by:
isEmptyin interfaceTraversable<K>- Overrides:
isEmptyin classAbstractTraversable<Pair<K,V>>
-
remove
@NotNull public @NotNull TreeMap<K,V> remove(@NotNull K key)
Description copied from interface:MapReturns a map with the value associated with the key removed if it exists.
-
forEach
public <U> void forEach(@NotNull @NotNull Function<Pair<K,V>,U> f)Description copied from interface:TraversableAll collection methods can be built upon thisforEachdefinition.- Specified by:
forEachin interfaceTraversable<K>- Overrides:
forEachin classAbstractIterable<Pair<K,V>>
-
first
@Nullable public @Nullable Pair<K,V> first()
Description copied from interface:SortedMapReturns the first entry in the map ornullif the map is empty.
-
last
@Nullable public @Nullable Pair<K,V> last()
Description copied from interface:SortedMapReturns the last entry in the map ornullif the map is empty.
-
drop
@NotNull public @NotNull SortedMap<K,V> drop(int number)
Description copied from interface:SortedMapReturns a map containing all elements in this map, excluding the firstnumberof elements.
-
take
@NotNull public @NotNull SortedMap<K,V> take(int number)
Description copied from interface:SortedMapReturns a list containing the firstnumberof elements from this list.
-
from
@NotNull public @NotNull SortedMap<K,V> from(@NotNull K key, boolean inclusive)
Description copied from interface:SortedMapReturns the bottom of the map starting from the key specified.
-
to
@NotNull public @NotNull SortedMap<K,V> to(@NotNull K key, boolean inclusive)
Description copied from interface:SortedMapReturns 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:SortedMapReturns a subset of the map between thefromandtokeys 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
-
keys
@NotNull public @NotNull Iterable<K> keys()
Description copied from interface:MapReturns the keys for this map.
-
values
@NotNull public @NotNull Iterable<V> values()
Description copied from interface:MapReturns the values for this map.
-
-