Class VarMap

java.lang.Object
com.graphbuilder.math.VarMap

public class VarMap extends Object

VarMap maps a name to a value. A VarMap is used in the eval method of an Expression object. This class can be used as the default variable-map.

During the evaluation of an expression, if a variable is not supported then a RuntimeException is thrown. Case sensitivity can only be specified in the constructor (for consistency). When case sensitivity is false, the String.equalsIgnoreCase method is used. When case sensitivity is true, the String.equals method is used. By default, case sensitivity is true.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
    VarMap(boolean caseSensitive)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    getValue(String varName)
    Returns the value associated with the specified variable name.
    double[]
    Returns an array of exact length of the values stored in this map.
    Returns an array of exact length of the variable names stored in this map.
    boolean
    Returns true if the case of the variable names is considered.
    void
    remove(String varName)
    Removes the variable-name from the map.
    void
    setValue(String varName, double val)
    Assigns the value to the specified variable name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • VarMap

      public VarMap()
    • VarMap

      public VarMap(boolean caseSensitive)
  • Method Details

    • getValue

      public double getValue(String varName)
      Returns the value associated with the specified variable name.
      Throws:
      RuntimeException - If a matching variable name cannot be found.
    • setValue

      public void setValue(String varName, double val)
      Assigns the value to the specified variable name.
      Throws:
      IllegalArgumentException - If the variable name is null.
    • isCaseSensitive

      public boolean isCaseSensitive()
      Returns true if the case of the variable names is considered.
    • getVariableNames

      public String[] getVariableNames()
      Returns an array of exact length of the variable names stored in this map.
    • getValues

      public double[] getValues()
      Returns an array of exact length of the values stored in this map. The returned array corresponds to the order of the names returned by getVariableNames.
    • remove

      public void remove(String varName)
      Removes the variable-name from the map. Does nothing if the variable-name is not found.