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

com.kenshoo.pl.entity.internal.fetch.BFS Maven / Gradle / Ivy

Go to download

A Java persistence layer based on JOOQ for high performance and business flow support.

There is a newer version: 0.1.121-jooq-3.16.3
Show 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