Simplify two remove-if loops (#77)

These are semantically identical easier to read.
This commit is contained in:
Eitan Adler 2019-07-10 07:39:51 -07:00 committed by Gary Gregory
parent 8cbb4fd865
commit 07b82f6a69
2 changed files with 3 additions and 12 deletions

View File

@ -274,12 +274,7 @@ public class CursorableLinkedList<E> extends AbstractLinkedList<E> implements Se
protected void registerCursor(final Cursor<E> cursor) {
// We take this opportunity to clean the cursors list
// of WeakReference objects to garbage-collected cursors.
for (final Iterator<WeakReference<Cursor<E>>> it = cursors.iterator(); it.hasNext();) {
final WeakReference<Cursor<E>> ref = it.next();
if (ref.get() == null) {
it.remove();
}
}
cursors.removeIf(ref -> ref.get() == null);
cursors.add(new WeakReference<>(cursor));
}

View File

@ -261,14 +261,10 @@ public class ListOrderedSet<E>
if (result == false) {
return false;
}
if (decorated().size() == 0) {
if (decorated().isEmpty()) {
setOrder.clear();
} else {
for (final Iterator<E> it = setOrder.iterator(); it.hasNext();) {
if (!decorated().contains(it.next())) {
it.remove();
}
}
setOrder.removeIf(e -> !decorated().contains(e));
}
return result;
}