コード例 #1
0
  /**
   * Replaces a number of elements in the receiver with the same number of elements of another list.
   * Replaces elements in the receiver, between <code>from</code> (inclusive) and <code>to</code>
   * (inclusive), with elements of <code>other</code>, starting from <code>otherFrom</code>
   * (inclusive).
   *
   * @param from the position of the first element to be replaced in the receiver
   * @param to the position of the last element to be replaced in the receiver
   * @param other list holding elements to be copied into the receiver.
   * @param otherFrom position of first element within other list to be copied.
   */
  public void replaceFromToWithFrom(int from, int to, AbstractLongList other, int otherFrom) {
    int length = to - from + 1;
    if (length > 0) {
      checkRangeFromTo(from, to, size());
      checkRangeFromTo(otherFrom, otherFrom + length - 1, other.size());

      // unambiguous copy (it may hold other==this)
      if (from <= otherFrom) {
        for (; --length >= 0; ) setQuick(from++, other.getQuick(otherFrom++));
      } else {
        int otherTo = otherFrom + length - 1;
        for (; --length >= 0; ) setQuick(to--, other.getQuick(otherTo--));
      }
    }
  }
コード例 #2
0
  /**
   * Compares the specified Object with the receiver. Returns true if and only if the specified
   * Object is also an ArrayList of the same type, both Lists have the same size, and all
   * corresponding pairs of elements in the two Lists are identical. In other words, two Lists are
   * defined to be equal if they contain the same elements in the same order.
   *
   * @param otherObj the Object to be compared for equality with the receiver.
   * @return true if the specified Object is equal to the receiver.
   */
  public boolean equals(Object otherObj) { // delta
    if (!(otherObj instanceof AbstractLongList)) {
      return false;
    }
    if (this == otherObj) return true;
    if (otherObj == null) return false;
    AbstractLongList other = (AbstractLongList) otherObj;
    if (size() != other.size()) return false;

    for (int i = size(); --i >= 0; ) {
      if (getQuick(i) != other.getQuick(i)) return false;
    }
    return true;
  }