javadoc.com.google.common.collect.ImmutableMultiset.Builder.html Maven / Gradle / Ivy
The newest version!
ImmutableMultiset.Builder (Guava: Google Core Libraries for Java 11.0.1 API)
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
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>
- Enclosing class:
- ImmutableMultiset<E>
public static class ImmutableMultiset.Builder<E>
- extends ImmutableCollection.Builder<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 (imported from Google Collections Library)
Constructor Summary | |
---|---|
ImmutableMultiset.Builder()
Creates a new builder. |
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
ImmutableMultiset.Builder
public ImmutableMultiset.Builder()
- Creates a new builder. The returned builder is equivalent to the builder
generated by
ImmutableMultiset.builder()
.
Method Detail |
---|
add
public ImmutableMultiset.Builder<E> add(E element)
- Adds
element
to theImmutableMultiset
.- Specified by:
add
in classImmutableCollection.Builder<E>
- Parameters:
element
- the element to add- Returns:
- this
Builder
object - Throws:
NullPointerException
- ifelement
is null
addCopies
public ImmutableMultiset.Builder<E> addCopies(E element, int occurrences)
- Adds a number of occurrences of an element to this
ImmutableMultiset
.- 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
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
Builder
object - Throws:
NullPointerException
- ifelement
is nullIllegalArgumentException
- ifcount
is negative
add
public ImmutableMultiset.Builder<E> add(E... elements)
- Adds each element of
elements
to theImmutableMultiset
.- Overrides:
add
in classImmutableCollection.Builder<E>
- Parameters:
elements
- the elements to add- Returns:
- this
Builder
object - Throws:
NullPointerException
- ifelements
is null or contains a null element
addAll
public ImmutableMultiset.Builder<E> addAll(Iterable<? extends E> elements)
- Adds each element of
elements
to theImmutableMultiset
.- Overrides:
addAll
in classImmutableCollection.Builder<E>
- Parameters:
elements
- theIterable
to add to theImmutableMultiset
- Returns:
- this
Builder
object - Throws:
NullPointerException
- ifelements
is null or contains a null element
addAll
public ImmutableMultiset.Builder<E> addAll(Iterator<? extends E> elements)
- Adds each element of
elements
to theImmutableMultiset
.- Overrides:
addAll
in classImmutableCollection.Builder<E>
- Parameters:
elements
- the elements to add to theImmutableMultiset
- Returns:
- this
Builder
object - Throws:
NullPointerException
- ifelements
is null or contains a null element
build
public ImmutableMultiset<E> build()
- Returns a newly-created
ImmutableMultiset
based on the contents of theBuilder
.- Specified by:
build
in classImmutableCollection.Builder<E>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2010-2012. All Rights Reserved.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy