You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
package net.yacy.visualization;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class GridTree {
|
|
|
|
private String name, description;
|
|
private List<GridTree> children;
|
|
|
|
public GridTree(String name, String description) {
|
|
this.name = name;
|
|
this.description = description;
|
|
this.children = null;
|
|
}
|
|
|
|
public void addChild(GridTree child) {
|
|
if (this.children == null) this.children = new ArrayList<GridTree>();
|
|
this.children.add(child);
|
|
}
|
|
|
|
public boolean isLeaf() {
|
|
return this.children == null;
|
|
}
|
|
|
|
public int depth() {
|
|
if (this.isLeaf()) return 1;
|
|
int maxChildDepth = 0;
|
|
for (GridTree child: children) {
|
|
maxChildDepth = Math.max(maxChildDepth, child.depth());
|
|
}
|
|
return maxChildDepth + 1;
|
|
}
|
|
|
|
public int width() {
|
|
if (this.isLeaf()) return 1;
|
|
int maxChildDepth = 0;
|
|
for (GridTree child: children) {
|
|
maxChildDepth = Math.max(maxChildDepth, child.depth());
|
|
}
|
|
return maxChildDepth + 1;
|
|
}
|
|
|
|
}
|