1 18 19 package org.apache.jmeter.functions; 20 21 import java.io.Serializable ; 22 import java.util.Collection ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 26 import org.apache.jmeter.engine.util.CompoundVariable; 27 import org.apache.jmeter.samplers.SampleResult; 28 import org.apache.jmeter.samplers.Sampler; 29 import org.apache.jmeter.threads.JMeterVariables; 30 import org.apache.jmeter.util.JMeterUtils; 31 32 38 public class IntSum extends AbstractFunction implements Serializable 39 { 40 41 private static final List desc = new LinkedList (); 42 private static final String KEY = "__intSum"; 43 44 static { 45 desc.add(JMeterUtils.getResString("intsum_param_1")); 46 desc.add(JMeterUtils.getResString("intsum_param_2")); 47 desc.add(JMeterUtils.getResString("function_name_param")); 48 } 49 50 private Object [] values; 51 52 55 public IntSum() 56 { 57 } 58 59 64 public Object clone() 65 { 66 IntSum newIntSum = new IntSum(); 67 return newIntSum; 68 } 69 70 75 public synchronized String execute( 76 SampleResult previousResult, 77 Sampler currentSampler) 78 throws InvalidVariableException 79 { 80 81 JMeterVariables vars = getVariables(); 82 83 int sum = 0; 84 String varName = 85 ((CompoundVariable) values[values.length - 1]).execute(); 86 87 for (int i = 0; i < values.length - 1; i++) 88 { 89 sum += Integer.parseInt(((CompoundVariable) values[i]).execute()); 90 } 91 92 String totalString = Integer.toString(sum); 93 vars.put(varName, totalString); 94 95 return totalString; 96 97 } 98 99 104 public void setParameters(Collection parameters) 105 throws InvalidVariableException 106 { 107 values = parameters.toArray(); 108 109 if (values.length < 3) 110 { 111 throw new InvalidVariableException(); 112 } 113 114 } 115 116 121 public String getReferenceKey() 122 { 123 return KEY; 124 } 125 126 131 public List getArgumentDesc() 132 { 133 return desc; 134 } 135 } 136 | Popular Tags |