Class ImmutableSortedSet.Builder<E>
java.lang.Object
com.google.common.collect.ImmutableCollection.Builder<E>
com.google.common.collect.ImmutableSet.Builder<E>
com.google.common.collect.ImmutableSortedSet.Builder<E>
- Enclosing class:
ImmutableSortedSet<E>
A builder for creating immutable sorted set instances, especially
public static final
sets ("constant sets"), with a given comparator. Example:
public static final ImmutableSortedSet<Number> LUCKY_NUMBERS =
new ImmutableSortedSet.Builder<Number>(ODDS_FIRST_COMPARATOR)
.addAll(SINGLE_DIGIT_PRIMES)
.add(42)
.build();
Builder instances can be reused; it is safe to call build() multiple times to build
multiple sets in series. Each set is a superset of the set created before it.
- Since:
- 2.0
- Author:
- Jared Levy, Louis Wasserman
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAddselementto theImmutableSortedSet.Adds each element ofelementsto theImmutableSortedSet, ignoring duplicate elements (only the first duplicate element is added).Adds each element ofelementsto theImmutableSortedSet, ignoring duplicate elements (only the first duplicate element is added).Adds each element ofelementsto theImmutableSortedSet, ignoring duplicate elements (only the first duplicate element is added).build()Returns a newly-createdImmutableSortedSetbased on the contents of theBuilderand its comparator.
-
Constructor Details
-
Builder
Creates a new builder. The returned builder is equivalent to the builder generated byImmutableSortedSet.orderedBy(java.util.Comparator<E>).
-
-
Method Details
-
add
Addselementto theImmutableSortedSet. If theImmutableSortedSetalready containselement, thenaddhas no effect. (only the previously added element is retained).- Overrides:
addin classImmutableSet.Builder<E>- Parameters:
element- the element to add- Returns:
- this
Builderobject - Throws:
NullPointerException- ifelementis null
-
add
Adds each element ofelementsto theImmutableSortedSet, ignoring duplicate elements (only the first duplicate element is added).- Overrides:
addin classImmutableSet.Builder<E>- Parameters:
elements- the elements to add- Returns:
- this
Builderobject - Throws:
NullPointerException- ifelementscontains a null element
-
addAll
Adds each element ofelementsto theImmutableSortedSet, ignoring duplicate elements (only the first duplicate element is added).- Overrides:
addAllin classImmutableSet.Builder<E>- Parameters:
elements- the elements to add to theImmutableSortedSet- Returns:
- this
Builderobject - Throws:
NullPointerException- ifelementscontains a null element
-
addAll
Adds each element ofelementsto theImmutableSortedSet, ignoring duplicate elements (only the first duplicate element is added).- Overrides:
addAllin classImmutableSet.Builder<E>- Parameters:
elements- the elements to add to theImmutableSortedSet- Returns:
- this
Builderobject - Throws:
NullPointerException- ifelementscontains a null element
-
build
Returns a newly-createdImmutableSortedSetbased on the contents of theBuilderand its comparator.- Overrides:
buildin classImmutableSet.Builder<E>
-