Package io.vavr.collection
Class LinkedHashMultimap<K,V>
java.lang.Object
io.vavr.collection.AbstractMultimap<K,V,LinkedHashMultimap<K,V>>
io.vavr.collection.LinkedHashMultimap<K,V>
- Type Parameters:
K- Key typeV- Value type
- 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>> Serializable,Iterable<Tuple2<K,,V>> Function<K,Traversable<V>>
public final class LinkedHashMultimap<K,V>
extends AbstractMultimap<K,V,LinkedHashMultimap<K,V>>
implements Serializable
A
LinkedHashMap-based implementation of Multimap- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for creating LinkedHashMultimap instances.Nested classes/interfaces inherited from class io.vavr.collection.AbstractMultimap
AbstractMultimap.SerializableSupplier<T>Nested classes/interfaces inherited from interface io.vavr.collection.Multimap
Multimap.ContainerType -
Field Summary
FieldsFields inherited from class io.vavr.collection.AbstractMultimap
back, emptyContainer -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateLinkedHashMultimap(Map<K, Traversable<V>> back, Multimap.ContainerType containerType, AbstractMultimap.SerializableSupplier<Traversable<?>> emptyContainer) -
Method Summary
Modifier and TypeMethodDescriptionprotected <K2,V2> LinkedHashMultimap <K2, V2> createFromMap(@NonNull Map<K2, Traversable<V2>> back) Creates a new Multimap instance from the given backing map.protected <K2,V2> LinkedHashMultimap <K2, V2> Returns an empty Multimap instance specific to the implementing class.protected <K2,V2> Map <K2, V2> Returns an empty Map instance specific to the implementing class.booleanIndicates whether the elements of this Traversable appear in encounter (insertion) order.static <K,V> LinkedHashMultimap <K, V> narrow(LinkedHashMultimap<? extends K, ? extends V> map) Narrows aLinkedHashMultimap<? extends K, ? extends V>toLinkedHashMultimap<K, V>via a type-safe cast.static <V> LinkedHashMultimap.Builder<V> withSeq()Returns a builder for LinkedHashMultimap instances where values are stored in a sequence.static <V> LinkedHashMultimap.Builder<V> withSet()Returns a builder for LinkedHashMultimap instances where values are stored in a set.static <V extends Comparable<?>>
LinkedHashMultimap.Builder<V> Returns a builder for LinkedHashMultimap instances where values are stored in a sorted set.static <V> LinkedHashMultimap.Builder<V> withSortedSet(@NonNull Comparator<? super V> comparator) Returns a builder for LinkedHashMultimap instances where values are stored in a sorted set with a custom comparator.Methods inherited from class io.vavr.collection.AbstractMultimap
asMap, bimap, containsKey, distinct, distinctBy, distinctBy, drop, dropRight, dropUntil, dropWhile, equals, filter, filter, filterKeys, filterValues, flatMap, get, getContainerType, getOrElse, groupBy, grouped, hashCode, head, init, initOption, isAsync, isEmpty, isLazy, iterator, keySet, last, map, mapValues, merge, merge, orElse, orElse, partition, peek, put, put, reject, reject, rejectKeys, rejectValues, remove, remove, removeAll, removeAll, removeKeys, removeValues, replace, replace, replaceAll, replaceAll, replaceValue, retainAll, scan, size, slideBy, sliding, sliding, span, stringPrefix, tail, tailOption, take, takeRight, takeUntil, takeWhile, toJavaMap, toJavaMap, toString, valuesMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.vavr.collection.Foldable
fold, reduce, reduceOptionMethods inherited from interface io.vavr.Function1
andThen, arity, compose, compose1, curried, isMemoized, memoized, partial, reversed, tupledMethods 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, zipWithIndexMethods inherited from interface io.vavr.PartialFunction
liftMethods inherited from interface io.vavr.collection.Traversable
arrangeBy, average, containsAll, count, existsUnique, find, findLast, foldLeft, forEachWithIndex, get, headOption, isOrdered, isSingleValued, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, spliterator, sumMethods 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 Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
LinkedHashMultimap
private LinkedHashMultimap(Map<K, Traversable<V>> back, Multimap.ContainerType containerType, AbstractMultimap.SerializableSupplier<Traversable<?>> emptyContainer)
-
-
Method Details
-
withSeq
Returns a builder for LinkedHashMultimap instances where values are stored in a sequence. Values for each key will be stored in a Vavr List, allowing duplicates and preserving insertion order.- Type Parameters:
V- The value type- Returns:
- A new Builder for creating LinkedHashMultimap instances with sequence-based value storage
-
withSet
Returns a builder for LinkedHashMultimap instances where values are stored in a set. Values for each key will be stored in a Vavr HashSet, eliminating duplicates.- Type Parameters:
V- The value type- Returns:
- A new Builder for creating LinkedHashMultimap instances with set-based value storage
-
withSortedSet
Returns a builder for LinkedHashMultimap instances where values are stored in a sorted set. Values for each key will be stored in a Vavr TreeSet, eliminating duplicates and maintaining natural ordering.- Type Parameters:
V- The value type, must be Comparable- Returns:
- A new Builder for creating LinkedHashMultimap instances with sorted set-based value storage
-
withSortedSet
public static <V> LinkedHashMultimap.Builder<V> withSortedSet(@NonNull Comparator<? super V> comparator) Returns a builder for LinkedHashMultimap instances where values are stored in a sorted set with a custom comparator. Values for each key will be stored in a Vavr TreeSet, eliminating duplicates and maintaining order defined by the comparator.- Type Parameters:
V- The value type- Parameters:
comparator- The comparator to define the ordering of values- Returns:
- A new Builder for creating LinkedHashMultimap instances with sorted set-based value storage using the given comparator
- Throws:
NullPointerException- ifcomparatorisnull
-
narrow
public static <K,V> LinkedHashMultimap<K,V> narrow(LinkedHashMultimap<? extends K, ? extends V> map) Narrows aLinkedHashMultimap<? extends K, ? extends V>toLinkedHashMultimap<K, V>via a type-safe cast. Safe here because the multimap is immutable and no elements can be added that would violate the type (covariance)- Type Parameters:
K- the target key typeV- the target value type- Parameters:
map- the multimap to narrow- Returns:
- the same multimap viewed as
LinkedHashMultimap<K, V>
-
emptyMapSupplier
Description copied from class:AbstractMultimapReturns an empty Map instance specific to the implementing class.- Specified by:
emptyMapSupplierin classAbstractMultimap<K,V, LinkedHashMultimap<K, V>> - Type Parameters:
K2- Key type of the empty mapV2- Value type of the empty map- Returns:
- An empty Map instance
-
emptyInstance
Description copied from class:AbstractMultimapReturns an empty Multimap instance specific to the implementing class.- Specified by:
emptyInstancein classAbstractMultimap<K,V, LinkedHashMultimap<K, V>> - Type Parameters:
K2- Key type of the empty multimapV2- Value type of the empty multimap- Returns:
- An empty Multimap instance
-
createFromMap
Description copied from class:AbstractMultimapCreates a new Multimap instance from the given backing map.- Specified by:
createFromMapin classAbstractMultimap<K,V, LinkedHashMultimap<K, V>> - 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
-
isSequential
public boolean isSequential()Description copied from interface:TraversableIndicates whether the elements of this Traversable appear in encounter (insertion) order.- Specified by:
isSequentialin interfaceTraversable<K>- Returns:
trueif insertion order is preserved,falseotherwise
-