Package com.google.common.collect
Class ImmutableSortedMultiset.Builder<E>
java.lang.Object
com.google.common.collect.ImmutableCollection.Builder<E>
com.google.common.collect.ImmutableMultiset.Builder<E>
com.google.common.collect.ImmutableSortedMultiset.Builder<E>
- Enclosing class:
ImmutableSortedMultiset<E>
A builder for creating immutable multiset instances, especially
public static final
multisets ("constant multisets"). Example:
public static final ImmutableSortedMultiset<Bean> BEANS =
new ImmutableSortedMultiset.Builder<Bean>(colorComparator())
.addCopies(Bean.COCOA, 4)
.addCopies(Bean.GARDEN, 6)
.addCopies(Bean.RED, 8)
.addCopies(Bean.BLACK_EYED, 10)
.build();
Builder instances can be reused; it is safe to call build()
multiple times to build
multiple multisets in series.
- Since:
- 12.0
-
Field Summary
Fields inherited from class com.google.common.collect.ImmutableMultiset.Builder
contents
Fields inherited from class com.google.common.collect.ImmutableCollection.Builder
DEFAULT_INITIAL_CAPACITY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAddselement
to theImmutableSortedMultiset
.Adds each element ofelements
to theImmutableSortedMultiset
.Adds each element ofelements
to theImmutableSortedMultiset
.Adds each element ofelements
to theImmutableSortedMultiset
.Adds a number of occurrences of an element to thisImmutableSortedMultiset
.build()
Returns a newly-createdImmutableSortedMultiset
based on the contents of theBuilder
.Adds or removes the necessary occurrences of an element such that the element attains the desired count.Methods inherited from class com.google.common.collect.ImmutableMultiset.Builder
buildJdkBacked
Methods inherited from class com.google.common.collect.ImmutableCollection.Builder
expandedCapacity
-
Constructor Details
-
Builder
Creates a new builder. The returned builder is equivalent to the builder generated byImmutableSortedMultiset.orderedBy(Comparator)
.
-
-
Method Details
-
add
Addselement
to theImmutableSortedMultiset
.- Overrides:
add
in classImmutableMultiset.Builder<E>
- Parameters:
element
- the element to add- Returns:
- this
Builder
object - Throws:
NullPointerException
- ifelement
is null
-
add
Adds each element ofelements
to theImmutableSortedMultiset
.- Overrides:
add
in classImmutableMultiset.Builder<E>
- Parameters:
elements
- the elements to add- Returns:
- this
Builder
object - Throws:
NullPointerException
- ifelements
is null or contains a null element
-
addCopies
Adds a number of occurrences of an element to thisImmutableSortedMultiset
.- Overrides:
addCopies
in classImmutableMultiset.Builder<E>
- Parameters:
element
- the element to addoccurrences
- the number of occurrences of the element to add. May be zero, in which case no change will be made.- Returns:
- this
Builder
object - Throws:
NullPointerException
- ifelement
is nullIllegalArgumentException
- ifoccurrences
is negative, or if this operation would result in more thanInteger.MAX_VALUE
occurrences of the element
-
setCount
Adds or removes the necessary occurrences of an element such that the element attains the desired count.- Overrides:
setCount
in classImmutableMultiset.Builder<E>
- Parameters:
element
- the element to add or remove occurrences ofcount
- the desired count of the element in this multiset- Returns:
- this
Builder
object - Throws:
NullPointerException
- ifelement
is nullIllegalArgumentException
- ifcount
is negative
-
addAll
Adds each element ofelements
to theImmutableSortedMultiset
.- Overrides:
addAll
in classImmutableMultiset.Builder<E>
- Parameters:
elements
- theIterable
to add to theImmutableSortedMultiset
- Returns:
- this
Builder
object - Throws:
NullPointerException
- ifelements
is null or contains a null element
-
addAll
Adds each element ofelements
to theImmutableSortedMultiset
.- Overrides:
addAll
in classImmutableMultiset.Builder<E>
- Parameters:
elements
- the elements to add to theImmutableSortedMultiset
- Returns:
- this
Builder
object - Throws:
NullPointerException
- ifelements
is null or contains a null element
-
build
Returns a newly-createdImmutableSortedMultiset
based on the contents of theBuilder
.- Overrides:
build
in classImmutableMultiset.Builder<E>
-