Exemplo n.º 1
0
  /**
   * Removes from the receiver all elements that are contained in the specified list. Tests for
   * identity.
   *
   * @param other the other list.
   * @return <code>true</code> if the receiver changed as a result of the call.
   */
  public boolean removeAll(AbstractLongList other) {
    if (other.size() == 0) return false; // nothing to do
    int limit = other.size() - 1;
    int j = 0;

    for (int i = 0; i < size; i++) {
      if (other.indexOfFromTo(getQuick(i), 0, limit) < 0) setQuick(j++, getQuick(i));
    }

    boolean modified = (j != size);
    setSize(j);
    return modified;
  }
Exemplo n.º 2
0
  /**
   * Retains (keeps) only the elements in the receiver that are contained in the specified other
   * list. In other words, removes from the receiver all of its elements that are not contained in
   * the specified other list.
   *
   * @param other the other list to test against.
   * @return <code>true</code> if the receiver changed as a result of the call.
   */
  public boolean retainAll(AbstractLongList other) {
    if (other.size() == 0) {
      if (size == 0) return false;
      setSize(0);
      return true;
    }

    int limit = other.size() - 1;
    int j = 0;
    for (int i = 0; i < size; i++) {
      if (other.indexOfFromTo(getQuick(i), 0, limit) >= 0) setQuick(j++, getQuick(i));
    }

    boolean modified = (j != size);
    setSize(j);
    return modified;
  }