com.kenshoo.pl.entity.internal.fetch.BFS Maven / Gradle / Ivy
                 Go to download
                
        
                    Show more of this group  Show more artifacts with this name
Show all versions of persistence-layer Show documentation
                Show all versions of persistence-layer Show documentation
A Java persistence layer based on JOOQ for high performance and business flow support.
                
             The newest version!
        
        package com.kenshoo.pl.entity.internal.fetch;
import com.google.common.collect.TreeTraverser;
import org.jooq.lambda.Seq;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import static java.util.Collections.singletonList;
import static org.jooq.lambda.Seq.seq;
import static org.jooq.lambda.function.Functions.not;
public class BFS {
    public static  Seq visit(Tree root, Function> neighbours) {
        TreeTraverser visitor = new TreeTraverser() {
            Set alreadyVisited = new HashSet<>(singletonList(root));
            @Override
            public Iterable children(Tree node) {
                List unvisitedChildren = seq(neighbours.apply(node)).filter(not(alreadyVisited::contains)).toList();
                alreadyVisited.addAll(unvisitedChildren);
                return unvisitedChildren;
            }
        };
        return seq(visitor.breadthFirstTraversal(root));
    }
}
            © 2015 - 2025 Weber Informatics LLC | Privacy Policy