@Override public void add(int val) { list.add(val); }
/** * Adds the values in the array <tt>vals</tt> to the end of the list, in order. * * @param vals an <code>int[]</code> value */ public void add(int[] vals) { add(vals, 0, vals.length); }
/** * Creates a new <code>TIntArrayList</code> instance whose capacity is the greater of the length * of <tt>values</tt> and DEFAULT_CAPACITY and whose initial contents are the specified values. * * @param values an <code>int[]</code> value */ public TIntArrayList(int[] values) { this(Math.max(values.length, DEFAULT_CAPACITY)); add(values); }
/** * 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++; }
/** * 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; }
/** * Returns a sublist of this list. * * @param begin low endpoint (inclusive) of the subList. * @param end high endpoint (exclusive) of the subList. * @return sublist of this list from begin, inclusive to end, exclusive. * @throws IndexOutOfBoundsException - endpoint out of range * @throws IllegalArgumentException - endpoints out of order (end > begin) */ public TIntArrayList subList(int begin, int end) { if (end < begin) throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); if (begin < 0) throw new IndexOutOfBoundsException("begin index can not be < 0"); if (end > _data.length) throw new IndexOutOfBoundsException("end index < " + _data.length); TIntArrayList list = new TIntArrayList(end - begin); for (int i = begin; i < end; i++) { list.add(_data[i]); } return list; }
/** * Searches the list for values satisfying <tt>condition</tt> in the manner of the *nix * <tt>grep</tt> utility. * * @param condition a condition to apply to each element in the list * @return a list of values which match the condition. */ public TIntArrayList grep(TIntProcedure condition) { TIntArrayList list = new TIntArrayList(); for (int i = 0; i < _pos; i++) { if (condition.execute(_data[i])) { list.add(_data[i]); } } return list; }
/** * Searches the list for values which do <b>not</b> satisfy <tt>condition</tt>. This is akin to * *nix <code>grep -v</code>. * * @param condition a condition to apply to each element in the list * @return a list of values which do not match the condition. */ public TIntArrayList inverseGrep(TIntProcedure condition) { TIntArrayList list = new TIntArrayList(); for (int i = 0; i < _pos; i++) { if (!condition.execute(_data[i])) { list.add(_data[i]); } } return list; }