MutableSetMultimap

A Multimap that cannot hold duplicate key-value pairs and that maintains the insertion ordering of values for a given key.

See the Multimap documentation for information common to all multimaps.

The get, asMap, and removeAll methods return a Set of values.

See the Guava User Guide article on Multimap.

See also

Parameters

K

the type of map keys. The map is invariant in its key type.

V

the type of map values. The mutable map is invariant in its value type.

Functions

Link copied to clipboard
abstract override fun asMap(): Map<K, Set<V>>

Returns a view of this multimap as a Map from each distinct key to the nonempty collection of that key's associated values. Note that this.asMap().get(k) is equivalent to this.get(k) only when k is a key contained in the multimap; otherwise it returns null as opposed to an empty collection.

Link copied to clipboard
abstract fun clear()

Removes all elements from this map.

Link copied to clipboard
abstract fun containsEntry(entry: Pair<K, V>): Boolean

Returns true if the multimap contains at least one key-value pair with the key key and the value value.

Link copied to clipboard
abstract fun containsKey(key: K): Boolean

Returns true if the multimap contains the specified key.

Link copied to clipboard
abstract fun containsValue(value: V): Boolean

Returns true if the multimap maps one or more keys to the specified value.

Link copied to clipboard
open fun forEach(p0: Consumer<in Map.Entry<K, V>>)
Link copied to clipboard
abstract operator override fun get(key: K): MutableSet<@UnsafeVariance V>

Returns a mutable view of the set of all the values corresponding to the given key in the multimap.

Link copied to clipboard
abstract fun isEmpty(): Boolean

Returns true if the multimap is empty (contains no elements), false otherwise.

Link copied to clipboard
open operator override fun iterator(): Iterator<Map.Entry<K, V>>

Returns an iterator over the elements of this object.

Link copied to clipboard
abstract fun put(key: K, value: V): Boolean

Associates the specified value with the specified key in the map.

Link copied to clipboard
abstract fun putAll(from: Multimap<K, V>): Boolean

Updates this map with key/value pairs from the specified map from.

abstract fun putAll(key: K, values: Collection<V>): Boolean

Updates this map with key/value pair specified by key and values.

Link copied to clipboard
abstract fun remove(key: K, value: V): Boolean

Removes a single key-value pair with the key key and the value value from this multimap, if such exists. If multiple key-value pairs in the multimap fit this description, which one is removed is unspecified.

Link copied to clipboard
abstract override fun removeAll(key: K): Set<V>

Removes all values associated with the key key.

Link copied to clipboard

Properties

Link copied to clipboard
abstract val entries: Collection<Map.Entry<K, V>>

Returns a read-only Collection of all key/value pairs in this map.

Link copied to clipboard
abstract val keys: Multiset<K>

Returns a read-only Set of all keys in this multimap.

Link copied to clipboard
abstract val keySet: Set<K>

Returns a read-only Set of all the keys in this multimap.

Link copied to clipboard
abstract val size: Int

Returns the number of key/value pairs in the multimap.

Link copied to clipboard
abstract val values: Collection<V>

Returns a read-only Collection of all values in this map. Note that this collection may contain duplicate values.

Extensions

Link copied to clipboard
inline fun <T> Iterable<T>.all(noinline predicate: (T) -> Boolean): Boolean

Returns true if every element in this satisfies the predicate. If this is empty, true is returned.

Link copied to clipboard
inline fun <T> Iterable<T>.any(noinline predicate: (T) -> Boolean): Boolean

Returns true if any element in this satisfies the predicate.

Link copied to clipboard
inline fun <T> Iterable<T>.asString(): String

Returns a string representation of this, with the format [e1, e2, ..., en] (that is, identical to Arrays.toString(Iterables.toArray(iterable))). Note that for most implementations of Collection, collection.toString() also gives the same result, but that behavior is not generally guaranteed.

Link copied to clipboard
infix inline fun <T> Iterable<T>.concat(other: Iterable<T>): Iterable<T>
@JvmName(name = "concatMutable")
infix inline fun <T> MutableIterable<T>.concat(other: MutableIterable<T>): MutableIterable<T>

Combines two iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this, followed by the elements in other. The source iterators are not polled until necessary.

inline fun <T> Iterable<T>.concat(a: Iterable<T>, b: Iterable<T>): Iterable<T>
@JvmName(name = "concatMutable")
inline fun <T> MutableIterable<T>.concat(a: MutableIterable<T>, b: MutableIterable<T>): MutableIterable<T>

Combines three iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this, followed by the elements in a, followed by the elements in b. The source iterators are not polled until necessary.

