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

impl.treelinearizers.FullTreeLinearizer Maven / Gradle / Ivy

The newest version!
package impl.treelinearizers;

import api.ChildTree;
import api.Node;
import api.utils.NodePath;
import api.utils.TreeLinearizer;
import impl.nodepaths.ImmutableNodePath;

import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * Builds a collection of immutable NodePaths. It contains all the node paths the tree including
 * nodes that are not leafs
 */
public class FullTreeLinearizer implements TreeLinearizer {

    @Override
    public Predicate>, ChildTree>> getFilter() {
        return nodePathChildTreeEntry -> {
            boolean empty = nodePathChildTreeEntry.getValue().getNodes().isEmpty();
            return empty;
        };
    }

    @Override
    public NodeConverter getConverter() {
        return nodePath -> {
            NodePath> path = nodePath.getKey();
            List nodes = path.getNodes().parallelStream().map(node -> node.getValue().getValue()).collect(Collectors.toList());
            return new ImmutableNodePath<>(nodes);
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy