void (ServiceEvent e) { boolean update = false; List<ServiceViewItem> toRemove = new ArrayList<>(); for (int i = 0; i < myRoots.size(); i++) { ServiceViewItem node = myRoots.get(i); if (!e.contributorClass.isInstance(node.getRootContributor())) continue; ServiceViewItem updatedNode = findItemSafe(node); if (updatedNode != null) { //noinspection SuspiciousListRemoveInLoop myRoots.remove(i); myRoots.add(i, updatedNode); } else { toRemove.add(node); } update = true; } myRoots.removeAll(toRemove); if (update) { notifyListeners(e); } }