CopyOnWriteMultiset


@UnstableApi
class CopyOnWriteMultiset<E : Any?> : Iterable


An unordered collection of elements that allows duplicates, but also allows access to a set of unique elements.

This class is thread-safe using the same method as . Mutation methods cause the underlying data to be copied. elementSet and iterator return snapshots that are unaffected by subsequent mutations.

Iterating directly on this class reveals duplicate elements. Unique elements can be accessed via elementSet. Iteration order for both of these is not defined.

Parameters
<E : Any?>

The type of element being stored.

Summary

Public constructors

Public functions

Unit
add(element: E!)

Adds element to the multiset.

Int
count(element: E!)

Returns the number of occurrences of an element in this multiset.

(Mutable)Set<E!>!

Returns a snapshot of the unique elements currently in this multiset.

(Mutable)Iterator<E!>!

Returns an iterator over a snapshot of all the elements currently in this multiset (including duplicates).

Unit
remove(element: E!)

Removes element from the multiset.

Inherited functions

From java.lang.Iterable
Unit
forEach(action: Consumer<T!>!)
Spliterator<T!>!

Public constructors

CopyOnWriteMultiset

CopyOnWriteMultiset()

Public functions

add

fun add(element: E!): Unit

Adds element to the multiset.

Parameters
element: E!

The element to be added.

count

fun count(element: E!): Int

Returns the number of occurrences of an element in this multiset.

elementSet

fun elementSet(): (Mutable)Set<E!>!

Returns a snapshot of the unique elements currently in this multiset.

Changes to the underlying multiset are not reflected in the returned value.

Returns
(Mutable)Set<E!>!

An unmodifiable set containing the unique elements in this multiset.

iterator

fun iterator(): (Mutable)Iterator<E!>!

Returns an iterator over a snapshot of all the elements currently in this multiset (including duplicates).

Changes to the underlying multiset are not reflected in the returned value.

Returns
(Mutable)Iterator<E!>!

An unmodifiable iterator over all the elements in this multiset (including duplicates).

remove

fun remove(element: E!): Unit

Removes element from the multiset.

Parameters
element: E!

The element to be removed.