K
- Key typeV
- Value typepublic final class TreeMap<K,V> extends Object implements Kind2<TreeMap<?,?>,K,V>, SortedMap<K,V>, Serializable
λ.Memoized
Modifier and Type | Method and Description |
---|---|
<K2,V2> TreeMap<K2,V2> |
bimap(Comparator<? super K2> keyComparator,
Function<? super K,? extends K2> keyMapper,
Function<? super V,? extends V2> valueMapper)
Same as
SortedMap.bimap(Function, Function) , using a specific comparator for keys of the codomain of the given
keyMapper . |
<K2,V2> TreeMap<K2,V2> |
bimap(Function<? super K,? extends K2> keyMapper,
Function<? super V,? extends V2> valueMapper)
Maps this
Map to a new Map with different component type by applying a function to its elements. |
static <K extends Comparable<? super K>,V> |
collector()
Returns a
Collector which may be used in conjunction with
Stream.collect(Collector) to obtain a
TreeMap . |
static <K,V> Collector<Tuple2<K,V>,ArrayList<Tuple2<K,V>>,TreeMap<K,V>> |
collector(Comparator<? super K> keyComparator)
Returns a
Collector which may be used in conjunction with
Stream.collect(Collector) to obtain a
TreeMap . |
Comparator<K> |
comparator()
Returns the comparator which defines the order of the elements contained in this collection.
|
Tuple2<V,TreeMap<K,V>> |
computeIfAbsent(K key,
Function<? super K,? extends V> mappingFunction)
If the specified key is not already associated with a value,
attempts to compute its value using the given mapping
function and enters it into this map.
|
Tuple2<Option<V>,TreeMap<K,V>> |
computeIfPresent(K key,
BiFunction<? super K,? super V,? extends V> remappingFunction)
If the value for the specified key is present, attempts to
compute a new mapping given the key and its current mapped value.
|
boolean |
containsKey(K key)
Returns
true if this map contains a mapping for the specified key. |
TreeMap<K,V> |
distinct()
Returns a new version of this which contains no duplicates.
|
TreeMap<K,V> |
distinctBy(Comparator<? super Tuple2<K,V>> comparator)
Returns a new version of this which contains no duplicates.
|
<U> TreeMap<K,V> |
distinctBy(Function<? super Tuple2<K,V>,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.
|
TreeMap<K,V> |
drop(int n)
Drops the first n elements of this or all elements, if this length < n.
|
TreeMap<K,V> |
dropRight(int n)
Drops the last n elements of this or all elements, if this length < n.
|
TreeMap<K,V> |
dropUntil(Predicate<? super Tuple2<K,V>> predicate)
Drops elements until the predicate holds for the current element.
|
TreeMap<K,V> |
dropWhile(Predicate<? super Tuple2<K,V>> predicate)
Drops elements while the predicate holds for the current element.
|
static <K extends Comparable<? super K>,V> |
empty()
Returns the empty TreeMap.
|
static <K,V> TreeMap<K,V> |
empty(Comparator<? super K> keyComparator)
Returns the empty TreeMap using the given key comparator.
|
boolean |
equals(Object o)
Clarifies that values have a proper equals() method implemented.
|
static <K,V> TreeMap<K,V> |
fill(Comparator<? super K> keyComparator,
int n,
Supplier<? extends Tuple2<? extends K,? extends V>> s)
Returns a TreeMap containing
n values supplied by a given Supplier s . |
static <K extends Comparable<? super K>,V> |
fill(int n,
Supplier<? extends Tuple2<? extends K,? extends V>> s)
Returns a TreeMap containing
n values supplied by a given Supplier s . |
TreeMap<K,V> |
filter(BiPredicate<? super K,? super V> predicate)
Returns a new Map consisting of all elements which satisfy the given predicate.
|
TreeMap<K,V> |
filter(Predicate<? super Tuple2<K,V>> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
TreeMap<K,V> |
filterKeys(Predicate<? super K> predicate)
Returns a new Map consisting of all elements with keys which satisfy the given predicate.
|
TreeMap<K,V> |
filterValues(Predicate<? super V> predicate)
Returns a new Map consisting of all elements with values which satisfy the given predicate.
|
<K2,V2> TreeMap<K2,V2> |
flatMap(BiFunction<? super K,? super V,? extends Iterable<Tuple2<K2,V2>>> mapper)
FlatMaps this
Map to a new Map with different component type. |
<K2,V2> TreeMap<K2,V2> |
flatMap(Comparator<? super K2> keyComparator,
BiFunction<? super K,? super V,? extends Iterable<Tuple2<K2,V2>>> mapper)
Same as
SortedMap.flatMap(BiFunction) but using a specific comparator for values of the codomain of the given
mapper . |
Option<V> |
get(K key)
Returns the
Some of value to which the specified key
is mapped, or None if this map contains no mapping for the key. |
V |
getOrElse(K key,
V defaultValue)
Returns the value associated with a key, or a default value if the key is not contained in the map.
|
<C> Map<C,TreeMap<K,V>> |
groupBy(Function<? super Tuple2<K,V>,? extends C> classifier)
Groups this elements by classifying the elements.
|
Iterator<TreeMap<K,V>> |
grouped(int size)
Groups this
Traversable into fixed size blocks. |
int |
hashCode()
Clarifies that values have a proper hashCode() method implemented.
|
Tuple2<K,V> |
head()
Returns the first element of a non-empty Traversable.
|
TreeMap<K,V> |
init()
Dual of Traversable.tail(), returning all elements except the last.
|
Option<TreeMap<K,V>> |
initOption()
Dual of Traversable.tailOption(), returning all elements except the last as
Option . |
boolean |
isEmpty()
Checks if this Traversable is empty.
|
Iterator<Tuple2<K,V>> |
iterator()
An iterator by means of head() and tail().
|
Comparator<K> |
keyComparator()
Returns the underlying key-comparator which defines the order of the elements contained in this map.
|
SortedSet<K> |
keySet()
Returns the keys contained in this map.
|
<K2,V2> TreeMap<K2,V2> |
map(BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
Maps the entries of this
Map to form a new Map . |
<K2,V2> TreeMap<K2,V2> |
map(Comparator<? super K2> keyComparator,
BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
Same as
SortedMap.map(BiFunction) , using a specific comparator for keys of the codomain of the given
mapper . |
<K2> TreeMap<K2,V> |
mapKeys(Function<? super K,? extends K2> keyMapper)
Maps the keys of this
Map while preserving the corresponding values. |
<K2> TreeMap<K2,V> |
mapKeys(Function<? super K,? extends K2> keyMapper,
BiFunction<? super V,? super V,? extends V> valueMerge)
Maps the keys of this
Map while preserving the corresponding values and applying a value merge function on collisions. |
<W> TreeMap<K,W> |
mapValues(Function<? super V,? extends W> valueMapper)
Maps the values of this
Map while preserving the corresponding keys. |
TreeMap<K,V> |
merge(Map<? extends K,? extends V> that)
Creates a new map which by merging the entries of
this map and that map. |
<U extends V> |
merge(Map<? extends K,U> that,
BiFunction<? super V,? super U,? extends V> collisionResolution)
Creates a new map which by merging the entries of
this map and that map. |
static <K,V> TreeMap<K,V> |
narrow(TreeMap<? extends K,? extends V> treeMap)
Narrows a widened
TreeMap<? extends K, ? extends V> to TreeMap<K, V>
by performing a type-safe cast. |
static <K,V> TreeMap<K,V> |
of(Comparator<? super K> keyComparator,
K key,
V value)
Returns a singleton
TreeMap , i.e. |
static <K,V> TreeMap<K,V> |
of(Comparator<? super K> keyComparator,
K k1,
V v1,
K k2,
V v2)
Creates a
TreeMap of the given list of key-value pairs. |
static <K,V> TreeMap<K,V> |
of(Comparator<? super K> keyComparator,
K k1,
V v1,
K k2,
V v2,
K k3,
V v3)
Creates a
TreeMap of the given list of key-value pairs. |
static <K,V> TreeMap<K,V> |
of(Comparator<? super K> keyComparator,
K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4)
Creates a
TreeMap of the given list of key-value pairs. |
static <K,V> TreeMap<K,V> |
of(Comparator<? super K> keyComparator,
K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5)
Creates a
TreeMap of the given list of key-value pairs. |
static <K,V> TreeMap<K,V> |
of(Comparator<? super K> keyComparator,
K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6)
Creates a
TreeMap of the given list of key-value pairs. |
static <K,V> TreeMap<K,V> |
of(Comparator<? super K> keyComparator,
K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7)
Creates a
TreeMap of the given list of key-value pairs. |
static <K,V> TreeMap<K,V> |
of(Comparator<? super K> keyComparator,
K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8)
Creates a
TreeMap of the given list of key-value pairs. |
static <K,V> TreeMap<K,V> |
of(Comparator<? super K> keyComparator,
K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8,
K k9,
V v9)
Creates a
TreeMap of the given list of key-value pairs. |
static <K,V> TreeMap<K,V> |
of(Comparator<? super K> keyComparator,
K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8,
K k9,
V v9,
K k10,
V v10)
Creates a
TreeMap of the given list of key-value pairs. |
static <K,V> TreeMap<K,V> |
of(Comparator<? super K> keyComparator,
Tuple2<? extends K,? extends V> entry)
Returns a singleton
TreeMap , i.e. |
static <K extends Comparable<? super K>,V> |
of(K key,
V value)
Returns a singleton
TreeMap , i.e. |
static <K extends Comparable<? super K>,V> |
of(K k1,
V v1,
K k2,
V v2)
Creates a
TreeMap of the given list of key-value pairs. |
static <K extends Comparable<? super K>,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3)
Creates a
TreeMap of the given list of key-value pairs. |
static <K extends Comparable<? super K>,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4)
Creates a
TreeMap of the given list of key-value pairs. |
static <K extends Comparable<? super K>,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5)
Creates a
TreeMap of the given list of key-value pairs. |
static <K extends Comparable<? super K>,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6)
Creates a
TreeMap of the given list of key-value pairs. |
static <K extends Comparable<? super K>,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7)
Creates a
TreeMap of the given list of key-value pairs. |
static <K extends Comparable<? super K>,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8)
Creates a
TreeMap of the given list of key-value pairs. |
static <K extends Comparable<? super K>,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8,
K k9,
V v9)
Creates a
TreeMap of the given list of key-value pairs. |
static <K extends Comparable<? super K>,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8,
K k9,
V v9,
K k10,
V v10)
Creates a
TreeMap of the given list of key-value pairs. |
static <K extends Comparable<? super K>,V> |
of(Tuple2<? extends K,? extends V> entry)
Returns a singleton
TreeMap , i.e. |
static <K,V> TreeMap<K,V> |
ofAll(Comparator<? super K> keyComparator,
Map<? extends K,? extends V> map)
Returns a
TreeMap , from a source java.util.Map. |
static <T,K,V> TreeMap<K,V> |
ofAll(Comparator<? super K> keyComparator,
Stream<? extends T> stream,
Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper)
Returns a
TreeMap , from entries mapped from stream. |
static <T,K,V> TreeMap<K,V> |
ofAll(Comparator<? super K> keyComparator,
Stream<? extends T> stream,
Function<? super T,Tuple2<? extends K,? extends V>> entryMapper)
Returns a
TreeMap , from entries mapped from stream. |
static <K extends Comparable<? super K>,V> |
ofAll(Map<? extends K,? extends V> map)
Returns a
TreeMap , from a source java.util.Map. |
static <T,K extends Comparable<? super K>,V> |
ofAll(Stream<? extends T> stream,
Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper)
Returns a
TreeMap , from entries mapped from stream. |
static <T,K extends Comparable<? super K>,V> |
ofAll(Stream<? extends T> stream,
Function<? super T,Tuple2<? extends K,? extends V>> entryMapper)
Returns a
TreeMap , from entries mapped from stream. |
static <K,V> TreeMap<K,V> |
ofEntries(Comparator<? super K> keyComparator,
Iterable<? extends Tuple2<? extends K,? extends V>> entries)
Creates a
TreeMap of the given entries. |
static <K,V> TreeMap<K,V> |
ofEntries(Comparator<? super K> keyComparator,
Map.Entry<? extends K,? extends V>... entries)
Creates a
TreeMap of the given entries using the given key comparator. |
static <K,V> TreeMap<K,V> |
ofEntries(Comparator<? super K> keyComparator,
Tuple2<? extends K,? extends V>... entries)
Creates a
TreeMap of the given entries using the given key comparator. |
static <K extends Comparable<? super K>,V> |
ofEntries(Iterable<? extends Tuple2<? extends K,? extends V>> entries)
Creates a
TreeMap of the given entries. |
static <K extends Comparable<? super K>,V> |
ofEntries(Map.Entry<? extends K,? extends V>... entries)
Creates a
TreeMap of the given entries using the natural key comparator. |
static <K extends Comparable<? super K>,V> |
ofEntries(Tuple2<? extends K,? extends V>... entries)
Creates a
TreeMap of the given entries using the natural key comparator. |
Tuple2<TreeMap<K,V>,TreeMap<K,V>> |
partition(Predicate<? super Tuple2<K,V>> predicate)
Creates a partition of this
Traversable by splitting this elements in two in distinct tarversables
according to a predicate. |
TreeMap<K,V> |
peek(Consumer<? super Tuple2<K,V>> action)
Performs the given
action on the first element if this is an eager implementation. |
<U extends V> |
put(K key,
U value,
BiFunction<? super V,? super U,? extends V> merge)
Associates the specified value with the specified key in this map.
|
TreeMap<K,V> |
put(K key,
V value)
Associates the specified value with the specified key in this map.
|
TreeMap<K,V> |
put(Tuple2<? extends K,? extends V> entry)
Convenience method for
put(entry._1, entry._2) . |
<U extends V> |
put(Tuple2<? extends K,U> entry,
BiFunction<? super V,? super U,? extends V> merge)
Convenience method for
put(entry._1, entry._2, merge) . |
TreeMap<K,V> |
remove(K key)
Removes the mapping for a key from this map if it is present.
|
TreeMap<K,V> |
removeAll(BiPredicate<? super K,? super V> predicate)
Returns a new Map consisting of all elements which do not satisfy the given predicate.
|
TreeMap<K,V> |
removeAll(Iterable<? extends K> keys)
Removes the mapping for a key from this map if it is present.
|
TreeMap<K,V> |
removeKeys(Predicate<? super K> predicate)
Returns a new Map consisting of all elements with keys which do not satisfy the given predicate.
|
TreeMap<K,V> |
removeValues(Predicate<? super V> predicate)
Returns a new Map consisting of all elements with values which do not satisfy the given predicate.
|
TreeMap<K,V> |
replace(K key,
V oldValue,
V newValue)
Replaces the entry for the specified key only if currently mapped to the specified value.
|
TreeMap<K,V> |
replace(Tuple2<K,V> currentElement,
Tuple2<K,V> newElement)
Replaces the first occurrence (if exists) of the given currentElement with newElement.
|
TreeMap<K,V> |
replaceAll(BiFunction<? super K,? super V,? extends V> function)
Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.
|
TreeMap<K,V> |
replaceAll(Tuple2<K,V> currentElement,
Tuple2<K,V> newElement)
Replaces all occurrences of the given currentElement with newElement.
|
TreeMap<K,V> |
replaceValue(K key,
V value)
Replaces the entry for the specified key only if it is currently mapped to some value.
|
TreeMap<K,V> |
retainAll(Iterable<? extends Tuple2<K,V>> elements)
Keeps all occurrences of the given elements from this.
|
TreeMap<K,V> |
scan(Tuple2<K,V> zero,
BiFunction<? super Tuple2<K,V>,? super Tuple2<K,V>,? extends Tuple2<K,V>> operation)
Computes a prefix scan of the elements of the collection.
|
int |
size()
Computes the number of elements of this Traversable.
|
Iterator<TreeMap<K,V>> |
sliding(int size)
Slides a window of a specific
size and step size 1 over this Traversable by calling
Traversable.sliding(int, int) . |
Iterator<TreeMap<K,V>> |
sliding(int size,
int step)
Slides a window of a specific
size and step size over this Traversable . |
Tuple2<TreeMap<K,V>,TreeMap<K,V>> |
span(Predicate<? super Tuple2<K,V>> predicate)
Returns a tuple where the first element is the longest prefix of elements that satisfy the given
predicate and the second element is the remainder. |
String |
stringPrefix()
Returns the name of this Value type, which is used by toString().
|
static <K,V> TreeMap<K,V> |
tabulate(Comparator<? super K> keyComparator,
int n,
Function<? super Integer,? extends Tuple2<? extends K,? extends V>> f)
Returns a TreeMap containing
n values of a given Function f
over a range of integer values from 0 to n - 1 . |
static <K extends Comparable<? super K>,V> |
tabulate(int n,
Function<? super Integer,? extends Tuple2<? extends K,? extends V>> f)
Returns a TreeMap containing
n values of a given Function f
over a range of integer values from 0 to n - 1 . |
TreeMap<K,V> |
tail()
Drops the first element of a non-empty Traversable.
|
Option<TreeMap<K,V>> |
tailOption()
Drops the first element of a non-empty Traversable and returns an
Option . |
TreeMap<K,V> |
take(int n)
Takes the first n elements of this or all elements, if this length < n.
|
TreeMap<K,V> |
takeRight(int n)
Takes the last n elements of this or all elements, if this length < n.
|
TreeMap<K,V> |
takeUntil(Predicate<? super Tuple2<K,V>> predicate)
Takes elements until the predicate holds for the current element.
|
TreeMap<K,V> |
takeWhile(Predicate<? super Tuple2<K,V>> predicate)
Takes elements while the predicate holds for the current element.
|
TreeMap<K,V> |
toJavaMap()
Converts this Javaslang
Map to a java.util.Map while preserving characteristics
like insertion order (LinkedHashMap ) and sort order (SortedMap ). |
String |
toString()
Clarifies that values have a proper toString() method implemented.
|
Seq<V> |
values() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
apply, contains, containsValue, entry, flatMap, foldRight, forEach, hasDefiniteSize, isDistinct, isTraversableAgain, length, lift, map, narrow, scanLeft, scanRight, spliterator, transform, traverse, unzip, unzip, unzip, unzip3, unzip3, withDefault, withDefaultValue, zip, zipAll, zipWith, zipWithIndex, zipWithIndex
average, containsAll, count, existsUnique, find, findLast, foldLeft, get, hash, headOption, isSingleValued, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, narrow, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, sum
fold, reduce, reduceOption
collect, collect, corresponds, eq, exists, forAll, forEach, getOption, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, narrow, out, out, stderr, stdout, toArray, toCharSeq, toEither, toEither, toInvalid, toInvalid, toJavaArray, toJavaArray, toJavaCollection, toJavaList, toJavaList, toJavaMap, toJavaMap, toJavaMap, toJavaOptional, toJavaParallelStream, toJavaSet, toJavaSet, toJavaStream, toLeft, toLeft, toLinkedMap, toLinkedMap, toLinkedSet, toList, toMap, toMap, toOption, toPriorityQueue, toPriorityQueue, toQueue, toRight, toRight, toSet, toSortedMap, toSortedMap, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toStack, toStream, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
andThen, arity, compose, constant, curried, identity, lift, liftTry, memoized, of, reversed, tupled
isMemoized
public static <K extends Comparable<? super K>,V> Collector<Tuple2<K,V>,ArrayList<Tuple2<K,V>>,TreeMap<K,V>> collector()
Collector
which may be used in conjunction with
Stream.collect(Collector)
to obtain a
TreeMap
.
The natural comparator is used to compare TreeMap keys.
K
- The key typeV
- The value typeTreeMap
Collector.public static <K,V> Collector<Tuple2<K,V>,ArrayList<Tuple2<K,V>>,TreeMap<K,V>> collector(Comparator<? super K> keyComparator)
Collector
which may be used in conjunction with
Stream.collect(Collector)
to obtain a
TreeMap
.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.TreeMap
Collector.public static <K extends Comparable<? super K>,V> TreeMap<K,V> empty()
K
- The key typeV
- The value typepublic static <K,V> TreeMap<K,V> empty(Comparator<? super K> keyComparator)
K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.public static <K,V> TreeMap<K,V> narrow(TreeMap<? extends K,? extends V> treeMap)
TreeMap<? extends K, ? extends V>
to TreeMap<K, V>
by performing a type-safe cast. This is eligible because immutable/read-only
collections are covariant.
CAUTION: If K
is narrowed, the underlying Comparator
might fail!
K
- Key typeV
- Value typetreeMap
- A TreeMap
.treeMap
instance as narrowed type TreeMap<K, V>
.public static <K extends Comparable<? super K>,V> TreeMap<K,V> of(Tuple2<? extends K,? extends V> entry)
TreeMap
, i.e. a TreeMap
of one entry.
The underlying key comparator is the natural comparator of K.K
- The key typeV
- The value typeentry
- A map entry.public static <K,V> TreeMap<K,V> of(Comparator<? super K> keyComparator, Tuple2<? extends K,? extends V> entry)
TreeMap
, i.e. a TreeMap
of one entry using a specific key comparator.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.entry
- A map entry.public static <K extends Comparable<? super K>,V> TreeMap<K,V> ofAll(Map<? extends K,? extends V> map)
TreeMap
, from a source java.util.Map.K
- The key typeV
- The value typemap
- A map entry.public static <T,K extends Comparable<? super K>,V> TreeMap<K,V> ofAll(Stream<? extends T> stream, Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper)
TreeMap
, from entries mapped from stream.T
- The stream typeK
- The key typeV
- The value typestream
- the source streamkeyMapper
- the key mappervalueMapper
- the value mapperpublic static <T,K,V> TreeMap<K,V> ofAll(Comparator<? super K> keyComparator, Stream<? extends T> stream, Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper)
TreeMap
, from entries mapped from stream.T
- The stream typeK
- The key typeV
- The value typestream
- the source streamkeyMapper
- the key mappervalueMapper
- the value mapperpublic static <T,K extends Comparable<? super K>,V> TreeMap<K,V> ofAll(Stream<? extends T> stream, Function<? super T,Tuple2<? extends K,? extends V>> entryMapper)
TreeMap
, from entries mapped from stream.T
- The stream typeK
- The key typeV
- The value typestream
- the source streamentryMapper
- the entry mapperpublic static <T,K,V> TreeMap<K,V> ofAll(Comparator<? super K> keyComparator, Stream<? extends T> stream, Function<? super T,Tuple2<? extends K,? extends V>> entryMapper)
TreeMap
, from entries mapped from stream.T
- The stream typeK
- The key typeV
- The value typestream
- the source streamentryMapper
- the entry mapperpublic static <K,V> TreeMap<K,V> ofAll(Comparator<? super K> keyComparator, Map<? extends K,? extends V> map)
TreeMap
, from a source java.util.Map.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.map
- A map entry.public static <K extends Comparable<? super K>,V> TreeMap<K,V> of(K key, V value)
TreeMap
, i.e. a TreeMap
of one element.K
- The key typeV
- The value typekey
- A singleton map key.value
- A singleton map value.public static <K extends Comparable<? super K>,V> TreeMap<K,V> of(K k1, V v1, K k2, V v2)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typek1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2public static <K extends Comparable<? super K>,V> TreeMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typek1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3public static <K extends Comparable<? super K>,V> TreeMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typek1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4public static <K extends Comparable<? super K>,V> TreeMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typek1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4k5
- a key for the mapv5
- the value for k5public static <K extends Comparable<? super K>,V> TreeMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typek1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4k5
- a key for the mapv5
- the value for k5k6
- a key for the mapv6
- the value for k6public static <K extends Comparable<? super K>,V> TreeMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typek1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4k5
- a key for the mapv5
- the value for k5k6
- a key for the mapv6
- the value for k6k7
- a key for the mapv7
- the value for k7public static <K extends Comparable<? super K>,V> TreeMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typek1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4k5
- a key for the mapv5
- the value for k5k6
- a key for the mapv6
- the value for k6k7
- a key for the mapv7
- the value for k7k8
- a key for the mapv8
- the value for k8public static <K extends Comparable<? super K>,V> TreeMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typek1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4k5
- a key for the mapv5
- the value for k5k6
- a key for the mapv6
- the value for k6k7
- a key for the mapv7
- the value for k7k8
- a key for the mapv8
- the value for k8k9
- a key for the mapv9
- the value for k9public static <K extends Comparable<? super K>,V> TreeMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typek1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4k5
- a key for the mapv5
- the value for k5k6
- a key for the mapv6
- the value for k6k7
- a key for the mapv7
- the value for k7k8
- a key for the mapv8
- the value for k8k9
- a key for the mapv9
- the value for k9k10
- a key for the mapv10
- the value for k10public static <K,V> TreeMap<K,V> of(Comparator<? super K> keyComparator, K key, V value)
TreeMap
, i.e. a TreeMap
of one element.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.key
- A singleton map key.value
- A singleton map value.public static <K,V> TreeMap<K,V> of(Comparator<? super K> keyComparator, K k1, V v1, K k2, V v2)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.k1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2public static <K,V> TreeMap<K,V> of(Comparator<? super K> keyComparator, K k1, V v1, K k2, V v2, K k3, V v3)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.k1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3public static <K,V> TreeMap<K,V> of(Comparator<? super K> keyComparator, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.k1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4public static <K,V> TreeMap<K,V> of(Comparator<? super K> keyComparator, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.k1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4k5
- a key for the mapv5
- the value for k5public static <K,V> TreeMap<K,V> of(Comparator<? super K> keyComparator, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.k1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4k5
- a key for the mapv5
- the value for k5k6
- a key for the mapv6
- the value for k6public static <K,V> TreeMap<K,V> of(Comparator<? super K> keyComparator, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.k1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4k5
- a key for the mapv5
- the value for k5k6
- a key for the mapv6
- the value for k6k7
- a key for the mapv7
- the value for k7public static <K,V> TreeMap<K,V> of(Comparator<? super K> keyComparator, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.k1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4k5
- a key for the mapv5
- the value for k5k6
- a key for the mapv6
- the value for k6k7
- a key for the mapv7
- the value for k7k8
- a key for the mapv8
- the value for k8public static <K,V> TreeMap<K,V> of(Comparator<? super K> keyComparator, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.k1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4k5
- a key for the mapv5
- the value for k5k6
- a key for the mapv6
- the value for k6k7
- a key for the mapv7
- the value for k7k8
- a key for the mapv8
- the value for k8k9
- a key for the mapv9
- the value for k9public static <K,V> TreeMap<K,V> of(Comparator<? super K> keyComparator, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10)
TreeMap
of the given list of key-value pairs.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.k1
- a key for the mapv1
- the value for k1k2
- a key for the mapv2
- the value for k2k3
- a key for the mapv3
- the value for k3k4
- a key for the mapv4
- the value for k4k5
- a key for the mapv5
- the value for k5k6
- a key for the mapv6
- the value for k6k7
- a key for the mapv7
- the value for k7k8
- a key for the mapv8
- the value for k8k9
- a key for the mapv9
- the value for k9k10
- a key for the mapv10
- the value for k10public static <K,V> TreeMap<K,V> tabulate(Comparator<? super K> keyComparator, int n, Function<? super Integer,? extends Tuple2<? extends K,? extends V>> f)
n
values of a given Function f
over a range of integer values from 0 to n - 1
.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their keyn
- The number of elements in the TreeMapf
- The Function computing element valuesf(0),f(1), ..., f(n - 1)
NullPointerException
- if keyComparator
or f
are nullpublic static <K extends Comparable<? super K>,V> TreeMap<K,V> tabulate(int n, Function<? super Integer,? extends Tuple2<? extends K,? extends V>> f)
n
values of a given Function f
over a range of integer values from 0 to n - 1
.
The underlying key comparator is the natural comparator of K.K
- The key typeV
- The value typen
- The number of elements in the TreeMapf
- The Function computing element valuesf(0),f(1), ..., f(n - 1)
NullPointerException
- if f
is nullpublic static <K,V> TreeMap<K,V> fill(Comparator<? super K> keyComparator, int n, Supplier<? extends Tuple2<? extends K,? extends V>> s)
n
values supplied by a given Supplier s
.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their keyn
- The number of elements in the TreeMaps
- The Supplier computing element valuesn
, where each element contains the result supplied by s
.NullPointerException
- if keyComparator
or s
are nullpublic static <K extends Comparable<? super K>,V> TreeMap<K,V> fill(int n, Supplier<? extends Tuple2<? extends K,? extends V>> s)
n
values supplied by a given Supplier s
.
The underlying key comparator is the natural comparator of K.K
- The key typeV
- The value typen
- The number of elements in the TreeMaps
- The Supplier computing element valuesn
, where each element contains the result supplied by s
.NullPointerException
- if s
is null@SafeVarargs public static <K extends Comparable<? super K>,V> TreeMap<K,V> ofEntries(Tuple2<? extends K,? extends V>... entries)
TreeMap
of the given entries using the natural key comparator.K
- The key typeV
- The value typeentries
- Map entries@SafeVarargs public static <K,V> TreeMap<K,V> ofEntries(Comparator<? super K> keyComparator, Tuple2<? extends K,? extends V>... entries)
TreeMap
of the given entries using the given key comparator.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.entries
- Map entries@SafeVarargs public static <K extends Comparable<? super K>,V> TreeMap<K,V> ofEntries(Map.Entry<? extends K,? extends V>... entries)
TreeMap
of the given entries using the natural key comparator.K
- The key typeV
- The value typeentries
- Map entries@SafeVarargs public static <K,V> TreeMap<K,V> ofEntries(Comparator<? super K> keyComparator, Map.Entry<? extends K,? extends V>... entries)
TreeMap
of the given entries using the given key comparator.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.entries
- Map entriespublic static <K extends Comparable<? super K>,V> TreeMap<K,V> ofEntries(Iterable<? extends Tuple2<? extends K,? extends V>> entries)
TreeMap
of the given entries.K
- The key typeV
- The value typeentries
- Map entriespublic static <K,V> TreeMap<K,V> ofEntries(Comparator<? super K> keyComparator, Iterable<? extends Tuple2<? extends K,? extends V>> entries)
TreeMap
of the given entries.K
- The key typeV
- The value typekeyComparator
- The comparator used to sort the entries by their key.entries
- Map entriespublic <K2,V2> TreeMap<K2,V2> bimap(Function<? super K,? extends K2> keyMapper, Function<? super V,? extends V2> valueMapper)
Map
Map
to a new Map
with different component type by applying a function to its elements.bimap
in interface Map<K,V>
bimap
in interface SortedMap<K,V>
K2
- key's component type of the map resultV2
- value's component type of the map resultkeyMapper
- a Function
that maps the keys of type K
to keys of type K2
valueMapper
- a Function
that the values of type V
to values of type V2
Map
public <K2,V2> TreeMap<K2,V2> bimap(Comparator<? super K2> keyComparator, Function<? super K,? extends K2> keyMapper, Function<? super V,? extends V2> valueMapper)
SortedMap
SortedMap.bimap(Function, Function)
, using a specific comparator for keys of the codomain of the given
keyMapper
.bimap
in interface SortedMap<K,V>
K2
- key's component type of the map resultV2
- value's component type of the map resultkeyComparator
- A comparator for keys of type K2keyMapper
- a Function
that maps the keys of type K
to keys of type K2
valueMapper
- a Function
that the values of type V
to values of type V2
SortedMap
public Tuple2<V,TreeMap<K,V>> computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
Map
computeIfAbsent
in interface Map<K,V>
computeIfAbsent
in interface SortedMap<K,V>
key
- key whose presence in this map is to be testedmappingFunction
- mapping functionTuple2
of current or modified map and existing or computed value associated with the specified keypublic Tuple2<Option<V>,TreeMap<K,V>> computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
Map
computeIfPresent
in interface Map<K,V>
computeIfPresent
in interface SortedMap<K,V>
key
- key whose presence in this map is to be testedremappingFunction
- remapping functionTuple2
of current or modified map and the Some
of the value associated
with the specified key, or None
if nonepublic boolean containsKey(K key)
Map
true
if this map contains a mapping for the specified key.containsKey
in interface Map<K,V>
key
- key whose presence in this map is to be testedtrue
if this map contains a mapping for the specified keypublic TreeMap<K,V> distinct()
Traversable
equals
.public TreeMap<K,V> distinctBy(Comparator<? super Tuple2<K,V>> comparator)
Traversable
comparator
.distinctBy
in interface Map<K,V>
distinctBy
in interface SortedMap<K,V>
distinctBy
in interface Traversable<Tuple2<K,V>>
comparator
- A comparatorTraversable
containing this elements without duplicatespublic <U> TreeMap<K,V> distinctBy(Function<? super Tuple2<K,V>,? extends U> keyExtractor)
Traversable
equals
.
The elements of the result are determined in the order of their occurrence - first match wins.
distinctBy
in interface Map<K,V>
distinctBy
in interface SortedMap<K,V>
distinctBy
in interface Traversable<Tuple2<K,V>>
U
- key typekeyExtractor
- A key extractorTraversable
containing this elements without duplicatespublic TreeMap<K,V> drop(int n)
Traversable
drop
in interface Map<K,V>
drop
in interface SortedMap<K,V>
drop
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to drop.public TreeMap<K,V> dropRight(int n)
Traversable
dropRight
in interface Map<K,V>
dropRight
in interface SortedMap<K,V>
dropRight
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to drop.public TreeMap<K,V> dropUntil(Predicate<? super Tuple2<K,V>> predicate)
Traversable
Note: This is essentially the same as dropWhile(predicate.negate())
. It is intended to be used with
method references, which cannot be negated directly.
dropUntil
in interface Map<K,V>
dropUntil
in interface SortedMap<K,V>
dropUntil
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements.public TreeMap<K,V> dropWhile(Predicate<? super Tuple2<K,V>> predicate)
Traversable
dropWhile
in interface Map<K,V>
dropWhile
in interface SortedMap<K,V>
dropWhile
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements starting with the first.public TreeMap<K,V> filter(BiPredicate<? super K,? super V> predicate)
Map
public TreeMap<K,V> filter(Predicate<? super Tuple2<K,V>> predicate)
Traversable
public TreeMap<K,V> filterKeys(Predicate<? super K> predicate)
Map
filterKeys
in interface Map<K,V>
filterKeys
in interface SortedMap<K,V>
predicate
- the predicate used to test keys of elementspublic TreeMap<K,V> filterValues(Predicate<? super V> predicate)
Map
filterValues
in interface Map<K,V>
filterValues
in interface SortedMap<K,V>
predicate
- the predicate used to test values of elementspublic <K2,V2> TreeMap<K2,V2> flatMap(BiFunction<? super K,? super V,? extends Iterable<Tuple2<K2,V2>>> mapper)
Map
Map
to a new Map
with different component type.public <K2,V2> TreeMap<K2,V2> flatMap(Comparator<? super K2> keyComparator, BiFunction<? super K,? super V,? extends Iterable<Tuple2<K2,V2>>> mapper)
SortedMap
SortedMap.flatMap(BiFunction)
but using a specific comparator for values of the codomain of the given
mapper
.public Option<V> get(K key)
Map
Some
of value to which the specified key
is mapped, or None
if this map contains no mapping for the key.public V getOrElse(K key, V defaultValue)
Map
public <C> Map<C,TreeMap<K,V>> groupBy(Function<? super Tuple2<K,V>,? extends C> classifier)
Traversable
groupBy
in interface Map<K,V>
groupBy
in interface SortedMap<K,V>
groupBy
in interface Traversable<Tuple2<K,V>>
C
- classified class typeclassifier
- A function which classifies elements into classespublic Iterator<TreeMap<K,V>> grouped(int size)
Traversable
Traversable
into fixed size blocks.
Let length be the length of this Iterable. Then grouped is defined as follows:
this.isEmpty()
, the resulting Iterator
is empty.size <= length
, the resulting Iterator
will contain length / size
blocks of size
size
and maybe a non-empty block of size length % size
, if there are remaining elements.size > length
, the resulting Iterator
will contain one block of size length
.
[].grouped(1) = []
[].grouped(0) throws
[].grouped(-1) throws
[1,2,3,4].grouped(2) = [[1,2],[3,4]]
[1,2,3,4,5].grouped(2) = [[1,2],[3,4],[5]]
[1,2,3,4].grouped(5) = [[1,2,3,4]]
Please note that grouped(int)
is a special case of Traversable.sliding(int, int), i.e.
grouped(size)
is the same as sliding(size, size)
.public Tuple2<K,V> head()
Traversable
head
in interface Traversable<Tuple2<K,V>>
public TreeMap<K,V> init()
Traversable
public Option<TreeMap<K,V>> initOption()
Traversable
Option
.initOption
in interface Map<K,V>
initOption
in interface SortedMap<K,V>
initOption
in interface Traversable<Tuple2<K,V>>
Some(traversable)
or None
if this is empty.public boolean isEmpty()
Traversable
public Iterator<Tuple2<K,V>> iterator()
Traversable
public Comparator<K> keyComparator()
SortedMap
keyComparator
in interface SortedMap<K,V>
public SortedSet<K> keySet()
Map
public <K2,V2> TreeMap<K2,V2> map(BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
Map
Map
to form a new Map
.map
in interface Map<K,V>
map
in interface SortedMap<K,V>
K2
- key's component type of the map resultV2
- value's component type of the map resultmapper
- a Function
that maps entries of type (K, V)
to entries of type (K2, V2)
Map
public <K2,V2> TreeMap<K2,V2> map(Comparator<? super K2> keyComparator, BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
SortedMap
SortedMap.map(BiFunction)
, using a specific comparator for keys of the codomain of the given
mapper
.map
in interface SortedMap<K,V>
K2
- key's component type of the map resultV2
- value's component type of the map resultkeyComparator
- A comparator for keys of type Umapper
- a Function
that maps entries of type (K, V)
to entries of type (K2, V2)
SortedMap
public <K2> TreeMap<K2,V> mapKeys(Function<? super K,? extends K2> keyMapper)
Map
Map
while preserving the corresponding values.
The size of the result map may be smaller if keyMapper
maps two or more distinct keys to the same new key.
In this case the value at the latest
of the original keys is retained.
Order of keys is predictable in TreeMap
(by comparator) and LinkedHashMap
(insertion-order) and not predictable in HashMap
.
public <K2> TreeMap<K2,V> mapKeys(Function<? super K,? extends K2> keyMapper, BiFunction<? super V,? super V,? extends V> valueMerge)
Map
Map
while preserving the corresponding values and applying a value merge function on collisions.
The size of the result map may be smaller if keyMapper
maps two or more distinct keys to the same new key.
In this case the associated values will be combined using valueMerge
.
public <W> TreeMap<K,W> mapValues(Function<? super V,? extends W> valueMapper)
Map
Map
while preserving the corresponding keys.public TreeMap<K,V> merge(Map<? extends K,? extends V> that)
Map
this
map and that
map.
If collisions occur, the value of this
map is taken.
public <U extends V> TreeMap<K,V> merge(Map<? extends K,U> that, BiFunction<? super V,? super U,? extends V> collisionResolution)
Map
this
map and that
map.
Uses the specified collision resolution function if two keys are the same.
The collision resolution function will always take the first argument from this
map
and the second from that
map.
public Tuple2<TreeMap<K,V>,TreeMap<K,V>> partition(Predicate<? super Tuple2<K,V>> predicate)
Traversable
Traversable
by splitting this elements in two in distinct tarversables
according to a predicate.partition
in interface Map<K,V>
partition
in interface SortedMap<K,V>
partition
in interface Traversable<Tuple2<K,V>>
predicate
- A predicate which classifies an element if it is in the first or the second traversable.Traversable
contains all elements that satisfy the given predicate
, the second Traversable
contains all elements that don't. The original order of elements is preserved.public TreeMap<K,V> peek(Consumer<? super Tuple2<K,V>> action)
Value
action
on the first element if this is an eager implementation.
Performs the given action
on all elements (the first immediately, successive deferred),
if this is a lazy implementation.public <U extends V> TreeMap<K,V> put(K key, U value, BiFunction<? super V,? super U,? extends V> merge)
Map
put
in interface Map<K,V>
U
- the value typekey
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keymerge
- function taking the old and new values and merging them.public TreeMap<K,V> put(K key, V value)
Map
public TreeMap<K,V> put(Tuple2<? extends K,? extends V> entry)
Map
put(entry._1, entry._2)
.public <U extends V> TreeMap<K,V> put(Tuple2<? extends K,U> entry, BiFunction<? super V,? super U,? extends V> merge)
Map
put(entry._1, entry._2, merge)
.public TreeMap<K,V> remove(K key)
Map
public TreeMap<K,V> removeAll(BiPredicate<? super K,? super V> predicate)
Map
public TreeMap<K,V> removeAll(Iterable<? extends K> keys)
Map
public TreeMap<K,V> removeKeys(Predicate<? super K> predicate)
Map
removeKeys
in interface Map<K,V>
removeKeys
in interface SortedMap<K,V>
predicate
- the predicate used to test keys of elementspublic TreeMap<K,V> removeValues(Predicate<? super V> predicate)
Map
removeValues
in interface Map<K,V>
removeValues
in interface SortedMap<K,V>
predicate
- the predicate used to test values of elementspublic TreeMap<K,V> replace(Tuple2<K,V> currentElement, Tuple2<K,V> newElement)
Traversable
replace
in interface Map<K,V>
replace
in interface SortedMap<K,V>
replace
in interface Traversable<Tuple2<K,V>>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.public TreeMap<K,V> replaceAll(Tuple2<K,V> currentElement, Tuple2<K,V> newElement)
Traversable
replaceAll
in interface Map<K,V>
replaceAll
in interface SortedMap<K,V>
replaceAll
in interface Traversable<Tuple2<K,V>>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.public TreeMap<K,V> replaceValue(K key, V value)
Map
replaceValue
in interface Map<K,V>
key
- the key of the element to be substituted.value
- the new value to be associated with the keypublic TreeMap<K,V> replace(K key, V oldValue, V newValue)
Map
replace
in interface Map<K,V>
key
- the key of the element to be substituted.oldValue
- the expected current value that the key is currently mapped tonewValue
- the new value to be associated with the keypublic TreeMap<K,V> replaceAll(BiFunction<? super K,? super V,? extends V> function)
Map
replaceAll
in interface Map<K,V>
function
- function transforming key and current value to a new valuepublic TreeMap<K,V> retainAll(Iterable<? extends Tuple2<K,V>> elements)
Traversable
public TreeMap<K,V> scan(Tuple2<K,V> zero, BiFunction<? super Tuple2<K,V>,? super Tuple2<K,V>,? extends Tuple2<K,V>> operation)
Traversable
scan
in interface Map<K,V>
scan
in interface SortedMap<K,V>
scan
in interface Traversable<Tuple2<K,V>>
zero
- neutral element for the operator opoperation
- the associative operator for the scanpublic int size()
Traversable
Same as Traversable.length()
.
public Iterator<TreeMap<K,V>> sliding(int size)
Traversable
size
and step size 1 over this Traversable
by calling
Traversable.sliding(int, int)
.public Iterator<TreeMap<K,V>> sliding(int size, int step)
Traversable
size
and step
size over this Traversable
.
Examples:
[].sliding(1,1) = []
[1,2,3,4,5].sliding(2,3) = [[1,2],[4,5]]
[1,2,3,4,5].sliding(2,4) = [[1,2],[5]]
[1,2,3,4,5].sliding(2,5) = [[1,2]]
[1,2,3,4].sliding(5,3) = [[1,2,3,4],[4]]
sliding
in interface Map<K,V>
sliding
in interface SortedMap<K,V>
sliding
in interface Traversable<Tuple2<K,V>>
size
- a positive window sizestep
- a positive step sizepublic Tuple2<TreeMap<K,V>,TreeMap<K,V>> span(Predicate<? super Tuple2<K,V>> predicate)
Traversable
predicate
and the second element is the remainder.public TreeMap<K,V> tail()
Traversable
public Option<TreeMap<K,V>> tailOption()
Traversable
Option
.tailOption
in interface Map<K,V>
tailOption
in interface SortedMap<K,V>
tailOption
in interface Traversable<Tuple2<K,V>>
Some(traversable)
or None
if this is empty.public TreeMap<K,V> take(int n)
Traversable
The result is equivalent to sublist(0, max(0, min(length(), n)))
but does not throw if n < 0
or
n > length()
.
In the case of n < 0
the empty instance is returned, in the case of n > length()
this is returned.
take
in interface Map<K,V>
take
in interface SortedMap<K,V>
take
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to take.public TreeMap<K,V> takeRight(int n)
Traversable
The result is equivalent to sublist(max(0, min(length(), length() - n)), n)
, i.e. takeRight will not
throw if n < 0
or n > length()
.
In the case of n < 0
the empty instance is returned, in the case of n > length()
this is returned.
takeRight
in interface Map<K,V>
takeRight
in interface SortedMap<K,V>
takeRight
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to take.public TreeMap<K,V> takeUntil(Predicate<? super Tuple2<K,V>> predicate)
Traversable
Note: This is essentially the same as takeWhile(predicate.negate())
. It is intended to be used with
method references, which cannot be negated directly.
takeUntil
in interface Map<K,V>
takeUntil
in interface SortedMap<K,V>
takeUntil
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements.public TreeMap<K,V> takeWhile(Predicate<? super Tuple2<K,V>> predicate)
Traversable
takeWhile
in interface Map<K,V>
takeWhile
in interface SortedMap<K,V>
takeWhile
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for the contained elements.public TreeMap<K,V> toJavaMap()
Map
Map
to a java.util.Map
while preserving characteristics
like insertion order (LinkedHashMap
) and sort order (SortedMap
).public boolean equals(Object o)
Value
public int hashCode()
Value
See Object.hashCode().
public String stringPrefix()
Value
stringPrefix
in interface Value<Tuple2<K,V>>
public String toString()
Value
See Object.toString().
public Comparator<K> comparator()
Ordered
comparator
in interface Ordered<K>
Copyright © 2016. All Rights Reserved.