All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.ssb.lds.api.specification.SpecificationTraverals Maven / Gradle / Ivy

There is a newer version: 0.13
Show newest version
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();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy