From ac3087fc3f0362a66c0c8fac3ea8b6ec547c6a14 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 24 Jul 2017 20:45:56 -0700 Subject: [PATCH] Add a new function to add children into collection. --- src/org/nwapw/abacus/lexing/pattern/LinkNode.java | 7 +++---- src/org/nwapw/abacus/lexing/pattern/PatternNode.java | 7 ++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/org/nwapw/abacus/lexing/pattern/LinkNode.java b/src/org/nwapw/abacus/lexing/pattern/LinkNode.java index 69b16ed..460c418 100644 --- a/src/org/nwapw/abacus/lexing/pattern/LinkNode.java +++ b/src/org/nwapw/abacus/lexing/pattern/LinkNode.java @@ -1,14 +1,13 @@ package org.nwapw.abacus.lexing.pattern; import java.util.ArrayList; +import java.util.Collection; public class LinkNode extends PatternNode { @Override - public void addInto(ArrayList> into) { - for(PatternNode node : outputStates){ - node.addInto(into); - } + public void addInto(Collection> into) { + addOutputsInto(into); } } diff --git a/src/org/nwapw/abacus/lexing/pattern/PatternNode.java b/src/org/nwapw/abacus/lexing/pattern/PatternNode.java index 3ef36d7..4c0908a 100644 --- a/src/org/nwapw/abacus/lexing/pattern/PatternNode.java +++ b/src/org/nwapw/abacus/lexing/pattern/PatternNode.java @@ -1,6 +1,7 @@ package org.nwapw.abacus.lexing.pattern; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; public class PatternNode { @@ -19,8 +20,12 @@ public class PatternNode { return '\0'; } - public void addInto(ArrayList> into){ + public void addInto(Collection> into){ into.add(this); } + public void addOutputsInto(Collection> into){ + outputStates.forEach(e -> e.addInto(into)); + } + }