/** * 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; }
/** * Returns a newly-created {@code ImmutableSortedSet} based on the contents of the {@code * Builder} and its comparator. */ @Override public ImmutableSortedSet<E> build() { sortAndDedup(); if (n == 0) { return emptySet(comparator); } else { forceCopy = true; return new RegularImmutableSortedSet<E>( ImmutableList.asImmutableList(elements, n), comparator); } } }
/** * Returns a newly-created {@code ImmutableSortedSet} based on the contents of the {@code * Builder} and its comparator. */ @Override public ImmutableSortedSet<E> build() { sortAndDedup(); if (n == 0) { return emptySet(comparator); } else { forceCopy = true; return new RegularImmutableSortedSet<E>( ImmutableList.asImmutableList(elements, n), comparator); } } }
/** * Returns a newly-created {@code ImmutableSortedSet} based on the contents of the {@code * Builder} and its comparator. */ @Override public ImmutableSortedSet<E> build() { sortAndDedup(); if (n == 0) { return emptySet(comparator); } else { forceCopy = true; return new RegularImmutableSortedSet<E>( ImmutableList.asImmutableList(elements, n), comparator); } } }
/** * Returns a newly-created {@code ImmutableSortedSet} based on the contents of the {@code * Builder} and its comparator. */ @Override public ImmutableSortedSet<E> build() { sortAndDedup(); if (n == 0) { return emptySet(comparator); } else { forceCopy = true; return new RegularImmutableSortedSet<E>( ImmutableList.asImmutableList(elements, n), comparator); } } }