/** * Adds {@code element} to the {@code ImmutableSortedSet}. If the {@code ImmutableSortedSet} * already contains {@code element}, then {@code add} has no effect. (only the previously added * element is retained). * * @param element the element to add * @return this {@code Builder} object * @throws NullPointerException if {@code element} is null */ @CanIgnoreReturnValue @Override public Builder<E> add(E element) { checkNotNull(element); copyIfNecessary(); if (n == elements.length) { sortAndDedup(); /* * Sorting operations can only be allowed to occur once every O(n) operations to keep * amortized O(n log n) performance. Therefore, ensure there are at least O(n) *unused* * spaces in the builder array. */ int newLength = ImmutableCollection.Builder.expandedCapacity(n, n + 1); if (newLength > elements.length) { elements = Arrays.copyOf(elements, newLength); } } elements[n++] = element; return this; }
/** * Adds {@code element} to the {@code ImmutableSortedSet}. If the {@code ImmutableSortedSet} * already contains {@code element}, then {@code add} has no effect. (only the previously added * element is retained). * * @param element the element to add * @return this {@code Builder} object * @throws NullPointerException if {@code element} is null */ @CanIgnoreReturnValue @Override public Builder<E> add(E element) { checkNotNull(element); copyIfNecessary(); if (n == elements.length) { sortAndDedup(); /* * Sorting operations can only be allowed to occur once every O(n) operations to keep * amortized O(n log n) performance. Therefore, ensure there are at least O(n) *unused* * spaces in the builder array. */ int newLength = ImmutableCollection.Builder.expandedCapacity(n, n + 1); if (newLength > elements.length) { elements = Arrays.copyOf(elements, newLength); } } elements[n++] = element; return this; }
/** * Adds {@code element} to the {@code ImmutableSortedSet}. If the {@code ImmutableSortedSet} * already contains {@code element}, then {@code add} has no effect. (only the previously added * element is retained). * * @param element the element to add * @return this {@code Builder} object * @throws NullPointerException if {@code element} is null */ @CanIgnoreReturnValue @Override public Builder<E> add(E element) { checkNotNull(element); copyIfNecessary(); if (n == elements.length) { sortAndDedup(); /* * Sorting operations can only be allowed to occur once every O(n) operations to keep * amortized O(n log n) performance. Therefore, ensure there are at least O(n) *unused* * spaces in the builder array. */ int newLength = ImmutableCollection.Builder.expandedCapacity(n, n + 1); if (newLength > elements.length) { elements = Arrays.copyOf(elements, newLength); } } elements[n++] = element; return this; }
/** * Adds {@code element} to the {@code ImmutableSortedSet}. If the {@code ImmutableSortedSet} * already contains {@code element}, then {@code add} has no effect. (only the previously added * element is retained). * * @param element the element to add * @return this {@code Builder} object * @throws NullPointerException if {@code element} is null */ @CanIgnoreReturnValue @Override public Builder<E> add(E element) { checkNotNull(element); copyIfNecessary(); if (n == elements.length) { sortAndDedup(); /* * Sorting operations can only be allowed to occur once every O(n) operations to keep * amortized O(n log n) performance. Therefore, ensure there are at least O(n) *unused* * spaces in the builder array. */ int newLength = ImmutableCollection.Builder.expandedCapacity(n, n + 1); if (newLength > elements.length) { elements = Arrays.copyOf(elements, newLength); } } elements[n++] = element; return this; }
@CanIgnoreReturnValue @Override Builder<E> combine(ImmutableSet.Builder<E> builder) { copyIfNecessary(); Builder<E> other = (Builder<E>) builder; for (int i = 0; i < other.n; i++) { add(other.elements[i]); } return this; }
@CanIgnoreReturnValue @Override Builder<E> combine(ImmutableSet.Builder<E> builder) { copyIfNecessary(); Builder<E> other = (Builder<E>) builder; for (int i = 0; i < other.n; i++) { add(other.elements[i]); } return this; }
@CanIgnoreReturnValue @Override Builder<E> combine(ImmutableSet.Builder<E> builder) { copyIfNecessary(); Builder<E> other = (Builder<E>) builder; for (int i = 0; i < other.n; i++) { add(other.elements[i]); } return this; }
@CanIgnoreReturnValue @Override Builder<E> combine(ImmutableSet.Builder<E> builder) { copyIfNecessary(); Builder<E> other = (Builder<E>) builder; for (int i = 0; i < other.n; i++) { add(other.elements[i]); } return this; }