Package com.google.common.collect
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>
 
 public static final class ImmutableSortedSet.Builder<E> extends ImmutableSet.Builder<E> A builder for creating immutable sorted set instances, especiallypublic static finalsets ("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
 
- 
- 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description ImmutableSortedSet.Builder<E>add(E element)Addselementto theImmutableSortedSet.ImmutableSortedSet.Builder<E>add(E... elements)Adds each element ofelementsto theImmutableSortedSet, ignoring duplicate elements (only the first duplicate element is added).ImmutableSortedSet.Builder<E>addAll(java.lang.Iterable<? extends E> elements)Adds each element ofelementsto theImmutableSortedSet, ignoring duplicate elements (only the first duplicate element is added).ImmutableSortedSet.Builder<E>addAll(java.util.Iterator<? extends E> elements)Adds each element ofelementsto theImmutableSortedSet, ignoring duplicate elements (only the first duplicate element is added).ImmutableSortedSet<E>build()Returns a newly-createdImmutableSortedSetbased on the contents of theBuilderand its comparator.
 
- 
- 
- 
Constructor Detail- 
Builderpublic Builder(java.util.Comparator<? super E> comparator) Creates a new builder. The returned builder is equivalent to the builder generated byImmutableSortedSet.orderedBy(java.util.Comparator<E>).
 
- 
 - 
Method Detail- 
add@CanIgnoreReturnValue public ImmutableSortedSet.Builder<E> add(E element) Addselementto theImmutableSortedSet. If theImmutableSortedSetalready containselement, thenaddhas no effect. (only the previously added element is retained).- Overrides:
- addin class- ImmutableSet.Builder<E>
- Parameters:
- element- the element to add
- Returns:
- this Builderobject
- Throws:
- java.lang.NullPointerException- if- elementis null
 
 - 
add@CanIgnoreReturnValue public ImmutableSortedSet.Builder<E> add(E... elements) Adds each element ofelementsto theImmutableSortedSet, ignoring duplicate elements (only the first duplicate element is added).- Overrides:
- addin class- ImmutableSet.Builder<E>
- Parameters:
- elements- the elements to add
- Returns:
- this Builderobject
- Throws:
- java.lang.NullPointerException- if- elementscontains a null element
 
 - 
addAll@CanIgnoreReturnValue public ImmutableSortedSet.Builder<E> addAll(java.lang.Iterable<? extends E> elements) Adds each element ofelementsto theImmutableSortedSet, ignoring duplicate elements (only the first duplicate element is added).- Overrides:
- addAllin class- ImmutableSet.Builder<E>
- Parameters:
- elements- the elements to add to the- ImmutableSortedSet
- Returns:
- this Builderobject
- Throws:
- java.lang.NullPointerException- if- elementscontains a null element
 
 - 
addAll@CanIgnoreReturnValue public ImmutableSortedSet.Builder<E> addAll(java.util.Iterator<? extends E> elements) Adds each element ofelementsto theImmutableSortedSet, ignoring duplicate elements (only the first duplicate element is added).- Overrides:
- addAllin class- ImmutableSet.Builder<E>
- Parameters:
- elements- the elements to add to the- ImmutableSortedSet
- Returns:
- this Builderobject
- Throws:
- java.lang.NullPointerException- if- elementscontains a null element
 
 - 
buildpublic ImmutableSortedSet<E> build() Returns a newly-createdImmutableSortedSetbased on the contents of theBuilderand its comparator.- Overrides:
- buildin class- ImmutableSet.Builder<E>
 
 
- 
 
-