Package io.vavr.collection
Class TreeMultimap<K,V>
- java.lang.Object
-
- io.vavr.collection.AbstractMultimap<K,V,TreeMultimap<K,V>>
-
- io.vavr.collection.TreeMultimap<K,V>
-
- Type Parameters:
K- Key typeV- Value type
- All Implemented Interfaces:
Foldable<Tuple2<K,V>>,Multimap<K,V>,Ordered<K>,SortedMultimap<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>>
public final class TreeMultimap<K,V> extends AbstractMultimap<K,V,TreeMultimap<K,V>> implements java.io.Serializable, SortedMultimap<K,V>
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTreeMultimap.Builder<V>Builder class for creating TreeMultimap 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
Fields Modifier and Type Field Description private static longserialVersionUID-
Fields inherited from class io.vavr.collection.AbstractMultimap
back, emptyContainer
-
-
Constructor Summary
Constructors Modifier Constructor Description privateTreeMultimap(Map<K,Traversable<V>> back, Multimap.ContainerType containerType, AbstractMultimap.SerializableSupplier<Traversable<?>> emptyContainer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Comparator<K>comparator()Returns the comparator that governs the ordering of elements in this collection.protected <K2,V2>
TreeMultimap<K2,V2>createFromMap(@NonNull Map<K2,Traversable<V2>> back)Creates a new Multimap instance from the given backing map.protected <K2,V2>
TreeMultimap<K2,V2>emptyInstance()Returns an empty Multimap instance specific to the implementing class.protected <K2,V2>
Map<K2,V2>emptyMapSupplier()Returns an empty Map instance specific to the implementing class.SortedSet<K>keySet()Returns the keys contained in this multimap.static <K,V>
TreeMultimap<K,V>narrow(TreeMultimap<? extends K,? extends V> map)Narrows aTreeMultimap<? extends K, ? extends V>toTreeMultimap<K, V>via a type-safe cast.java.util.SortedMap<K,java.util.Collection<V>>toJavaMap()Converts this VavrMapto ajava.util.Mapwhile preserving characteristics like insertion order (LinkedHashMultimap) and sort order (SortedMultimap).static <V> TreeMultimap.Builder<V>withSeq()Returns a builder for TreeMultimap instances where values are stored in a sequence.static <V> TreeMultimap.Builder<V>withSet()Returns a builder for TreeMultimap instances where values are stored in a set.static <V extends java.lang.Comparable<?>>
TreeMultimap.Builder<V>withSortedSet()Returns a builder for TreeMultimap instances where values are stored in a sorted set.static <V> TreeMultimap.Builder<V>withSortedSet(java.util.Comparator<? super V> comparator)Returns a builder for TreeMultimap 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, 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, toString, values
-
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, asMap, asPartialFunction, bimap, collect, contains, containsKey, containsValue, flatMap, flatMap, foldRight, forEach, get, getContainerType, getOrElse, hasDefiniteSize, isDefinedAt, isDistinct, isTraversableAgain, iterator, iterator, length, map, map, mapTo, mapToVoid, mapValues, scanLeft, scanRight, size, transform, unzip, unzip, unzip3, unzip3, values, zip, zipAll, zipWith, zipWithIndex, zipWithIndex
-
Methods inherited from interface io.vavr.PartialFunction
lift
-
Methods inherited from interface io.vavr.collection.SortedMultimap
distinct, distinctBy, distinctBy, drop, dropRight, dropUntil, dropWhile, filter, filter, filterKeys, filterValues, groupBy, grouped, init, initOption, 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, slideBy, sliding, sliding, span, tail, tailOption, take, takeRight, takeUntil, takeWhile
-
Methods inherited from interface io.vavr.collection.Traversable
arrangeBy, average, containsAll, count, equals, existsUnique, find, findLast, foldLeft, forEachWithIndex, get, hashCode, head, headOption, isEmpty, isOrdered, isSequential, isSingleValued, last, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, 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, isAsync, isLazy, 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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TreeMultimap
private TreeMultimap(Map<K,Traversable<V>> back, Multimap.ContainerType containerType, AbstractMultimap.SerializableSupplier<Traversable<?>> emptyContainer)
-
-
Method Detail
-
withSeq
public static <V> TreeMultimap.Builder<V> withSeq()
Returns a builder for TreeMultimap 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 TreeMultimap instances with sequence-based value storage
-
withSet
public static <V> TreeMultimap.Builder<V> withSet()
Returns a builder for TreeMultimap 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 TreeMultimap instances with set-based value storage
-
withSortedSet
public static <V extends java.lang.Comparable<?>> TreeMultimap.Builder<V> withSortedSet()
Returns a builder for TreeMultimap 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 TreeMultimap instances with sorted set-based value storage
-
withSortedSet
public static <V> TreeMultimap.Builder<V> withSortedSet(java.util.Comparator<? super V> comparator)
Returns a builder for TreeMultimap 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 TreeMultimap instances with sorted set-based value storage using the given comparator
-
narrow
public static <K,V> TreeMultimap<K,V> narrow(TreeMultimap<? extends K,? extends V> map)
Narrows aTreeMultimap<? extends K, ? extends V>toTreeMultimap<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)CAUTION: If
Kis narrowed, the underlyingComparatormight fail!- Type Parameters:
K- the target key typeV- the target value type- Parameters:
map- the multimap to narrow- Returns:
- the same multimap viewed as
TreeMultimap<K, V>
-
emptyMapSupplier
protected <K2,V2> Map<K2,V2> emptyMapSupplier()
Description copied from class:AbstractMultimapReturns an empty Map instance specific to the implementing class.- Specified by:
emptyMapSupplierin classAbstractMultimap<K,V,TreeMultimap<K,V>>- Type Parameters:
K2- Key type of the empty mapV2- Value type of the empty map- Returns:
- An empty Map instance
-
emptyInstance
protected <K2,V2> TreeMultimap<K2,V2> emptyInstance()
Description copied from class:AbstractMultimapReturns an empty Multimap instance specific to the implementing class.- Specified by:
emptyInstancein classAbstractMultimap<K,V,TreeMultimap<K,V>>- Type Parameters:
K2- Key type of the empty multimapV2- Value type of the empty multimap- Returns:
- An empty Multimap instance
-
createFromMap
protected <K2,V2> TreeMultimap<K2,V2> createFromMap(@NonNull Map<K2,Traversable<V2>> back)
Description copied from class:AbstractMultimapCreates a new Multimap instance from the given backing map.- Specified by:
createFromMapin classAbstractMultimap<K,V,TreeMultimap<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
-
comparator
public java.util.Comparator<K> comparator()
Description copied from interface:OrderedReturns the comparator that governs the ordering of elements in this collection. The returned comparator must be consistent with the collection's iteration order.- Specified by:
comparatorin interfaceOrdered<K>- Returns:
- the comparator defining the element order
-
keySet
public SortedSet<K> keySet()
Description copied from interface:MultimapReturns the keys contained in this multimap.- Specified by:
keySetin interfaceMultimap<K,V>- Specified by:
keySetin interfaceSortedMultimap<K,V>- Overrides:
keySetin classAbstractMultimap<K,V,TreeMultimap<K,V>>- Returns:
Setof the keys contained in this multimap.
-
toJavaMap
public java.util.SortedMap<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).- Specified by:
toJavaMapin interfaceMultimap<K,V>- Specified by:
toJavaMapin interfaceSortedMultimap<K,V>- Overrides:
toJavaMapin classAbstractMultimap<K,V,TreeMultimap<K,V>>- Returns:
- a new
java.util.Mapinstance
-
-