blob: 4c747327d11c531d6e272e9b14b72684bf01633a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package model.util;
import org.javatuples.*;
import java.util.*;
// Utility class for a general tree: we'll be using these a lot
public abstract class AbstractTree<T> {
// An AbstractTree holds some kind of data; we'll want this to be generic
// e.g. a tag, attributes, a tag and attributes, etc
private T data;
// Since it's a tree every node also has children.
private ArrayList<AbstractTree<T>> children;
// future implementations may want to consider adding an Optional<> parent; or an Optional<> prevSibling
public T getData() {
return data;
}
public ArrayList<AbstractTree<T>> getChildren() {
return children;
}
// god so much boilerplate
public AbstractTree(T data, ArrayList<AbstractTree<T>> children) {
this.data = data;
this.children = children;
}
public void addChild(AbstractTree<T> child) {
this.children.add(child);
}
}
|