geoportal-data-entry-app/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/Tree_Node.java

148 lines
2.4 KiB
Java
Raw Normal View History

2022-07-06 17:47:39 +02:00
package org.gcube.portlets.user.geoportaldataentry.shared;
2022-07-07 12:36:08 +02:00
import java.io.Serializable;
2022-07-06 17:47:39 +02:00
import java.util.ArrayList;
import java.util.List;
/**
2022-07-07 18:21:34 +02:00
* The Class Tree_Node.
2022-07-06 17:47:39 +02:00
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
2022-07-07 18:21:34 +02:00
* Jul 7, 2022
2022-07-06 17:47:39 +02:00
* @param <T> the generic type
*/
2022-07-07 18:21:34 +02:00
public class Tree_Node<T> implements Serializable {
2022-07-07 12:36:08 +02:00
/**
*
*/
private static final long serialVersionUID = -7319055031988865761L;
2022-07-07 18:21:34 +02:00
private String name;
2022-07-06 17:47:39 +02:00
private T data;
2022-07-07 18:21:34 +02:00
private List<Tree_Node<T>> children = new ArrayList<Tree_Node<T>>();
private Tree_Node<T> parent;
2022-07-08 16:38:45 +02:00
private boolean isRoot;
2022-07-06 17:47:39 +02:00
2022-07-07 18:21:34 +02:00
/**
* Instantiates a new tree node.
*/
public Tree_Node() {
2022-07-07 12:36:08 +02:00
}
2022-07-06 17:47:39 +02:00
/**
2022-07-07 18:21:34 +02:00
* Instantiates a new tree node.
2022-07-06 17:47:39 +02:00
*
2022-07-07 18:21:34 +02:00
* @param name the name
2022-07-06 17:47:39 +02:00
* @param data the data
*/
2022-07-07 18:21:34 +02:00
public Tree_Node(String name, T data) {
this.name = name;
2022-07-06 17:47:39 +02:00
this.data = data;
}
2022-07-08 16:38:45 +02:00
/**
* Checks if is root.
*
* @return true, if is root
*/
public boolean isRoot() {
return isRoot;
}
/**
* Sets the root.
*
* @param isRoot the new root
*/
public void setRoot(boolean isRoot) {
this.isRoot = isRoot;
}
2022-07-06 17:47:39 +02:00
/**
2022-07-07 18:21:34 +02:00
* Adds the child.
2022-07-06 17:47:39 +02:00
*
2022-07-07 18:21:34 +02:00
* @param child the child
2022-07-06 17:47:39 +02:00
*/
2022-07-07 18:21:34 +02:00
public void addChild(Tree_Node<T> child) {
child.setParent(this);
children.add(child);
2022-07-06 17:47:39 +02:00
}
/**
2022-07-07 18:21:34 +02:00
* Gets the name.
2022-07-06 17:47:39 +02:00
*
2022-07-07 18:21:34 +02:00
* @return the name
2022-07-06 17:47:39 +02:00
*/
2022-07-07 18:21:34 +02:00
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
2022-07-06 17:47:39 +02:00
}
/**
* 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
*/
2022-07-07 18:21:34 +02:00
public Tree_Node<T> getParent() {
2022-07-06 17:47:39 +02:00
return this.parent;
}
/**
* Sets the parent.
*
* @param parent the new parent
*/
2022-07-07 18:21:34 +02:00
public void setParent(Tree_Node<T> parent) {
2022-07-06 17:47:39 +02:00
this.parent = parent;
}
/**
* Gets the children.
*
* @return the children
*/
2022-07-07 18:21:34 +02:00
public List<Tree_Node<T>> getChildren() {
2022-07-06 17:47:39 +02:00
return this.children;
}
2022-07-07 18:21:34 +02:00
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Tree_Node [name=");
builder.append(name);
builder.append(", data=");
builder.append(data);
2022-07-08 16:38:45 +02:00
builder.append(", isRoot=");
builder.append(isRoot);
2022-07-07 18:21:34 +02:00
builder.append("]");
return builder.toString();
}
2022-07-08 16:38:45 +02:00
2022-07-06 17:47:39 +02:00
}