/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.apache.jmeter.threads;

import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import org.apache.jmeter.util.JMeterUtils;

/**
 * Class which defines JMeter variables.
 * These are similar to properties, but they are local to a single thread.
 */
public class JMeterVariables {
    private final Map<String, Object> variables = new HashMap<String, Object>();

    private int iteration = 0;

    // Property names to preload into JMeter variables:
    private static final String [] PRE_LOAD = {
      "START.MS",     // $NON-NLS-1$
      "START.YMD",    // $NON-NLS-1$
      "START.HMS",    //$NON-NLS-1$
      "TESTSTART.MS", // $NON-NLS-1$
    };

    public JMeterVariables() {
        preloadVariables();
    }

    private void preloadVariables(){
        for (int i = 0; i < PRE_LOAD.length; i++){
            String property=PRE_LOAD[i];
            String value=JMeterUtils.getProperty(property);
            if (value != null){
                variables.put(property,value);
            }
        }
    }

    public String getThreadName() {
        return Thread.currentThread().getName();
    }

    public int getIteration() {
        return iteration;
    }

    public void incIteration() {
        iteration++;
    }

    // Does not appear to be used
    public void initialize() {
        variables.clear();
        preloadVariables();
    }

    public Object remove(String key) {
        return variables.remove(key);
    }

    public void put(String key, String value) {
        variables.put(key, value);
    }

    public void putObject(String key, Object value) {
        variables.put(key, value);
    }

    public void putAll(Map<String, ?> vars) {
        variables.putAll(vars);
    }

    public void putAll(JMeterVariables vars) {
        putAll(vars.variables);
    }

    /**
     * Returns null values if variable doesn't exist. Users of this must check
     * for null.
     */
    public String get(String key) {
        return (String) variables.get(key);
    }

    public Object getObject(String key) {
        return variables.get(key);
    }

    public Iterator<Entry<String, Object>> getIterator(){
        return Collections.unmodifiableMap(variables).entrySet().iterator() ;
    }

    // Used by DebugSampler
    public Set<Entry<String, Object>> entrySet(){
        return Collections.unmodifiableMap(variables).entrySet();
    }
}
@@ -2279,177 +2279,703 @@
     
-public Object remove(String key) %7B%0A        return variables.remove(key);%0A    %7D%0A%0A    public void put(String key, String value) %7B%0A        variables.put(key, value);%0A    %7D%0A
+/**%0A     * Remove a variable.%0A     * %0A     * @param key the variable name to remove%0A     * %0A     * @return the variable value, or %7B@code null%7D if there was no such variable%0A     */%0A    public Object remove(String key) %7B%0A        return variables.remove(key);%0A    %7D%0A%0A    /**%0A     * Creates or updates a variable with a String value.%0A     * %0A     * @param key the variable name%0A     * @param value the variable value%0A     */%0A    public void put(String key, String value) %7B%0A        variables.put(key, value);%0A    %7D%0A%0A    /**%0A     * Creates or updates a variable with a value that does not have to be a String.%0A     * %0A     * @param key the variable name%0A     * @param value the variable value%0A     */
 %0A   
@@ -3257,30 +3257,27 @@
   * 
-Returns null
+Gets the
  value
-s if
+ of a
  var
@@ -3285,244 +3285,653 @@
 able
- doesn't exist. Users of this must check%0A     * for null.%0A     */%0A    public String get(String key) %7B%0A        return (String) variables.get(key);%0A    %7D%0A%0A    public Object getObject(String key) %7B%0A        return variables.get(key);%0A    %7D%0A
+, coerced to a String.%0A     * %0A     * @param key the name of the variable%0A     * @return the value of the variable, or %7B@code null%7D if it does not exist%0A     */%0A    public String get(String key) %7B%0A        return (String) variables.get(key);%0A    %7D%0A%0A    /**%0A     * Gets the value of a variable (not converted to String).%0A     * %0A     * @param key the name of the variable%0A     * @return the value of the variable, or %7B@code null%7D if it does not exist%0A     */%0A    public Object getObject(String key) %7B%0A        return variables.get(key);%0A    %7D%0A%0A    /**%0A     * Gets a read-only Iterator over the variables.%0A     * %0A     * @return the iterator%0A     */
 %0A   

Update Javadoc for methods that are likely to be used by scripting test elements