public static class ImmutableMultiset.Builder<E> extends ImmutableCollection.Builder<E>
public static final
multisets ("constant multisets"). Example:
public static final ImmutableMultiset<Bean> BEANS =
new ImmutableMultiset.Builder<Bean>()
.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.
Constructor and Description |
---|
Builder()
Creates a new builder.
|
Modifier and Type | Method and Description |
---|---|
ImmutableMultiset.Builder<E> |
add(E... elements)
Adds each element of
elements to the ImmutableMultiset . |
ImmutableMultiset.Builder<E> |
add(E element)
Adds
element to the ImmutableMultiset . |
ImmutableMultiset.Builder<E> |
addAll(Iterable<? extends E> elements)
Adds each element of
elements to the ImmutableMultiset . |
ImmutableMultiset.Builder<E> |
addAll(Iterator<? extends E> elements)
Adds each element of
elements to the ImmutableMultiset . |
ImmutableMultiset.Builder<E> |
addCopies(E element,
int occurrences)
Adds a number of occurrences of an element to this
ImmutableMultiset . |
ImmutableMultiset<E> |
build()
Returns a newly-created
ImmutableMultiset based on the contents of the Builder . |
ImmutableMultiset.Builder<E> |
setCount(E element,
int count)
Adds or removes the necessary occurrences of an element such that the element attains the
desired count.
|
public Builder()
ImmutableMultiset.builder()
.@CanIgnoreReturnValue public ImmutableMultiset.Builder<E> add(E element)
element
to the ImmutableMultiset
.add
in class ImmutableCollection.Builder<E>
element
- the element to addBuilder
objectNullPointerException
- if element
is null@CanIgnoreReturnValue public ImmutableMultiset.Builder<E> addCopies(E element, int occurrences)
ImmutableMultiset
.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.Builder
objectNullPointerException
- if element
is nullIllegalArgumentException
- if occurrences
is negative, or if this operation
would result in more than Integer.MAX_VALUE
occurrences of the element@CanIgnoreReturnValue public ImmutableMultiset.Builder<E> setCount(E element, int count)
element
- the element to add or remove occurrences ofcount
- the desired count of the element in this multisetBuilder
objectNullPointerException
- if element
is nullIllegalArgumentException
- if count
is negative@CanIgnoreReturnValue public ImmutableMultiset.Builder<E> add(E... elements)
elements
to the ImmutableMultiset
.add
in class ImmutableCollection.Builder<E>
elements
- the elements to addBuilder
objectNullPointerException
- if elements
is null or contains a null element@CanIgnoreReturnValue public ImmutableMultiset.Builder<E> addAll(Iterable<? extends E> elements)
elements
to the ImmutableMultiset
.addAll
in class ImmutableCollection.Builder<E>
elements
- the Iterable
to add to the ImmutableMultiset
Builder
objectNullPointerException
- if elements
is null or contains a null element@CanIgnoreReturnValue public ImmutableMultiset.Builder<E> addAll(Iterator<? extends E> elements)
elements
to the ImmutableMultiset
.addAll
in class ImmutableCollection.Builder<E>
elements
- the elements to add to the ImmutableMultiset
Builder
objectNullPointerException
- if elements
is null or contains a null elementpublic ImmutableMultiset<E> build()
ImmutableMultiset
based on the contents of the Builder
.build
in class ImmutableCollection.Builder<E>
Copyright © 2010–2018. All rights reserved.