/** * Appends the specified element to the end of this list. */ @Override public boolean add(E e) { int index = size; ensureCapacity(index, 1); // increments modCount!! buffer[end] = e; end++; size++; return true; }
/** * Adds the specified element to the beginning of this list. */ public boolean addFirst(E e) { int index = 0; ensureCapacity(index, 1); // increments modCount!! if (size > 0) { start--; } else { end++; } buffer[start] = e; size++; return true; }
protected boolean doAddAll(Object[] array) { int numNew = array.length; ensureCapacity(end, numNew); // increments modCount System.arraycopy(array, 0, buffer, end, numNew); size += numNew; end += numNew; return true; }
protected boolean doAddAll(int index, Object[] array) { int numNew = array.length; ensureCapacity(index, numNew); // increments modCount int realIndex = start + index; if (realIndex <= pivotIndex) { // add left int numMoved = index; if (numMoved > 0) { System.arraycopy(buffer, start, buffer, start - numNew, numMoved); } realIndex -= numNew; System.arraycopy(array, 0, buffer, realIndex, numNew); start -= numNew; } else { // add right int numMoved = end - realIndex; if (numMoved > 0) { System.arraycopy(buffer, realIndex, buffer, realIndex + numNew, numMoved); } System.arraycopy(array, 0, buffer, realIndex, numNew); end += numNew; } size += numNew; return numNew != 0; }
ensureCapacity(index, 1); // increments modCount!!
/** * Appends the specified element to the end of this list. */ @Override public boolean add(E e) { int index = size; ensureCapacity(index, 1); // increments modCount!! buffer[end] = e; end++; size++; return true; }
/** * Adds the specified element to the beginning of this list. */ public boolean addFirst(E e) { int index = 0; ensureCapacity(index, 1); // increments modCount!! if (size > 0) { start--; } else { end++; } buffer[start] = e; size++; return true; }
protected boolean doAddAll(Object[] array) { int numNew = array.length; ensureCapacity(end, numNew); // increments modCount System.arraycopy(array, 0, buffer, end, numNew); size += numNew; end += numNew; return true; }
protected boolean doAddAll(int index, Object[] array) { int numNew = array.length; ensureCapacity(index, numNew); // increments modCount int realIndex = start + index; if (realIndex <= pivotIndex) { // add left int numMoved = index; if (numMoved > 0) { System.arraycopy(buffer, start, buffer, start - numNew, numMoved); } realIndex -= numNew; System.arraycopy(array, 0, buffer, realIndex, numNew); start -= numNew; } else { // add right int numMoved = end - realIndex; if (numMoved > 0) { System.arraycopy(buffer, realIndex, buffer, realIndex + numNew, numMoved); } System.arraycopy(array, 0, buffer, realIndex, numNew); end += numNew; } size += numNew; return numNew != 0; }
ensureCapacity(index, 1); // increments modCount!!