Commit 2929ab7e authored by Nico Mack's avatar Nico Mack
Browse files

Replaced splitter by regex matcher to extract variables from trigger

condition
parent 27b373d4
...@@ -32,8 +32,6 @@ import lu.list.itis.dkd.tui.cps.variable.Variable; ...@@ -32,8 +32,6 @@ import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.exception.BuildException; import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization; import lu.list.itis.dkd.tui.utility.Externalization;
import com.google.common.base.Splitter;
import org.jdom2.Element; import org.jdom2.Element;
import java.awt.Graphics2D; import java.awt.Graphics2D;
...@@ -43,6 +41,8 @@ import java.io.FileNotFoundException; ...@@ -43,6 +41,8 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.Base64; import java.util.Base64;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioFormat;
...@@ -80,6 +80,8 @@ public class Scene extends Content { ...@@ -80,6 +80,8 @@ public class Scene extends Content {
private AudioInputStream audioStream; private AudioInputStream audioStream;
private boolean isPlaying; private boolean isPlaying;
private static final Pattern VARIABLE_PATTERN = Pattern.compile("([a-z0-9\\_]+)", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
/** /**
* Constructor initializing all fields. * Constructor initializing all fields.
* *
...@@ -97,13 +99,14 @@ public class Scene extends Content { ...@@ -97,13 +99,14 @@ public class Scene extends Content {
final String triggerCondition = element.getChildText(Externalization.TRIGGER_CONDITION_NODE); final String triggerCondition = element.getChildText(Externalization.TRIGGER_CONDITION_NODE);
for (final String _name : Splitter.on(Externalization.SPACE).trimResults().omitEmptyStrings().split(triggerCondition)) { final Matcher variableMatcher = VARIABLE_PATTERN.matcher(triggerCondition);
// System.out.println(_name);
while (variableMatcher.find()) {
final String _name = variableMatcher.group(1);
final Variable variable = Scenario.retrieveVariableByName(_name); final Variable variable = Scenario.retrieveVariableByName(_name);
if (null != variable) { if (null != variable) {
variables.add(variable); variables.add(variable);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment