retainAll method

void retainAll (Iterable<Object> elements)

Implementation

void retainAll(Iterable<Object> elements) {
  // Build a set with the same sense of equality as this set.
  SplayTreeSet<E> retainSet = new SplayTreeSet<E>(_comparator, _validKey);
  int modificationCount = _modificationCount;
  for (Object object in elements) {
    if (modificationCount != _modificationCount) {
      // The iterator should not have side effects.
      throw new ConcurrentModificationError(this);
    }
    // Equivalent to this.contains(object).
    if (_validKey(object) && _splay(object) == 0) {
      retainSet.add(_root.key);
    }
  }
  // Take over the elements from the retained set, if it differs.
  if (retainSet._count != _count) {
    _root = retainSet._root;
    _count = retainSet._count;
    _modificationCount++;
  }
}