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.
Constructor and Description |
---|
Builder() |
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(Iterable<? extends E> elements)
Adds each element of
elements to the ImmutableCollection being built. |
ImmutableSet.Builder<E> |
addAll(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. |
public Builder()
@CanIgnoreReturnValue 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
instance@CanIgnoreReturnValue public 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
instance@CanIgnoreReturnValue public ImmutableSet.Builder<E> addAll(Iterable<? 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
instance@CanIgnoreReturnValue public ImmutableSet.Builder<E> addAll(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
instancepublic 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>
Copyright © 2010–2020. All rights reserved.