From 006d987518390da140a77bcaa8f4ac3e5ab1f265 Mon Sep 17 00:00:00 2001 From: asofold Date: Fri, 9 Nov 2012 11:13:05 +0100 Subject: [PATCH] Optimize ActionWithParameters. Only return true for needsParameters() if a wildcard is present at all. --- .../actions/types/ActionWithParameters.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/actions/types/ActionWithParameters.java b/src/fr/neatmonster/nocheatplus/actions/types/ActionWithParameters.java index 02c7ddea..2742d29f 100644 --- a/src/fr/neatmonster/nocheatplus/actions/types/ActionWithParameters.java +++ b/src/fr/neatmonster/nocheatplus/actions/types/ActionWithParameters.java @@ -30,6 +30,8 @@ public abstract class ActionWithParameters extends Action { /** The parts of the message. */ protected final ArrayList messageParts; + protected boolean needsParameters = true; + /** * Instantiates a new action with parameters. * @@ -42,16 +44,18 @@ public abstract class ActionWithParameters extends Action { * @param message * the message */ - public ActionWithParameters(final String name, final int delay, final int repeat, final String message) { - super(name, delay, repeat); + public ActionWithParameters(final String name, final int delay, final int repeat, final String message) { + super(name, delay, repeat); - messageParts = new ArrayList(); - - parseMessage(message); - } + messageParts = new ArrayList(); + // Assume we don't nee parameters. + needsParameters = false; + parseMessage(message); + } /** - * Get a string with all the wildcards replaced with data from the violation data. + * Get a string with all the wildcards replaced with data from the violation data.
+ * This should set the flag needsParameters if parameters are actually needed. * * @param violationData * the violation data @@ -99,7 +103,8 @@ public abstract class ActionWithParameters extends Action { final ParameterName w = ParameterName.get(parts2[0].toLowerCase()); if (w != null) { - // Found an existing wildcard inbetween the braces. + needsParameters = true; + // Found an existing wildcard in between the braces. messageParts.add(parts[0]); messageParts.add(w); @@ -113,6 +118,6 @@ public abstract class ActionWithParameters extends Action { @Override public boolean needsParameters() { - return true; + return needsParameters; } }