ImmutableSortedSet.Builder
Date: 2016-05-24

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, 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

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ImmutableSortedSet.Builder(java.util.Comparator<? super E> comparator)` Creates a new builder.

  - ### Method Summary

    Methods
    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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ImmutableSortedSet.Builder

          public ImmutableSortedSet.Builder(java.util.Comparator<? super E> comparator)

      Creates a new builder. The returned builder is equivalent to the builder generated by `ImmutableSortedSet.orderedBy(java.util.Comparator<E>)`.

  - ### Method Detail

    - #### add

          public ImmutableSortedSet.Builder<E> add(E element)

      Adds `element` to the `ImmutableSortedSet`. If the `ImmutableSortedSet` already contains `element`, then `add` has no effect. (only the previously added element is retained).
      Overrides:
        `add` in class `ImmutableSet.Builder<E>`
      Parameters:
        `element` - the element to add
      Returns:
        this `Builder` object
      Throws:
        `java.lang.NullPointerException` - if `element` is null

    - #### add

          public ImmutableSortedSet.Builder<E> add(E... elements)

      Adds each element of `elements` to the `ImmutableSortedSet`, ignoring duplicate elements (only the first duplicate element is added).
      Overrides:
        `add` in class `ImmutableSet.Builder<E>`
      Parameters:
        `elements` - the elements to add
      Returns:
        this `Builder` object
      Throws:
        `java.lang.NullPointerException` - if `elements` contains a null element

    - #### addAll

          public 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).
      Overrides:
        `addAll` in class `ImmutableSet.Builder<E>`
      Parameters:
        `elements` - the elements to add to the `ImmutableSortedSet`
      Returns:
        this `Builder` object
      Throws:
        `java.lang.NullPointerException` - if `elements` contains a null element

    - #### addAll

          public 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).
      Overrides:
        `addAll` in class `ImmutableSet.Builder<E>`
      Parameters:
        `elements` - the elements to add to the `ImmutableSortedSet`
      Returns:
        this `Builder` object
      Throws:
        `java.lang.NullPointerException` - if `elements` contains a null element

    - #### build

          public ImmutableSortedSet<E> build()

      Returns a newly-created `ImmutableSortedSet` based on the contents of the `Builder` and its comparator.
      Overrides:
        `build` in class `ImmutableSet.Builder<E>`