void (@NotNull JpsElementCollectionImpl<E> modified) { Set<E> toRemove = new LinkedHashSet<>(myElements); List<E> toAdd = new ArrayList<>(); final Map<E, E> copyToOriginal = modified.myCopyToOriginal; for (E element : modified.myElements) { final E original = copyToOriginal != null ? copyToOriginal.get(element) : null; if (original != null) { //noinspection unchecked ((BulkModificationSupport<E>)original.getBulkModificationSupport()).applyChanges(element); toRemove.remove(original); } else { //noinspection unchecked final E copy = (E)element.getBulkModificationSupport().createCopy(); toAdd.add(copy); } } for (E e : toRemove) { removeChild(e); } for (E e : toAdd) { addChild(e); } }