inline fun <T> Iterable<T>.concat(a: Iterable<T>, b: Iterable<T>, c: Iterable<T>): Iterable<T>
@JvmName(name = "concatMutable")
inline fun <T> MutableIterable<T>.concat(a: MutableIterable<T>, b: MutableIterable<T>, c: MutableIterable<T>): MutableIterable<T>

Combines four iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this, followed by the elements in a, followed by the elements in b, followed by the elements in c. The source iterators are not polled until necessary.

inline fun <T> Iterable<T>.concat(vararg iterables: Iterable<T>): Iterable<T>
@JvmName(name = "concatMutable")
inline fun <T> MutableIterable<T>.concat(vararg iterables: MutableIterable<T>): MutableIterable<T>

Combines multiple iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this, followed by the elements of each iterable in iterables sequentially. The source iterators are not polled until necessary.

Link copied to clipboard

Returns a view of the supplied iterable that wraps each generated Iterator through Iterators.consumingIterator.

Link copied to clipboard
inline fun <T> Iterable<T>.cycleIterable(): Iterable<T>
@JvmName(name = "cycleIterableMutable")
inline fun <T> MutableIterable<T>.cycleIterable(): MutableIterable<T>

Returns an iterable whose iterators cycle indefinitely over the elements of this.

Link copied to clipboard
inline fun <T> Iterable<T>.cycleIterator(): Iterator<T>
@JvmName(name = "cycleMutable")
inline fun <T> MutableIterable<T>.cycleIterator(): MutableIterator<T>

Returns an iterator that cycles indefinitely over the elements of this.

Link copied to clipboard
inline fun <T> Iterable<T>.elementsEqual(other: Iterable<T>): Boolean

Determines whether two iterables contain equal elements in the same order. More specifically, this method returns true if this and other contain the same number of elements and every element of other is equal to the corresponding element of other.

Link copied to clipboard

Returns a view of this containing all elements that are of the type T.

Link copied to clipboard
inline fun <T> Iterable<T>.filterView(noinline retainIfTrue: (T) -> Boolean): Iterable<T>

Returns a view of this containing all elements that satisfy the input predicate retainIfTrue.

Link copied to clipboard
inline fun <T> Iterable<T>.find(defaultValue: T? = null, noinline predicate: (T) -> Boolean): T

Returns the first element in this that satisfies the given predicate; use this method only when such an element is known to exist. If it is possible that no element will match, use tryFind or find instead.

Link copied to clipboard
inline fun <T> Iterable<Iterable<T>>.flatConcat(): Iterable<T>
@JvmName(name = "flatConcatMutable")
inline fun <T> Iterable<MutableIterable<T>>.flatConcat(): MutableIterable<T>

Combines multiple iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this sequentially. The source iterators are not polled until necessary.

inline fun <T> Iterable<Iterator<T>>.flatConcat(): Iterator<T>
@JvmName(name = "flatConcatMutable")
inline fun <T> Iterable<MutableIterator<T>>.flatConcat(): MutableIterator<T>

Combines two iterators into a single iterator. The returned iterator iterates across the elements in this sequentially. The source iterators are not polled until necessary.

Link copied to clipboard
inline fun <T> Iterable<T>.frequency(element: T): Int

Returns the number of elements in the specified iterable that equal the specified object. This implementation avoids a full iteration when the iterable is a Multiset or Set.

Link copied to clipboard
inline operator fun <T> Iterable<T>.get(position: Int): T

Returns the element at the specified position in an iterable.

inline fun <T> Iterable<T>.get(position: Int, defaultValue: T? = null): T

Returns the element at the specified position in an iterable or a default value otherwise.

Link copied to clipboard
inline fun <T> Iterable<T>.getFirst(defaultValue: T): T

Returns the first element in this or defaultValue if the iterable is empty. The Iterators analog to this method is Iterators.getNext.

Link copied to clipboard
inline fun <T> Iterable<T>.getLast(defaultValue: T? = null): T

Returns the last element of this or defaultValue if the iterable is empty. If this is a List with RandomAccess support, then this operation is guaranteed to be O(1).

Link copied to clipboard
inline fun <T> Iterable<T>.indexOf(noinline predicate: (T) -> Boolean): Int

Returns the index in this of the first element that satisfies the provided predicate, or -1 if the Iterable has no such elements.

Link copied to clipboard
inline fun <T> Iterable<T>.isEmpty(): Boolean

Determines if the given iterable contains no elements.

