You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2006/05/01 20:05:07 UTC
svn commit: r398654 -
/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/functions/AbstractFunction.java
Author: sebb
Date: Mon May 1 11:05:05 2006
New Revision: 398654
URL: http://svn.apache.org/viewcvs?rev=398654&view=rev
Log:
Utility method for functions to check argument counts
Modified:
jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/functions/AbstractFunction.java
Modified: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/functions/AbstractFunction.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/functions/AbstractFunction.java?rev=398654&r1=398653&r2=398654&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/functions/AbstractFunction.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/functions/AbstractFunction.java Mon May 1 11:05:05 2006
@@ -1,4 +1,3 @@
-// $Header$
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
@@ -18,11 +17,7 @@
package org.apache.jmeter.functions;
-// import java.io.UnsupportedEncodingException;
import java.util.Collection;
-// import java.util.LinkedList;
-// import java.util.List;
-// import java.util.StringTokenizer;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
@@ -30,10 +25,8 @@
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;
-// import org.apache.jorphan.util.JOrphanUtils;
-
/**
- * @version $Revision$ on $Date$
+ * Provides common methods for all functions
*/
public abstract class AbstractFunction implements Function {
@@ -51,6 +44,8 @@
/**
* @see Function#setParameters(Collection)
+ * Note: This may not be called (e.g. if no parameters are provided)
+ *
*/
abstract public void setParameters(Collection parameters) throws InvalidVariableException;
@@ -59,70 +54,23 @@
*/
abstract public String getReferenceKey();
- // Not used
- // /**
- // * Provides a convenient way to parse the given argument string into a
- // * collection of individual arguments. Takes care of splitting the string
- // * based on commas, generates blank strings for values between adjacent
- // * commas, and decodes the string using URLDecoder.
- // *
- // * @deprecated
- // */
- // protected Collection parseArguments(String params)
- // {
- // StringTokenizer tk = new StringTokenizer(params, ",", true);
- // List arguments = new LinkedList();
- // String previous = "";
- // while (tk.hasMoreTokens())
- // {
- // String arg = tk.nextToken();
- //
- // if (arg.equals(",") && previous.equals(","))
- // {
- // arguments.add("");
- // }
- // else if (!arg.equals(","))
- // {
- // try
- // {
- // arguments.add(JOrphanUtils.decode(arg, "UTF-8"));
- // }
- // catch (UnsupportedEncodingException e)
- // {
- // // UTF-8 unsupported? You must be joking!
- // throw new Error("Should not happen: "+e.toString());
- // }
- // }
- // previous = arg;
- // }
- // return arguments;
- // }
-
- /**
- * Provides a convenient way to parse the given argument string into a
- * collection of individual arguments. Takes care of splitting the string
- * based on commas, generates blank strings for values between adjacent
- * commas, and decodes the string using URLDecoder.
- */
- /*
- * protected Collection parseArguments2(String params) { StringTokenizer tk =
- * new StringTokenizer(params, ",", true); List arguments = new
- * LinkedList(); String previous = ""; while (tk.hasMoreTokens()) { String
- * arg = tk.nextToken();
- *
- * if (arg.equals(",") && (previous.equals(",") || previous.length() == 0)) {
- * arguments.add(new CompoundVariable()); } else if (!arg.equals(",")) { try {
- * CompoundVariable compoundArg = new CompoundVariable();
- * compoundArg.setParameters(URLDecoder.decode(arg));
- * arguments.add(compoundArg); } catch (InvalidVariableException e) { } }
- * previous = arg; }
- *
- * if (previous.equals(",")) { arguments.add(new CompoundVariable()); }
- *
- * return arguments; }
- */
-
protected JMeterVariables getVariables() {
return JMeterContextService.getContext().getVariables();
}
+
+ /*
+ * Utility method to check parameter counts
+ */
+ protected void checkParameterCount(Collection parameters, int min, int max)
+ throws InvalidVariableException
+ {
+ int num = parameters.size();
+ if ((num > max) || (num < min)) {
+ throw new InvalidVariableException(
+ "Wrong number of parameters. Actual: "+num+
+ ". Expected: >= "+min
+ +" and <= "+max
+ );
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org