/** * Adds {@code element} to the {@code ImmutableList}. * * @param element the element to add * @return this {@code Builder} object * @throws NullPointerException if {@code element} is null */ @Override public Builder<E> add(E element) { checkNotNull(element); ensureCapacity(size + 1); contents[size++] = element; return this; }
/** * Adds each element of {@code elements} to the {@code ImmutableList}. * * @param elements the {@code Iterable} to add to the {@code ImmutableList} * @return this {@code Builder} object * @throws NullPointerException if {@code elements} is null or contains a * null element */ @Override public Builder<E> addAll(Iterable<? extends E> elements) { if (elements instanceof Collection) { Collection<?> collection = (Collection<?>) elements; ensureCapacity(size + collection.size()); } super.addAll(elements); return this; }
/** * Adds each element of {@code elements} to the {@code ImmutableList}. * * @param elements the {@code Iterable} to add to the {@code ImmutableList} * @return this {@code Builder} object * @throws NullPointerException if {@code elements} is null or contains a * null element */ @Override public Builder<E> add(E... elements) { for (int i = 0; i < elements.length; i++) { checkElementNotNull(elements[i], i); } ensureCapacity(size + elements.length); System.arraycopy(elements, 0, contents, size, elements.length); size += elements.length; return this; }