private Map<String, List<Element>> elementsByTagNameAndId(List<Element> children) {
        Map<String, List<Element>> elementsByTagName = new LinkedHashMap<>();
        // Index by tag name and optionally add "id" or "idref" to key if they are set
        for (Element child : children) {
            String key = child.getTagName();
            if (child.hasAttribute(ID_ATTRIBUTE))
                key += child.getAttribute(ID_ATTRIBUTE);
            if (child.hasAttribute(IDREF_ATTRIBUTE))
                key += child.getAttribute(IDREF_ATTRIBUTE);
            if ( ! elementsByTagName.containsKey(key)) {
                elementsByTagName.put(key, new ArrayList<>());
            }
            elementsByTagName.get(key).add(child);
        }
        return elementsByTagName;
    }
Retains all elements where at least one element is overridden. Removes non-overridden elements from map.
config-application-package/src/main/java/com/yahoo/config/application/OverrideProcessor.java