/** * {@inheritDoc} */ @Override public void add(int e1) { ensureBufferSpace(1); buffer[elementsCount++] = e1; }
/** * Appends two elements at the end of the list. To add more than two elements, * use <code>add</code> (vararg-version) or access the buffer directly (tight * loop). */ public void add(int e1, int e2) { ensureBufferSpace(2); buffer[elementsCount++] = e1; buffer[elementsCount++] = e2; }
/** * Add all elements from a range of given array to the list. */ public void add(int[] elements, int start, int length) { assert length >= 0 : "Length must be >= 0"; ensureBufferSpace(length); System.arraycopy(elements, start, buffer, elementsCount, length); elementsCount += length; }
/** * Ensure this container can hold at least the given number of elements * without resizing its buffers. * * @param expectedElements * The total number of elements, inclusive. */ @Override public void ensureCapacity(int expectedElements) { final int bufferLen = (buffer == null ? 0 : buffer.length); if (expectedElements > bufferLen) { ensureBufferSpace(expectedElements - size()); } }
/** * {@inheritDoc} */ @Override public void insert(int index, int e1) { assert (index >= 0 && index <= size()) : "Index " + index + " out of bounds [" + 0 + ", " + size() + "]."; ensureBufferSpace(1); System.arraycopy(buffer, index, buffer, index + 1, elementsCount - index); buffer[index] = e1; elementsCount++; }
/** * Adds all elements from another container. */ public int addAll(IntContainer container) { final int size = container.size(); ensureBufferSpace(size); for (IntCursor cursor : container) { add(cursor.value); } return size; }
/** * {@inheritDoc} */ @Override public void add(int e1) { ensureBufferSpace(1); buffer[elementsCount++] = e1; }
/** * Appends two elements at the end of the list. To add more than two elements, * use <code>add</code> (vararg-version) or access the buffer directly (tight * loop). */ public void add(int e1, int e2) { ensureBufferSpace(2); buffer[elementsCount++] = e1; buffer[elementsCount++] = e2; }
/** * Add all elements from a range of given array to the list. */ public void add(int[] elements, int start, int length) { assert length >= 0 : "Length must be >= 0"; ensureBufferSpace(length); System.arraycopy(elements, start, buffer, elementsCount, length); elementsCount += length; }
/** * Ensure this container can hold at least the given number of elements * without resizing its buffers. * * @param expectedElements * The total number of elements, inclusive. */ @Override public void ensureCapacity(int expectedElements) { final int bufferLen = (buffer == null ? 0 : buffer.length); if (expectedElements > bufferLen) { ensureBufferSpace(expectedElements - size()); } }
/** * {@inheritDoc} */ @Override public void insert(int index, int e1) { assert (index >= 0 && index <= size()) : "Index " + index + " out of bounds [" + 0 + ", " + size() + "]."; ensureBufferSpace(1); System.arraycopy(buffer, index, buffer, index + 1, elementsCount - index); buffer[index] = e1; elementsCount++; }
/** * Adds all elements from another container. */ public int addAll(IntContainer container) { final int size = container.size(); ensureBufferSpace(size); for (IntCursor cursor : container) { add(cursor.value); } return size; }