public List<List<T>> pathsToValue(final Function<T, Boolean> pred) { return pathsToValue(false, pred); }
private List<List<SchemaElement>> alternateElements(final boolean includeValue, final Function<SchemaElement, Boolean> pred) { return schemaTree().pathsToValue(includeValue, pred) .stream() .filter(this::allowPath) .map(this::schemaPathWithPrefix) .collect(Collectors.toList()); }
public List<List<SchemaElement>> pathsToSchemaElement(final Function<SchemaElement, Boolean> pred) { return schemaTree().pathsToValue(true, pred); }
public List<List<DocElement>> pathsToDocElement(final Function<DocElement, Boolean> pred) { return documentTree().pathsToValue(true, pred); }
public List<List<T>> pathsToValue(final boolean includeValue, final Function<T, Boolean> pred) { final List<List<T>> paths = new ArrayList<>(); if (!isRoot() && pred.apply(this.value)) { List<T> path = new ArrayList<>(); if (includeValue) { path.add(this.value); } paths.add(path); } this.children().forEach(c -> { final List<List<T>> childPaths = c.pathsToValue(includeValue, pred); if (!childPaths.isEmpty() && !isRoot()) { childPaths.forEach(p -> p.add(0, this.value)); } paths.addAll(childPaths); }); return paths; }
public List<SchemaElement> schemaPathWithPrefix(final List<SchemaElement> path) { if (this.prefixProvider == null) { this.prefixProvider = (p, __) -> { final List<List<DocElement>> prefixPaths = documentTree().pathsToValue(e -> e.name().equals(p.get(0).getLocalPart())); if (!prefixPaths.isEmpty()) { return prefixPaths.get(0) .stream() .map(e -> QName.valueOf(e.name())) .collect(Collectors.toList()); } return Collections.emptyList(); }; } final List<QName> prefix = this.prefixProvider.prefixFor(path.stream() .map(SchemaElement::qname) .collect(Collectors.toList()), this); if (prefix != null && !prefix.isEmpty()) { final List<SchemaElement> fullPath = new ArrayList<>(); fullPath.addAll(prefix.stream() .map(SchemaElement::new) .collect(Collectors.toList())); fullPath.addAll(path); return fullPath; } return path; }