Метод retainAll
void retainAll(Удаляет все элементы этого множества, которые не являются элементами elements.
Проверяет для каждого элемента elements наличие в этом множестве элемента, равного ему (в соответствии с this.contains), и если такой элемент есть, то равный ему элемент в этом множестве сохраняется, а элементы, не равные ни одному элементу в elements, удаляются.
Исходный код
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 as dynamic/*=E*/) == 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++;
}
}
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-collection/SplayTreeSet/retainAll.html