List<T> (@NotNull List<? extends T> copiedSchemes, @Nullable BiConsumer<? super T, ? super T> changedConsumer) { copiedToOriginal.values().removeIf(it -> !ContainerUtil.containsIdentity(copiedSchemes, it)); List<T> originals = new ArrayList<>(copiedSchemes.size()); for (T copied : copiedSchemes) { T original = copiedToOriginal.remove(copied); if (original == null) { //noinspection unchecked original = (T)copied.copy(); copiedToOriginal.put(copied, original); } else { if (changedConsumer != null) { changedConsumer.accept(original, copied); } original.resetFrom(copied); } originals.add(original); } return originals; }