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>
A builder for creating immutable multiset instances, especially 
 
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.
- Since:
- 2.0
- Author:
- Jared Levy, Louis Wasserman
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionAddselementto theImmutableMultiset.Adds each element ofelementsto theImmutableMultiset.Adds each element ofelementsto theImmutableMultiset.Adds each element ofelementsto theImmutableMultiset.Adds a number of occurrences of an element to thisImmutableMultiset.build()Returns a newly-createdImmutableMultisetbased on the contents of theBuilder.Adds or removes the necessary occurrences of an element such that the element attains the desired count.
- 
Constructor Details- 
Builderpublic Builder()Creates a new builder. The returned builder is equivalent to the builder generated byImmutableMultiset.builder().
 
- 
- 
Method Details- 
addAddselementto theImmutableMultiset.- Specified by:
- addin class- ImmutableCollection.Builder<E>
- Parameters:
- element- the element to add
- Returns:
- this Builderobject
- Throws:
- NullPointerException- if- elementis null
 
- 
addAdds each element ofelementsto theImmutableMultiset.- Overrides:
- addin class- ImmutableCollection.Builder<E>
- Parameters:
- elements- the elements to add
- Returns:
- this Builderobject
- Throws:
- NullPointerException- if- elementsis null or contains a null element
 
- 
addCopiesAdds a number of occurrences of an element to thisImmutableMultiset.- Parameters:
- element- the element to add
- occurrences- 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- if- elementis null
- IllegalArgumentException- if- occurrencesis negative, or if this operation would result in more than- Integer.MAX_VALUEoccurrences of the element
 
- 
setCountAdds 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 of
- count- the desired count of the element in this multiset
- Returns:
- this Builderobject
- Throws:
- NullPointerException- if- elementis null
- IllegalArgumentException- if- countis negative
 
- 
addAllAdds each element ofelementsto theImmutableMultiset.- Overrides:
- addAllin class- ImmutableCollection.Builder<E>
- Parameters:
- elements- the- Iterableto add to the- ImmutableMultiset
- Returns:
- this Builderobject
- Throws:
- NullPointerException- if- elementsis null or contains a null element
 
- 
addAllAdds each element ofelementsto theImmutableMultiset.- Overrides:
- addAllin class- ImmutableCollection.Builder<E>
- Parameters:
- elements- the elements to add to the- ImmutableMultiset
- Returns:
- this Builderobject
- Throws:
- NullPointerException- if- elementsis null or contains a null element
 
- 
buildReturns a newly-createdImmutableMultisetbased on the contents of theBuilder.- Specified by:
- buildin class- ImmutableCollection.Builder<E>
 
 
-