Пример #1
0
 /**
  * Returns a list which is a concatenation of <code>times</code> times the receiver.
  *
  * @param times the number of times the receiver shall be copied.
  */
 public ObjectArrayList times(int times) {
   ObjectArrayList newList = new ObjectArrayList(times * size);
   for (int i = times; --i >= 0; ) {
     newList.addAllOfFromTo(this, 0, size() - 1);
   }
   return newList;
 }
Пример #2
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;
  }
Пример #3
0
  /**
   * Removes from the receiver all elements that are contained in the specified list. Tests for
   * equality or identity as specified by <code>testForEquality</code>.
   *
   * @param other the other list.
   * @param testForEquality if <code>true</code> -> test for equality, otherwise for identity.
   * @return <code>true</code> if the receiver changed as a result of the call.
   */
  public boolean removeAll(ObjectArrayList other, boolean testForEquality) {
    if (other.size == 0) return false; // nothing to do
    int limit = other.size - 1;
    int j = 0;
    Object[] theElements = elements;
    for (int i = 0; i < size; i++) {
      if (other.indexOfFromTo(theElements[i], 0, limit, testForEquality) < 0)
        theElements[j++] = theElements[i];
    }

    boolean modified = (j != size);
    setSize(j);
    return modified;
  }
Пример #4
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;
 }