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

org.aksw.commons.collections.trees.SubTree Maven / Gradle / Ivy

There is a newer version: 0.9.9
Show newest version
package org.aksw.commons.collections.trees;

import java.util.Collection;
import java.util.List;
import java.util.function.BiPredicate;


public class SubTree
    extends TreeBase
{
    protected T root;
    protected Tree delegate;
    protected BiPredicate nodeComparator;

    public SubTree(Tree delegate, T root) {
        this(delegate, root, (a, b) -> a == b);
    }

    public SubTree(Tree delegate, T root, BiPredicate nodeComparator) {
        super();
        this.root = root;
        this.delegate = delegate;
        this.nodeComparator = nodeComparator;
    }

    @Override
    public T getRoot() {
        return root;
    }

    @Override
    public Collection getChildren(T node) {
        Collection result = delegate.getChildren(node);
        return result;
    }

    @Override
    public T getParent(T node) {
        boolean isRoot = nodeComparator.test(node, root);
        T result = isRoot ? null : delegate.getParent(node);
        return result;
    }

    @Override
    public T copy(T node, List children) {
        T result = delegate.copy(node, children);
        return result;
    }

    @Override
    public Tree createNew(T root) {
        Tree result = delegate.createNew(root);
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy