1 | public class IntSum extends AbstractFunction implements Serializable {↵ | | 1 | public class LongSum extends AbstractFunction implements Serializable {↵
|
|
2 | private static final long serialVersionUID = 232L;↵ | | 2 | private static final long serialVersionUID = 232L;↵
|
3 | ↵ | | 3 | ↵
|
4 | private static final List desc = new LinkedList();↵ | | 4 | private static final List desc = new LinkedList();↵
|
|
5 | private static final String KEY = "__intSum"; //$NON-NLS-1$↵ | | 5 | private static final String KEY = "__longSum"; //$NON-NLS-1$↵
|
|
6 | static {↵ | | 6 | static {↵
|
7 | desc.add(JMeterUtils.getResString("intsum_param_1")); //$NON-NLS-1$↵ | | 7 | desc.add(JMeterUtils.getResString("longsum_param_1")); //$NON-NLS-1$↵
|
8 | desc.add(JMeterUtils.getResString("intsum_param_2")); //$NON-NLS-1$↵ | | 8 | desc.add(JMeterUtils.getResString("longsum_param_2")); //$NON-NLS-1$↵
|
9 | desc.add(JMeterUtils.getResString("function_name_paropt")); //$NON-NLS-1$↵ | | 9 | desc.add(JMeterUtils.getResString("function_name_paropt")); //$NON-NLS-1$↵
|
10 | }↵ | | 10 | }↵
|
|
11 | private Object[] values;↵ | | 11 | private Object[] values;↵
|
|
12 | /**↵ | | 12 | /**↵
|
13 | * No-arg constructor.↵ | | 13 | * No-arg constructor.↵
|
14 | */↵ | | 14 | */↵
|
15 | public IntSum() {↵ | | 15 | public LongSum() {↵
|
16 | }↵ | | 16 | }↵
|
|
17 | /**↵ | | 17 | /**↵
|
18 | * Clone this Add object.↵ | | 18 | * Clone this Add object.↵
|
19 | * ↵ | | 19 | * ↵
|
20 | * @return A new Add object.↵ | | 20 | * @return A new Add object.↵
|
21 | * @throws CloneNotSupportedException ↵ | | 21 | * @throws CloneNotSupportedException ↵
|
22 | */↵ | | 22 | */↵
|
23 | public Object clone() throws CloneNotSupportedException {↵ | | 23 | public Object clone() throws CloneNotSupportedException {↵
|
24 | return super.clone();↵ | | 24 | return super.clone();↵
|
25 | }↵ | | 25 | }↵
|
|
26 | /**↵ | | 26 | /**↵
|
27 | * Execute the function.↵ | | 27 | * Execute the function.↵
|
28 | * ↵ | | 28 | * ↵
|
29 | * @see Function#execute(SampleResult, Sampler)↵ | | 29 | * @see Function#execute(SampleResult, Sampler)↵
|
30 | */↵ | | 30 | */↵
|
31 | public synchronized String execute(SampleResult previousResult, Sampler currentSampler)↵ | | 31 | public synchronized String execute(SampleResult previousResult, Sampler currentSampler)↵
|
32 | throws InvalidVariableException {↵ | | 32 | throws InvalidVariableException {↵
|
|
33 | JMeterVariables vars = getVariables();↵ | | 33 | JMeterVariables vars = getVariables();↵
|
|
34 | int sum = 0;↵ | | 34 | long sum = 0;↵
|
35 | String varName = ((CompoundVariable) values[values.length - 1]).execute();↵ | | 35 | String varName = ((CompoundVariable) values[values.length - 1]).execute().trim();↵
|
|
36 | for (int i = 0; i < values.length - 1; i++) {↵ | | 36 | for (int i = 0; i < values.length - 1; i++) {↵
|
37 | sum += Integer.parseInt(((CompoundVariable) values[i]).execute());↵ | | 37 | sum += Long.parseLong(((CompoundVariable) values[i]).execute());↵
|
38 | }↵ | | 38 | }↵
|
|
39 | try {↵ | | 39 | try {↵
|
40 | sum += Integer.parseInt(varName);↵ | | 40 | sum += Long.parseLong(varName);↵
|
41 | varName = null; // there is no variable name↵ | | 41 | varName = null; // there is no variable name↵
|
42 | } catch (NumberFormatException ignored) {↵ | | 42 | } catch (NumberFormatException ignored) {↵
|
43 | }↵ | | 43 | }↵
|
|
44 | ↵ | | 44 | ↵
|
45 | String totalString = Integer.toString(sum);↵ | | 45 | String totalString = Long.toString(sum);↵
|
46 | if (vars != null && varName != null){// vars will be null on TestPlan↵ | | 46 | if (vars != null && varName != null && varName.length() > 0){// vars will be null on TestPlan↵
|
47 | vars.put(varName.trim(), totalString);↵ | | 47 | vars.put(varName, totalString);↵
|
48 | }↵ | | 48 | }↵
|
|
49 | return totalString;↵ | | 49 | return totalString;↵
|
|
50 | }↵ | | 50 | }↵
|
|
51 | /**↵ | | 51 | /**↵
|
52 | * Set the parameters for the function.↵ | | 52 | * Set the parameters for the function.↵
|
53 | * ↵ | | 53 | * ↵
|
54 | * @see Function#setParameters(Collection)↵ | | 54 | * @see Function#setParameters(Collection)↵
|
55 | */↵ | | 55 | */↵
|
56 | public synchronized void setParameters(Collection parameters) throws InvalidVariableException {↵ | | 56 | public synchronized void setParameters(Collection parameters) throws InvalidVariableException {↵
|
57 | checkMinParameterCount(parameters, 2);↵ | | 57 | checkMinParameterCount(parameters, 2);↵
|
58 | values = parameters.toArray();↵ | | 58 | values = parameters.toArray();↵
|
59 | }↵ | | 59 | }↵
|
|
60 | /**↵ | | 60 | /**↵
|
61 | * Get the invocation key for this function.↵ | | 61 | * Get the invocation key for this function.↵
|
62 | * ↵ | | 62 | * ↵
|
63 | * @see Function#getReferenceKey()↵ | | 63 | * @see Function#getReferenceKey()↵
|
64 | */↵ | | 64 | */↵
|
65 | public String getReferenceKey() {↵ | | 65 | public String getReferenceKey() {↵
|
66 | return KEY;↵ | | 66 | return KEY;↵
|
67 | }↵ | | 67 | }↵
|
|
68 | /**↵ | | 68 | /**↵
|
69 | * Get the description of this function.↵ | | 69 | * Get the description of this function.↵
|
70 | * ↵ | | 70 | * ↵
|
71 | * @see Function#getArgumentDesc()↵ | | 71 | * @see Function#getArgumentDesc()↵
|
72 | */↵ | | 72 | */↵
|
73 | public List getArgumentDesc() {↵ | | 73 | public List getArgumentDesc() {↵
|
74 | return desc;↵ | | 74 | return desc;↵
|
75 | | | 75 |
|