Stack<String> nameStack = new Stack<>(); nameStack.push(route.getName()); nameStack.pushIfNotEmpty(routeGroup.getName()); Stack<Map<String, Object>> attributesStack = new Stack<>(); attributesStack.push(route.getAttributes()); attributesStack.push(routeGroup.getAttributes()); nameStack.pushIfNotEmpty(parent.getName()); attributesStack.push(parent.getAttributes()); if (!nameStack.isEmpty()) { route.setName(StreamSupport.stream(nameStack.spliterator(), false) .collect(Collectors.joining(""))); if (!attributesStack.isEmpty()) { route.bindAll(StreamSupport.stream(attributesStack.spliterator(), false) .flatMap(map -> map.entrySet().stream()) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)));