From 5e0ad7d9ffd12ed0aa0994fa7635beed6e842412 Mon Sep 17 00:00:00 2001 From: Supermjork Date: Thu, 2 Jun 2022 21:09:59 +0200 Subject: [PATCH] Failed action adder --- .idea/misc.xml | 2 +- src/RecipeInstructions.java | 2 +- src/RecipeTree.java | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 07115cd..f3f4fc6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/RecipeInstructions.java b/src/RecipeInstructions.java index 78230ad..f4f09eb 100644 --- a/src/RecipeInstructions.java +++ b/src/RecipeInstructions.java @@ -54,7 +54,7 @@ public class RecipeInstructions String[] words = split[1].split(" "); construct_children(newAction, words); //we add the thing to the tree (this also needs to be checked for WHERE it gets added) - fullInstructions.addNode((RecipeNode) null, newAction); + fullInstructions.actionAdd(newAction); } } diff --git a/src/RecipeTree.java b/src/RecipeTree.java index e961aa9..58546e5 100644 --- a/src/RecipeTree.java +++ b/src/RecipeTree.java @@ -130,5 +130,19 @@ public class RecipeTree } } + public void actionAdd(RecipeNode actionNchild) { + if(root == null) { + root = actionNchild; + } else { + for(RecipeNode node : root.children) { + if(node.getPortion() != 0 || !actionNchild.getIngredient().equals(node.getIngredient())) { + actionAdd(actionNchild); + } else if(node.getPortion() == 0 && actionNchild.getIngredient().equals(node.getIngredient())) { + actionNchild.parent = node.parent; + node.parent = actionNchild; + } + } + } + } }