Ejemplo n.º 1
0
  /**
   * Compares the specified Object with the receiver for equality. Returns true if and only if the
   * specified Object is also an ObjectArrayList, both lists have the same size, and all
   * corresponding pairs of elements in the two lists are the same. In other words, two lists are
   * defined to be equal if they contain the same elements in the same order. Tests elements for
   * equality or identity as specified by <tt>testForEquality</tt>. When testing for equality, two
   * elements <tt>e1</tt> and <tt>e2</tt> are <i>equal</i> if <tt>(e1==null ? e2==null :
   * e1.equals(e2))</tt>.)
   *
   * @param otherObj the Object to be compared for equality with the receiver.
   * @param testForEquality if true -> tests for equality, otherwise for identity.
   * @return true if the specified Object is equal to the receiver.
   */
  public boolean equals(Object otherObj, boolean testForEquality) { // delta
    if (!(otherObj instanceof ObjectArrayList)) {
      return false;
    }
    if (this == otherObj) return true;
    if (otherObj == null) return false;
    ObjectArrayList other = (ObjectArrayList) otherObj;
    if (elements == other.elements()) return true;
    if (size != other.size()) return false;

    Object[] otherElements = other.elements();
    Object[] theElements = elements;
    if (!testForEquality) {
      for (int i = size; --i >= 0; ) {
        if (theElements[i] != otherElements[i]) return false;
      }
    } else {
      for (int i = size; --i >= 0; ) {
        if (!(theElements[i] == null
            ? otherElements[i] == null
            : theElements[i].equals(otherElements[i]))) return false;
      }
    }

    return true;
  }
Ejemplo n.º 2
0
 /**
  * Returns a copy of the receiver such that the copy and the receiver <i>share</i> the same
  * elements, but do not share the same array to index them; So modifying an object in the copy
  * modifies the object in the receiver and vice versa; However, structurally modifying the copy
  * (for example changing its size, setting other objects at indexes, etc.) does not affect the
  * receiver and vice versa.
  *
  * @return a copy of the receiver.
  */
 public Object clone() {
   ObjectArrayList v = (ObjectArrayList) super.clone();
   v.elements = (Object[]) elements.clone();
   return v;
 }