Package math.matrix
Class MatrixVariableManager
java.lang.Object
math.matrix.MatrixVariableManager
public class MatrixVariableManager
extends java.lang.Object
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.
- Author:
- GBEMIRO
-
Constructor Summary
Constructors Constructor Description MatrixVariableManager()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. -
Method Summary
Modifier and Type Method Description voidclearVariables()Clears all VariablesvoidclearVariablesAndConstants()Clears All Variables and Constantsbooleancontains(java.lang.String name)voiddeleteVar(int index)deletes a Variable or constant whose location in varStore is knownvoiddeleteVar(java.lang.String varName)deletes a Variable or constant whose name is knownintgetInterval()MatrixVariablegetVarFromIndex(int index)intgetVarIndexFromVarName(java.lang.String name)java.util.ArrayList<MatrixVariable>getVarStore()booleanisIntervalChanged()static booleanisValidCommandString()static voidmain(java.lang.String[] args)voidremoveDuplicates()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.voidsetInterval(int interval)voidsetIntervalChanged(boolean intervalChanged)static voidsetValidCommandString(boolean validCommandString)voidsetVarStore(java.util.ArrayList<MatrixVariable> varStore)set the storage to the new one specified by the parameter of this methodvoidstoreVariable(java.lang.String cmd)
-
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
public int getVarIndexFromVarName(java.lang.String name)- 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
public boolean contains(java.lang.String name)- Parameters:
name- the name of the Variable.- Returns:
- true if the manager contains the Variable that goes by this name.
-
storeVariable
public void storeVariable(java.lang.String cmd)- 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
public void deleteVar(java.lang.String varName)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
public static void main(java.lang.String[] args)
-