com.github.andrewoma.dexx.collection
Class TreeMap<K,V>

java.lang.Object
  extended by com.github.andrewoma.dexx.collection.internal.base.AbstractTraversable<E>
      extended by com.github.andrewoma.dexx.collection.internal.base.AbstractIterable<Pair<K,V>>
          extended by com.github.andrewoma.dexx.collection.internal.base.AbstractMap<K,V>
              extended by com.github.andrewoma.dexx.collection.internal.base.AbstractSortedMap<K,V>
                  extended by com.github.andrewoma.dexx.collection.TreeMap<K,V>
All Implemented Interfaces:
Map<K,V>, SortedMap<K,V>, Traversable<Pair<K,V>>, Iterable<Pair<K,V>>

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 Summary
TreeMap()
           
TreeMap(Comparator<? super K> ordering, KeyFunction<K,V> keyFunction)
           
 
Method Summary
 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(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.
 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.
 
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.Map
asMap
 
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(Comparator<? super K> ordering,
               KeyFunction<K,V> keyFunction)
Method Detail

factory

@NotNull
public static <K,V> BuilderFactory<Pair<K,V>,TreeMap<K,V>> factory(Comparator<? super K> ordering,
                                                                           KeyFunction<K,V> keyFunction)

comparator

public Comparator<? super K> comparator()
Description copied from interface: SortedMap
Returns the comparator associated with this map, or null if the default ordering is used.


containsKey

public boolean containsKey(@NotNull
                           K key)
Description copied from interface: Map
Returns true if this map contains the specified key.


put

@NotNull
public TreeMap<K,V> put(@NotNull
                                K key,
                                V value)
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

public V get(@NotNull
             K key)
Description copied from interface: Map
Returns the value associated with the key or null 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 interface Traversable<Pair<K,V>>
Overrides:
size in class AbstractTraversable<Pair<K,V>>

isEmpty

public boolean isEmpty()
Description copied from interface: Traversable
Returns true if this collection is empty.

Specified by:
isEmpty in interface Traversable<Pair<K,V>>
Overrides:
isEmpty in class AbstractTraversable<Pair<K,V>>

remove

@NotNull
public TreeMap<K,V> remove(@NotNull
                                   K key)
Description copied from interface: Map
Returns a map with the value associated with the key removed if it exists.


iterator

@NotNull
public Iterator<Pair<K,V>> iterator()

forEach

public <U> void forEach(@NotNull
                        Function<Pair<K,V>,U> f)
Description copied from interface: Traversable
All collection methods can be built upon this forEach definition.

Specified by:
forEach in interface Traversable<Pair<K,V>>
Overrides:
forEach in class AbstractIterable<Pair<K,V>>

first

@Nullable
public Pair<K,V> first()
Description copied from interface: SortedMap
Returns the first entry in the map or null if the map is empty.


last

@Nullable
public Pair<K,V> last()
Description copied from interface: SortedMap
Returns the last entry in the map or null if the map is empty.


drop

@NotNull
public SortedMap<K,V> drop(int number)
Description copied from interface: SortedMap
Returns a map containing all elements in this map, excluding the first number of elements.


take

@NotNull
public SortedMap<K,V> take(int number)
Description copied from interface: SortedMap
Returns a list containing the first number of elements from this list.


from

@NotNull
public SortedMap<K,V> from(@NotNull
                                   K key,
                                   boolean inclusive)
Description copied from interface: SortedMap
Returns the bottom of the map starting from the key specified.

Specified by:
from in interface SortedMap<K,V>
Overrides:
from in class AbstractSortedMap<K,V>
inclusive - if true, the key will be included in the result, otherwise it will be excluded

to

@NotNull
public SortedMap<K,V> to(@NotNull
                                 K key,
                                 boolean inclusive)
Description copied from interface: SortedMap
Returns the top of the map up until the key specified.

Specified by:
to in interface SortedMap<K,V>
Overrides:
to in class AbstractSortedMap<K,V>
inclusive - if true, the key will be included in the result, otherwise it will be excluded

range

@NotNull
public 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 the from and to keys specified.

fromInclusive - if true, the key will be included in the result, otherwise it will be excluded
toInclusive - if true, the key will be included in the result, otherwise it will be excluded

keys

@NotNull
public Iterable<K> keys()
Description copied from interface: Map
Returns the keys for this map.

Specified by:
keys in interface Map<K,V>
Overrides:
keys in class AbstractMap<K,V>

values

@NotNull
public Iterable<V> values()
Description copied from interface: Map
Returns the values for this map.

Specified by:
values in interface Map<K,V>
Overrides:
values in class AbstractMap<K,V>

slice

@NotNull
protected TreeMap<K,V> slice(int from,
                                     int until)


Copyright © 2014. All Rights Reserved.