Package util
Class VariableManager
- java.lang.Object
-
- util.VariableManager
-
public class VariableManager extends java.lang.Object- Author:
- JIBOYE Oluwagbemiro Olaoluwa
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classVariableManager.CommandInterpreterObjects of this class parse a variable initialization or modifying command string.
-
Constructor Summary
Constructors Constructor Description VariableManager()
-
Method Summary
Modifier and Type Method Description static voidadd(Variable var)Introduces a Variablestatic voidadd(Variable... vars)Introduces an array or variable-args list of VariablevoidclearConstants()Clears all constantsstatic voidclearVariables()Clears all VariablesvoidclearVariablesAndConstants()Clears All Variables and Constantsbooleancontains(java.lang.String variableName)static voiddelete(java.lang.String varName)deletes a Variable or constant whose name is knownstatic java.lang.StringgenerateCommandStringFromVariableNamesArray(java.lang.String[] variableNames)VariableManager.CommandInterpretergetCommandParser()static java.lang.StringgetEndOfLine()static VariablegetVariable(java.lang.String vName)static java.util.ArrayList<Variable>getVariables()java.util.Map<java.lang.String,Variable>getVarStore()static voidinit()Initializes the variables store and loads them from persistent storagestatic voidload(java.util.Collection<Variable> variables)static voidload(java.util.Map<java.lang.String,Variable> variables)static voidload(java.util.Map<java.lang.String,Variable> variables, boolean clearFirst)static VariablelookUp(java.lang.String vName)Attempts to retrieve a Variable object from a VariableManager based on its name.static voidmain(java.lang.String[] args)voidparseCommand(java.lang.String cmd)Parses a command that creates or changes the value of variables.VariableparseSingleCommand(java.lang.String cmd)Parses a command that creates a single variable or changes its value.voidsetCommandParser(VariableManager.CommandInterpreter commandParser)java.lang.StringtoString()static voidupdate()Saves stored vasriables and updates the UI that renders the variables.
-
-
-
Field Detail
-
endOfLine
public static final java.lang.String endOfLine
- See Also:
- Constant Field Values
-
VARIABLES
public static final java.util.Map<java.lang.String,Variable> VARIABLES
-
-
Method Detail
-
getCommandParser
public VariableManager.CommandInterpreter getCommandParser()
-
setCommandParser
public void setCommandParser(VariableManager.CommandInterpreter commandParser)
-
getEndOfLine
public static java.lang.String getEndOfLine()
-
getVarStore
public java.util.Map<java.lang.String,Variable> getVarStore()
- Returns:
- the ArrayList object that stores the Variable data of objects of this class.
-
load
public static void load(java.util.Collection<Variable> variables)
- Parameters:
variables- ACollectionofVariableobjects.
-
load
public static void load(java.util.Map<java.lang.String,Variable> variables)
- Parameters:
variables- AMapofVariableobjects.
-
load
public static void load(java.util.Map<java.lang.String,Variable> variables, boolean clearFirst)
-
contains
public boolean contains(java.lang.String variableName)
- Parameters:
variableName- The name attribute of the variable we are searching the variable store for.- Returns:
- true if it finds a variable by that name in the store.
-
parseSingleCommand
public Variable parseSingleCommand(java.lang.String cmd)
Parses a command that creates a single variable or changes its value.- Parameters:
cmd- The command string to parse.
-
parseCommand
public void parseCommand(java.lang.String cmd)
Parses a command that creates or changes the value of variables.- Parameters:
cmd- The command string to parse.
-
update
public static void update()
Saves stored vasriables and updates the UI that renders the variables.
-
init
public static void init()
Initializes the variables store and loads them from persistent storage
-
getVariable
public static Variable getVariable(java.lang.String vName)
- Parameters:
vName- The name of the Variable object.- Returns:
- the Variable object that has the name supplied if it exists. If no such Variable object exists, then it returns null.
-
lookUp
public static Variable lookUp(java.lang.String vName)
Attempts to retrieve a Variable object from a VariableManager based on its name.- Parameters:
vName- The name of the Variable object.- Returns:
- the Variable object that has that name or null if the Variable is not found.
-
delete
public static void delete(java.lang.String varName)
deletes a Variable or constant whose name is known- Parameters:
varName- the name of the Variable object to be deleted
-
add
public static void add(Variable var)
Introduces a Variable- Parameters:
var- the name of the Variable object to be added to the Variable Registry
-
add
public static void add(Variable... vars)
Introduces an array or variable-args list of Variable- Parameters:
vars- the variable args list of the Variable objects to be added to the Variable Registry
-
clearVariables
public static void clearVariables()
Clears all Variables
-
clearConstants
public void clearConstants()
Clears all constants
-
clearVariablesAndConstants
public void clearVariablesAndConstants()
Clears All Variables and Constants
-
generateCommandStringFromVariableNamesArray
public static java.lang.String generateCommandStringFromVariableNamesArray(java.lang.String[] variableNames)
- Parameters:
variableNames- An array containing valid variable names- Returns:
- a command string that initializes the variable names to 0.0 e.g if the array is [a,v,b,m,n], then the output is: a=0.0;v=0.0;b=0.0;m=0.0;n=0.0
-
getVariables
public static final java.util.ArrayList<Variable> getVariables()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
main
public static void main(java.lang.String[] args)
-
-