Package com.scriptbasic.interfaces
Interface VariableMap
- All Known Subinterfaces:
HierarchicalVariableMap,LocalVariableMap
- All Known Implementing Classes:
BasicLocalVariableMap,MixedBasicVariableMap
public interface VariableMap
Manage local or global variables. One Map manages the global variables in a
BASIC program. There is a map for each local level of function calls storing
the local variables. This interface is also implemented by the
MixedBasicVariableMap that manages the global and the local variables
transparently.
The methods may throw ScriptBasicException. The interface provides this
possibility to implement features like denying case sensitive reuse of
variable names. For example jScriptBasic does not allow you to use the
variable Apple is ever you already used apple. In other basic
implementations the casing is insensitive and the two variable names are the
same. Other languages treat Apple and apple as two different
variables. jScriptBasic believes that both practices are bad.
- Author:
- Peter Verhas date June 22, 2012
-
Method Summary
Modifier and Type Method Description java.util.Set<java.lang.String>getVariableNameSet()Get the set of the variables stored in the variable map so that the caller can iterate through the variables.RightValuegetVariableValue(java.lang.String variableName)Get the value of a variable.voidsetVariable(java.lang.String variableName, RightValue rightValue)Set the value of the variable.java.lang.BooleanvariableDefined(java.lang.String variableName)Checks that a variable exists and has a defined value in this map.java.lang.BooleanvariableExists(java.lang.String variableName)Checks that a variable exists in this map.
-
Method Details
-
getVariableValue
Get the value of a variable.- Parameters:
variableName- parameter- Returns:
- the right value the variable has or
nullif the variable is not defined or does not exists. - Throws:
ScriptBasicException- in case there is an exception
-
variableExists
Checks that a variable exists in this map.- Parameters:
variableName- parameter- Returns:
trueif the variable exists, even if the variable has undefined value.falseif the variable does not exist in this map.- Throws:
ScriptBasicException- in case there is an exception
-
variableDefined
Checks that a variable exists and has a defined value in this map. Undefined value is represented bynull.- Parameters:
variableName- parameter- Returns:
trueif the variable exists and has a defined value.- Throws:
ScriptBasicException- in case there is an exception
-
setVariable
Set the value of the variable. If the variable did not exist then the variable is automatically created. If the variable had undefined value then the new value will be the one defined by the argument.You can set a variable to undefined passing
nullto this method asrightValue.- Parameters:
variableName- parameterrightValue- the new value of the variable- Throws:
ScriptBasicException- in case there is an exception
-
getVariableNameSet
java.util.Set<java.lang.String> getVariableNameSet()Get the set of the variables stored in the variable map so that the caller can iterate through the variables.- Returns:
- return value
-