com.graphbuilder.math
Class VarMap

java.lang.Object
  extended bycom.graphbuilder.math.VarMap

public class VarMap
extends java.lang.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
VarMap()
           
VarMap(boolean caseSensitive)
           
 
Method Summary
 double getValue(java.lang.String varName)
          Returns the value associated with the specified variable name.
 double[] getValues()
          Returns an array of exact length of the values stored in this map.
 java.lang.String[] getVariableNames()
          Returns an array of exact length of the variable names stored in this map.
 boolean isCaseSensitive()
          Returns true if the case of the variable names is considered.
 void remove(java.lang.String varName)
          Removes the variable-name from the map.
 void setValue(java.lang.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 Detail

VarMap

public VarMap()

VarMap

public VarMap(boolean caseSensitive)
Method Detail

getValue

public double getValue(java.lang.String varName)
Returns the value associated with the specified variable name.

Throws:
java.lang.RuntimeException - If a matching variable name cannot be found.

setValue

public void setValue(java.lang.String varName,
                     double val)
Assigns the value to the specified variable name.

Throws:
java.lang.IllegalArgumentException - If the variable name is null.

isCaseSensitive

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


getVariableNames

public java.lang.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(java.lang.String varName)
Removes the variable-name from the map. Does nothing if the variable-name is not found.