K
- Key typeV
- Value typepublic interface Multimap<K,V> extends Traversable<Tuple2<K,V>>, PartialFunction<K,Traversable<V>>, Serializable
Multimap
interface.
Basic operations:
containsKey(Object)
containsValue(Object)
get(Object)
getContainerType()
keySet()
merge(Multimap)
merge(Multimap, BiFunction)
put(Object, Object)
put(Tuple2)
values()
Modifier and Type | Interface and Description |
---|---|
static class |
Multimap.ContainerType |
Modifier and Type | Field and Description |
---|---|
static long |
serialVersionUID |
Modifier and Type | Method and Description |
---|---|
default Traversable<V> |
apply(K key)
Deprecated.
|
Map<K,Traversable<V>> |
asMap()
Converts this
Multimap to a Map |
default PartialFunction<K,Traversable<V>> |
asPartialFunction()
Turns this
Multimap into a PartialFunction which is defined at a specific index, if this Multimap
contains the given key. |
<K2,V2> Multimap<K2,V2> |
bimap(Function<? super K,? extends K2> keyMapper,
Function<? super V,? extends V2> valueMapper)
Maps this
Multimap to a new Multimap with different component type by applying a function to its elements. |
default <R> Seq<R> |
collect(PartialFunction<? super Tuple2<K,V>,? extends R> partialFunction)
Collects all elements that are in the domain of the given
partialFunction by mapping the elements to type R . |
default boolean |
contains(Tuple2<K,V> element)
Shortcut for
exists(e -> Objects.equals(e, element)) , tests if the given element is contained. |
boolean |
containsKey(K key)
Returns
true if this multimap contains a mapping for the specified key. |
default boolean |
containsValue(V value)
Returns
true if this multimap maps one or more keys to the
specified value. |
Multimap<K,V> |
distinct()
Returns a new version of this which contains no duplicates.
|
Multimap<K,V> |
distinctBy(Comparator<? super Tuple2<K,V>> comparator)
Returns a new version of this which contains no duplicates.
|
<U> Multimap<K,V> |
distinctBy(Function<? super Tuple2<K,V>,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.
|
Multimap<K,V> |
drop(int n)
Drops the first n elements of this or all elements, if this length < n.
|
Multimap<K,V> |
dropRight(int n)
Drops the last n elements of this or all elements, if this length < n.
|
Multimap<K,V> |
dropUntil(Predicate<? super Tuple2<K,V>> predicate)
Drops elements until the predicate holds for the current element.
|
Multimap<K,V> |
dropWhile(Predicate<? super Tuple2<K,V>> predicate)
Drops elements while the predicate holds for the current element.
|
Multimap<K,V> |
filter(BiPredicate<? super K,? super V> predicate)
Returns a new Multimap consisting of all elements which satisfy the given predicate.
|
Multimap<K,V> |
filter(Predicate<? super Tuple2<K,V>> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
Multimap<K,V> |
filterKeys(Predicate<? super K> predicate)
Returns a new Multimap consisting of all elements with keys which satisfy the given predicate.
|
Multimap<K,V> |
filterValues(Predicate<? super V> predicate)
Returns a new Multimap consisting of all elements with values which satisfy the given predicate.
|
<K2,V2> Multimap<K2,V2> |
flatMap(BiFunction<? super K,? super V,? extends Iterable<Tuple2<K2,V2>>> mapper)
FlatMaps this
Multimap to a new Multimap with different component type. |
default <U> Seq<U> |
flatMap(Function<? super Tuple2<K,V>,? extends Iterable<? extends U>> mapper)
Flat-maps this entries to a sequence of values.
|
default <U> U |
foldRight(U zero,
BiFunction<? super Tuple2<K,V>,? super U,? extends U> f)
Folds this elements from the right, starting with
zero and successively calling combine . |
default void |
forEach(BiConsumer<K,V> action)
Performs an action on key, value pair.
|
Option<Traversable<V>> |
get(K key)
Returns the
Some of value to which the specified key
is mapped, or None if this multimap contains no mapping for the key. |
Multimap.ContainerType |
getContainerType()
Returns the type of the
Traversable value container of this MultiMap . |
Traversable<V> |
getOrElse(K key,
Traversable<? extends 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,? extends Multimap<K,V>> |
groupBy(Function<? super Tuple2<K,V>,? extends C> classifier)
Groups this elements by classifying the elements.
|
Iterator<? extends Multimap<K,V>> |
grouped(int size)
Groups this
Traversable into fixed size blocks. |
default boolean |
hasDefiniteSize()
Checks if this Traversable is known to have a finite size.
|
Multimap<K,V> |
init()
Dual of Traversable.tail(), returning all elements except the last.
|
Option<? extends Multimap<K,V>> |
initOption()
Dual of Traversable.tailOption(), returning all elements except the last as
Option . |
default boolean |
isDefinedAt(K key)
Deprecated.
|
default boolean |
isDistinct()
Checks if this Traversable may consist of distinct elements only.
|
default boolean |
isTraversableAgain()
Checks if this Traversable can be repeatedly traversed.
|
Iterator<Tuple2<K,V>> |
iterator()
An iterator by means of head() and tail().
|
default <U> Iterator<U> |
iterator(BiFunction<K,V,? extends U> mapper)
Iterates this Multimap sequentially, mapping the (key, value) pairs to elements.
|
Set<K> |
keySet()
Returns the keys contained in this multimap.
|
default int |
length()
Computes the number of elements of this Traversable.
|
<K2,V2> Multimap<K2,V2> |
map(BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
Maps the entries of this
Multimap to form a new Multimap . |
default <U> Seq<U> |
map(Function<? super Tuple2<K,V>,? extends U> mapper)
Maps the
Multimap entries to a sequence of values. |
<V2> Multimap<K,V2> |
mapValues(Function<? super V,? extends V2> valueMapper)
Maps the values of this
Multimap while preserving the corresponding keys. |
Multimap<K,V> |
merge(Multimap<? extends K,? extends V> that)
Creates a new multimap which by merging the entries of
this multimap and that multimap. |
<K2 extends K,V2 extends V> |
merge(Multimap<K2,V2> that,
BiFunction<Traversable<V>,Traversable<V2>,Traversable<V>> collisionResolution)
Creates a new multimap which by merging the entries of
this multimap and that multimap. |
static <K,V> Multimap<K,V> |
narrow(Multimap<? extends K,? extends V> map)
Narrows a widened
Multimap<? extends K, ? extends V> to Multimap<K, V>
by performing a type-safe cast. |
Multimap<K,V> |
orElse(Iterable<? extends Tuple2<K,V>> other)
Returns this
Traversable if it is nonempty, otherwise return the alternative. |
Multimap<K,V> |
orElse(Supplier<? extends Iterable<? extends Tuple2<K,V>>> supplier)
Returns this
Traversable if it is nonempty, otherwise return the result of evaluating supplier. |
Tuple2<? extends Multimap<K,V>,? extends Multimap<K,V>> |
partition(Predicate<? super Tuple2<K,V>> predicate)
Creates a partition of this
Traversable by splitting this elements in two in distinct traversables
according to a predicate. |
Multimap<K,V> |
peek(Consumer<? super Tuple2<K,V>> action)
Performs the given
action on the first element if this is an eager implementation. |
Multimap<K,V> |
put(K key,
V value)
Associates the specified value with the specified key in this multimap.
|
Multimap<K,V> |
put(Tuple2<? extends K,? extends V> entry)
Convenience method for
put(entry._1, entry._2) . |
Multimap<K,V> |
reject(BiPredicate<? super K,? super V> predicate)
Returns a new Multimap consisting of all elements which do not satisfy the given predicate.
|
Multimap<K,V> |
reject(Predicate<? super Tuple2<K,V>> predicate)
Returns a new traversable consisting of all elements which do not satisfy the given predicate.
|
Multimap<K,V> |
rejectKeys(Predicate<? super K> predicate)
Returns a new Multimap consisting of all elements with keys which do not satisfy the given predicate.
|
Multimap<K,V> |
rejectValues(Predicate<? super V> predicate)
Returns a new Multimap consisting of all elements with values which do not satisfy the given predicate.
|
Multimap<K,V> |
remove(K key)
Removes the mapping for a key from this multimap if it is present.
|
Multimap<K,V> |
remove(K key,
V value)
Removes the key-value pair from this multimap if it is present.
|
Multimap<K,V> |
removeAll(BiPredicate<? super K,? super V> predicate)
Deprecated.
Please use
reject(BiPredicate) |
Multimap<K,V> |
removeAll(Iterable<? extends K> keys)
Removes the mapping for a key from this multimap if it is present.
|
Multimap<K,V> |
removeKeys(Predicate<? super K> predicate)
Deprecated.
Please use
rejectKeys(Predicate) |
Multimap<K,V> |
removeValues(Predicate<? super V> predicate)
Deprecated.
Please use
rejectValues(Predicate) |
Multimap<K,V> |
replace(K key,
V oldValue,
V newValue)
Replaces the entry with the specified key and oldValue.
|
Multimap<K,V> |
replace(Tuple2<K,V> currentElement,
Tuple2<K,V> newElement)
Replaces the first occurrence (if exists) of the given currentElement with newElement.
|
Multimap<K,V> |
replaceAll(BiFunction<? super K,? super V,? extends V> function)
Replaces each entry's values with the result of invoking the given function on that each tuple until all entries have been processed or the function throws an exception.
|
Multimap<K,V> |
replaceAll(Tuple2<K,V> currentElement,
Tuple2<K,V> newElement)
Replaces all occurrences of the given currentElement with newElement.
|
Multimap<K,V> |
replaceValue(K key,
V value)
Replaces the entry for the specified key only if it is currently mapped to some value.
|
Multimap<K,V> |
retainAll(Iterable<? extends Tuple2<K,V>> elements)
Keeps all occurrences of the given elements from this.
|
Multimap<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.
|
default <U> Seq<U> |
scanLeft(U zero,
BiFunction<? super U,? super Tuple2<K,V>,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going left to right.
|
default <U> Seq<U> |
scanRight(U zero,
BiFunction<? super Tuple2<K,V>,? super U,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going right to left.
|
int |
size()
Computes the number of elements of this Traversable.
|
Iterator<? extends Multimap<K,V>> |
slideBy(Function<? super Tuple2<K,V>,?> classifier)
Slides a non-overlapping window of a variable size over this
Traversable . |
Iterator<? extends Multimap<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 Multimap<K,V>> |
sliding(int size,
int step)
Slides a window of a specific
size and step size over this Traversable . |
Tuple2<? extends Multimap<K,V>,? extends Multimap<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. |
Multimap<K,V> |
tail()
Drops the first element of a non-empty Traversable.
|
Option<? extends Multimap<K,V>> |
tailOption()
Drops the first element of a non-empty Traversable and returns an
Option . |
Multimap<K,V> |
take(int n)
Takes the first n elements of this or all elements, if this length < n.
|
Multimap<K,V> |
takeRight(int n)
Takes the last n elements of this or all elements, if this length < n.
|
Multimap<K,V> |
takeUntil(Predicate<? super Tuple2<K,V>> predicate)
Takes elements until the predicate holds for the current element.
|
Multimap<K,V> |
takeWhile(Predicate<? super Tuple2<K,V>> predicate)
Takes elements while the predicate holds for the current element.
|
Map<K,Collection<V>> |
toJavaMap()
Converts this Vavr
Map to a java.util.Map while preserving characteristics
like insertion order (LinkedHashMultimap ) and sort order (SortedMultimap ). |
default <U> U |
transform(Function<? super Multimap<K,V>,? extends U> f)
Transforms this
Multimap . |
default <T1,T2> Tuple2<Seq<T1>,Seq<T2>> |
unzip(BiFunction<? super K,? super V,Tuple2<? extends T1,? extends T2>> unzipper) |
default <T1,T2> Tuple2<Seq<T1>,Seq<T2>> |
unzip(Function<? super Tuple2<K,V>,Tuple2<? extends T1,? extends T2>> unzipper)
Unzips this elements by mapping this elements to pairs which are subsequently split into two distinct
sets.
|
default <T1,T2,T3> Tuple3<Seq<T1>,Seq<T2>,Seq<T3>> |
unzip3(BiFunction<? super K,? super V,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper) |
default <T1,T2,T3> Tuple3<Seq<T1>,Seq<T2>,Seq<T3>> |
unzip3(Function<? super Tuple2<K,V>,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Unzips this elements by mapping this elements to triples which are subsequently split into three distinct
sets.
|
Traversable<V> |
values() |
default <U> Seq<Tuple2<Tuple2<K,V>,U>> |
zip(Iterable<? extends U> that)
Returns a traversable formed from this traversable and another Iterable collection by combining
corresponding elements in pairs.
|
default <U> Seq<Tuple2<Tuple2<K,V>,U>> |
zipAll(Iterable<? extends U> that,
Tuple2<K,V> thisElem,
U thatElem)
Returns a traversable formed from this traversable and another Iterable by combining corresponding elements in
pairs.
|
default <U,R> Seq<R> |
zipWith(Iterable<? extends U> that,
BiFunction<? super Tuple2<K,V>,? super U,? extends R> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.
|
default Seq<Tuple2<Tuple2<K,V>,Integer>> |
zipWithIndex()
Zips this traversable with its indices.
|
default <U> Seq<U> |
zipWithIndex(BiFunction<? super Tuple2<K,V>,? super Integer,? extends U> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.
|
arrangeBy, average, containsAll, count, equals, existsUnique, find, findLast, foldLeft, forEachWithIndex, get, hashCode, head, headOption, isEmpty, isOrdered, isSequential, isSingleValued, last, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, narrow, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, spliterator, sum
fold, reduce, reduceOption
collect, collect, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, isAsync, isLazy, narrow, out, out, stderr, stdout, stringPrefix, toArray, toCharSeq, toCompletableFuture, toEither, toEither, toInvalid, toInvalid, toJavaArray, 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, toStream, toString, toTree, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
getIfDefined, lift, unlift
static final long serialVersionUID
static <K,V> Multimap<K,V> narrow(Multimap<? extends K,? extends V> map)
Multimap<? extends K, ? extends V>
to Multimap<K, V>
by performing a type-safe cast. This is eligible because immutable/read-only
collections are covariant.K
- Key typeV
- Value typemap
- A Multimap
.multimap
instance as narrowed type Multimap<K, V>
.@Deprecated default Traversable<V> apply(K key)
PartialFunction
apply
in interface Function<K,Traversable<V>>
apply
in interface Function1<K,Traversable<V>>
apply
in interface PartialFunction<K,Traversable<V>>
key
- the argumentMap<K,Traversable<V>> asMap()
Multimap
to a Map
Map<K, Traversable<V>>
default PartialFunction<K,Traversable<V>> asPartialFunction() throws IndexOutOfBoundsException
Multimap
into a PartialFunction
which is defined at a specific index, if this Multimap
contains the given key. When applied to a defined key, the partial function will return
the Traversable
of this Multimap
that is associated with the key.PartialFunction
NoSuchElementException
- when a non-existing key is applied to the partial functionIndexOutOfBoundsException
<K2,V2> Multimap<K2,V2> bimap(Function<? super K,? extends K2> keyMapper, Function<? super V,? extends V2> valueMapper)
Multimap
to a new Multimap
with different component type by applying a function to its elements.K2
- key's component type of the multimap resultV2
- value's component type of the multimap 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
Multimap
NullPointerException
- if keyMapper
or valueMapper
is nulldefault <R> Seq<R> collect(PartialFunction<? super Tuple2<K,V>,? extends R> partialFunction)
Traversable
partialFunction
by mapping the elements to type R
.
More specifically, for each of this elements in iteration order first it is checked
partialFunction.isDefinedAt(element)
If the elements makes it through that filter, the mapped instance is added to the result collection
R newElement = partialFunction.apply(element)
Note:If this Traversable
is ordered (i.e. extends Ordered
,
the caller of collect
has to ensure that the elements are comparable (i.e. extend Comparable
).collect
in interface Traversable<Tuple2<K,V>>
R
- The new element typepartialFunction
- A function that is not necessarily defined of all elements of this traversable.Traversable
instance containing elements of type R
default boolean contains(Tuple2<K,V> element)
Value
exists(e -> Objects.equals(e, element))
, tests if the given element
is contained.boolean containsKey(K key)
true
if this multimap contains a mapping for the specified key.key
- key whose presence in this multimap is to be testedtrue
if this multimap contains a mapping for the specified keydefault boolean containsValue(V value)
true
if this multimap maps one or more keys to the
specified value. This operation will require time linear in the map size.value
- value whose presence in this multimap is to be testedtrue
if this multimap maps one or more keys to the
specified valueMultimap<K,V> filter(BiPredicate<? super K,? super V> predicate)
predicate
- the predicate used to test elementsNullPointerException
- if predicate
is nullMultimap<K,V> reject(BiPredicate<? super K,? super V> predicate)
predicate
- the predicate used to test elementsNullPointerException
- if predicate
is nullMultimap<K,V> filterKeys(Predicate<? super K> predicate)
predicate
- the predicate used to test keys of elementsNullPointerException
- if predicate
is nullMultimap<K,V> rejectKeys(Predicate<? super K> predicate)
predicate
- the predicate used to test keys of elementsNullPointerException
- if predicate
is nullMultimap<K,V> filterValues(Predicate<? super V> predicate)
predicate
- the predicate used to test values of elementsNullPointerException
- if predicate
is nullMultimap<K,V> rejectValues(Predicate<? super V> predicate)
predicate
- the predicate used to test values of elementsNullPointerException
- if predicate
is null<K2,V2> Multimap<K2,V2> flatMap(BiFunction<? super K,? super V,? extends Iterable<Tuple2<K2,V2>>> mapper)
Multimap
to a new Multimap
with different component type.K2
- key's component type of the mapped Multimap
V2
- value's component type of the mapped Multimap
mapper
- A mapperMultimap
.NullPointerException
- if mapper
is nulldefault void forEach(BiConsumer<K,V> action)
action
- A BiConsumer
NullPointerException
- if action
is nullOption<Traversable<V>> get(K key)
Some
of value to which the specified key
is mapped, or None
if this multimap contains no mapping for the key.key
- the key whose associated value is to be returnedSome
of value to which the specified key
is mapped, or None
if this multimap contains no mapping
for the keyTraversable<V> getOrElse(K key, Traversable<? extends V> defaultValue)
key
- the keydefaultValue
- a default valueMultimap.ContainerType getContainerType()
Traversable
value container of this MultiMap
.default boolean hasDefiniteSize()
Traversable
This method should be implemented by classes only, i.e. not by interfaces.
hasDefiniteSize
in interface Traversable<Tuple2<K,V>>
@Deprecated default boolean isDefinedAt(K key)
PartialFunction
isDefinedAt
in interface PartialFunction<K,Traversable<V>>
key
- a potential function argumentdefault boolean isDistinct()
Traversable
isDistinct
in interface Traversable<Tuple2<K,V>>
default boolean isTraversableAgain()
Traversable
This method should be implemented by classes only, i.e. not by interfaces.
isTraversableAgain
in interface Traversable<Tuple2<K,V>>
Iterator<Tuple2<K,V>> iterator()
Traversable
default <U> Iterator<U> iterator(BiFunction<K,V,? extends U> mapper)
U
- The type of the resulting elementsmapper
- A function that maps (key, value) pairs to elements of type USet<K> keySet()
Set
of the keys contained in this multimap.default int length()
Traversable
Same as Traversable.size()
.
length
in interface Traversable<Tuple2<K,V>>
<K2,V2> Multimap<K2,V2> map(BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
Multimap
to form a new Multimap
.K2
- key's component type of the multimap resultV2
- value's component type of the multimap resultmapper
- a Function
that maps entries of type (K, V)
to entries of type (K2, V2)
Multimap
NullPointerException
- if mapper
is nulldefault <U> Seq<U> map(Function<? super Tuple2<K,V>,? extends U> mapper)
Multimap
entries to a sequence of values.
Please use map(BiFunction)
if the result has to be of type Multimap
.
<V2> Multimap<K,V2> mapValues(Function<? super V,? extends V2> valueMapper)
Multimap
while preserving the corresponding keys.V2
- the new value typevalueMapper
- a Function
that maps values of type V
to values of type V2
Multimap
NullPointerException
- if valueMapper
is nullMultimap<K,V> merge(Multimap<? extends K,? extends V> that)
this
multimap and that
multimap.
If collisions occur, the value of this
multimap is taken.
that
- the other multimapNullPointerException
- if that multimap is null<K2 extends K,V2 extends V> Multimap<K,V> merge(Multimap<K2,V2> that, BiFunction<Traversable<V>,Traversable<V2>,Traversable<V>> collisionResolution)
this
multimap and that
multimap.
Uses the specified collision resolution function if two keys are the same.
The collision resolution function will always take the first argument from this
multimap
and the second from that
multimap.
K2
- key type of that MultimapV2
- value type of that Multimapthat
- the other multimapcollisionResolution
- the collision resolution functionNullPointerException
- if that multimap or the given collision resolution function is nullMultimap<K,V> put(K key, V value)
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keyMultimap<K,V> put(Tuple2<? extends K,? extends V> entry)
put(entry._1, entry._2)
.entry
- A Tuple2 containing the key and valueMultimap<K,V> remove(K key)
key
- key whose mapping is to be removed from the multimapMultimap<K,V> remove(K key, V value)
key
- key whose mapping is to be removed from the multimapvalue
- value whose mapping is to be removed from the multimap@Deprecated Multimap<K,V> removeAll(BiPredicate<? super K,? super V> predicate)
reject(BiPredicate)
predicate
- the predicate used to test elementsNullPointerException
- if predicate
is nullMultimap<K,V> removeAll(Iterable<? extends K> keys)
keys
- keys are to be removed from the multimap@Deprecated Multimap<K,V> removeKeys(Predicate<? super K> predicate)
rejectKeys(Predicate)
predicate
- the predicate used to test keys of elementsNullPointerException
- if predicate
is null@Deprecated Multimap<K,V> removeValues(Predicate<? super V> predicate)
rejectValues(Predicate)
predicate
- the predicate used to test values of elementsNullPointerException
- if predicate
is nulldefault <U> Seq<U> scanLeft(U zero, BiFunction<? super U,? super Tuple2<K,V>,? extends U> operation)
Traversable
scanLeft
in interface Traversable<Tuple2<K,V>>
U
- the type of the elements in the resulting collectionzero
- the initial valueoperation
- the binary operator applied to the intermediate result and the elementdefault <U> Seq<U> scanRight(U zero, BiFunction<? super Tuple2<K,V>,? super U,? extends U> operation)
Traversable
scanRight
in interface Traversable<Tuple2<K,V>>
U
- the type of the elements in the resulting collectionzero
- the initial valueoperation
- the binary operator applied to the intermediate result and the elementint size()
Traversable
Same as Traversable.length()
.
size
in interface Traversable<Tuple2<K,V>>
Map<K,Collection<V>> toJavaMap()
Map
to a java.util.Map
while preserving characteristics
like insertion order (LinkedHashMultimap
) and sort order (SortedMultimap
).java.util.Map
instancedefault <U> U transform(Function<? super Multimap<K,V>,? extends U> f)
Multimap
.U
- Type of transformation resultf
- A transformationU
NullPointerException
- if f
is nulldefault <T1,T2> Tuple2<Seq<T1>,Seq<T2>> unzip(BiFunction<? super K,? super V,Tuple2<? extends T1,? extends T2>> unzipper)
default <T1,T2> Tuple2<Seq<T1>,Seq<T2>> unzip(Function<? super Tuple2<K,V>,Tuple2<? extends T1,? extends T2>> unzipper)
Traversable
unzip
in interface Traversable<Tuple2<K,V>>
T1
- 1st element type of a pair returned by unzipperT2
- 2nd element type of a pair returned by unzipperunzipper
- a function which converts elements of this to pairsdefault <T1,T2,T3> Tuple3<Seq<T1>,Seq<T2>,Seq<T3>> unzip3(BiFunction<? super K,? super V,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
default <T1,T2,T3> Tuple3<Seq<T1>,Seq<T2>,Seq<T3>> unzip3(Function<? super Tuple2<K,V>,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Traversable
unzip3
in interface Traversable<Tuple2<K,V>>
T1
- 1st element type of a triplet returned by unzipperT2
- 2nd element type of a triplet returned by unzipperT3
- 3rd element type of a triplet returned by unzipperunzipper
- a function which converts elements of this to pairsTraversable<V> values()
default <U> Seq<Tuple2<Tuple2<K,V>,U>> zip(Iterable<? extends U> that)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zip
in interface Traversable<Tuple2<K,V>>
U
- The type of the second half of the returned pairs.that
- The Iterable providing the second half of each result pair.that
iterable.default <U> Seq<Tuple2<Tuple2<K,V>,U>> zipAll(Iterable<? extends U> that, Tuple2<K,V> thisElem, U thatElem)
Traversable
The length of the returned traversable is the maximum of the lengths of this traversable and that
iterable.
Special case: if this traversable is shorter than that elements, and that elements contains duplicates, the resulting traversable may be shorter than the maximum of the lengths of this and that because a traversable contains an element at most once.
If this Traversable is shorter than that, thisElem values are used to fill the result. If that is shorter than this Traversable, thatElem values are used to fill the result.
zipAll
in interface Traversable<Tuple2<K,V>>
U
- The type of the second half of the returned pairs.that
- The Iterable providing the second half of each result pair.thisElem
- The element to be used to fill up the result if this traversable is shorter than that.thatElem
- The element to be used to fill up the result if that is shorter than this traversable.default <U,R> Seq<R> zipWith(Iterable<? extends U> that, BiFunction<? super Tuple2<K,V>,? super U,? extends R> mapper)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zipWith
in interface Traversable<Tuple2<K,V>>
U
- The type of the second parameter of the mapper.R
- The type of the mapped elements.that
- The Iterable providing the second parameter of the mapper.mapper
- a mapper.that
iterable.default Seq<Tuple2<Tuple2<K,V>,Integer>> zipWithIndex()
Traversable
zipWithIndex
in interface Traversable<Tuple2<K,V>>
default <U> Seq<U> zipWithIndex(BiFunction<? super Tuple2<K,V>,? super Integer,? extends U> mapper)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zipWithIndex
in interface Traversable<Tuple2<K,V>>
U
- The type of the mapped elements.mapper
- a mapper.that
iterable.Multimap<K,V> distinct()
Traversable
equals
.distinct
in interface Traversable<Tuple2<K,V>>
Traversable
containing this elements without duplicatesMultimap<K,V> distinctBy(Comparator<? super Tuple2<K,V>> comparator)
Traversable
comparator
.distinctBy
in interface Traversable<Tuple2<K,V>>
comparator
- A comparatorTraversable
containing this elements without duplicates<U> Multimap<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 Traversable<Tuple2<K,V>>
U
- key typekeyExtractor
- A key extractorTraversable
containing this elements without duplicatesMultimap<K,V> drop(int n)
Traversable
drop
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to drop.Multimap<K,V> dropRight(int n)
Traversable
dropRight
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to drop.Multimap<K,V> dropUntil(Predicate<? super Tuple2<K,V>> predicate)
Traversable
dropUntil
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements.Multimap<K,V> dropWhile(Predicate<? super Tuple2<K,V>> predicate)
Traversable
Note: This is essentially the same as dropUntil(predicate.negate())
.
It is intended to be used with method references, which cannot be negated directly.
dropWhile
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements.Multimap<K,V> filter(Predicate<? super Tuple2<K,V>> predicate)
Traversable
filter
in interface Traversable<Tuple2<K,V>>
predicate
- A predicateMultimap<K,V> reject(Predicate<? super Tuple2<K,V>> predicate)
Traversable
The default implementation is equivalent to
filter(predicate.negate()
reject
in interface Traversable<Tuple2<K,V>>
predicate
- A predicatedefault <U> Seq<U> flatMap(Function<? super Tuple2<K,V>,? extends Iterable<? extends U>> mapper)
Please use flatMap(BiFunction)
if the result should be a Multimap
flatMap
in interface Traversable<Tuple2<K,V>>
U
- Component typemapper
- A mapperdefault <U> U foldRight(U zero, BiFunction<? super Tuple2<K,V>,? super U,? extends U> f)
Foldable
zero
and successively calling combine
.
Example:
// = "!cba"
List("a", "b", "c").foldRight("!", (x, xs) -> xs + x)
<C> Map<C,? extends Multimap<K,V>> groupBy(Function<? super Tuple2<K,V>,? extends C> classifier)
Traversable
groupBy
in interface Traversable<Tuple2<K,V>>
C
- classified class typeclassifier
- A function which classifies elements into classesTraversable.arrangeBy(Function)
Iterator<? extends Multimap<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)
.grouped
in interface Traversable<Tuple2<K,V>>
size
- a positive block sizeMultimap<K,V> init()
Traversable
init
in interface Traversable<Tuple2<K,V>>
Option<? extends Multimap<K,V>> initOption()
Traversable
Option
.initOption
in interface Traversable<Tuple2<K,V>>
Some(traversable)
or None
if this is empty.Multimap<K,V> orElse(Iterable<? extends Tuple2<K,V>> other)
Traversable
Traversable
if it is nonempty, otherwise return the alternative.orElse
in interface Traversable<Tuple2<K,V>>
other
- An alternative Traversable
Traversable
if it is nonempty, otherwise return the alternative.Multimap<K,V> orElse(Supplier<? extends Iterable<? extends Tuple2<K,V>>> supplier)
Traversable
Traversable
if it is nonempty, otherwise return the result of evaluating supplier.orElse
in interface Traversable<Tuple2<K,V>>
supplier
- An alternative Traversable
supplierTraversable
if it is nonempty, otherwise return the result of evaluating supplier.Tuple2<? extends Multimap<K,V>,? extends Multimap<K,V>> partition(Predicate<? super Tuple2<K,V>> predicate)
Traversable
Traversable
by splitting this elements in two in distinct traversables
according to a predicate.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.Multimap<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.Multimap<K,V> replace(Tuple2<K,V> currentElement, Tuple2<K,V> newElement)
Traversable
replace
in interface Traversable<Tuple2<K,V>>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.Multimap<K,V> replaceAll(Tuple2<K,V> currentElement, Tuple2<K,V> newElement)
Traversable
replaceAll
in interface Traversable<Tuple2<K,V>>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.Multimap<K,V> replaceValue(K key, V value)
key
- the key of the element to be substitutedvalue
- the new value to be associated with the keyMultimap<K,V> replace(K key, V oldValue, V newValue)
key
- the key of the element to be substitutedoldValue
- the expected current value associated with the keynewValue
- the new value to be associated with the keyMultimap<K,V> replaceAll(BiFunction<? super K,? super V,? extends V> function)
function
- function transforming key and current value to a new valueMultimap<K,V> retainAll(Iterable<? extends Tuple2<K,V>> elements)
Traversable
retainAll
in interface Traversable<Tuple2<K,V>>
elements
- Elements to be kept.Multimap<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 Traversable<Tuple2<K,V>>
zero
- neutral element for the operator opoperation
- the associative operator for the scanIterator<? extends Multimap<K,V>> slideBy(Function<? super Tuple2<K,V>,?> classifier)
Traversable
Traversable
.
Each window contains elements with the same class, as determined by classifier
. Two consecutive
values in this Traversable
will be in the same window only if classifier
returns equal
values for them. Otherwise, the values will constitute the last element of the previous window and the
first element of the next window.
Examples:
[].slideBy(Function.identity()) = []
[1,2,3,4,4,5].slideBy(Function.identity()) = [[1],[2],[3],[4,4],[5]]
[1,2,3,10,12,5,7,20,29].slideBy(x -> x/10) = [[1,2,3],[10,12],[5,7],[20,29]]
slideBy
in interface Traversable<Tuple2<K,V>>
classifier
- A function which classifies elements into classesIterator<? extends Multimap<K,V>> sliding(int size)
Traversable
size
and step size 1 over this Traversable
by calling
Traversable.sliding(int, int)
.sliding
in interface Traversable<Tuple2<K,V>>
size
- a positive window sizeIterator<? extends Multimap<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 Traversable<Tuple2<K,V>>
size
- a positive window sizestep
- a positive step sizeTuple2<? extends Multimap<K,V>,? extends Multimap<K,V>> span(Predicate<? super Tuple2<K,V>> predicate)
Traversable
predicate
and the second element is the remainder.span
in interface Traversable<Tuple2<K,V>>
predicate
- A predicate.Tuple
containing the longest prefix of elements that satisfy p and the remainder.Multimap<K,V> tail()
Traversable
tail
in interface Traversable<Tuple2<K,V>>
Option<? extends Multimap<K,V>> tailOption()
Traversable
Option
.tailOption
in interface Traversable<Tuple2<K,V>>
Some(traversable)
or None
if this is empty.Multimap<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 Traversable<Tuple2<K,V>>
n
- The number of elements to take.Multimap<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 Traversable<Tuple2<K,V>>
n
- The number of elements to take.Multimap<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 Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements.Multimap<K,V> takeWhile(Predicate<? super Tuple2<K,V>> predicate)
Traversable
takeWhile
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for the contained elements.Copyright © 2020. All Rights Reserved.