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

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

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

/**
 * Data structure that pairs a tree with one of its nodes.
 * Useful to keep references to specific nodes in a tree while still allowing traversal.
 *
 * @author raven
 *
 * @param 
 */
public class TreeNodeImpl
    implements TreeNode
{
    protected Tree tree;
    protected T node;

    public TreeNodeImpl(Tree tree, T node) {
        super();
        this.tree = tree;
        this.node = node;
    }

    public Tree getTree() {
        return tree;
    }

    public T getNode() {
        return node;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((node == null) ? 0 : node.hashCode());
        result = prime * result + ((tree == null) ? 0 : tree.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        TreeNodeImpl other = (TreeNodeImpl) obj;
        if (node == null) {
            if (other.node != null)
                return false;
        } else if (!node.equals(other.node))
            return false;
        if (tree == null) {
            if (other.tree != null)
                return false;
        } else if (!tree.equals(other.tree))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return "TreeNodeImpl [tree=" + tree + ", node=" + node + "]";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy