Class TreeMap<K,V>
java.lang.Object
org.javimmutable.collections.common.AbstractMap<K,V>
org.javimmutable.collections.tree.TreeMap<K,V>
- All Implemented Interfaces:
Serializable
,Iterable<IMapEntry<K,
,V>> ICollection<IMapEntry<K,
,V>> IMap<K,
,V> InvariantCheckable
,IStreamable<IMapEntry<K,
,V>> Mapped<K,
,V> SplitableIterable<IMapEntry<K,
V>>
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionSets the value associated with a specific key.static <K extends Comparable<K>,
V>
IMapBuilder<K, V> builder()
static <K,
V> IMapBuilder <K, V> builder
(Comparator<K> comparator) void
Checks invariants of implementing class.static <K extends Comparable<K>,
V>
java.util.stream.Collector<IMapEntry<K, V>, ?, IMap<K, V>> createMapCollector
(Comparator<K> comparator) Deletes the entry for the specified key (if any).Search for a value within the map and return a Holder indicating if the value was found and, if it was found, the value itself.Search for an Entry within the map and return a Holder indicating if the Entry was found and, if it was found, the Entry itself.void
Processes every key/value pair in this map using the provided function.<E extends Exception>
voidforEachThrows
(Proc2Throws<K, V, E> proc) Processes every key/value pair in this map using the provided function.int
getValueOr
(K key, V defaultValue) Return the value associated with key or defaultValue if no value is associated.iterator()
Overridden here to require implementations to return a SplitableIterator rather than a basic Iterator.Creates a Builder with the same type signature as this Map.static <K extends Comparable<K>,
V>
TreeMap<K, V> of()
static <K,
V> TreeMap <K, V> of
(Comparator<K> comparator) <R> R
Processes every key value pair in this map using the provided function to produce a value.<R,
E extends Exception>
RreduceThrows
(R sum, Sum2Throws<K, V, R, E> proc) Processes every key value pair in this map using the provided function to produce a value.int
size()
Update the value at the key.Methods inherited from class org.javimmutable.collections.common.AbstractMap
assignAll, assignAll, equals, get, getMap, hashCode, insert, keys, reject, select, toString, values
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.javimmutable.collections.ICollection
isEmpty, isNonEmpty
Methods inherited from interface org.javimmutable.collections.IMap
insertAll, insertAll, mapCollector
Methods inherited from interface org.javimmutable.collections.IStreamable
parallelStream, spliterator, stream
Methods inherited from interface org.javimmutable.collections.SplitableIterable
forEachThrows, indexedForEach, indexedForEachThrows, reduce, reduceThrows
-
Method Details
-
of
-
of
-
builder
-
builder
-
mapBuilder
Description copied from interface:IMap
Creates a Builder with the same type signature as this Map.- Specified by:
mapBuilder
in interfaceIMap<K,
V>
-
createMapCollector
@Nonnull public static <K extends Comparable<K>,V> java.util.stream.Collector<IMapEntry<K,V>, createMapCollector()?, IMap<K, V>> -
createMapCollector
@Nonnull public static <K,V> java.util.stream.Collector<IMapEntry<K,V>, createMapCollector?, IMap<K, V>> (@Nonnull Comparator<K> comparator) -
getValueOr
Description copied from interface:Mapped
Return the value associated with key or defaultValue if no value is associated. Note that if defaultValue is an acceptable value to the container then this method will be ambiguous and find() should be used instead.- Specified by:
getValueOr
in interfaceMapped<K,
V> - Parameters:
key
- identifies the value to retrievedefaultValue
- value to return if no entry exists for key- Returns:
- value associated with key or defaultValue if no value is associated
-
find
Description copied from interface:IMap
Search for a value within the map and return a Holder indicating if the value was found and, if it was found, the value itself. Holder allows null values to be returned unambiguously. -
findEntry
Description copied from interface:IMap
Search for an Entry within the map and return a Holder indicating if the Entry was found and, if it was found, the Entry itself. -
assign
Description copied from interface:IMap
Sets the value associated with a specific key. Key must be non-null but value can be null. If the key already has a value in the map the old value is discarded and the new value is stored in its place. Returns a newIMap
reflecting any changes. The original map is always left unchanged. -
update
Description copied from interface:IMap
Update the value at the key. A Holder containing the value currently stored at the key, or an empty Holder if the key is not currently bound, is passed to the generator function. -
delete
Description copied from interface:IMap
Deletes the entry for the specified key (if any). Returns a new map if the value was deleted or the current map if the key was not contained in the map. -
size
public int size()- Specified by:
size
in interfaceICollection<K>
- Returns:
- number of values in the collection
-
deleteAll
-
getSpliteratorCharacteristics
public int getSpliteratorCharacteristics()- Specified by:
getSpliteratorCharacteristics
in interfaceIStreamable<K>
- Overrides:
getSpliteratorCharacteristics
in classAbstractMap<K,
V> - Returns:
- characteristics value used when creating Spliterators
-
iterator
Description copied from interface:IStreamable
Overridden here to require implementations to return a SplitableIterator rather than a basic Iterator. This is necessary to allow composition of new objects from methods like keys() and values().- Specified by:
iterator
in interfaceIStreamable<K>
- Specified by:
iterator
in interfaceIterable<K>
- Specified by:
iterator
in interfaceSplitableIterable<K>
-
forEach
Description copied from interface:IMap
Processes every key/value pair in this map using the provided function. -
forEachThrows
Description copied from interface:IMap
Processes every key/value pair in this map using the provided function.- Specified by:
forEachThrows
in interfaceIMap<K,
V> - Throws:
E
-
reduce
Description copied from interface:IMap
Processes every key value pair in this map using the provided function to produce a value.- Specified by:
reduce
in interfaceIMap<K,
V> - Type Parameters:
R
- type of the sum- Parameters:
sum
- initial value for process (used with first key/value pair of map)proc
- function to combine a sum with a key value pair to produce a new sum- Returns:
- final value (or initial value if this map is empty)
-
reduceThrows
Description copied from interface:IMap
Processes every key value pair in this map using the provided function to produce a value.- Specified by:
reduceThrows
in interfaceIMap<K,
V> - Type Parameters:
R
- type of the sumE
- type of the Exception thrown by the function- Parameters:
sum
- initial value for process (used with first key/value pair of map)proc
- function to combine a sum with a key value pair to produce a new sum- Returns:
- final value (or initial value if this map is empty)
- Throws:
E
-
checkInvariants
public void checkInvariants()Description copied from interface:InvariantCheckable
Checks invariants of implementing class.- Specified by:
checkInvariants
in interfaceInvariantCheckable
-
getComparator
-