List<Change> (List<? extends Change> list) { final List<Change> result = new ArrayList<>(); final Map<FilePath, Change> map = new HashMap<>(); for (Change change : list) { if (change.getBeforeRevision() == null) { result.add(change); } else { final FilePath beforePath = ChangesUtil.getBeforePath(change); final Change existing = map.get(beforePath); if (existing == null) { map.put(beforePath, change); continue; } if (change.getAfterRevision() == null && existing.getAfterRevision() == null) continue; if (change.getAfterRevision() != null && existing.getAfterRevision() != null) { LOG.error("Incorrect changes list: " + list); } if (existing.getAfterRevision() != null && change.getAfterRevision() == null) { continue; // skip delete change } if (change.getAfterRevision() != null && existing.getAfterRevision() == null) { map.put(beforePath, change); // skip delete change } } } result.addAll(map.values()); return result; }