Link copied to clipboard
inline fun <T> Iterable<T>.limit(limitSize: Int): Iterable<T>

Returns a view of this containing its first limitSize elements. If this contains fewer than limitSize elements, the returned view contains all of its elements. The returned iterable's iterator supports remove() if this's iterator does.

Link copied to clipboard
inline fun <T, R : Comparable<R>> Iterable<Iterable<T>>.mergeSorted(crossinline selector: (T) -> Comparable<R>): Iterable<T>

Returns an iterable over the merged contents of all given Iterables in this. Equivalent entries will not be de-duplicated.

inline fun <T, R : Comparable<R>> Iterable<Iterator<T>>.mergeSorted(crossinline selector: (T) -> Comparable<R>): Iterator<T>

Returns an iterator over the merged contents of all given this, traversing every element of the input iterators. Equivalent entries will not be de-duplicated.

Link copied to clipboard

Returns a Collection of all the permutations of the specified Iterable using naturalOrder for establishing the lexicographical ordering.

Returns a Collection of all the permutations of the specified Iterable using the specified selector for establishing the lexicographical ordering.

Returns a Collection of all the permutations of the specified Iterable using the specified comparator for establishing the lexicographical ordering.

Link copied to clipboard
inline fun <T> Iterable<T>.paddedPartition(size: Int): Iterable<List<T?>>

Divides an iterable into unmodifiable sublists of the given size, padding the final iterable with null values if necessary. For example, partitioning an iterable containing [a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e, null]] -- an outer iterable containing two inner lists of three elements each, all in the original order.

Link copied to clipboard
inline fun <T> Iterable<T>.partition(size: Int): Iterable<List<T>>

Divides an iterable into unmodifiable sublists of the given size (the final iterable may be smaller). For example, partitioning an iterable containing [a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e]] -- an outer iterable containing two inner lists of three and two elements, all in the original order.

Link copied to clipboard
inline fun <T> MutableIterable<T>.removeAll(elementsToRemove: Collection<T>): Boolean

Removes, from an iterable, every element that belongs to the provided collection.

Link copied to clipboard
inline fun <T> MutableIterable<T>.removeIf(noinline predicate: (T) -> Boolean): Boolean

Removes, from an iterable, every element that satisfies the provided predicate.

Link copied to clipboard
inline fun <T> MutableIterable<T>.retainAll(elementsToRetain: Collection<T>): Boolean

Removes, from an iterable, every element that does not belong to the provided collection.

Link copied to clipboard
val Iterable<*>.size: Int

Returns the number of elements in this.

Link copied to clipboard
inline fun <T> Iterable<T>.skip(numberToSkip: Int): Iterable<T>
@JvmName(name = "skipMutable")
inline fun <T> MutableIterable<T>.skip(numberToSkip: Int): Iterable<T>

Returns a view of this that skips its first numberToSkip elements. If this contains fewer than numberToSkip elements, the returned iterable skips all of its elements.

Link copied to clipboard

Transforms a MutableSetMultimap into its guava equivalent

Transforms a SetMultimap into its immutable guava equivalent

Transforms a Multimap into its immutable guava equivalent

Transforms a MutableMultimap into its guava equivalent

Link copied to clipboard

Returns a new ListMultimap filled with all elements of this multimap.

Link copied to clipboard
fun <K, V> Multimap<K, V>.toMultimap(): Multimap<K, V>

Returns a new Multiset filled with all elements of this multimap.

Link copied to clipboard

Returns a new MutableListMultimap filled with all elements of this multimap.

Link copied to clipboard

Returns a new MutableMultimap filled with all elements of this multimap.

Link copied to clipboard

Returns a new MutableSetMultimap filled with all elements of this multimap.

Link copied to clipboard

Returns a new SetMultimap filled with all elements of this multimap.

Link copied to clipboard
inline fun <T> Iterable<T>.toTypedArray(): Array<out T>

Copies an iterable's elements into an array.

Link copied to clipboard
inline fun <F, T> Iterable<F>.transform(noinline function: (F) -> T): Iterable<T>

Returns a view containing the result of applying function to each element of this.

@JvmName(name = "transformMutable")
inline fun <F, T> MutableIterable<F>.transform(noinline function: (F) -> T): MutableIterable<T>

Returns a view containing the result of applying function to each element of fromIterable.

Link copied to clipboard
inline fun <T> Iterable<T>.tryFind(noinline predicate: (T) -> Boolean): Optional<T>

Returns an Optional containing the first element in this that satisfies the given predicate, if such an element exists.

Link copied to clipboard

Returns an unmodifiable view of this.