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

cdc.graphs.impl.BasicTreeNode Maven / Gradle / Ivy

There is a newer version: 0.71.2
Show newest version
package cdc.graphs.impl;

import java.util.ArrayList;
import java.util.List;

public class BasicTreeNode> {
    private N parent;
    private final List children = new ArrayList<>();

    public BasicTreeNode() {
        super();
    }

    public BasicTreeNode(N parent) {
        this.setParent(parent);
    }

    void removeChild(BasicTreeNode child) {
        children.remove(child);
    }

    void addChild(N child) {
        children.add(child);
    }

    public N getParent() {
        return parent;
    }

    protected void setParent(N parent) {
        if (this.parent != parent) {
            if (this.parent != null) {
                this.parent.removeChild(this);
                this.parent = null;
            }
            if (parent != null) {
                this.parent = parent;
                @SuppressWarnings("unchecked")
                final N nthis = (N) this;
                parent.addChild(nthis);
            }
        }
    }

    public List getChildren() {
        return children;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy