Exemplo n.º 1
0
 /**
  * Copy the respective elements of <code>other</code> to <code>this</code> over the specified
  * index range. The other array must be of a compatible type.
  *
  * @param to first index of receiver to be included in the receivers range..
  * @param other other elements to be copied into this.
  * @param from first index of the other array to be included in the range.
  * @param count number of elements from the other array included in range, or -1 for all others
  *     elements starting at from. Fail if <code>count</code> is greater than number of available
  *     elements.
  */
 protected void copyElements(int to, PrimArray other, int from, int count) {
   int n = count;
   if (n == -1) {
     n = other.count() - from;
   }
   if (n < 0 || to < 0 || from < 0 || from + n > other.count() || to + n > count()) {
     throw new IndexOutOfBoundsException();
   }
   for (int i = 0; i < n; i += 1) {
     storeValue(to + i, other.fetchValue(from + i));
   }
 }
Exemplo n.º 2
0
  /**
   * Copy the respective elements of <code>other</code> to <code>this</code> over the specified
   * index range. The other array must be of a compatible type.
   *
   * @param to first index of receiver to be included in the receivers range..
   * @param other other elements to be copied into this.
   * @param count number of elements from the other array included in range, or -1 for all others
   *     elements starting at from. Fail if <code>count</code> is greater than number of available
   *     elements.
   * @param from first index of the other array to be included in the range.
   * @throws ClassCastException if <code>other</code> is not compatible with this array
   * @throws IllegalArgumentException if <code>other</code>s elements can not be held by this array
   */
  public void storeMany(int to, PrimArray other, int count, int from) {
    int n;

    if (count < 0) {
      n = other.count() - from;
    } else {
      n = count;
    }
    if (to + n > count() || from + n > other.count()) {
      throw new IndexOutOfBoundsException();
    }
    copyElements(to, other, from, n);
  }
Exemplo n.º 3
0
 /**
  * Return the index of the <code>nth</code> occurrence of the given sequence of values of other at
  * or after (before if <code>nth</code> is negative) the given index in this, or -1 if there is
  * none. Negative numbers for <code>start</code> are relative to the end of the array.
  *
  * @param other array of elements that is being searched for in this.
  * @param otherCount number of elements from <code>other</code> that is being searched for, or -1
  *     to include all elements after <code>otherStart</code>.
  * @param otherStart index of first element of <code>other</code> to start searching for.
  * @param start index to start the search from. If positive start from that index, if negative
  *     start from relative to end of array where -1 is the last valid index.
  * @param nth nth occurrence of the matched value at or after the <code>start</code> if positive,
  *     or at or before if negative. A 0 <code>nth</code> immediately fails.
  * @return index of match or -1 if failed
  */
 public int indexOfElements(PrimArray other, int otherCount, int otherStart, int start, int nth) {
   if (count() == 0 || nth == 0) {
     return -1;
   }
   int otherN;
   if (otherCount < 0) {
     otherN = other.count();
   } else {
     if (otherCount > other.count()) {
       throw new IndexOutOfBoundsException();
     }
     otherN = otherCount;
   }
   int result;
   if (start >= 0) {
     result = start;
   } else {
     result = count() + start;
   }
   int n = nth < 0 ? -nth : nth; // TODO = Math.abs(nth);
   boolean forward = nth > 0;
   for (; ; ) {
     {
       if (forward ? (result > count() - otherN) : result < 0) {
         return -1;
       }
       if (elementsEqual(result, other, otherStart, otherN)) {
         n -= 1;
         if (n == 0) {
           return result;
         }
       }
       if (forward) {
         result += 1;
       } else {
         result -= 1;
       }
     }
   }
 }