102 lines
1.6 KiB
Java
102 lines
1.6 KiB
Java
package org.gcube.portlets.user.geoportaldataentry.shared;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* The Class TNode.
|
|
*
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
*
|
|
* Jul 6, 2022
|
|
* @param <T> the generic type
|
|
*/
|
|
public class TNode<T> implements Serializable {
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = -7319055031988865761L;
|
|
private T data;
|
|
private List<TNode<T>> children;
|
|
private TNode<T> parent;
|
|
|
|
public TNode() {
|
|
|
|
}
|
|
|
|
/**
|
|
* Instantiates a new node.
|
|
*
|
|
* @param data the data
|
|
*/
|
|
public TNode(T data) {
|
|
this.data = data;
|
|
this.children = new ArrayList<TNode<T>>();
|
|
}
|
|
|
|
/**
|
|
* Instantiates a new node.
|
|
*
|
|
* @param node the node
|
|
*/
|
|
public TNode(TNode<T> node) {
|
|
this.data = (T) node.getData();
|
|
children = new ArrayList<TNode<T>>();
|
|
}
|
|
|
|
/**
|
|
* Adds the child.
|
|
*
|
|
* @param child the child
|
|
*/
|
|
public void addChild(TNode<T> child) {
|
|
child.setParent(this);
|
|
children.add(child);
|
|
}
|
|
|
|
/**
|
|
* Gets the data.
|
|
*
|
|
* @return the data
|
|
*/
|
|
public T getData() {
|
|
return this.data;
|
|
}
|
|
|
|
/**
|
|
* Sets the data.
|
|
*
|
|
* @param data the new data
|
|
*/
|
|
public void setData(T data) {
|
|
this.data = data;
|
|
}
|
|
|
|
/**
|
|
* Gets the parent.
|
|
*
|
|
* @return the parent
|
|
*/
|
|
public TNode<T> getParent() {
|
|
return this.parent;
|
|
}
|
|
|
|
/**
|
|
* Sets the parent.
|
|
*
|
|
* @param parent the new parent
|
|
*/
|
|
public void setParent(TNode<T> parent) {
|
|
this.parent = parent;
|
|
}
|
|
|
|
/**
|
|
* Gets the children.
|
|
*
|
|
* @return the children
|
|
*/
|
|
public List<TNode<T>> getChildren() {
|
|
return this.children;
|
|
}
|
|
} |