diff options
author | j-james | 2022-10-17 06:25:45 +0000 |
---|---|---|
committer | j-james | 2022-10-17 06:27:55 +0000 |
commit | 3e9bb5fae16c35938bc1f7f7669c12cc355c9331 (patch) | |
tree | 82e1ab837579e7762071ea97c064c0750a38c106 /src/main/model/util/AbstractTree.java | |
parent | 0845be5ec0215fb43f9dbdef00b22a733d4080b3 (diff) |
Basic prototypes of HTML/CSS lexers
Diffstat (limited to 'src/main/model/util/AbstractTree.java')
-rw-r--r-- | src/main/model/util/AbstractTree.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main/model/util/AbstractTree.java b/src/main/model/util/AbstractTree.java new file mode 100644 index 0000000..4c74732 --- /dev/null +++ b/src/main/model/util/AbstractTree.java @@ -0,0 +1,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); + } +} |