class ElementMapper {

    public Map<String, Object> toMap(List<Object> elements) {
        Map<String, List<Object>> collect = elements.stream()
            .filter(item -> item instanceof Element)
            .map(item -> (Element) item)
            .map(item -> new SimpleImmutableEntry<>(item.getLocalName(), elementToMap(item)))
            .collect(Collectors.toMap(
                SimpleImmutableEntry::getKey,
                SimpleImmutableEntry::getValue,
                (o, o2) -> Stream.concat(o.stream(), o2.stream()).collect(Collectors.toList())));

        return (Map) collect;
    }

}