ValueReplacer (Apache JMeter dist API)
Description: declaration: package: org.apache.jmeter.engine.util, class: ValueReplacer

Package org.apache.jmeter.engine.util

# Class ValueReplacer

java.lang.Object
org.apache.jmeter.engine.util.ValueReplacer

public class ValueReplacer extends Object
Perform replacement of ${variable} references.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ValueReplacer()`
  `ValueReplacer(TestPlan tp)`
  Constructor which couples the given `TestPlan` to this by means of the user defined variables

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addVariable(String name, String value)`
  Add a variable to this replacer's variables map
  `void`
  `addVariables(Map<String,String> vars)`
  Add all the given variables to this replacer's variables map.
  `void`
  `replaceValues(org.apache.jmeter.testelement.TestElement el)`
  Replaces TestElement StringProperties containing functions with their Function properties equivalent, example: ${__time()}_${__threadNum()}_${__machineName()} will become a FunctionProperty of a CompoundVariable containing 3 functions
  `void`
  `reverseReplace(org.apache.jmeter.testelement.TestElement el)`
  Transforms strings into variable references
  `void`
  `reverseReplace(org.apache.jmeter.testelement.TestElement el, boolean regexMatch)`
  Transforms strings into variable references using regexp matching if regexMatch is `true`
  `void`
  `setUserDefinedVariables(Map<String,String> variables)`
  Set this `ValueReplacer`'s variable map
  `void`
  `undoReverseReplace(org.apache.jmeter.testelement.TestElement el)`
  Replaces ${key} by value extracted from variables if any

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ValueReplacer

    public ValueReplacer()

  - ### ValueReplacer

    public ValueReplacer(TestPlan tp)
    Constructor which couples the given `TestPlan` to this by means of the user defined variables
    Parameters:
      `tp` - `TestPlan` from which we will take the user defined variables as variables map

- ## Method Details

  - ### setUserDefinedVariables

    public void setUserDefinedVariables(Map<String,String> variables)
    Set this `ValueReplacer`'s variable map
    Parameters:
      `variables` - Map which stores the variables

  - ### replaceValues

    public void replaceValues(org.apache.jmeter.testelement.TestElement el) throws InvalidVariableException
    Replaces TestElement StringProperties containing functions with their Function properties equivalent, example: ${__time()}_${__threadNum()}_${__machineName()} will become a FunctionProperty of a CompoundVariable containing 3 functions
    Parameters:
      `el` - `TestElement` in which the values should be replaced
    Throws:
      `InvalidVariableException` - when transforming of the variables goes awry and the used transformer throws an `InvalidVariableException`

  - ### reverseReplace

    public void reverseReplace(org.apache.jmeter.testelement.TestElement el) throws InvalidVariableException
    Transforms strings into variable references
    Parameters:
      `el` - `TestElement` in which the we will look for strings, that can be replaced by variable references
    Throws:
      `InvalidVariableException` - when transforming of the strings goes awry and the used transformer throws an `InvalidVariableException`

  - ### reverseReplace

    public void reverseReplace(org.apache.jmeter.testelement.TestElement el, boolean regexMatch) throws InvalidVariableException
    Transforms strings into variable references using regexp matching if regexMatch is `true`
    Parameters:
      `el` - `TestElement` in which the we will look for strings, that can be replaced by variable references
      `regexMatch` - when `true` variable substitution will be done in regexp matching mode
    Throws:
      `InvalidVariableException` - when transforming of the strings goes awry and the used transformer throws an `InvalidVariableException`

  - ### undoReverseReplace

    public void undoReverseReplace(org.apache.jmeter.testelement.TestElement el) throws InvalidVariableException
    Replaces ${key} by value extracted from variables if any
    Parameters:
      `el` - `TestElement` in which values should be replaced
    Throws:
      `InvalidVariableException` - when transforming of the variables goes awry and the used transformer throws an `InvalidVariableException`

  - ### addVariable

    public void addVariable(String name, String value)
    Add a variable to this replacer's variables map
    Parameters:
      `name` - Name of the variable
      `value` - Value of the variable

  - ### addVariables

    public void addVariables(Map<String,String> vars)
    Add all the given variables to this replacer's variables map.
    Parameters:
      `vars` - A map of variable name-value pairs (String-to-String).