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

impl.treelinearizers.CompactTreeLinearizer 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 only the node paths of the
 * child nodes and not of their parents
 */

public class CompactTreeLinearizer implements TreeLinearizer {

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

    @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