android/guava/src/com/google/common/collect/ImmutableSortedSet.java
static <E> ImmutableSortedSet<E> construct(
      Comparator<? super E> comparator, int n, E... contents) {
    if (n == 0) {
      return emptySet(comparator);
    }
    checkElementsNotNull(contents, n);
    Arrays.sort(contents, 0, n, comparator);
    int uniques = 1;
    for (int i = 1; i < n; i++) {
      E cur = contents[i];
      E prev = contents[uniques - 1];
      if (comparator.compare(cur, prev) != 0) {
        contents[uniques++] = cur;
      }
    }
    Arrays.fill(contents, uniques, n, null);
    if (uniques < contents.length / 2) {
      // Deduplication eliminated many of the elements.  We don't want to retain an arbitrarily
      // large array relative to the number of elements, so we cap the ratio.
      contents = Arrays.copyOf(contents, uniques);
    }
    return new RegularImmutableSortedSet<E>(
        ImmutableList.<E>asImmutableList(contents, uniques), comparator);
  }
static <E> ImmutableSortedSet<E> construct(
      Comparator<? super E> comparator, int n, E... contents) {
    if (n == 0) {
      return emptySet(comparator);
    }
    checkElementsNotNull(contents, n);
    Arrays.sort(contents, 0, n, comparator);
    int uniques = 1;
    for (int i = 1; i < n; i++) {
      E cur = contents[i];
      E prev = contents[uniques - 1];
      if (comparator.compare(cur, prev) != 0) {
        contents[uniques++] = cur;
      }
    }
    Arrays.fill(contents, uniques, n, null);
    if (uniques < contents.length / 2) {
      // Deduplication eliminated many of the elements.  We don't want to retain an arbitrarily
      // large array relative to the number of elements, so we cap the ratio.
      contents = Arrays.copyOf(contents, uniques);
    }
    return new RegularImmutableSortedSet<E>(
        ImmutableList.<E>asImmutableList(contents, uniques), comparator);
  }
Constructs an {@code ImmutableSortedSet} from the first {@code n} elements of {@code contents}.
If {@code k} is the size of the returned {@code ImmutableSortedSet}, then the sorted unique
elements are in the first {@code k} positions of {@code contents}, and {@code contents[i] ==
null} for {@code k <= i < n}.

<p>This method takes ownership of {@code contents}; do not modify {@code contents} after this
returns.

@throws NullPointerException if any of the first {@code n} elements of {@code contents} is null