Package com.google.common.collect
Class ImmutableMultiset.Builder<E>
- java.lang.Object
 - 
- com.google.common.collect.ImmutableCollection.Builder<E>
 - 
- com.google.common.collect.ImmutableMultiset.Builder<E>
 
 
 
- 
- Direct Known Subclasses:
 ImmutableSortedMultiset.Builder
- Enclosing class:
 - ImmutableMultiset<E>
 
public static class ImmutableMultiset.Builder<E> extends ImmutableCollection.Builder<E>
A builder for creating immutable multiset instances, especiallypublic static finalmultisets ("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.- Since:
 - 2.0
 
 
- 
- 
Constructor Summary
Constructors Constructor Description Builder()Creates a new builder. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ImmutableMultiset.Builder<E>add(E element)Addselementto theImmutableMultiset.ImmutableMultiset.Builder<E>add(E... elements)Adds each element ofelementsto theImmutableMultiset.ImmutableMultiset.Builder<E>addAll(Iterable<? extends E> elements)Adds each element ofelementsto theImmutableMultiset.ImmutableMultiset.Builder<E>addAll(Iterator<? extends E> elements)Adds each element ofelementsto theImmutableMultiset.ImmutableMultiset.Builder<E>addCopies(E element, int occurrences)Adds a number of occurrences of an element to thisImmutableMultiset.ImmutableMultiset<E>build()Returns a newly-createdImmutableMultisetbased on the contents of theBuilder.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. 
 - 
 
- 
- 
Constructor Detail
- 
Builder
public Builder()
Creates a new builder. The returned builder is equivalent to the builder generated byImmutableMultiset.builder(). 
 - 
 
- 
Method Detail
- 
add
@CanIgnoreReturnValue public ImmutableMultiset.Builder<E> add(E element)
Addselementto theImmutableMultiset.- Specified by:
 addin classImmutableCollection.Builder<E>- Parameters:
 element- the element to add- Returns:
 - this 
Builderobject - Throws:
 NullPointerException- ifelementis null
 
- 
add
@CanIgnoreReturnValue public ImmutableMultiset.Builder<E> add(E... elements)
Adds each element ofelementsto theImmutableMultiset.- Overrides:
 addin classImmutableCollection.Builder<E>- Parameters:
 elements- the elements to add- Returns:
 - this 
Builderobject - Throws:
 NullPointerException- ifelementsis null or contains a null element
 
- 
addCopies
@CanIgnoreReturnValue public ImmutableMultiset.Builder<E> addCopies(E element, int occurrences)
Adds a number of occurrences of an element to thisImmutableMultiset.- 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 
Builderobject - Throws:
 NullPointerException- ifelementis nullIllegalArgumentException- ifoccurrencesis negative, or if this operation would result in more thanInteger.MAX_VALUEoccurrences of the element
 
- 
setCount
@CanIgnoreReturnValue public 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.- Parameters:
 element- the element to add or remove occurrences ofcount- the desired count of the element in this multiset- Returns:
 - this 
Builderobject - Throws:
 NullPointerException- ifelementis nullIllegalArgumentException- ifcountis negative
 
- 
addAll
@CanIgnoreReturnValue public ImmutableMultiset.Builder<E> addAll(Iterable<? extends E> elements)
Adds each element ofelementsto theImmutableMultiset.- Overrides:
 addAllin classImmutableCollection.Builder<E>- Parameters:
 elements- theIterableto add to theImmutableMultiset- Returns:
 - this 
Builderobject - Throws:
 NullPointerException- ifelementsis null or contains a null element
 
- 
addAll
@CanIgnoreReturnValue public ImmutableMultiset.Builder<E> addAll(Iterator<? extends E> elements)
Adds each element ofelementsto theImmutableMultiset.- Overrides:
 addAllin classImmutableCollection.Builder<E>- Parameters:
 elements- the elements to add to theImmutableMultiset- Returns:
 - this 
Builderobject - Throws:
 NullPointerException- ifelementsis null or contains a null element
 
- 
build
public ImmutableMultiset<E> build()
Returns a newly-createdImmutableMultisetbased on the contents of theBuilder.- Specified by:
 buildin classImmutableCollection.Builder<E>
 
 - 
 
 -