summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/funcutils/TreeUtils.java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-08 22:39:59 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-08 22:39:59 -0300
commitc82e3b3b2de0633317ec8fc85925e91422820597 (patch)
tree96567416ce23c5ce85601f9cedc3a94bb1c55cba /BJC-Utils2/src/main/java/bjc/utils/funcutils/TreeUtils.java
parentb3ac1c8690c3e14c879913e5dcc03a5f5e14876e (diff)
Start splitting into maven modules
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils/TreeUtils.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/TreeUtils.java56
1 files changed, 0 insertions, 56 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TreeUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TreeUtils.java
deleted file mode 100644
index dcd5738..0000000
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TreeUtils.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package bjc.utils.funcutils;
-
-import java.util.LinkedList;
-import java.util.function.Predicate;
-
-import bjc.utils.data.ITree;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-
-/**
- * Implements various utilities for trees.
- *
- * @author Benjamin Culkin
- */
-public class TreeUtils {
- /*
- * Convert a tree into a list of outline nodes that match a certain
- * path.
- */
- public static <T> IList<IList<T>> outlineTree(ITree<T> tre, Predicate<T> leafMarker) {
- IList<IList<T>> paths = new FunctionalList<>();
-
- LinkedList<T> path = new LinkedList<>();
- path.add(tre.getHead());
-
- tre.doForChildren((child) -> findPath(child, path, leafMarker, paths));
-
- return paths;
- }
-
- private static <T> void findPath(ITree<T> subtree, LinkedList<T> path, Predicate<T> leafMarker, IList<IList<T>> paths) {
- if(subtree.getChildrenCount() == 0 && leafMarker.test(subtree.getHead())) {
- /*
- * We're at a matching leaf node. Add it.
- */
- IList<T> finalPath = new FunctionalList<>();
-
- for(T ePath : path) {
- finalPath.add(ePath);
- }
-
- finalPath.add(subtree.getHead());
-
- paths.add(finalPath);
- } else {
- /*
- * Check the children of this node.
- */
- path.add(subtree.getHead());
-
- subtree.doForChildren((child) -> findPath(child, path, leafMarker, paths));
-
- path.removeLast();
- }
- }
-}