List<LookupElement> (final Set<LookupElement> retained) { List<LookupElement> filtered = new ArrayList<>(); List<LookupElement> removed = new ArrayList<>(); for (LookupElement item : myItems) { (retained.contains(item) ? filtered : removed).add(item); } myItems.clear(); myItems.addAll(filtered); rebuildItemCache(); return removed; }