void (@NotNull Element root, @NotNull Element component) { String componentName = component.getAttributeValue(Constants.NAME); Element old = findComponent(root, componentName); if (old != null) { root.removeContent(old); } for (int i = 0; i < root.getContent().size(); i++) { Content o = root.getContent().get(i); if (o instanceof Element) { Element element = (Element)o; if (element.getName().equals(COMPONENT_ELEMENT)) { final String name = element.getAttributeValue(Constants.NAME); if (componentName.compareTo(name) < 0) { root.addContent(i, component); return; } } } } root.addContent(component); }