Class AbstractMultimap<K,V,M extends Multimap<K,V>>
- java.lang.Object
-
- io.vavr.collection.AbstractMultimap<K,V,M>
-
- Type Parameters:
K- Key typeV- Value typeM- Concrete Multimap type extending this class
- All Implemented Interfaces:
Foldable<Tuple2<K,V>>,Multimap<K,V>,Traversable<Tuple2<K,V>>,Function1<K,Traversable<V>>,PartialFunction<K,Traversable<V>>,Value<Tuple2<K,V>>,java.io.Serializable,java.lang.Iterable<Tuple2<K,V>>,java.util.function.Function<K,Traversable<V>>
- Direct Known Subclasses:
HashMultimap,LinkedHashMultimap,TreeMultimap
abstract class AbstractMultimap<K,V,M extends Multimap<K,V>> extends java.lang.Object implements Multimap<K,V>
An abstract base implementation of theMultimapinterface that provides common functionality for concrete Multimap implementations. This class is not intended to be public and serves as a foundation for specialized Multimap types.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interfaceAbstractMultimap.SerializableSupplier<T>-
Nested classes/interfaces inherited from interface io.vavr.collection.Multimap
Multimap.ContainerType
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<K,Traversable<V>>backThe backing map that stores the key-value pairs.private Multimap.ContainerTypecontainerTypeprotected AbstractMultimap.SerializableSupplier<Traversable<?>>emptyContainerA supplier that creates empty containers for new key entries.private static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description AbstractMultimap(Map<K,Traversable<V>> back, Multimap.ContainerType containerType, AbstractMultimap.SerializableSupplier<Traversable<?>> emptyContainer)Creates a new AbstractMultimap with the specified backing map, container type, and empty container supplier.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Map<K,Traversable<V>>asMap()Converts thisMultimapto aMap<K2,V2>
Multimap<K2,V2>bimap(@NonNull java.util.function.Function<? super K,? extends K2> keyMapper, @NonNull java.util.function.Function<? super V,? extends V2> valueMapper)Maps thisMultimapto a newMultimapwith different component type by applying a function to its elements.booleancontainsKey(K key)Returnstrueif this multimap contains a mapping for the specified key.private <K2,V2>
Multimap<K2,V2>createFromEntries(java.lang.Iterable<? extends Tuple2<? extends K2,? extends V2>> entries)Creates a new Multimap from the given entries by grouping values by their keys.protected abstract <K2,V2>
Multimap<K2,V2>createFromMap(Map<K2,Traversable<V2>> back)Creates a new Multimap instance from the given backing map.Mdistinct()Returns a newTraversablecontaining the elements of this instance with all duplicates removed.MdistinctBy(@NonNull java.util.Comparator<? super Tuple2<K,V>> comparator)Returns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.<U> MdistinctBy(@NonNull java.util.function.Function<? super Tuple2<K,V>,? extends U> keyExtractor)Returns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.Mdrop(int n)Returns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.MdropRight(int n)Returns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.MdropUntil(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)Returns a newTraversablestarting from the first element that satisfies the givenpredicate, dropping all preceding elements.MdropWhile(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)Returns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.protected abstract <K2,V2>
Multimap<K2,V2>emptyInstance()Returns an empty Multimap instance specific to the implementing class.protected abstract <K2,V2>
Map<K2,V2>emptyMapSupplier()Returns an empty Map instance specific to the implementing class.booleanequals(java.lang.Object o)Determines whether this collection is equal to the given object.Mfilter(@NonNull java.util.function.BiPredicate<? super K,? super V> predicate)Returns a new Multimap consisting of all elements which satisfy the given predicate.Mfilter(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)Returns a new traversable containing only the elements that satisfy the given predicate.MfilterKeys(@NonNull java.util.function.Predicate<? super K> predicate)Returns a new Multimap consisting of all elements with keys which satisfy the given predicate.MfilterValues(@NonNull java.util.function.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(@NonNull java.util.function.BiFunction<? super K,? super V,? extends java.lang.Iterable<Tuple2<K2,V2>>> mapper)FlatMaps thisMultimapto a newMultimapwith different component type.Option<Traversable<V>>get(K key)Returns theSomeof value to which the specified key is mapped, orNoneif this multimap contains no mapping for the key.Multimap.ContainerTypegetContainerType()Returns the type of theTraversablevalue container of thisMultiMap.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,M>groupBy(@NonNull java.util.function.Function<? super Tuple2<K,V>,? extends C> classifier)Groups elements of thisTraversablebased on a classifier function.Iterator<M>grouped(int size)Splits thisTraversableinto consecutive blocks of the given size.inthashCode()Returns the hash code of this collection.Tuple2<K,V>head()Returns the first element of this non-emptyTraversable.Minit()Returns all elements of this Traversable except the last one.Option<M>initOption()Returns all elements of this Traversable except the last one, wrapped in anOption.booleanisAsync()Checks if thisValueis asynchronously (short: async) computed.booleanisEmpty()Checks if this Traversable contains no elements.booleanisLazy()Checks if thisValueis lazily evaluated.@NonNull Iterator<Tuple2<K,V>>iterator()Returns an iterator over the elements of this Traversable, implemented viaTraversable.head()andTraversable.tail().Set<K>keySet()Returns the keys contained in this multimap.Tuple2<K,V>last()Returns the last element of this Traversable.<K2,V2>
Multimap<K2,V2>map(@NonNull java.util.function.BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)Maps the entries of thisMultimapto form a newMultimap.<V2> Multimap<K,V2>mapValues(@NonNull java.util.function.Function<? super V,? extends V2> valueMapper)Maps the values of thisMultimapwhile preserving the corresponding keys.Mmerge(@NonNull Multimap<? extends K,? extends V> that)Creates a new multimap which by merging the entries ofthismultimap andthatmultimap.<K2 extends K,V2 extends V>
Mmerge(@NonNull Multimap<K2,V2> that, @NonNull java.util.function.BiFunction<Traversable<V>,Traversable<V2>,Traversable<V>> collisionResolution)Creates a new multimap which by merging the entries ofthismultimap andthatmultimap.MorElse(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends Tuple2<K,V>>> supplier)Returns thisMultimapif it is nonempty, otherwiseMultimapcreated from result of evaluating supplier, using existing multimap properties.MorElse(java.lang.Iterable<? extends Tuple2<K,V>> other)Returns thisMultimapif it is nonempty, otherwiseMultimapcreated from iterable, using existing multimap properties.Tuple2<M,M>partition(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)Splits thisTraversableinto two partitions according to a predicate.Mpeek(@NonNull java.util.function.Consumer<? super Tuple2<K,V>> action)Performs the givenactionon the first element if this is an eager implementation.Mput(@NonNull Tuple2<? extends K,? extends V> entry)Convenience method forput(entry._1, entry._2).Mput(K key, V value)Associates the specified value with the specified key in this multimap.Mreject(@NonNull java.util.function.BiPredicate<? super K,? super V> predicate)Returns a new Multimap consisting of all elements which do not satisfy the given predicate.Mreject(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)Returns a new traversable containing only the elements that do not satisfy the given predicate.MrejectKeys(@NonNull java.util.function.Predicate<? super K> predicate)Returns a new Multimap consisting of all elements with keys which do not satisfy the given predicate.MrejectValues(@NonNull java.util.function.Predicate<? super V> predicate)Returns a new Multimap consisting of all elements with values which do not satisfy the given predicate.Mremove(K key)Removes the mapping for a key from this multimap if it is present.Mremove(K key, V value)Removes the key-value pair from this multimap if it is present.MremoveAll(@NonNull java.lang.Iterable<? extends K> keys)Removes the mapping for a key from this multimap if it is present.MremoveAll(@NonNull java.util.function.BiPredicate<? super K,? super V> predicate)Deprecated.MremoveKeys(@NonNull java.util.function.Predicate<? super K> predicate)Deprecated.MremoveValues(@NonNull java.util.function.Predicate<? super V> predicate)Deprecated.Mreplace(@NonNull Tuple2<K,V> currentElement, Tuple2<K,V> newElement)Replaces the first occurrence ofcurrentElementwithnewElement, if it exists.Mreplace(K key, V oldValue, V newValue)Replaces the entry with the specified key and oldValue.MreplaceAll(@NonNull Tuple2<K,V> currentElement, Tuple2<K,V> newElement)Replaces all occurrences ofcurrentElementwithnewElement.MreplaceAll(@NonNull java.util.function.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.MreplaceValue(K key, V value)Replaces the entry for the specified key only if it is currently mapped to some value.MretainAll(@NonNull java.lang.Iterable<? extends Tuple2<K,V>> elements)Retains only the elements from this Traversable that are contained in the givenelements.Mscan(Tuple2<K,V> zero, @NonNull java.util.function.BiFunction<? super Tuple2<K,V>,? super Tuple2<K,V>,? extends Tuple2<K,V>> operation)Computes a prefix scan of the elements of this Traversable.intsize()Returns the number of elements in this Traversable.Iterator<M>slideBy(@NonNull java.util.function.Function<? super Tuple2<K,V>,?> classifier)Partitions thisTraversableinto consecutive non-overlapping windows according to a classification function.Iterator<M>sliding(int size)Slides a window of a givensizeover thisTraversablewith a step size of 1.Iterator<M>sliding(int size, int step)Slides a window of a specificsizewith a givenstepover thisTraversable.Tuple2<M,M>span(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)Splits thisTraversableinto a prefix and remainder according to the givenpredicate.java.lang.StringstringPrefix()Returns the name of this Value type, which is used by toString().Mtail()Returns a newTraversablewithout its first element.Option<M>tailOption()Returns a newTraversablewithout its first element as anOption.Mtake(int n)Returns the firstnelements of thisTraversable, or all elements ifnexceeds the length.MtakeRight(int n)Returns the lastnelements of thisTraversable, or all elements ifnexceeds the length.MtakeUntil(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)Takes elements from thisTraversableuntil the given predicate holds for an element.MtakeWhile(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)Takes elements from thisTraversablewhile the given predicate holds.java.util.Map<K,java.util.Collection<V>>toJavaMap()Converts this VavrMapto ajava.util.Mapwhile preserving characteristics like insertion order (LinkedHashMultimap) and sort order (SortedMultimap).protected <JM extends java.util.Map<K,java.util.Collection<V>>>
JMtoJavaMap(JM javaMap)Converts thisMultimapto a JavaMapusing the provided map instance.java.lang.StringtoString()Clarifies that values have a proper toString() method implemented.Traversable<V>values()Returns aTraversablecontaining all the values of thisMultimap.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.vavr.collection.Foldable
fold, reduce, reduceOption
-
Methods inherited from interface io.vavr.Function1
andThen, arity, compose, compose1, curried, isMemoized, memoized, partial, reversed, tupled
-
Methods inherited from interface io.vavr.collection.Multimap
apply, asPartialFunction, collect, contains, containsValue, flatMap, foldRight, forEach, hasDefiniteSize, isDefinedAt, isDistinct, isTraversableAgain, iterator, length, map, mapTo, mapToVoid, scanLeft, scanRight, transform, unzip, unzip, unzip3, unzip3, zip, zipAll, zipWith, zipWithIndex, zipWithIndex
-
Methods inherited from interface io.vavr.PartialFunction
lift
-
Methods inherited from interface io.vavr.collection.Traversable
arrangeBy, average, containsAll, count, existsUnique, find, findLast, foldLeft, forEachWithIndex, get, headOption, isOrdered, isSequential, isSingleValued, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, spliterator, sum
-
Methods inherited from interface io.vavr.Value
collect, collect, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, out, out, stderr, stdout, 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, toTree, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
back
protected final Map<K,Traversable<V>> back
The backing map that stores the key-value pairs.
-
emptyContainer
protected final AbstractMultimap.SerializableSupplier<Traversable<?>> emptyContainer
A supplier that creates empty containers for new key entries.
-
containerType
private final Multimap.ContainerType containerType
-
-
Constructor Detail
-
AbstractMultimap
AbstractMultimap(Map<K,Traversable<V>> back, Multimap.ContainerType containerType, AbstractMultimap.SerializableSupplier<Traversable<?>> emptyContainer)
Creates a new AbstractMultimap with the specified backing map, container type, and empty container supplier.- Parameters:
back- The backing map that stores the key-value pairscontainerType- The type of container used to store multiple values for a keyemptyContainer- A supplier that creates empty containers for new key entries
-
-
Method Detail
-
emptyMapSupplier
protected abstract <K2,V2> Map<K2,V2> emptyMapSupplier()
Returns an empty Map instance specific to the implementing class.- Type Parameters:
K2- Key type of the empty mapV2- Value type of the empty map- Returns:
- An empty Map instance
-
emptyInstance
protected abstract <K2,V2> Multimap<K2,V2> emptyInstance()
Returns an empty Multimap instance specific to the implementing class.- Type Parameters:
K2- Key type of the empty multimapV2- Value type of the empty multimap- Returns:
- An empty Multimap instance
-
createFromMap
protected abstract <K2,V2> Multimap<K2,V2> createFromMap(Map<K2,Traversable<V2>> back)
Creates a new Multimap instance from the given backing map.- Type Parameters:
K2- Key type of the new multimapV2- Value type of the new multimap- Parameters:
back- The backing map to create the multimap from- Returns:
- A new Multimap instance containing the entries from the backing map
-
createFromEntries
private <K2,V2> Multimap<K2,V2> createFromEntries(java.lang.Iterable<? extends Tuple2<? extends K2,? extends V2>> entries)
Creates a new Multimap from the given entries by grouping values by their keys. For each key, a new container is created using the emptyContainer supplier, and values are added using the containerType's add operation.- Type Parameters:
K2- Key type of the new multimapV2- Value type of the new multimap- Parameters:
entries- The entries to create the multimap from- Returns:
- A new Multimap containing all the entries with values grouped by keys
-
asMap
public Map<K,Traversable<V>> asMap()
Description copied from interface:MultimapConverts thisMultimapto aMap
-
bimap
public <K2,V2> Multimap<K2,V2> bimap(@NonNull java.util.function.Function<? super K,? extends K2> keyMapper, @NonNull java.util.function.Function<? super V,? extends V2> valueMapper)
Description copied from interface:MultimapMaps thisMultimapto a newMultimapwith different component type by applying a function to its elements.- Specified by:
bimapin interfaceMultimap<K,V>- Type Parameters:
K2- key's component type of the multimap resultV2- value's component type of the multimap result- Parameters:
keyMapper- aFunctionthat maps the keys of typeKto keys of typeK2valueMapper- aFunctionthat the values of typeVto values of typeV2- Returns:
- a new
Multimap
-
containsKey
public boolean containsKey(K key)
Description copied from interface:MultimapReturnstrueif this multimap contains a mapping for the specified key.- Specified by:
containsKeyin interfaceMultimap<K,V>- Parameters:
key- key whose presence in this multimap is to be tested- Returns:
trueif this multimap contains a mapping for the specified key
-
getContainerType
public Multimap.ContainerType getContainerType()
Description copied from interface:MultimapReturns the type of theTraversablevalue container of thisMultiMap.- Specified by:
getContainerTypein interfaceMultimap<K,V>- Returns:
- an enum value representing the container type
-
flatMap
public <K2,V2> Multimap<K2,V2> flatMap(@NonNull java.util.function.BiFunction<? super K,? super V,? extends java.lang.Iterable<Tuple2<K2,V2>>> mapper)
Description copied from interface:MultimapFlatMaps thisMultimapto a newMultimapwith different component type.
-
get
public Option<Traversable<V>> get(K key)
Description copied from interface:MultimapReturns theSomeof value to which the specified key is mapped, orNoneif this multimap contains no mapping for the key.
-
getOrElse
public Traversable<V> getOrElse(K key, Traversable<? extends V> defaultValue)
Description copied from interface:MultimapReturns the value associated with a key, or a default value if the key is not contained in the map
-
keySet
public Set<K> keySet()
Description copied from interface:MultimapReturns the keys contained in this multimap.
-
map
public <K2,V2> Multimap<K2,V2> map(@NonNull java.util.function.BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
Description copied from interface:MultimapMaps the entries of thisMultimapto form a newMultimap.
-
mapValues
public <V2> Multimap<K,V2> mapValues(@NonNull java.util.function.Function<? super V,? extends V2> valueMapper)
Description copied from interface:MultimapMaps the values of thisMultimapwhile preserving the corresponding keys.
-
put
public M put(K key, V value)
Description copied from interface:MultimapAssociates the specified value with the specified key in this multimap. If the map previously contained a mapping for the key, the old value is replaced by the specified value.
-
put
public M put(@NonNull Tuple2<? extends K,? extends V> entry)
Description copied from interface:MultimapConvenience method forput(entry._1, entry._2).
-
remove
public M remove(K key)
Description copied from interface:MultimapRemoves the mapping for a key from this multimap if it is present.
-
remove
public M remove(K key, V value)
Description copied from interface:MultimapRemoves the key-value pair from this multimap if it is present.
-
removeAll
public M removeAll(@NonNull java.lang.Iterable<? extends K> keys)
Description copied from interface:MultimapRemoves the mapping for a key from this multimap if it is present.
-
size
public int size()
Description copied from interface:TraversableReturns the number of elements in this Traversable.Alias for
Traversable.length().
-
values
public Traversable<V> values()
Description copied from interface:MultimapReturns aTraversablecontaining all the values of thisMultimap.- Specified by:
valuesin interfaceMultimap<K,V>- Returns:
- a new
Traversable
-
distinct
public M distinct()
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance with all duplicates removed. Element equality is determined usingequals.
-
distinctBy
public M distinctBy(@NonNull java.util.Comparator<? super Tuple2<K,V>> comparator)
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.- Specified by:
distinctByin interfaceMultimap<K,V>- Specified by:
distinctByin interfaceTraversable<K>- Parameters:
comparator- a comparator used to determine equality of elements- Returns:
- a new
Traversablewith duplicates removed
-
distinctBy
public <U> M distinctBy(@NonNull java.util.function.Function<? super Tuple2<K,V>,? extends U> keyExtractor)
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.The first occurrence of each key is retained in the resulting sequence.
- Specified by:
distinctByin interfaceMultimap<K,V>- Specified by:
distinctByin interfaceTraversable<K>- Type Parameters:
U- the type of key- Parameters:
keyExtractor- a function to extract keys for determining uniqueness- Returns:
- a new
Traversablewith duplicates removed based on keys
-
drop
public M drop(int n)
Description copied from interface:TraversableReturns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.
-
dropRight
public M dropRight(int n)
Description copied from interface:TraversableReturns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.
-
dropUntil
public M dropUntil(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Description copied from interface:TraversableReturns a newTraversablestarting from the first element that satisfies the givenpredicate, dropping all preceding elements.
-
dropWhile
public M dropWhile(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Description copied from interface:TraversableReturns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.This is equivalent to
dropUntil(predicate.negate()), which is useful for method references that cannot be negated directly.
-
filter
public M filter(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Description copied from interface:TraversableReturns a new traversable containing only the elements that satisfy the given predicate.
-
reject
public M reject(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Description copied from interface:TraversableReturns a new traversable containing only the elements that do not satisfy the given predicate.This is equivalent to
filter(predicate.negate()).
-
filter
public M filter(@NonNull java.util.function.BiPredicate<? super K,? super V> predicate)
Description copied from interface:MultimapReturns a new Multimap consisting of all elements which satisfy the given predicate.
-
reject
public M reject(@NonNull java.util.function.BiPredicate<? super K,? super V> predicate)
Description copied from interface:MultimapReturns a new Multimap consisting of all elements which do not satisfy the given predicate.
-
filterKeys
public M filterKeys(@NonNull java.util.function.Predicate<? super K> predicate)
Description copied from interface:MultimapReturns a new Multimap consisting of all elements with keys which satisfy the given predicate.- Specified by:
filterKeysin interfaceMultimap<K,V>- Parameters:
predicate- the predicate used to test keys of elements- Returns:
- a new Multimap
-
rejectKeys
public M rejectKeys(@NonNull java.util.function.Predicate<? super K> predicate)
Description copied from interface:MultimapReturns a new Multimap consisting of all elements with keys which do not satisfy the given predicate.- Specified by:
rejectKeysin interfaceMultimap<K,V>- Parameters:
predicate- the predicate used to test keys of elements- Returns:
- a new Multimap
-
filterValues
public M filterValues(@NonNull java.util.function.Predicate<? super V> predicate)
Description copied from interface:MultimapReturns a new Multimap consisting of all elements with values which satisfy the given predicate.- Specified by:
filterValuesin interfaceMultimap<K,V>- Parameters:
predicate- the predicate used to test values of elements- Returns:
- a new Multimap
-
rejectValues
public M rejectValues(@NonNull java.util.function.Predicate<? super V> predicate)
Description copied from interface:MultimapReturns a new Multimap consisting of all elements with values which do not satisfy the given predicate.- Specified by:
rejectValuesin interfaceMultimap<K,V>- Parameters:
predicate- the predicate used to test values of elements- Returns:
- a new Multimap
-
removeAll
@Deprecated public M removeAll(@NonNull java.util.function.BiPredicate<? super K,? super V> predicate)
Deprecated.Description copied from interface:MultimapReturns a new Multimap consisting of all elements which do not satisfy the given predicate.
-
removeKeys
@Deprecated public M removeKeys(@NonNull java.util.function.Predicate<? super K> predicate)
Deprecated.Description copied from interface:MultimapReturns a new Multimap consisting of all elements with keys which do not satisfy the given predicate.- Specified by:
removeKeysin interfaceMultimap<K,V>- Parameters:
predicate- the predicate used to test keys of elements- Returns:
- a new Multimap
-
removeValues
@Deprecated public M removeValues(@NonNull java.util.function.Predicate<? super V> predicate)
Deprecated.Description copied from interface:MultimapReturns a new Multimap consisting of all elements with values which do not satisfy the given predicate.- Specified by:
removeValuesin interfaceMultimap<K,V>- Parameters:
predicate- the predicate used to test values of elements- Returns:
- a new Multimap
-
groupBy
public <C> Map<C,M> groupBy(@NonNull java.util.function.Function<? super Tuple2<K,V>,? extends C> classifier)
Description copied from interface:TraversableGroups elements of thisTraversablebased on a classifier function.- Specified by:
groupByin interfaceMultimap<K,V>- Specified by:
groupByin interfaceTraversable<K>- Type Parameters:
C- The type of the group keys- Parameters:
classifier- A function that assigns each element to a group- Returns:
- A map where each key corresponds to a group of elements
- See Also:
Traversable.arrangeBy(Function)
-
grouped
public Iterator<M> grouped(int size)
Description copied from interface:TraversableSplits thisTraversableinto consecutive blocks of the given size.Let
lengthbe the number of elements in thisTraversable:- If empty, the resulting
Iteratoris empty. - If
size <= length, the resultingIteratorcontainslength / sizeblocks of sizesizeand possibly a final smaller block of sizelength % size. - If
size > length, the resultingIteratorcontains a single block of sizelength.
Examples:
[].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]]Note:
grouped(size)is equivalent tosliding(size, size). - If empty, the resulting
-
init
public M init()
Description copied from interface:TraversableReturns all elements of this Traversable except the last one.This is the dual of
Traversable.tail().
-
head
public Tuple2<K,V> head()
Description copied from interface:TraversableReturns the first element of this non-emptyTraversable.- Specified by:
headin interfaceTraversable<K>- Returns:
- the first element
-
initOption
public Option<M> initOption()
Description copied from interface:TraversableReturns all elements of this Traversable except the last one, wrapped in anOption.This is the dual of
Traversable.tailOption().- Specified by:
initOptionin interfaceMultimap<K,V>- Specified by:
initOptionin interfaceTraversable<K>- Returns:
Some(traversable)if non-empty, orNoneif this Traversable is empty
-
isAsync
public boolean isAsync()
Description copied from interface:ValueChecks if thisValueis asynchronously (short: async) computed.Methods of a
Valueinstance that operate on the underlying value may block the current thread until the value is present and the computation can be performed.
-
isEmpty
public boolean isEmpty()
Description copied from interface:TraversableChecks if this Traversable contains no elements.
-
isLazy
public boolean isLazy()
Description copied from interface:ValueChecks if thisValueis lazily evaluated.
-
iterator
public @NonNull Iterator<Tuple2<K,V>> iterator()
Description copied from interface:TraversableReturns an iterator over the elements of this Traversable, implemented viaTraversable.head()andTraversable.tail(). Subclasses may override for a more efficient implementation.
-
last
public Tuple2<K,V> last()
Description copied from interface:TraversableReturns the last element of this Traversable.- Specified by:
lastin interfaceTraversable<K>- Returns:
- the last element
-
merge
public M merge(@NonNull Multimap<? extends K,? extends V> that)
Description copied from interface:MultimapCreates a new multimap which by merging the entries ofthismultimap andthatmultimap.If collisions occur, the value of
thismultimap is taken.
-
merge
public <K2 extends K,V2 extends V> M merge(@NonNull Multimap<K2,V2> that, @NonNull java.util.function.BiFunction<Traversable<V>,Traversable<V2>,Traversable<V>> collisionResolution)
Description copied from interface:MultimapCreates a new multimap which by merging the entries ofthismultimap andthatmultimap.Uses the specified collision resolution function if two keys are the same. The collision resolution function will always take the first argument from
thismultimap and the second fromthatmultimap.
-
orElse
public M orElse(java.lang.Iterable<? extends Tuple2<K,V>> other)
Returns thisMultimapif it is nonempty, otherwiseMultimapcreated from iterable, using existing multimap properties.
-
orElse
public M orElse(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends Tuple2<K,V>>> supplier)
Returns thisMultimapif it is nonempty, otherwiseMultimapcreated from result of evaluating supplier, using existing multimap properties.
-
partition
public Tuple2<M,M> partition(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Description copied from interface:TraversableSplits thisTraversableinto two partitions according to a predicate.The first partition contains all elements that satisfy the predicate, and the second contains all elements that do not. The original iteration order is preserved.
-
peek
public M peek(@NonNull java.util.function.Consumer<? super Tuple2<K,V>> action)
Description copied from interface:ValuePerforms the givenactionon the first element if this is an eager implementation. Performs the givenactionon all elements (the first immediately, successive deferred), if this is a lazy implementation.
-
replace
public M replace(@NonNull Tuple2<K,V> currentElement, Tuple2<K,V> newElement)
Description copied from interface:TraversableReplaces the first occurrence ofcurrentElementwithnewElement, if it exists.
-
replaceAll
public M replaceAll(@NonNull Tuple2<K,V> currentElement, Tuple2<K,V> newElement)
Description copied from interface:TraversableReplaces all occurrences ofcurrentElementwithnewElement.- Specified by:
replaceAllin interfaceMultimap<K,V>- Specified by:
replaceAllin interfaceTraversable<K>- Parameters:
currentElement- the element to be replacednewElement- the replacement element- Returns:
- a new Traversable with all occurrences of
currentElementreplaced bynewElement
-
replaceValue
public M replaceValue(K key, V value)
Description copied from interface:MultimapReplaces the entry for the specified key only if it is currently mapped to some value.- Specified by:
replaceValuein interfaceMultimap<K,V>- Parameters:
key- the key of the element to be substitutedvalue- the new value to be associated with the key- Returns:
- a new map containing key mapped to value if key was contained before. The old map otherwise
-
replace
public M replace(K key, V oldValue, V newValue)
Description copied from interface:MultimapReplaces the entry with the specified key and oldValue.- Specified by:
replacein interfaceMultimap<K,V>- Parameters:
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 key- Returns:
- a new map containing key mapped to newValue if key was contained before and oldValue was associated with the key. The old map otherwise.
-
replaceAll
public M replaceAll(@NonNull java.util.function.BiFunction<? super K,? super V,? extends V> function)
Description copied from interface:MultimapReplaces 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.- Specified by:
replaceAllin interfaceMultimap<K,V>- Parameters:
function- function transforming key and current value to a new value- Returns:
- a new map with the same keySet but transformed values
-
retainAll
public M retainAll(@NonNull java.lang.Iterable<? extends Tuple2<K,V>> elements)
Description copied from interface:TraversableRetains only the elements from this Traversable that are contained in the givenelements.
-
scan
public M scan(Tuple2<K,V> zero, @NonNull java.util.function.BiFunction<? super Tuple2<K,V>,? super Tuple2<K,V>,? extends Tuple2<K,V>> operation)
Description copied from interface:TraversableComputes a prefix scan of the elements of this Traversable.The neutral element
zeromay be applied more than once.
-
slideBy
public Iterator<M> slideBy(@NonNull java.util.function.Function<? super Tuple2<K,V>,?> classifier)
Description copied from interface:TraversablePartitions thisTraversableinto consecutive non-overlapping windows according to a classification function.Each window contains elements with the same class, as determined by
classifier. Two consecutive elements belong to the same window only ifclassifierreturns equal values for both. Otherwise, the current window ends and a new window begins with the next element.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]]
-
sliding
public Iterator<M> sliding(int size)
Description copied from interface:TraversableSlides a window of a givensizeover thisTraversablewith a step size of 1.This is equivalent to calling
Traversable.sliding(int, int)with a step size of 1.
-
sliding
public Iterator<M> sliding(int size, int step)
Description copied from interface:TraversableSlides a window of a specificsizewith a givenstepover thisTraversable.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]]
-
span
public Tuple2<M,M> span(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Description copied from interface:TraversableSplits thisTraversableinto a prefix and remainder according to the givenpredicate.The first element of the returned
Tupleis the longest prefix of elements satisfyingpredicate, and the second element is the remaining elements.
-
tail
public M tail()
Description copied from interface:TraversableReturns a newTraversablewithout its first element.
-
tailOption
public Option<M> tailOption()
Description copied from interface:TraversableReturns a newTraversablewithout its first element as anOption.- Specified by:
tailOptionin interfaceMultimap<K,V>- Specified by:
tailOptionin interfaceTraversable<K>- Returns:
Some(traversable)if non-empty, otherwiseNone
-
take
public M take(int n)
Description copied from interface:TraversableReturns the firstnelements of thisTraversable, or all elements ifnexceeds the length.Equivalent to
sublist(0, max(0, min(length(), n))), but safe forn < 0orn > length().If
n < 0, an empty instance is returned. Ifn > length(), the full instance is returned.
-
takeRight
public M takeRight(int n)
Description copied from interface:TraversableReturns the lastnelements of thisTraversable, or all elements ifnexceeds the length.Equivalent to
sublist(max(0, length() - n), length()), but safe forn < 0orn > length().If
n < 0, an empty instance is returned. Ifn > length(), the full instance is returned.
-
takeUntil
public M takeUntil(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Description copied from interface:TraversableTakes elements from thisTraversableuntil the given predicate holds for an element.Equivalent to
takeWhile(predicate.negate()), but useful when using method references that cannot be negated directly.
-
takeWhile
public M takeWhile(@NonNull java.util.function.Predicate<? super Tuple2<K,V>> predicate)
Description copied from interface:TraversableTakes elements from thisTraversablewhile the given predicate holds.- Specified by:
takeWhilein interfaceMultimap<K,V>- Specified by:
takeWhilein interfaceTraversable<K>- Parameters:
predicate- a condition tested sequentially on the elements- Returns:
- a new
Traversablecontaining all elements up to (but not including) the first one that does not satisfy the predicate
-
equals
public boolean equals(java.lang.Object o)
Description copied from interface:TraversableDetermines whether this collection is equal to the given object.In Vavr, there are four basic collection types:
Seq– sequential elementsSet– distinct elementsMap– key-value pairsMultimap– keys mapped to multiple values
- They are of the same collection type (Seq, Set, Map, Multimap)
- They contain the same elements
- For
Seq, the element order is the same
For
MapandMultimap, two entries(key1, value1)and(key2, value2)are equal if both their keys and values are equal.Additional notes:
- No collection equals
null(e.g.,Queue(1) != null) - Null elements are allowed and treated as expected
(e.g.,
List(null, 1) == Stream(null, 1),HashMap((null,1)) == LinkedHashMap((null,1))) - Element order matters only for
Seq - Other collection classes are equal if their types and elements (in iteration order) are equal
- Iterators are compared by reference only
-
hashCode
public int hashCode()
Description copied from interface:TraversableReturns the hash code of this collection.Vavr distinguishes between collections with predictable iteration order (like
Seq) and collections with arbitrary iteration order (likeSet,Map, andMultimap). In all cases, the hash of an empty collection is defined as1.For collections with predictable iteration order, the hash is computed as:
int hash = 1; for (T t : this) { hash = hash * 31 + Objects.hashCode(t); }For collections with arbitrary iteration order, the hash is computed to be independent of element order:
int hash = 1; for (T t : this) { hash += Objects.hashCode(t); }Note that these algorithms may change in future Vavr versions. Hash codes are generally not cached, unlike size/length, because caching would increase memory usage due to persistent tree-based structures. Computing the hash code is linear in time, O(n). For frequently re-used collections (e.g., as
HashMapkeys), caching can be done externally using a wrapper, for example:{@code public final class Hashed{ private final K key; private final Lazy hashCode; public Hashed(K key) { this.key = key; this.hashCode = Lazy.of(() -> Objects.hashCode(key)); } public K key() { return key; }
-
stringPrefix
public java.lang.String stringPrefix()
Description copied from interface:ValueReturns the name of this Value type, which is used by toString().- Specified by:
stringPrefixin interfaceValue<K>- Returns:
- This type name.
-
toString
public java.lang.String toString()
Description copied from interface:ValueClarifies that values have a proper toString() method implemented.See Object.toString().
-
toJavaMap
public java.util.Map<K,java.util.Collection<V>> toJavaMap()
Description copied from interface:MultimapConverts this VavrMapto ajava.util.Mapwhile preserving characteristics like insertion order (LinkedHashMultimap) and sort order (SortedMultimap).
-
toJavaMap
protected <JM extends java.util.Map<K,java.util.Collection<V>>> JM toJavaMap(JM javaMap)
Converts thisMultimapto a JavaMapusing the provided map instance.- Type Parameters:
JM- The type of the Java map- Parameters:
javaMap- The Java map instance to populate with this multimap's entries- Returns:
- The populated Java map
-
-