/** * 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 LongSequence 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); LongSequence list = new LongSequence(end - begin); for (int i = begin; i < end; i++) { list.add(data[i]); } return list; }
/** * 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>long</code> value */ public LongSequence insert(int offset, long value) { if (offset == pos) { add(value); return this; } ensureCapacity(pos + 1); // shift right System.arraycopy(data, offset, data, offset + 1, pos - offset); // insert data[offset] = value; pos++; return this; }
/** * 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>long[]</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 LongSequence insert(int offset, int valOffset, int len, long... values) { if (offset == pos) { add(valOffset, len, values); return this; } ensureCapacity(pos + len); // shift right System.arraycopy(data, offset, data, offset + len, pos - offset); // insert System.arraycopy(values, valOffset, data, offset, len); pos += len; return this; }
public LongSequence(long... values) { this(Math.max(values.length, DEFAULT_CAPACITY)); add(values); }
public LongSequence addAll(long... vals) { add(0, vals.length, vals); return this; }
/** * Adds the values in the array <tt>vals</tt> to the end of the list, in order. * * @param vals an <code>long[]</code> value */ public LongSequence add(long[] vals) { add(0, vals.length, vals); return this; }
public LongSequence addIfMissing(long n) { if (lastIndexOf(pos, n) != -1) add(n); return this; }
public LongSequence addLast(long val) { add(val); return this; }