/** * Adds <tt>val</tt> to the end of the list, growing as needed. * * @param val an <code>int</code> value */ public void add(int val) { ensureCapacity(_pos + 1); _data[_pos++] = val; }
/** * Adds a subset of the values in the array <tt>vals</tt> to the end of the list, in order. * * @param vals an <code>int[]</code> value * @param offset the offset at which to start copying * @param length the number of values to copy. */ public void add(int[] vals, int offset, int length) { ensureCapacity(_pos + length); System.arraycopy(vals, offset, _data, _pos, length); _pos += length; }
/** * Fills a range in the list with the specified value. * * @param fromIndex the offset at which to start filling (inclusive) * @param toIndex the offset at which to stop filling (exclusive) * @param val the value to use when filling */ public void fill(int fromIndex, int toIndex, int val) { if (toIndex > _pos) { ensureCapacity(toIndex); _pos = toIndex; } Arrays.fill(_data, fromIndex, toIndex, val); }
/** * Inserts a slice of the array of <tt>values</tt> into the list at <tt>offset</tt>. All values * including and to the right of <tt>offset</tt> are shifted to the right. * * @param offset an <code>int</code> value * @param values an <code>int[]</code> value * @param valOffset the offset in the values array at which to start copying. * @param len the number of values to copy from the values array */ public void insert(int offset, int[] values, int valOffset, int len) { if (offset == _pos) { add(values, valOffset, len); return; } ensureCapacity(_pos + len); // shift right System.arraycopy(_data, offset, _data, offset + len, _pos - offset); // insert System.arraycopy(values, valOffset, _data, offset, len); _pos += len; }
/** * Inserts <tt>value</tt> into the list at <tt>offset</tt>. All values including and to the * right of <tt>offset</tt> are shifted to the right. * * @param offset an <code>int</code> value * @param value an <code>int</code> value */ public void insert(int offset, int value) { if (offset == _pos) { add(value); return; } ensureCapacity(_pos + 1); // shift right System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); // insert _data[offset] = value; _pos++; }