diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples/DefaultTreeNode.java | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/DefaultTreeNode.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/hjp5/examples/DefaultTreeNode.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/DefaultTreeNode.java b/Master/Reference Architectures and Patterns/hjp5/examples/DefaultTreeNode.java new file mode 100644 index 0000000..9d3764d --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/DefaultTreeNode.java @@ -0,0 +1,46 @@ +/* DefaultTreeNode.java */
+
+public class DefaultTreeNode
+implements SimpleTreeNode
+{
+ private int CAPACITY;
+ private String name;
+ private SimpleTreeNode[] childs;
+ private int childcnt;
+
+ public DefaultTreeNode(String name)
+ {
+ this.CAPACITY = 5;
+ this.name = name;
+ this.childs = new SimpleTreeNode[CAPACITY];
+ this.childcnt = 0;
+ }
+
+ public void addChild(SimpleTreeNode child)
+ {
+ if (childcnt >= CAPACITY) {
+ CAPACITY *= 2;
+ SimpleTreeNode[] newchilds = new SimpleTreeNode[CAPACITY];
+ for (int i = 0; i < childcnt; ++i) {
+ newchilds[i] = childs[i];
+ }
+ childs = newchilds;
+ }
+ childs[childcnt++] = child;
+ }
+
+ public int getChildCnt()
+ {
+ return childcnt;
+ }
+
+ public SimpleTreeNode getChild(int pos)
+ {
+ return childs[pos];
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+}
\ No newline at end of file |
