public static class ImmutableSet.Builder<E> extends ImmutableCollection.Builder<E>
ImmutableSet
instances. Example:
static final ImmutableSet<Color> GOOGLE_COLORS =
ImmutableSet.<Color>builder()
.addAll(WEBSAFE_COLORS)
.add(new Color(0, 191, 255))
.build();
Elements appear in the resulting set in the same order they were first added to the builder.
Building does not change the state of the builder, so it is still possible to add more elements and to build again.
Modifier and Type | Field and Description |
---|---|
(package private) boolean |
forceCopy |
private ImmutableSet.SetBuilderImpl<E> |
impl |
DEFAULT_INITIAL_CAPACITY
Constructor and Description |
---|
Builder() |
Builder(boolean subclass) |
Builder(int capacity) |
Modifier and Type | Method and Description |
---|---|
ImmutableSet.Builder<E> |
add(E... elements)
Adds each element of
elements to the ImmutableCollection being built. |
ImmutableSet.Builder<E> |
add(E element)
Adds
element to the ImmutableCollection being built. |
ImmutableSet.Builder<E> |
addAll(java.lang.Iterable<? extends E> elements)
Adds each element of
elements to the ImmutableSet , ignoring duplicate
elements (only the first duplicate element is added). |
ImmutableSet.Builder<E> |
addAll(java.util.Iterator<? extends E> elements)
Adds each element of
elements to the ImmutableCollection being built. |
ImmutableSet<E> |
build()
Returns a newly-created
ImmutableCollection of the appropriate type, containing the
elements provided to this builder. |
(package private) ImmutableSet.Builder<E> |
combine(ImmutableSet.Builder<E> other) |
(package private) void |
copy() |
(package private) void |
copyIfNecessary() |
(package private) void |
forceJdk() |
expandedCapacity
@CheckForNull private ImmutableSet.SetBuilderImpl<E> impl
boolean forceCopy
public Builder()
Builder(int capacity)
Builder(boolean subclass)
void forceJdk()
final void copyIfNecessary()
void copy()
public ImmutableSet.Builder<E> add(E element)
ImmutableCollection.Builder
element
to the ImmutableCollection
being built.
Note that each builder class covariantly returns its own type from this method.
add
in class ImmutableCollection.Builder<E>
element
- the element to addBuilder
instancepublic ImmutableSet.Builder<E> add(E... elements)
ImmutableCollection.Builder
elements
to the ImmutableCollection
being built.
Note that each builder class overrides this method in order to covariantly return its own type.
add
in class ImmutableCollection.Builder<E>
elements
- the elements to addBuilder
instancepublic ImmutableSet.Builder<E> addAll(java.lang.Iterable<? extends E> elements)
elements
to the ImmutableSet
, ignoring duplicate
elements (only the first duplicate element is added).addAll
in class ImmutableCollection.Builder<E>
elements
- the elements to addBuilder
objectjava.lang.NullPointerException
- if elements
is null or contains a null elementpublic ImmutableSet.Builder<E> addAll(java.util.Iterator<? extends E> elements)
ImmutableCollection.Builder
elements
to the ImmutableCollection
being built.
Note that each builder class overrides this method in order to covariantly return its own type.
addAll
in class ImmutableCollection.Builder<E>
elements
- the elements to addBuilder
instanceImmutableSet.Builder<E> combine(ImmutableSet.Builder<E> other)
public ImmutableSet<E> build()
ImmutableCollection.Builder
ImmutableCollection
of the appropriate type, containing the
elements provided to this builder.
Note that each builder class covariantly returns the appropriate type of ImmutableCollection
from this method.
build
in class ImmutableCollection.Builder<E>