K
- Key typeV
- Value type@Deprecated public final class TreeMultimap<K,V> extends java.lang.Object implements java.io.Serializable, SortedMultimap<K,V>
Modifier and Type | Class and Description |
---|---|
static class |
TreeMultimap.Builder<V>
Deprecated.
|
Multimap.ContainerType
Modifier and Type | Field and Description |
---|---|
protected Map<K,Traversable<V>> |
back
Deprecated.
|
protected io.vavr.collection.AbstractMultimap.SerializableSupplier<Traversable<?>> |
emptyContainer
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
Map<K,Traversable<V>> |
asMap()
Deprecated.
Converts this
Multimap to a Map |
<K2,V2> Multimap<K2,V2> |
bimap(java.util.function.Function<? super K,? extends K2> keyMapper,
java.util.function.Function<? super V,? extends V2> valueMapper)
Deprecated.
Maps this
Multimap to a new Multimap with different component type by applying a function to its elements. |
java.util.Comparator<K> |
comparator()
Deprecated.
Returns the comparator which defines the order of the elements contained in this collection.
|
boolean |
containsKey(K key)
Deprecated.
Returns
true if this multimap contains a mapping for the specified key. |
protected <K2,V2> TreeMultimap<K2,V2> |
createFromMap(Map<K2,Traversable<V2>> back)
Deprecated.
|
M |
distinct()
Deprecated.
Returns a new version of this which contains no duplicates.
|
M |
distinctBy(java.util.Comparator<? super Tuple2<K,V>> comparator)
Deprecated.
Returns a new version of this which contains no duplicates.
|
<U> M |
distinctBy(java.util.function.Function<? super Tuple2<K,V>,? extends U> keyExtractor)
Deprecated.
Returns a new version of this which contains no duplicates.
|
M |
drop(int n)
Deprecated.
Drops the first n elements of this or all elements, if this length < n.
|
M |
dropRight(int n)
Deprecated.
Drops the last n elements of this or all elements, if this length < n.
|
M |
dropUntil(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Deprecated.
Drops elements until the predicate holds for the current element.
|
M |
dropWhile(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Deprecated.
Drops elements while the predicate holds for the current element.
|
protected <K2,V2> TreeMultimap<K2,V2> |
emptyInstance()
Deprecated.
|
protected <K2,V2> Map<K2,V2> |
emptyMapSupplier()
Deprecated.
|
boolean |
equals(java.lang.Object o)
Deprecated.
In Vavr there are four basic classes of collections:
Seq (sequential elements)
Set (distinct elements)
Map (indexed elements)
Multimap (indexed collections)
Two collection instances of these classes are equal if and only if both collections
belong to the same basic collection class (Seq, Set, Map or Multimap)
contain the same elements
have the same element order, if the collections are of type Seq
Two Map/Multimap elements, resp.
|
M |
filter(java.util.function.BiPredicate<? super K,? super V> predicate)
Deprecated.
Returns a new Multimap consisting of all elements which satisfy the given predicate.
|
M |
filter(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Deprecated.
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
M |
filterKeys(java.util.function.Predicate<? super K> predicate)
Deprecated.
Returns a new Multimap consisting of all elements with keys which satisfy the given predicate.
|
M |
filterNot(java.util.function.BiPredicate<? super K,? super V> predicate)
Deprecated.
Returns a new Multimap consisting of all elements which do not satisfy the given predicate.
|
M |
filterNot(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Deprecated.
Returns a new traversable consisting of all elements which do not satisfy the given predicate.
|
M |
filterNotKeys(java.util.function.Predicate<? super K> predicate)
Deprecated.
Returns a new Multimap consisting of all elements with keys which do not satisfy the given predicate.
|
M |
filterNotValues(java.util.function.Predicate<? super V> predicate)
Deprecated.
Returns a new Multimap consisting of all elements with values which do not satisfy the given predicate.
|
M |
filterValues(java.util.function.Predicate<? super V> predicate)
Deprecated.
Returns a new Multimap consisting of all elements with values which satisfy the given predicate.
|
<K2,V2> Multimap<K2,V2> |
flatMap(java.util.function.BiFunction<? super K,? super V,? extends java.lang.Iterable<Tuple2<K2,V2>>> mapper)
Deprecated.
FlatMaps this
Multimap to a new Multimap with different component type. |
Option<Traversable<V>> |
get(K key)
Deprecated.
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()
Deprecated.
Returns the type of the
Traversable value container of this MultiMap . |
Traversable<V> |
getOrElse(K key,
Traversable<? extends V> defaultValue)
Deprecated.
Returns the value associated with a key, or a default value if the key is not contained in the map
|
<C> Map<C,M> |
groupBy(java.util.function.Function<? super Tuple2<K,V>,? extends C> classifier)
Deprecated.
Groups this elements by classifying the elements.
|
Iterator<M> |
grouped(int size)
Deprecated.
Groups this
Traversable into fixed size blocks. |
int |
hashCode()
Deprecated.
Returns the hash code of this collection.
|
Tuple2<K,V> |
head()
Deprecated.
Returns the first element of a non-empty Traversable.
|
M |
init()
Deprecated.
Dual of Traversable.tail(), returning all elements except the last.
|
Option<M> |
initOption()
Deprecated.
Dual of Traversable.tailOption(), returning all elements except the last as
Option . |
boolean |
isAsync()
Deprecated.
Checks if this
Value is asynchronously (short: async) computed. |
boolean |
isEmpty()
Deprecated.
Checks if this Traversable is empty.
|
boolean |
isLazy()
Deprecated.
Checks if this
Value is lazily evaluated. |
Iterator<Tuple2<K,V>> |
iterator()
Deprecated.
An iterator by means of head() and tail().
|
SortedSet<K> |
keySet()
Deprecated.
Returns the keys contained in this multimap.
|
Tuple2<K,V> |
last()
Deprecated.
Dual of Traversable.head(), returning the last element.
|
<K2,V2> Multimap<K2,V2> |
map(java.util.function.BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
Deprecated.
Maps the entries of this
Multimap to form a new Multimap . |
<V2> Multimap<K,V2> |
mapValues(java.util.function.Function<? super V,? extends V2> valueMapper)
Deprecated.
Maps the values of this
Multimap while preserving the corresponding keys. |
M |
merge(Multimap<? extends K,? extends V> that)
Deprecated.
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,
java.util.function.BiFunction<Traversable<V>,Traversable<V2>,Traversable<V>> collisionResolution)
Deprecated.
Creates a new multimap which by merging the entries of
this multimap and that multimap. |
static <K,V> TreeMultimap<K,V> |
narrow(TreeMultimap<? extends K,? extends V> map)
Deprecated.
Narrows a widened
HashMultimap<? extends K, ? extends V> to HashMultimap<K, V>
by performing a type safe-cast. |
M |
orElse(java.lang.Iterable<? extends Tuple2<K,V>> other)
Deprecated.
Returns this
Multimap if it is nonempty,
otherwise Multimap created from iterable, using existing multimap properties. |
M |
orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends Tuple2<K,V>>> supplier)
Deprecated.
Returns this
Multimap if it is nonempty,
otherwise Multimap created from result of evaluating supplier, using existing multimap properties. |
Tuple2<M,M> |
partition(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Deprecated.
Creates a partition of this
Traversable by splitting this elements in two in distinct traversables
according to a predicate. |
M |
peek(java.util.function.Consumer<? super Tuple2<K,V>> action)
Deprecated.
Performs the given
action on the first element if this is an eager implementation. |
M |
put(K key,
V value)
Deprecated.
Associates the specified value with the specified key in this multimap.
|
M |
put(Tuple2<? extends K,? extends V> entry)
Deprecated.
Convenience method for
put(entry._1, entry._2) . |
M |
remove(K key)
Deprecated.
Removes the mapping for a key from this multimap if it is present.
|
M |
remove(K key,
V value)
Deprecated.
Removes the key-value pair from this multimap if it is present.
|
M |
removeAll(java.lang.Iterable<? extends K> keys)
Deprecated.
Removes the mapping for a key from this multimap if it is present.
|
M |
replace(K key,
V oldValue,
V newValue)
Deprecated.
Replaces the entry with the specified key and oldValue.
|
M |
replace(Tuple2<K,V> currentElement,
Tuple2<K,V> newElement)
Deprecated.
Replaces the first occurrence (if exists) of the given currentElement with newElement.
|
M |
replaceAll(java.util.function.BiFunction<? super K,? super V,? extends V> function)
Deprecated.
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.
|
M |
replaceAll(Tuple2<K,V> currentElement,
Tuple2<K,V> newElement)
Deprecated.
Replaces all occurrences of the given currentElement with newElement.
|
M |
replaceValue(K key,
V value)
Deprecated.
Replaces the entry for the specified key only if it is currently mapped to some value.
|
M |
retainAll(java.lang.Iterable<? extends Tuple2<K,V>> elements)
Deprecated.
Keeps all occurrences of the given elements from this.
|
M |
scan(Tuple2<K,V> zero,
java.util.function.BiFunction<? super Tuple2<K,V>,? super Tuple2<K,V>,? extends Tuple2<K,V>> operation)
Deprecated.
Computes a prefix scan of the elements of the collection.
|
int |
size()
Deprecated.
Computes the number of elements of this Traversable.
|
Iterator<M> |
slideBy(java.util.function.Function<? super Tuple2<K,V>,?> classifier)
Deprecated.
Slides a non-overlapping window of a variable size over this
Traversable . |
Iterator<M> |
sliding(int size)
Deprecated.
Slides a window of a specific
size and step size 1 over this Traversable by calling
Traversable.sliding(int, int) . |
Iterator<M> |
sliding(int size,
int step)
Deprecated.
Slides a window of a specific
size and step size over this Traversable . |
Tuple2<M,M> |
span(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Deprecated.
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. |
java.lang.String |
stringPrefix()
Deprecated.
Returns the name of this Value type, which is used by toString().
|
M |
tail()
Deprecated.
Drops the first element of a non-empty Traversable.
|
Option<M> |
tailOption()
Deprecated.
Drops the first element of a non-empty Traversable and returns an
Option . |
M |
take(int n)
Deprecated.
Takes the first n elements of this or all elements, if this length < n.
|
M |
takeRight(int n)
Deprecated.
Takes the last n elements of this or all elements, if this length < n.
|
M |
takeUntil(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Deprecated.
Takes elements until the predicate holds for the current element.
|
M |
takeWhile(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Deprecated.
Takes elements while the predicate holds for the current element.
|
java.util.SortedMap<K,java.util.Collection<V>> |
toJavaMap()
Deprecated.
Converts this Vavr
Map to a java.util.Map while preserving characteristics
like insertion order (LinkedHashMultimap ) and sort order (SortedMultimap ). |
protected <JM extends java.util.Map<K,java.util.Collection<V>>> |
toJavaMap(JM javaMap)
Deprecated.
|
java.lang.String |
toString()
Deprecated.
Clarifies that values have a proper toString() method implemented.
|
Traversable<V> |
values()
Deprecated.
|
static <V> TreeMultimap.Builder<V> |
withSeq()
Deprecated.
|
static <V> TreeMultimap.Builder<V> |
withSet()
Deprecated.
|
static <V extends java.lang.Comparable<?>> |
withSortedSet()
Deprecated.
|
static <V> TreeMultimap.Builder<V> |
withSortedSet(java.util.Comparator<? super V> comparator)
Deprecated.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
distinct, distinctBy, distinctBy, drop, dropRight, dropUntil, dropWhile, filter, filter, filterKeys, filterNot, filterNot, filterNotKeys, filterNotValues, filterValues, groupBy, grouped, init, initOption, merge, merge, narrow, orElse, orElse, partition, peek, put, put, remove, remove, removeAll, replace, replace, replaceAll, replaceAll, replaceValue, retainAll, scan, slideBy, sliding, sliding, span, tail, tailOption, take, takeRight, takeUntil, takeWhile
apply, asMap, asPartialFunction, bimap, collect, contains, containsKey, containsValue, flatMap, flatMap, foldRight, forEach, get, getContainerType, getOrElse, hasDefiniteSize, isDefinedAt, isDistinct, isTraversableAgain, iterator, iterator, length, map, map, mapValues, narrow, scanLeft, scanRight, size, transform, values, zip, zipAll, zipWith, zipWithIndex, zipWithIndex
arrangeBy, average, containsAll, count, equals, existsUnique, find, findLast, fold, 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, reduce, reduceLeft, reduceLeftOption, reduceOption, reduceRight, reduceRightOption, single, singleOption, spliterator, sum, toLinkedMap, toMap, toSortedMap, toSortedMap, unzip, unzip3
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
lift
protected final Map<K,Traversable<V>> back
protected final io.vavr.collection.AbstractMultimap.SerializableSupplier<Traversable<?>> emptyContainer
public static <V> TreeMultimap.Builder<V> withSeq()
public static <V> TreeMultimap.Builder<V> withSet()
public static <V extends java.lang.Comparable<?>> TreeMultimap.Builder<V> withSortedSet()
public static <V> TreeMultimap.Builder<V> withSortedSet(java.util.Comparator<? super V> comparator)
public static <K,V> TreeMultimap<K,V> narrow(TreeMultimap<? extends K,? extends V> map)
HashMultimap<? extends K, ? extends V>
to HashMultimap<K, V>
by performing a type safe-cast. This is eligible because immutable/read-only
collections are covariant.K
- Key typeV
- Value typemap
- A Map
.multimap
instance as narrowed type Multimap<K, V>
.protected <K2,V2> Map<K2,V2> emptyMapSupplier()
protected <K2,V2> TreeMultimap<K2,V2> emptyInstance()
protected <K2,V2> TreeMultimap<K2,V2> createFromMap(Map<K2,Traversable<V2>> back)
public java.util.Comparator<K> comparator()
Ordered
comparator
in interface Ordered<K>
public SortedSet<K> keySet()
Multimap
public java.util.SortedMap<K,java.util.Collection<V>> toJavaMap()
Multimap
Map
to a java.util.Map
while preserving characteristics
like insertion order (LinkedHashMultimap
) and sort order (SortedMultimap
).public Map<K,Traversable<V>> asMap()
Multimap
Multimap
to a Map
public <K2,V2> Multimap<K2,V2> bimap(java.util.function.Function<? super K,? extends K2> keyMapper, java.util.function.Function<? super V,? extends V2> valueMapper)
Multimap
Multimap
to a new Multimap
with different component type by applying a function to its elements.bimap
in interface Multimap<K,V>
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
public boolean containsKey(K key)
Multimap
true
if this multimap contains a mapping for the specified key.containsKey
in interface Multimap<K,V>
key
- key whose presence in this multimap is to be testedtrue
if this multimap contains a mapping for the specified keypublic Multimap.ContainerType getContainerType()
Multimap
Traversable
value container of this MultiMap
.getContainerType
in interface Multimap<K,V>
public <K2,V2> Multimap<K2,V2> flatMap(java.util.function.BiFunction<? super K,? super V,? extends java.lang.Iterable<Tuple2<K2,V2>>> mapper)
Multimap
Multimap
to a new Multimap
with different component type.public Option<Traversable<V>> get(K key)
Multimap
Some
of value to which the specified key
is mapped, or None
if this multimap contains no mapping for the key.public Traversable<V> getOrElse(K key, Traversable<? extends V> defaultValue)
Multimap
public <K2,V2> Multimap<K2,V2> map(java.util.function.BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
Multimap
Multimap
to form a new Multimap
.public <V2> Multimap<K,V2> mapValues(java.util.function.Function<? super V,? extends V2> valueMapper)
Multimap
Multimap
while preserving the corresponding keys.public M put(K key, V value)
Multimap
public M put(Tuple2<? extends K,? extends V> entry)
Multimap
put(entry._1, entry._2)
.public M remove(K key)
Multimap
public M remove(K key, V value)
Multimap
public M removeAll(java.lang.Iterable<? extends K> keys)
Multimap
public int size()
Traversable
Same as Traversable.length()
.
size
in interface Multimap<K,V>
size
in interface Traversable<Tuple2<K,V>>
public Traversable<V> values()
public M distinct()
Traversable
equals
.distinct
in interface Multimap<K,V>
distinct
in interface Traversable<Tuple2<K,V>>
Traversable
containing this elements without duplicatespublic M distinctBy(java.util.Comparator<? super Tuple2<K,V>> comparator)
Traversable
comparator
.distinctBy
in interface Multimap<K,V>
distinctBy
in interface Traversable<Tuple2<K,V>>
comparator
- A comparatorTraversable
containing this elements without duplicatespublic <U> M distinctBy(java.util.function.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 Multimap<K,V>
distinctBy
in interface Traversable<Tuple2<K,V>>
U
- key typekeyExtractor
- A key extractorTraversable
containing this elements without duplicatespublic M drop(int n)
Traversable
drop
in interface Multimap<K,V>
drop
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to drop.public M dropRight(int n)
Traversable
dropRight
in interface Multimap<K,V>
dropRight
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to drop.public M dropUntil(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Traversable
dropUntil
in interface Multimap<K,V>
dropUntil
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements.public M dropWhile(java.util.function.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 Multimap<K,V>
dropWhile
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements.public M filter(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Traversable
filter
in interface Multimap<K,V>
filter
in interface Traversable<Tuple2<K,V>>
predicate
- A predicatepublic M filterNot(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Traversable
The default implementation is equivalent to
filter(predicate.negate()
filterNot
in interface Multimap<K,V>
filterNot
in interface Traversable<Tuple2<K,V>>
predicate
- A predicatepublic M filter(java.util.function.BiPredicate<? super K,? super V> predicate)
Multimap
public M filterNot(java.util.function.BiPredicate<? super K,? super V> predicate)
Multimap
public M filterKeys(java.util.function.Predicate<? super K> predicate)
Multimap
filterKeys
in interface Multimap<K,V>
predicate
- the predicate used to test keys of elementspublic M filterNotKeys(java.util.function.Predicate<? super K> predicate)
Multimap
filterNotKeys
in interface Multimap<K,V>
predicate
- the predicate used to test keys of elementspublic M filterValues(java.util.function.Predicate<? super V> predicate)
Multimap
filterValues
in interface Multimap<K,V>
predicate
- the predicate used to test values of elementspublic M filterNotValues(java.util.function.Predicate<? super V> predicate)
Multimap
filterNotValues
in interface Multimap<K,V>
predicate
- the predicate used to test values of elementspublic <C> Map<C,M> groupBy(java.util.function.Function<? super Tuple2<K,V>,? extends C> classifier)
Traversable
groupBy
in interface Multimap<K,V>
groupBy
in interface Traversable<Tuple2<K,V>>
C
- classified class typeclassifier
- A function which classifies elements into classesTraversable.arrangeBy(Function)
public Iterator<M> 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 Multimap<K,V>
grouped
in interface Traversable<Tuple2<K,V>>
size
- a positive block sizepublic M init()
Traversable
init
in interface Multimap<K,V>
init
in interface Traversable<Tuple2<K,V>>
public Tuple2<K,V> head()
Traversable
head
in interface Traversable<Tuple2<K,V>>
public Option<M> initOption()
Traversable
Option
.initOption
in interface Multimap<K,V>
initOption
in interface Traversable<Tuple2<K,V>>
Some(traversable)
or None
if this is empty.public boolean isAsync()
Value
Value
is asynchronously (short: async) computed.
Methods of a Value
instance that operate on the underlying value may block the current thread
until the value is present and the computation can be performed.
public boolean isEmpty()
Traversable
public boolean isLazy()
Value
Value
is lazily evaluated.public Iterator<Tuple2<K,V>> iterator()
Traversable
public Tuple2<K,V> last()
Traversable
last
in interface Traversable<Tuple2<K,V>>
public M merge(Multimap<? extends K,? extends V> that)
Multimap
this
multimap and that
multimap.
If collisions occur, the value of this
multimap is taken.
public <K2 extends K,V2 extends V> M merge(Multimap<K2,V2> that, java.util.function.BiFunction<Traversable<V>,Traversable<V2>,Traversable<V>> collisionResolution)
Multimap
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.
public M orElse(java.lang.Iterable<? extends Tuple2<K,V>> other)
Multimap
if it is nonempty,
otherwise Multimap
created from iterable, using existing multimap properties.orElse
in interface Multimap<K,V>
orElse
in interface Traversable<Tuple2<K,V>>
other
- An alternative Traversable
Multimap
if it is nonempty,
otherwise Multimap
created from iterable, using existing multimap properties.public M orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends Tuple2<K,V>>> supplier)
Multimap
if it is nonempty,
otherwise Multimap
created from result of evaluating supplier, using existing multimap properties.orElse
in interface Multimap<K,V>
orElse
in interface Traversable<Tuple2<K,V>>
supplier
- An alternative Traversable
Multimap
if it is nonempty,
otherwise Multimap
created from result of evaluating supplier, using existing multimap properties.public Tuple2<M,M> partition(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Traversable
Traversable
by splitting this elements in two in distinct traversables
according to a predicate.partition
in interface Multimap<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 M peek(java.util.function.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 M replace(Tuple2<K,V> currentElement, Tuple2<K,V> newElement)
Traversable
replace
in interface Multimap<K,V>
replace
in interface Traversable<Tuple2<K,V>>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.public M replaceAll(Tuple2<K,V> currentElement, Tuple2<K,V> newElement)
Traversable
replaceAll
in interface Multimap<K,V>
replaceAll
in interface Traversable<Tuple2<K,V>>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.public M replaceValue(K key, V value)
Multimap
replaceValue
in interface Multimap<K,V>
key
- the key of the element to be substitutedvalue
- the new value to be associated with the keypublic M replace(K key, V oldValue, V newValue)
Multimap
replace
in interface Multimap<K,V>
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 keypublic M replaceAll(java.util.function.BiFunction<? super K,? super V,? extends V> function)
Multimap
replaceAll
in interface Multimap<K,V>
function
- function transforming key and current value to a new valuepublic M retainAll(java.lang.Iterable<? extends Tuple2<K,V>> elements)
Traversable
retainAll
in interface Multimap<K,V>
retainAll
in interface Traversable<Tuple2<K,V>>
elements
- Elements to be kept.public M scan(Tuple2<K,V> zero, java.util.function.BiFunction<? super Tuple2<K,V>,? super Tuple2<K,V>,? extends Tuple2<K,V>> operation)
Traversable
scan
in interface Multimap<K,V>
scan
in interface Traversable<Tuple2<K,V>>
zero
- neutral element for the operator opoperation
- the associative operator for the scanpublic Iterator<M> slideBy(java.util.function.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 Multimap<K,V>
slideBy
in interface Traversable<Tuple2<K,V>>
classifier
- A function which classifies elements into classespublic Iterator<M> sliding(int size)
Traversable
size
and step size 1 over this Traversable
by calling
Traversable.sliding(int, int)
.sliding
in interface Multimap<K,V>
sliding
in interface Traversable<Tuple2<K,V>>
size
- a positive window sizepublic Iterator<M> 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]]
sliding
in interface Multimap<K,V>
sliding
in interface Traversable<Tuple2<K,V>>
size
- a positive window sizestep
- a positive step sizepublic Tuple2<M,M> span(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Traversable
predicate
and the second element is the remainder.span
in interface Multimap<K,V>
span
in interface Traversable<Tuple2<K,V>>
predicate
- A predicate.Tuple
containing the longest prefix of elements that satisfy p and the remainder.public M tail()
Traversable
tail
in interface Multimap<K,V>
tail
in interface Traversable<Tuple2<K,V>>
public Option<M> tailOption()
Traversable
Option
.tailOption
in interface Multimap<K,V>
tailOption
in interface Traversable<Tuple2<K,V>>
Some(traversable)
or None
if this is empty.public M 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 Multimap<K,V>
take
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to take.public M 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 Multimap<K,V>
takeRight
in interface Traversable<Tuple2<K,V>>
n
- The number of elements to take.public M takeUntil(java.util.function.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 Multimap<K,V>
takeUntil
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for this elements.public M takeWhile(java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Traversable
takeWhile
in interface Multimap<K,V>
takeWhile
in interface Traversable<Tuple2<K,V>>
predicate
- A condition tested subsequently for the contained elements.public boolean equals(java.lang.Object o)
Traversable
Notes:
equals
in interface Traversable<Tuple2<K,V>>
equals
in interface Value<Tuple2<K,V>>
equals
in class java.lang.Object
o
- an object, may be nullpublic int hashCode()
Traversable
int hash = 1;
for (T t : this) { hash = hash * 31 + Objects.hashCode(t); }
Collections with arbitrary iteration order are hashed in a way such that the hash of a fixed number of elements is independent of their iteration order.
int hash = 1;
for (T t : this) { hash += Objects.hashCode(t); }
Please note that the particular hashing algorithms may change in a future version of Vavr.
public final class Hashed<K> {
private final K key;
private final Lazy<Integer> hashCode;
public Hashed(K key) {
this.key = key;
this.hashCode = Lazy.of(() -> Objects.hashCode(key));
}
public K key() {
return key;
}
@Override
public boolean equals(Object o) {
if (o == key) {
return true;
} else if (key != null && o instanceof Hashed) {
final Hashed that = (Hashed) o;
return key.equals(that.key);
} else {
return false;
}
}
@Override
public int hashCode() {
return hashCode.get();
}
@Override
public String toString() {
return "Hashed(" + (key == null ? "null" : key.toString()) + ")";
}
}
public java.lang.String stringPrefix()
Value
stringPrefix
in interface Value<Tuple2<K,V>>
public java.lang.String toString()
Value
See Object.toString().
protected <JM extends java.util.Map<K,java.util.Collection<V>>> JM toJavaMap(JM javaMap)