Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
  /**
   * 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;
  }
Пример #4
0
 public LongSequence(long... values) {
   this(Math.max(values.length, DEFAULT_CAPACITY));
   add(values);
 }
Пример #5
0
 public LongSequence addAll(long... vals) {
   add(0, vals.length, vals);
   return this;
 }
Пример #6
0
 /**
  * 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;
 }
Пример #7
0
 public LongSequence addIfMissing(long n) {
   if (lastIndexOf(pos, n) != -1) add(n);
   return this;
 }
Пример #8
0
 public LongSequence addLast(long val) {
   add(val);
   return this;
 }