Package software.kes.collectionviews
Interface SetBuilder<A>
-
- Type Parameters:
A
- the element type
- All Known Subinterfaces:
NonEmptySetBuilder<A>
public interface SetBuilder<A>
A builder forImmutableSet
s.A
SetBuilder
is immutable and all add operations return a newSetBuilder
. To construct theImmutableSet
, callbuild()
.It is safe to continue adding to a
SetBuilder
even afterbuild
is called. It is also safe to "fork" aSetBuilder
, but be aware that internal copies may be made when doing so.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description NonEmptySetBuilder<A>
add(A element)
Adds an element to thisSetBuilder
.SetBuilder<A>
addAll(java.util.Collection<A> elements)
Adds all elements in ajava.util.Collection
to thisSetBuilder
.SetBuilder<A>
addAll(software.kes.enhancediterables.FiniteIterable<A> elements)
Adds all elements in aFiniteIterable
to thisSetBuilder
.NonEmptySetBuilder<A>
addAll(software.kes.enhancediterables.NonEmptyFiniteIterable<A> elements)
Adds all elements in aNonEmptyFiniteIterable
to thisSetBuilder
.ImmutableSet<A>
build()
Builds a newImmutableSet
.static <A> SetBuilder<A>
builder()
Creates a newSetBuilder
.static <A> SetBuilder<A>
builder(int initialCapacity)
Creates a newSetBuilder
with an initial capacity hint.
-
-
-
Method Detail
-
add
NonEmptySetBuilder<A> add(A element)
Adds an element to thisSetBuilder
.- Parameters:
element
- the element to add- Returns:
- a new
NonEmptySetBuilder
with the element added
-
addAll
SetBuilder<A> addAll(java.util.Collection<A> elements)
Adds all elements in ajava.util.Collection
to thisSetBuilder
.- Parameters:
elements
- the collection to add- Returns:
- a new
SetBuilder
with the elements added
-
addAll
SetBuilder<A> addAll(software.kes.enhancediterables.FiniteIterable<A> elements)
Adds all elements in aFiniteIterable
to thisSetBuilder
.Since
Set
s areFiniteIterable
s, this method accepts anySet
.- Parameters:
elements
- theFiniteIterable
to add- Returns:
- a new
SetBuilder
with the elements added
-
addAll
NonEmptySetBuilder<A> addAll(software.kes.enhancediterables.NonEmptyFiniteIterable<A> elements)
Adds all elements in aNonEmptyFiniteIterable
to thisSetBuilder
.Since
NonEmptyVector
s areNonEmptyFiniteIterable
s, this method accepts anyNonEmptyVector
.- Parameters:
elements
- theNonEmptyFiniteIterable
to add- Returns:
- a new
NonEmptySetBuilder
with the elements added
-
build
ImmutableSet<A> build()
Builds a newImmutableSet
.It is safe to call this at any point, and it safe to continue adding elements after calling this.
- Returns:
- an
ImmutableSet
.
-
builder
static <A> SetBuilder<A> builder()
Creates a newSetBuilder
.- Type Parameters:
A
- the element type- Returns:
- an empty
SetBuilder
-
builder
static <A> SetBuilder<A> builder(int initialCapacity)
Creates a newSetBuilder
with an initial capacity hint.- Type Parameters:
A
- the element type- Parameters:
initialCapacity
- an initial capacity hint. Must be >= 0.- Returns:
- an empty
SetBuilder
-
-