public static final class ImmutableSortedSet.Builder<E> extends ImmutableSet.Builder<E>
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.
| Modifier and Type | Field and Description |
|---|---|
private java.util.Comparator<? super E> |
comparator |
private E[] |
elements |
private int |
n |
forceCopyDEFAULT_INITIAL_CAPACITY| Constructor and Description |
|---|
Builder(java.util.Comparator<? super E> comparator)
Creates a new builder.
|
| Modifier and Type | Method and Description |
|---|---|
ImmutableSortedSet.Builder<E> |
add(E... elements)
Adds each element of
elements to the ImmutableSortedSet, ignoring duplicate
elements (only the first duplicate element is added). |
ImmutableSortedSet.Builder<E> |
add(E element)
Adds
element to the ImmutableSortedSet. |
ImmutableSortedSet.Builder<E> |
addAll(java.lang.Iterable<? extends E> elements)
Adds each element of
elements to the ImmutableSortedSet, ignoring duplicate
elements (only the first duplicate element is added). |
ImmutableSortedSet.Builder<E> |
addAll(java.util.Iterator<? extends E> elements)
Adds each element of
elements to the ImmutableSortedSet, ignoring duplicate
elements (only the first duplicate element is added). |
ImmutableSortedSet<E> |
build()
Returns a newly-created
ImmutableSortedSet based on the contents of the Builder and its comparator. |
(package private) ImmutableSortedSet.Builder<E> |
combine(ImmutableSet.Builder<E> builder) |
(package private) void |
copy() |
private void |
sortAndDedup() |
copyIfNecessary, forceJdkexpandedCapacityprivate final java.util.Comparator<? super E> comparator
private E[] elements
private int n
public Builder(java.util.Comparator<? super E> comparator)
ImmutableSortedSet.orderedBy(java.util.Comparator<E>).void copy()
copy in class ImmutableSet.Builder<E>private void sortAndDedup()
public ImmutableSortedSet.Builder<E> add(E element)
element to the ImmutableSortedSet. If the ImmutableSortedSet
already contains element, then add has no effect. (only the previously added
element is retained).add in class ImmutableSet.Builder<E>element - the element to addBuilder objectjava.lang.NullPointerException - if element is nullpublic ImmutableSortedSet.Builder<E> add(E... elements)
elements to the ImmutableSortedSet, ignoring duplicate
elements (only the first duplicate element is added).add in class ImmutableSet.Builder<E>elements - the elements to addBuilder objectjava.lang.NullPointerException - if elements contains a null elementpublic ImmutableSortedSet.Builder<E> addAll(java.lang.Iterable<? extends E> elements)
elements to the ImmutableSortedSet, ignoring duplicate
elements (only the first duplicate element is added).addAll in class ImmutableSet.Builder<E>elements - the elements to add to the ImmutableSortedSetBuilder objectjava.lang.NullPointerException - if elements contains a null elementpublic ImmutableSortedSet.Builder<E> addAll(java.util.Iterator<? extends E> elements)
elements to the ImmutableSortedSet, ignoring duplicate
elements (only the first duplicate element is added).addAll in class ImmutableSet.Builder<E>elements - the elements to add to the ImmutableSortedSetBuilder objectjava.lang.NullPointerException - if elements contains a null elementImmutableSortedSet.Builder<E> combine(ImmutableSet.Builder<E> builder)
combine in class ImmutableSet.Builder<E>public ImmutableSortedSet<E> build()
ImmutableSortedSet based on the contents of the Builder and its comparator.build in class ImmutableSet.Builder<E>