Document (@Nullable Element oldRoot, Element newRoot) { ourFileToProblem = new HashMap<>(); List newProblems = newRoot.getChildren("problem"); for (final Object o : newProblems) { Element newProblem = (Element)o; addProblem(newProblem); } if (oldRoot != null) { for (final Element oldProblem : oldRoot.getChildren("problem")) { if (!removeIfEquals(oldProblem)) { addProblem(oldProblem); } } } Element root = new Element(GlobalInspectionContextBase.PROBLEMS_TAG_NAME); Document delta = new Document(root); for (ArrayList<Element> fileList : ourFileToProblem.values()) { if (fileList != null) { for (Element element : fileList) { root.addContent(element.clone()); } } } return delta; }