K
- Key typeV
- Value typepublic interface SortedMap<K,V> extends Map<K,V>, Ordered<K>
SortedMap
interface.λ.Memoized
Modifier and Type | Field and Description |
---|---|
static long |
serialVersionUID |
Modifier and Type | Method and Description |
---|---|
<K2,V2> SortedMap<K2,V2> |
bimap(Comparator<? super K2> keyComparator,
Function<? super K,? extends K2> keyMapper,
Function<? super V,? extends V2> valueMapper)
Same as
bimap(Function, Function) , using a specific comparator for keys of the codomain of the given
keyMapper . |
<K2,V2> SortedMap<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. |
Tuple2<V,? extends SortedMap<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>,? extends SortedMap<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.
|
SortedMap<K,V> |
distinct()
Returns a new version of this which contains no duplicates.
|
SortedMap<K,V> |
distinctBy(Comparator<? super Tuple2<K,V>> comparator)
Returns a new version of this which contains no duplicates.
|
<U> SortedMap<K,V> |
distinctBy(Function<? super Tuple2<K,V>,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.
|
SortedMap<K,V> |
drop(int n)
Drops the first n elements of this or all elements, if this length < n.
|
SortedMap<K,V> |
dropRight(int n)
Drops the last n elements of this or all elements, if this length < n.
|
SortedMap<K,V> |
dropUntil(Predicate<? super Tuple2<K,V>> predicate)
Drops elements until the predicate holds for the current element.
|
SortedMap<K,V> |
dropWhile(Predicate<? super Tuple2<K,V>> predicate)
Drops elements while the predicate holds for the current element.
|
SortedMap<K,V> |
filter(BiPredicate<? super K,? super V> predicate)
Returns a new Map consisting of all elements which satisfy the given predicate.
|
SortedMap<K,V> |
filter(Predicate<? super Tuple2<K,V>> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
SortedMap<K,V> |
filterKeys(Predicate<? super K> predicate)
Returns a new Map consisting of all elements with keys which satisfy the given predicate.
|
SortedMap<K,V> |
filterValues(Predicate<? super V> predicate)
Returns a new Map consisting of all elements with values which satisfy the given predicate.
|
<K2,V2> SortedMap<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> SortedMap<K2,V2> |
flatMap(Comparator<? super K2> keyComparator,
BiFunction<? super K,? super V,? extends Iterable<Tuple2<K2,V2>>> mapper)
Same as
flatMap(BiFunction) but using a specific comparator for values of the codomain of the given
mapper . |
<C> Map<C,? extends SortedMap<K,V>> |
groupBy(Function<? super Tuple2<K,V>,? extends C> classifier)
Groups this elements by classifying the elements.
|
Iterator<? extends SortedMap<K,V>> |
grouped(int size)
Groups this
Traversable into fixed size blocks. |
SortedMap<K,V> |
init()
Dual of Traversable.tail(), returning all elements except the last.
|
Option<? extends SortedMap<K,V>> |
initOption()
Dual of Traversable.tailOption(), returning all elements except the last as
Option . |
default boolean |
isOrdered()
Checks if this Traversable is ordered
|
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.
|
default Tuple2<K,V> |
last()
Dual of Traversable.head(), returning the last element.
|
<K2,V2> SortedMap<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> SortedMap<K2,V2> |
map(Comparator<? super K2> keyComparator,
BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
Same as
map(BiFunction) , using a specific comparator for keys of the codomain of the given
mapper . |
<K2> SortedMap<K2,V> |
mapKeys(Function<? super K,? extends K2> keyMapper)
Maps the keys of this
Map while preserving the corresponding values. |
<K2> SortedMap<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. |
<V2> SortedMap<K,V2> |
mapValues(Function<? super V,? extends V2> valueMapper)
Maps the values of this
Map while preserving the corresponding keys. |
SortedMap<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> SortedMap<K,V> |
narrow(SortedMap<? extends K,? extends V> sortedMap)
Narrows a widened
SortedMap<? extends K, ? extends V> to SortedMap<K, V>
by performing a type-safe cast. |
Tuple2<? extends SortedMap<K,V>,? extends SortedMap<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. |
SortedMap<K,V> |
peek(Consumer<? super Tuple2<K,V>> action)
Performs the given
action on the first element if this is an eager implementation. |
SortedMap<K,V> |
put(K key,
V value)
Associates the specified value with the specified key in this map.
|
SortedMap<K,V> |
put(Tuple2<? extends K,? extends V> entry)
Convenience method for
put(entry._1, entry._2) . |
SortedMap<K,V> |
remove(K key)
Removes the mapping for a key from this map if it is present.
|
SortedMap<K,V> |
removeAll(BiPredicate<? super K,? super V> predicate)
Returns a new Map consisting of all elements which do not satisfy the given predicate.
|
SortedMap<K,V> |
removeAll(Iterable<? extends K> keys)
Removes the mapping for a key from this map if it is present.
|
SortedMap<K,V> |
removeKeys(Predicate<? super K> predicate)
Returns a new Map consisting of all elements with keys which do not satisfy the given predicate.
|
SortedMap<K,V> |
removeValues(Predicate<? super V> predicate)
Returns a new Map consisting of all elements with values which do not satisfy the given predicate.
|
SortedMap<K,V> |
replace(Tuple2<K,V> currentElement,
Tuple2<K,V> newElement)
Replaces the first occurrence (if exists) of the given currentElement with newElement.
|
SortedMap<K,V> |
replaceAll(Tuple2<K,V> currentElement,
Tuple2<K,V> newElement)
Replaces all occurrences of the given currentElement with newElement.
|
SortedMap<K,V> |
retainAll(Iterable<? extends Tuple2<K,V>> elements)
Keeps all occurrences of the given elements from this.
|
SortedMap<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.
|
Iterator<? extends SortedMap<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<? extends SortedMap<K,V>> |
sliding(int size,
int step)
Slides a window of a specific
size and step size over this Traversable . |
Tuple2<? extends SortedMap<K,V>,? extends SortedMap<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. |
SortedMap<K,V> |
tail()
Drops the first element of a non-empty Traversable.
|
Option<? extends SortedMap<K,V>> |
tailOption()
Drops the first element of a non-empty Traversable and returns an
Option . |
SortedMap<K,V> |
take(int n)
Takes the first n elements of this or all elements, if this length < n.
|
SortedMap<K,V> |
takeRight(int n)
Takes the last n elements of this or all elements, if this length < n.
|
SortedMap<K,V> |
takeUntil(Predicate<? super Tuple2<K,V>> predicate)
Takes elements until the predicate holds for the current element.
|
SortedMap<K,V> |
takeWhile(Predicate<? super Tuple2<K,V>> predicate)
Takes elements while the predicate holds for the current element.
|
SortedMap<K,V> |
toJavaMap()
Converts this Javaslang
Map to a java.util.Map while preserving characteristics
like insertion order (LinkedHashMap ) and sort order (SortedMap ). |
apply, contains, containsKey, containsValue, entry, flatMap, foldRight, forEach, get, getOrElse, hasDefiniteSize, isDistinct, isTraversableAgain, iterator, length, lift, map, narrow, put, put, replace, replaceAll, replaceValue, scanLeft, scanRight, size, spliterator, transform, traverse, unzip, unzip, unzip, unzip3, unzip3, values, withDefault, withDefaultValue, zip, zipAll, zipWith, zipWithIndex, zipWithIndex
average, containsAll, count, existsUnique, find, findLast, foldLeft, get, hash, head, headOption, isEmpty, 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, equals, exists, forAll, forEach, getOption, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, hashCode, narrow, out, out, stderr, stdout, stringPrefix, 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, toString, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
andThen, arity, compose, constant, curried, identity, lift, liftTry, memoized, of, reversed, tupled
isMemoized
comparator
static final long serialVersionUID
static <K,V> SortedMap<K,V> narrow(SortedMap<? extends K,? extends V> sortedMap)
SortedMap<? extends K, ? extends V>
to SortedMap<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 typesortedMap
- A SortedMap
.sortedMap
instance as narrowed type SortedMap<K, V>
.<K2,V2> SortedMap<K2,V2> bimap(Comparator<? super K2> keyComparator, Function<? super K,? extends K2> keyMapper, Function<? super V,? extends V2> valueMapper)
bimap(Function, Function)
, using a specific comparator for keys of the codomain of the given
keyMapper
.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
NullPointerException
- if keyMapper
or valueMapper
is null<K2,V2> SortedMap<K2,V2> flatMap(Comparator<? super K2> keyComparator, BiFunction<? super K,? super V,? extends Iterable<Tuple2<K2,V2>>> mapper)
flatMap(BiFunction)
but using a specific comparator for values of the codomain of the given
mapper
.K2
- New key typeV2
- New value typekeyComparator
- A comparator for keys of type Umapper
- A function which maps key/value pairs to Iterables map entriesComparator<K> keyComparator()
<K2,V2> SortedMap<K2,V2> map(Comparator<? super K2> keyComparator, BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
map(BiFunction)
, using a specific comparator for keys of the codomain of the given
mapper
.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
NullPointerException
- if mapper
is null<K2,V2> SortedMap<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>
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
Tuple2<V,? extends SortedMap<K,V>> computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
Map
computeIfAbsent
in interface Map<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 keyTuple2<Option<V>,? extends SortedMap<K,V>> computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
Map
computeIfPresent
in interface Map<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 noneSortedMap<K,V> distinct()
Traversable
equals
.SortedMap<K,V> distinctBy(Comparator<? super Tuple2<K,V>> comparator)
Traversable
comparator
.distinctBy
in interface Map<K,V>
distinctBy
in interface Traversable<Tuple2<K,V>>
comparator
- A comparatorTraversable
containing this elements without duplicates<U> SortedMap<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 Traversable<Tuple2<K,V>>
U
- key typekeyExtractor
- A key extractorTraversable
containing this elements without duplicatesSortedMap<K,V> drop(int n)
Traversable
SortedMap<K,V> dropRight(int n)
Traversable
dropRight
in interface Map<K,V>
dropRight
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to drop.SortedMap<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 Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements.SortedMap<K,V> dropWhile(Predicate<? super Tuple2<K,V>> predicate)
Traversable
dropWhile
in interface Map<K,V>
dropWhile
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements starting with the first.SortedMap<K,V> filter(Predicate<? super Tuple2<K,V>> predicate)
Traversable
SortedMap<K,V> filter(BiPredicate<? super K,? super V> predicate)
Map
SortedMap<K,V> filterKeys(Predicate<? super K> predicate)
Map
filterKeys
in interface Map<K,V>
predicate
- the predicate used to test keys of elementsSortedMap<K,V> filterValues(Predicate<? super V> predicate)
Map
filterValues
in interface Map<K,V>
predicate
- the predicate used to test values of elementsSortedMap<K,V> removeAll(BiPredicate<? super K,? super V> predicate)
Map
SortedMap<K,V> removeKeys(Predicate<? super K> predicate)
Map
removeKeys
in interface Map<K,V>
predicate
- the predicate used to test keys of elementsSortedMap<K,V> removeValues(Predicate<? super V> predicate)
Map
removeValues
in interface Map<K,V>
predicate
- the predicate used to test values of elements<K2,V2> SortedMap<K2,V2> flatMap(BiFunction<? super K,? super V,? extends Iterable<Tuple2<K2,V2>>> mapper)
Map
Map
to a new Map
with different component type.<C> Map<C,? extends SortedMap<K,V>> groupBy(Function<? super Tuple2<K,V>,? extends C> classifier)
Traversable
Iterator<? extends SortedMap<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)
.SortedMap<K,V> init()
Traversable
Option<? extends SortedMap<K,V>> initOption()
Traversable
Option
.initOption
in interface Map<K,V>
initOption
in interface Traversable<Tuple2<K,V>>
Some(traversable)
or None
if this is empty.default boolean isOrdered()
Traversable
isOrdered
in interface Traversable<Tuple2<K,V>>
SortedSet<K> keySet()
Map
default Tuple2<K,V> last()
Traversable
last
in interface Traversable<Tuple2<K,V>>
<K2,V2> SortedMap<K2,V2> map(BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
Map
Map
to form a new Map
.<K2> SortedMap<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
.
<K2> SortedMap<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
.
<V2> SortedMap<K,V2> mapValues(Function<? super V,? extends V2> valueMapper)
Map
Map
while preserving the corresponding keys.SortedMap<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.
<U extends V> SortedMap<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.
Tuple2<? extends SortedMap<K,V>,? extends SortedMap<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 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.SortedMap<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.SortedMap<K,V> put(K key, V value)
Map
SortedMap<K,V> put(Tuple2<? extends K,? extends V> entry)
Map
put(entry._1, entry._2)
.SortedMap<K,V> remove(K key)
Map
SortedMap<K,V> removeAll(Iterable<? extends K> keys)
Map
SortedMap<K,V> replace(Tuple2<K,V> currentElement, Tuple2<K,V> newElement)
Traversable
replace
in interface Map<K,V>
replace
in interface Traversable<Tuple2<K,V>>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.SortedMap<K,V> replaceAll(Tuple2<K,V> currentElement, Tuple2<K,V> newElement)
Traversable
replaceAll
in interface Map<K,V>
replaceAll
in interface Traversable<Tuple2<K,V>>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.SortedMap<K,V> retainAll(Iterable<? extends Tuple2<K,V>> elements)
Traversable
SortedMap<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 Traversable<Tuple2<K,V>>
zero
- neutral element for the operator opoperation
- the associative operator for the scanIterator<? extends SortedMap<K,V>> sliding(int size)
Traversable
size
and step size 1 over this Traversable
by calling
Traversable.sliding(int, int)
.Iterator<? extends SortedMap<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]]
Tuple2<? extends SortedMap<K,V>,? extends SortedMap<K,V>> span(Predicate<? super Tuple2<K,V>> predicate)
Traversable
predicate
and the second element is the remainder.SortedMap<K,V> tail()
Traversable
Option<? extends SortedMap<K,V>> tailOption()
Traversable
Option
.tailOption
in interface Map<K,V>
tailOption
in interface Traversable<Tuple2<K,V>>
Some(traversable)
or None
if this is empty.SortedMap<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.
SortedMap<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.
SortedMap<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.
SortedMap<K,V> takeWhile(Predicate<? super Tuple2<K,V>> predicate)
Traversable
takeWhile
in interface Map<K,V>
takeWhile
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for the contained elements.Copyright © 2016. All Rights Reserved.