K
- Key typeV
- Value typepublic final class HashMultimap<K,V> extends Object implements Serializable
Modifier and Type | Class and Description |
---|---|
static class |
HashMultimap.Builder<V> |
Multimap.ContainerType
Modifier and Type | Field and Description |
---|---|
protected Map<K,Traversable<V>> |
back |
protected io.vavr.collection.AbstractMultimap.SerializableSupplier<Traversable<?>> |
emptyContainer |
Modifier and Type | Method and Description |
---|---|
Map<K,Traversable<V>> |
asMap()
Converts this
Multimap to a Map |
<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. |
boolean |
containsKey(K key)
Returns
true if this multimap contains a mapping for the specified key. |
protected <K2,V2> HashMultimap<K2,V2> |
createFromMap(Map<K2,Traversable<V2>> back) |
M |
distinct()
Returns a new version of this which contains no duplicates.
|
M |
distinctBy(Comparator<? super Tuple2<K,V>> comparator)
Returns a new version of this which contains no duplicates.
|
<U> M |
distinctBy(Function<? super Tuple2<K,V>,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.
|
M |
drop(int n)
Drops the first n elements of this or all elements, if this length < n.
|
M |
dropRight(int n)
Drops the last n elements of this or all elements, if this length < n.
|
M |
dropUntil(Predicate<? super Tuple2<K,V>> predicate)
Drops elements until the predicate holds for the current element.
|
M |
dropWhile(Predicate<? super Tuple2<K,V>> predicate)
Drops elements while the predicate holds for the current element.
|
protected <K2,V2> HashMultimap<K2,V2> |
emptyInstance() |
protected <K2,V2> Map<K2,V2> |
emptyMapSupplier() |
boolean |
equals(Object o)
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(BiPredicate<? super K,? super V> predicate)
Returns a new Multimap consisting of all elements which satisfy the given predicate.
|
M |
filter(Predicate<? super Tuple2<K,V>> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
M |
filterKeys(Predicate<? super K> predicate)
Returns a new Multimap consisting of all elements with keys which satisfy the given predicate.
|
M |
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. |
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,M> |
groupBy(Function<? super Tuple2<K,V>,? extends C> classifier)
Groups this elements by classifying the elements.
|
Iterator<M> |
grouped(int size)
Groups this
Traversable into fixed size blocks. |
int |
hashCode()
Returns the hash code of this collection.
|
Tuple2<K,V> |
head()
Returns the first element of a non-empty Traversable.
|
M |
init()
Dual of Traversable.tail(), returning all elements except the last.
|
Option<M> |
initOption()
Dual of Traversable.tailOption(), returning all elements except the last as
Option . |
boolean |
isAsync()
Checks if this
Value is asynchronously (short: async) computed. |
boolean |
isEmpty()
Checks if this Traversable is empty.
|
boolean |
isLazy()
Checks if this
Value is lazily evaluated. |
Iterator<Tuple2<K,V>> |
iterator()
An iterator by means of head() and tail().
|
Set<K> |
keySet()
Returns the keys contained in this multimap.
|
Tuple2<K,V> |
last()
Dual of Traversable.head(), returning the last element.
|
<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 . |
<V2> Multimap<K,V2> |
mapValues(Function<? super V,? extends V2> valueMapper)
Maps the values of this
Multimap while preserving the corresponding keys. |
M |
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> HashMultimap<K,V> |
narrow(HashMultimap<? extends K,? extends V> map)
Narrows a widened
HashMultimap<? extends K, ? extends V> to HashMultimap<K, V>
by performing a type safe-cast. |
M |
orElse(Iterable<? extends Tuple2<K,V>> other)
Returns this
Multimap if it is nonempty,
otherwise Multimap created from iterable, using existing multimap properties. |
M |
orElse(Supplier<? extends Iterable<? extends Tuple2<K,V>>> supplier)
Returns this
Multimap if it is nonempty,
otherwise Multimap created from result of evaluating supplier, using existing multimap properties. |
Tuple2<M,M> |
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. |
M |
peek(Consumer<? super Tuple2<K,V>> action)
Performs the given
action on the first element if this is an eager implementation. |
M |
put(K key,
V value)
Associates the specified value with the specified key in this multimap.
|
M |
put(Tuple2<? extends K,? extends V> entry)
Convenience method for
put(entry._1, entry._2) . |
M |
reject(BiPredicate<? super K,? super V> predicate)
Returns a new Multimap consisting of all elements which do not satisfy the given predicate.
|
M |
reject(Predicate<? super Tuple2<K,V>> predicate)
Returns a new traversable consisting of all elements which do not satisfy the given predicate.
|
M |
rejectKeys(Predicate<? super K> predicate)
Returns a new Multimap consisting of all elements with keys which do not satisfy the given predicate.
|
M |
rejectValues(Predicate<? super V> predicate)
Returns a new Multimap consisting of all elements with values which do not satisfy the given predicate.
|
M |
remove(K key)
Removes the mapping for a key from this multimap if it is present.
|
M |
remove(K key,
V value)
Removes the key-value pair from this multimap if it is present.
|
M |
removeAll(BiPredicate<? super K,? super V> predicate)
Deprecated.
|
M |
removeAll(Iterable<? extends K> keys)
Removes the mapping for a key from this multimap if it is present.
|
M |
removeKeys(Predicate<? super K> predicate)
Deprecated.
|
M |
removeValues(Predicate<? super V> predicate)
Deprecated.
|
M |
replace(K key,
V oldValue,
V newValue)
Replaces the entry with the specified key and oldValue.
|
M |
replace(Tuple2<K,V> currentElement,
Tuple2<K,V> newElement)
Replaces the first occurrence (if exists) of the given currentElement with newElement.
|
M |
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.
|
M |
replaceAll(Tuple2<K,V> currentElement,
Tuple2<K,V> newElement)
Replaces all occurrences of the given currentElement with newElement.
|
M |
replaceValue(K key,
V value)
Replaces the entry for the specified key only if it is currently mapped to some value.
|
M |
retainAll(Iterable<? extends Tuple2<K,V>> elements)
Keeps all occurrences of the given elements from this.
|
M |
scan(Tuple2<K,V> zero,
BiFunction<? super Tuple2<K,V>,? super Tuple2<K,V>,? extends Tuple2<K,V>> operation)
Computes a prefix scan of the elements of the collection.
|
int |
size()
Computes the number of elements of this Traversable.
|
Iterator<M> |
slideBy(Function<? super Tuple2<K,V>,?> classifier)
Slides a non-overlapping window of a variable size over this
Traversable . |
Iterator<M> |
sliding(int size)
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)
Slides a window of a specific
size and step size over this Traversable . |
Tuple2<M,M> |
span(Predicate<? super Tuple2<K,V>> predicate)
Returns a tuple where the first element is the longest prefix of elements that satisfy the given
predicate and the second element is the remainder. |
String |
stringPrefix()
Returns the name of this Value type, which is used by toString().
|
M |
tail()
Drops the first element of a non-empty Traversable.
|
Option<M> |
tailOption()
Drops the first element of a non-empty Traversable and returns an
Option . |
M |
take(int n)
Takes the first n elements of this or all elements, if this length < n.
|
M |
takeRight(int n)
Takes the last n elements of this or all elements, if this length < n.
|
M |
takeUntil(Predicate<? super Tuple2<K,V>> predicate)
Takes elements until the predicate holds for the current element.
|
M |
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 ). |
protected <JM extends Map<K,Collection<V>>> |
toJavaMap(JM javaMap) |
String |
toString()
Clarifies that values have a proper toString() method implemented.
|
Traversable<V> |
values() |
static <V> HashMultimap.Builder<V> |
withSeq() |
static <V> HashMultimap.Builder<V> |
withSet() |
static <V extends Comparable<?>> |
withSortedSet() |
static <V> HashMultimap.Builder<V> |
withSortedSet(Comparator<? super V> comparator) |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
apply, asPartialFunction, collect, contains, containsValue, flatMap, foldRight, forEach, hasDefiniteSize, isDefinedAt, isDistinct, isTraversableAgain, iterator, length, map, narrow, scanLeft, scanRight, transform, unzip, unzip, unzip3, unzip3, zip, zipAll, zipWith, zipWithIndex, zipWithIndex
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, 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, narrow, 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
getIfDefined, lift, unlift
protected final Map<K,Traversable<V>> back
protected final io.vavr.collection.AbstractMultimap.SerializableSupplier<Traversable<?>> emptyContainer
public static <V> HashMultimap.Builder<V> withSeq()
public static <V> HashMultimap.Builder<V> withSet()
public static <V extends Comparable<?>> HashMultimap.Builder<V> withSortedSet()
public static <V> HashMultimap.Builder<V> withSortedSet(Comparator<? super V> comparator)
public static <K,V> HashMultimap<K,V> narrow(HashMultimap<? 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> HashMultimap<K2,V2> emptyInstance()
protected <K2,V2> HashMultimap<K2,V2> createFromMap(Map<K2,Traversable<V2>> back)
public Map<K,Traversable<V>> asMap()
Multimap
Multimap
to a Map
public <K2,V2> Multimap<K2,V2> bimap(Function<? super K,? extends K2> keyMapper, 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(BiFunction<? super K,? super V,? extends 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 Set<K> keySet()
Multimap
public <K2,V2> Multimap<K2,V2> map(BiFunction<? super K,? super V,Tuple2<K2,V2>> mapper)
Multimap
Multimap
to form a new Multimap
.public <V2> Multimap<K,V2> mapValues(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(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(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(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(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(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(Predicate<? super Tuple2<K,V>> predicate)
Traversable
filter
in interface Multimap<K,V>
filter
in interface Traversable<Tuple2<K,V>>
predicate
- A predicatepublic M reject(Predicate<? super Tuple2<K,V>> predicate)
Traversable
The default implementation is equivalent to
filter(predicate.negate()
reject
in interface Multimap<K,V>
reject
in interface Traversable<Tuple2<K,V>>
predicate
- A predicatepublic M filter(BiPredicate<? super K,? super V> predicate)
Multimap
public M reject(BiPredicate<? super K,? super V> predicate)
Multimap
public M filterKeys(Predicate<? super K> predicate)
Multimap
filterKeys
in interface Multimap<K,V>
predicate
- the predicate used to test keys of elementspublic M rejectKeys(Predicate<? super K> predicate)
Multimap
rejectKeys
in interface Multimap<K,V>
predicate
- the predicate used to test keys of elementspublic M filterValues(Predicate<? super V> predicate)
Multimap
filterValues
in interface Multimap<K,V>
predicate
- the predicate used to test values of elementspublic M rejectValues(Predicate<? super V> predicate)
Multimap
rejectValues
in interface Multimap<K,V>
predicate
- the predicate used to test values of elements@Deprecated public M removeAll(BiPredicate<? super K,? super V> predicate)
Multimap
@Deprecated public M removeKeys(Predicate<? super K> predicate)
Multimap
removeKeys
in interface Multimap<K,V>
predicate
- the predicate used to test keys of elements@Deprecated public M removeValues(Predicate<? super V> predicate)
Multimap
removeValues
in interface Multimap<K,V>
predicate
- the predicate used to test values of elementspublic <C> Map<C,M> groupBy(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, 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(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(Supplier<? extends 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(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(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(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(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, 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(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],[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(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(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(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(Object o)
Traversable
Notes:
public 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 String stringPrefix()
Value
stringPrefix
in interface Value<Tuple2<K,V>>
public String toString()
Value
See Object.toString().
public Map<K,Collection<V>> toJavaMap()
Multimap
Map
to a java.util.Map
while preserving characteristics
like insertion order (LinkedHashMultimap
) and sort order (SortedMultimap
).protected <JM extends Map<K,Collection<V>>> JM toJavaMap(JM javaMap)
Copyright © 2020. All Rights Reserved.