Class MatrixVariableManager
java.lang.Object
math.matrix.MatrixVariableManager
Objects of this class have data storing capability and store this data in the form of Constant( Once created its value cannot be changed,
neither can they be duplicated in an object of this class.) and Variable objects.
The class seres as storage and manages various desirable properties of the class.
e.g Display of data on tables, creation, deletion, guarding against de-naturing( of Constant objects by making their values
immutable.)
The class is created for working with the parser and the releveant calculating ware that will use it.
The parser will check with objects of this class (maintained by the calculator as a field)
for the value of its variables and place the value in its input before proceeding with parsing operations.
This implementation of the class uses a Timer object to remove earlier duplicates of Variable objects that it stores
at regular intervals.
The definitiion of a duplicate Variable here is that which any calculator user will automatically attach to it.i.e
A symbol represented with a particular character sequence to which any value can be assigned.
The current value stored by the Variable is the last value assigned to it.
In order to avoid confusion and prevent an over-growth of the size of the Variable store,
Later duplicates must be removed periodically or just before the user performs important operations
like viewing the Variable database, storing the Variable objects on a persistent storage device,
closing the program e.t.c.
A timer object can do this (remove later duplicates)automatically or the programmer can watch for actions that might require
the user or the program to perform the above specified operations and manually remove the duplicates.
If you do not wish this action to be automatic please either you remove the object entirely or set the
delay to a very large value say 2 billion, or Integer.MAX_VALUE or create objects of this class with
the no-argument constructor of the class, which does not start the timer object.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private boolean
private static boolean
private final ArrayList
<MatrixVariable> -
Constructor Summary
ConstructorsConstructorDescriptionMatrixVariableManager
(int interval) Creates a new VariableManager object with a given time interval in which it searches through its variable store and removes all duplicate elements. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears all Variablesvoid
Clears All Variables and Constantsboolean
private MatrixVariable
void
deleteVar
(int index) deletes a Variable or constant whose location in varStore is knownvoid
deletes a Variable or constant whose name is knownint
getVarFromIndex
(int index) int
getVarIndexFromVarName
(String name) boolean
static boolean
static void
void
scans the storage for Variables with similar names and removes all earlier occurences (found farther down the storage) from the storage.Note that later or more recent versions of Variables are found towards the beginning of the storage.void
setInterval
(int interval) void
setIntervalChanged
(boolean intervalChanged) static void
setValidCommandString
(boolean validCommandString) void
setVarStore
(ArrayList<MatrixVariable> varStore) set the storage to the new one specified by the parameter of this methodvoid
storeVariable
(String cmd)
-
Field Details
-
varStore
-
interval
private int interval -
intervalChanged
private boolean intervalChanged -
validCommandString
private static boolean validCommandString
-
-
Constructor Details
-
MatrixVariableManager
public MatrixVariableManager() -
MatrixVariableManager
public MatrixVariableManager(int interval) Creates a new VariableManager object with a given time interval in which it searches through its variable store and removes all duplicate elements.- Parameters:
interval
- the interval between which the object automatically refreshes its Variable store
-
-
Method Details
-
getInterval
public int getInterval() -
setInterval
public void setInterval(int interval) -
isIntervalChanged
public boolean isIntervalChanged() -
setIntervalChanged
public void setIntervalChanged(boolean intervalChanged) -
isValidCommandString
public static boolean isValidCommandString() -
setValidCommandString
public static void setValidCommandString(boolean validCommandString) -
getVarFromIndex
- Parameters:
index
- the Variable object located at the given index.- Returns:
- the Variable object located at the index.
-
getVarIndexFromVarName
- Parameters:
name
- the name of the Variable object whose index in the manager is desired.- Returns:
- the index of the Variable if found and -1 if not.
-
contains
- Parameters:
name
- the name of the Variable.- Returns:
- true if the manager contains the Variable that goes by this name.
-
createMatrixVariable
- Parameters:
cmd
- The command used to create the variable...must have the format....variable name = matrix value. e.g..#A = [123,43,4,54,5,55,5:87,43,4,5,6,7,89:12,32,1,4,5,3,56:] The import of this is that constants cannot be create in this manner.- Returns:
- the created Variable
- Throws:
NullPointerException
- if the command syntax is wrong.
-
storeVariable
- Parameters:
cmd
- The command used to create and store the variable
-
removeDuplicates
public void removeDuplicates()scans the storage for Variables with similar names and removes all earlier occurences (found farther down the storage) from the storage.Note that later or more recent versions of Variables are found towards the beginning of the storage. -
getVarStore
- Returns:
- the storage object of this class
-
setVarStore
set the storage to the new one specified by the parameter of this method- Parameters:
varStore
- a new storage to be used as the storage for objects of this class
-
deleteVar
deletes a Variable or constant whose name is known- Parameters:
varName
- the name of the Variable object to be deleted
-
deleteVar
public void deleteVar(int index) deletes a Variable or constant whose location in varStore is known- Parameters:
index
- the index of the Variable object to be deleted
-
clearVariables
public void clearVariables()Clears all Variables -
clearVariablesAndConstants
public void clearVariablesAndConstants()Clears All Variables and Constants -
main
-