<commit_before>package org.apache.jmeter.functions;

import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import org.apache.jmeter.engine.util.CompoundVariable;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.jmeter.util.JMeterUtils;

public class IterationCounter extends AbstractFunction implements Serializable
{
	
	private static final List desc = new LinkedList();
	private static final String KEY = "__counter";
	
	static
	{
		desc.add(JMeterUtils.getResString("iteration_counter_arg_1"));
		desc.add(JMeterUtils.getResString("function_name_param"));
	}
	
	private Object[] variables;
	private static int counter;


	public IterationCounter()
	{
		counter = 0;
	}
	
	public Object clone()
	{
		IterationCounter newCounter = new IterationCounter();
		return newCounter;
	}

    /* (non-Javadoc)
	 * @see org.apache.jmeter.functions.Function#execute(SampleResult, Sampler)
	 */
	public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
		throws InvalidVariableException 
	{
		counter++;

		JMeterVariables vars = getVariables();
		
		boolean perThread = new Boolean(((CompoundVariable)variables[0]).execute()).booleanValue();

		String varName = ((CompoundVariable)variables[variables.length - 1]).execute();
		String counterString = "";

		if(perThread)
		{
			counterString = Integer.toString(vars.getIteration());			
		}
		else
		{
			counterString = Integer.toString(counter);
		}
		
		vars.put( varName, counterString );
		return counterString;
	}


    /* (non-Javadoc)
	 * @see org.apache.jmeter.functions.Function#setParameters(Collection)
	 */
	public void setParameters(Collection parameters)
		throws InvalidVariableException {

			variables = parameters.toArray();
			
			if ( variables.length < 2 ) {
				throw new InvalidVariableException();
			}
	}

    /* (non-Javadoc)
	 * @see org.apache.jmeter.functions.Function#getReferenceKey()
	 */
	public String getReferenceKey() {
		return KEY;
	}

    /* (non-Javadoc)
	 * @see org.apache.jmeter.functions.Function#getArgumentDesc()
	 */
	public List getArgumentDesc() {
		return desc;
	}


}<commit_msg>Made counter function global value non-static (shared b/w clones only)<commit_after>package org.apache.jmeter.functions;

import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import org.apache.jmeter.engine.util.CompoundVariable;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.jmeter.util.JMeterUtils;

public class IterationCounter extends AbstractFunction implements Serializable
{
	
	private static final List desc = new LinkedList();
	private static final String KEY = "__counter";
	
	static
	{
		desc.add(JMeterUtils.getResString("iteration_counter_arg_1"));
		desc.add(JMeterUtils.getResString("function_name_param"));
	}
	
	private Object[] variables;
	private IntegerWrapper counter;


	public IterationCounter()
	{
		counter = new IntegerWrapper(new Integer(0));
	}
	
	public Object clone()
	{
		IterationCounter newCounter = new IterationCounter();
		newCounter.counter = counter;
		return newCounter;
	}

    /* (non-Javadoc)
	 * @see org.apache.jmeter.functions.Function#execute(SampleResult, Sampler)
	 */
	public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
		throws InvalidVariableException 
	{
		counter.setInteger((new Integer(counter.getInteger().intValue()+1)));

		JMeterVariables vars = getVariables();
		
		boolean perThread = new Boolean(((CompoundVariable)variables[0]).execute()).booleanValue();

		String varName = ((CompoundVariable)variables[variables.length - 1]).execute();
		String counterString = "";

		if(perThread)
		{
			counterString = Integer.toString(vars.getIteration());			
		}
		else
		{
			counterString = String.valueOf(counter.getInteger());
		}
		
		vars.put( varName, counterString );
		return counterString;
	}


    /* (non-Javadoc)
	 * @see org.apache.jmeter.functions.Function#setParameters(Collection)
	 */
	public void setParameters(Collection parameters)
		throws InvalidVariableException {

			variables = parameters.toArray();
			
			if ( variables.length < 2 ) {
				throw new InvalidVariableException();
			}
	}

    /* (non-Javadoc)
	 * @see org.apache.jmeter.functions.Function#getReferenceKey()
	 */
	public String getReferenceKey() {
		return KEY;
	}

    /* (non-Javadoc)
	 * @see org.apache.jmeter.functions.Function#getArgumentDesc()
	 */
	public List getArgumentDesc() {
		return desc;
	}
	
	protected class IntegerWrapper
		implements Serializable
	{
		Integer i;

		public IntegerWrapper() {}
	
		public IntegerWrapper(Integer i)
		{
			this.i = i;
		}
	
		public void setInteger(Integer i)
		{
			this.i = i;
		}
	
		public Integer getInteger()
		{
			return i;
		}
	}

}
{'fraction_non_alphanumeric': 0.11288392500997207, 'fraction_numerical': 0.0021938571998404467, 'mean_word_length': 4.369379014989294, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7149966', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1481, 'n_words': 306}