no.ssb.lds.api.specification.SpecificationTraverals Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of linked-data-store-persistence-provider-api Show documentation
Show all versions of linked-data-store-persistence-provider-api Show documentation
LinkedDataStore Persistence Provider API
package no.ssb.lds.api.specification;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Map;
import java.util.function.BiConsumer;
public class SpecificationTraverals {
public static void depthFirstPreOrderFullTraversal(SpecificationElement element, BiConsumer, SpecificationElement> visit) {
Deque ancestors = new LinkedList<>();
visit.accept(ancestors, element);
ancestors.addLast(element);
doDepthFirstPreOrderFullTraversal(element, ancestors, visit);
}
static void doDepthFirstPreOrderFullTraversal(SpecificationElement element, Deque ancestors, BiConsumer, SpecificationElement> visit) {
if (element.getProperties() == null) {
return;
}
for (Map.Entry e : element.getProperties().entrySet()) {
SpecificationElement childElement = e.getValue();
visit.accept(ancestors, childElement);
ancestors.addLast(childElement);
doDepthFirstPreOrderFullTraversal(childElement, ancestors, visit);
ancestors.removeLast();
}
}
}