@@ -0,0 +1,2147 @@
+package org.lvcp.eepperly.interpreter;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.Optional;%0A%0A/**%0A * @author Dimitriye Danilovic%0A * @since 2/1/16%0A */%0Apublic abstract class UnsafeTree %7B%0A%09public abstract List%3CUnsafeTree%3E getChildren();%0A%09public abstract Optional%3CString%3E getTokenIfLeaf();%0A%0A%09private static class Internal extends UnsafeTree %7B%0A%09%09private List%3CUnsafeTree%3E children;%0A%0A%09%09private Internal() %7B%0A%09%09%09this.children = new ArrayList%3C%3E();%0A%09%09%7D%0A%0A%09%09public List%3CUnsafeTree%3E getChildren() %7B%0A%09%09%09return Collections.unmodifiableList(children);%0A%09%09%7D%0A%0A%09%09public Optional%3CString%3E getTokenIfLeaf() %7B%0A%09%09%09return Optional.empty();%0A%09%09%7D%0A%09%7D%0A%0A%09private static class Leaf extends UnsafeTree %7B%0A%09%09private String token;%0A%0A%09%09private Leaf(String token) %7B%0A%09%09%09this.token = token;%0A%09%09%7D%0A%0A%09%09public List%3CUnsafeTree%3E getChildren() %7B%0A%09%09%09return Collections.emptyList();%0A%09%09%7D%0A%0A%09%09public Optional%3CString%3E getTokenIfLeaf() %7B%0A%09%09%09return Optional.of(token);%0A%09%09%7D%0A%09%7D%0A%0A%09public static class UnsafeTreeBuilder %7B%0A%09%09protected Internal tree;%0A%09%09private UnsafeTreeBuilder parent;%0A%09%09private boolean disabled = false;%0A%0A%09%09protected void verifyEnabled() %7B%0A%09%09%09if (disabled) throw new IllegalStateException(%22Attempt to use built %60UnsafeTreeBuilder%60%22);%0A%09%09%7D%0A%0A%09%09private UnsafeTreeBuilder() %7B%0A%09%09%09this.tree = new Internal();%0A%09%09%7D%0A%0A%09%09private UnsafeTreeBuilder(UnsafeTreeBuilder parent) %7B%0A%09%09%09this();%0A%09%09%09this.parent = parent;%0A%09%09%7D%0A%0A%09%09public UnsafeTreeBuilder addInternal() %7B%0A%09%09%09verifyEnabled();%0A%09%09%09UnsafeTreeBuilder ret = new UnsafeTreeBuilder(this);%0A%09%09%09tree.children.add(ret.tree);%0A%09%09%09return ret;%0A%09%09%7D%0A%0A%09%09public UnsafeTree build() %7B%0A%09%09%09if (parent != null) throw new UnsupportedOperationException(%22Cannot build internal %60UnsafeTreeBuilder%60%22);%0A%09%09%09verifyEnabled();%0A%09%09%09disabled = true;%0A%09%09%09return tree;%0A%09%09%7D%0A%0A%09%09public UnsafeTreeBuilder pop() %7B%0A%09%09%09if (parent == null) throw new UnsupportedOperationException(%22Cannot pop root %60UnsafeTreeBuilder%60%22);%0A%09%09%09verifyEnabled();%0A%09%09%09disabled = true;%0A%09%09%09return parent;%0A%09%09%7D%0A%09%7D%0A%0A%09public static UnsafeTree of(String token) %7B%0A%09%09return new Leaf(token);%0A%09%7D%0A%0A%09public static UnsafeTreeBuilder builder() %7B%0A%09%09return new UnsafeTreeBuilder();%0A%09%7D%0A%7D%0A

Implement `UnsafeTree`