diff --git a/.idea/misc.xml b/.idea/misc.xml index f3f4fc6..07115cd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/RecipeTree.java b/src/RecipeTree.java index 58546e5..f9037bd 100644 --- a/src/RecipeTree.java +++ b/src/RecipeTree.java @@ -130,19 +130,37 @@ public class RecipeTree } } - public void actionAdd(RecipeNode actionNchild) { +// public void actionAdd(RecipeNode root,RecipeNode actionNchild) { +// if(root == null) { +// this.root = actionNchild; +// } else { +// for(RecipeNode node : root.getChildren()) { +// if(node.getPortion() != 0 || !actionNchild.getIngredient().equals(node.getIngredient())) { +// actionAdd(node,actionNchild); +// } else if(node.getPortion() == 0 && actionNchild.getIngredient().equals(node.getIngredient())) { +// addNode(node, actionNchild); +// } +// } +// } +// } + public void actionAdd(RecipeNode root,RecipeNode actionNchild) { if(root == null) { - root = actionNchild; + this.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; + for(RecipeNode node : root.getChildren()) { + if(node.getPortion() == 0 && node.getChildren() != null) + actionAdd(node,actionNchild); + else + addNode(node,actionNchild); + + } } } - } + public void actionAdd(RecipeNode actionNchild) + { + actionAdd(root, actionNchild); + } + }