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>
public static class ImmutableSortedMultiset.Builder<E> extends ImmutableMultiset.Builder<E>
A builder for creating immutable multiset instances, especiallypublic static finalmultisets ("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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ImmutableSortedMultiset.Builder<E>add(E element)Addselementto theImmutableSortedMultiset.ImmutableSortedMultiset.Builder<E>add(E... elements)Adds each element ofelementsto theImmutableSortedMultiset.ImmutableSortedMultiset.Builder<E>addAll(java.lang.Iterable<? extends E> elements)Adds each element ofelementsto theImmutableSortedMultiset.ImmutableSortedMultiset.Builder<E>addAll(java.util.Iterator<? extends E> elements)Adds each element ofelementsto theImmutableSortedMultiset.ImmutableSortedMultiset.Builder<E>addCopies(E element, int occurrences)Adds a number of occurrences of an element to thisImmutableSortedMultiset.ImmutableSortedMultiset<E>build()Returns a newly-createdImmutableSortedMultisetbased on the contents of theBuilder.ImmutableSortedMultiset.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(java.util.Comparator<? super E> comparator)
Creates a new builder. The returned builder is equivalent to the builder generated byImmutableSortedMultiset.orderedBy(Comparator).
-
-
Method Detail
-
add
@CanIgnoreReturnValue public ImmutableSortedMultiset.Builder<E> add(E element)
Addselementto theImmutableSortedMultiset.- Overrides:
addin classImmutableMultiset.Builder<E>- Parameters:
element- the element to add- Returns:
- this
Builderobject - Throws:
java.lang.NullPointerException- ifelementis null
-
add
@CanIgnoreReturnValue public ImmutableSortedMultiset.Builder<E> add(E... elements)
Adds each element ofelementsto theImmutableSortedMultiset.- Overrides:
addin classImmutableMultiset.Builder<E>- Parameters:
elements- the elements to add- Returns:
- this
Builderobject - Throws:
java.lang.NullPointerException- ifelementsis null or contains a null element
-
addCopies
@CanIgnoreReturnValue public ImmutableSortedMultiset.Builder<E> addCopies(E element, int occurrences)
Adds a number of occurrences of an element to thisImmutableSortedMultiset.- Overrides:
addCopiesin 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
Builderobject - Throws:
java.lang.NullPointerException- ifelementis nulljava.lang.IllegalArgumentException- ifoccurrencesis negative, or if this operation would result in more thanInteger.MAX_VALUEoccurrences of the element
-
setCount
@CanIgnoreReturnValue public ImmutableSortedMultiset.Builder<E> setCount(E element, int count)
Adds or removes the necessary occurrences of an element such that the element attains the desired count.- Overrides:
setCountin classImmutableMultiset.Builder<E>- Parameters:
element- the element to add or remove occurrences ofcount- the desired count of the element in this multiset- Returns:
- this
Builderobject - Throws:
java.lang.NullPointerException- ifelementis nulljava.lang.IllegalArgumentException- ifcountis negative
-
addAll
@CanIgnoreReturnValue public ImmutableSortedMultiset.Builder<E> addAll(java.lang.Iterable<? extends E> elements)
Adds each element ofelementsto theImmutableSortedMultiset.- Overrides:
addAllin classImmutableMultiset.Builder<E>- Parameters:
elements- theIterableto add to theImmutableSortedMultiset- Returns:
- this
Builderobject - Throws:
java.lang.NullPointerException- ifelementsis null or contains a null element
-
addAll
@CanIgnoreReturnValue public ImmutableSortedMultiset.Builder<E> addAll(java.util.Iterator<? extends E> elements)
Adds each element ofelementsto theImmutableSortedMultiset.- Overrides:
addAllin classImmutableMultiset.Builder<E>- Parameters:
elements- the elements to add to theImmutableSortedMultiset- Returns:
- this
Builderobject - Throws:
java.lang.NullPointerException- ifelementsis null or contains a null element
-
build
public ImmutableSortedMultiset<E> build()
Returns a newly-createdImmutableSortedMultisetbased on the contents of theBuilder.- Overrides:
buildin classImmutableMultiset.Builder<E>
-
-