Package math.matrix.expressParser
Class MatrixExpressionScanner
java.lang.Object
math.matrix.expressParser.MatrixExpressionScanner
public class MatrixExpressionScanner
extends java.lang.Object
- Author:
- GBEMIRO
-
Constructor Summary
Constructors Constructor Description MatrixExpressionScanner(java.lang.String scannerInput) -
Method Summary
Modifier and Type Method Description java.lang.StringgetDelimiter()java.util.ArrayList<java.lang.String>getErrorList()intgetFirstIndexOfOperator()java.lang.StringgetFirstNumberSubstring(java.lang.String val)method getFirstNumberSubstring takes a String object and returns the first number string in the String.java.lang.StringgetFirstOperatorInString()method getFirstOperatorInString takes a String object and returns the the first occurence of an operator in the String.intgetFirstOpIndex()java.lang.StringgetFirstVariableInString(java.lang.String val)Will retrieve the first occurence of a full Variable in a number String.intgetFirstVarIndex()intgetIndexOfFirstVariable()java.util.ArrayList<java.lang.String>getNumberStrings(java.lang.String val)method getNumberStrings takes a String object and returns an ArrayList of substrings of all numbers in the input Stringjava.util.ArrayList<java.lang.String>getOperatorStrings()java.util.ArrayList<java.lang.String>getScanner()java.lang.StringgetScannerInput()booleanisNumber(java.lang.String num)booleanisRunnable()java.util.ArrayList<java.lang.String>scanner()Utility method,more popularly used as a scanner into mathematical tokens of mathematical expressions.java.util.ArrayList<java.lang.String>scanner(MatrixVariableManager matrixvarman, VariableManager varMan)Utility method,more popularly used as a scanner into mathematical tokens of mathematical expressionsvoidsetDelimiter(java.lang.String delimiter)voidsetErrorList(java.util.ArrayList<java.lang.String> errorList)voidsetFirstOpIndex(int firstOpIndex)voidsetFirstVarIndex(int firstVarIndex)voidsetRunnable(boolean runnable)voidsetScanner(java.util.ArrayList<java.lang.String> scanner)voidsetScannerInput(java.lang.String scannerInput)java.util.List<java.lang.String>splitListOnVariables(java.util.List<java.lang.String> val)Convenience form of splitStringOnOperators that inserts the string to be split into a List object and effects the split right inside it.java.util.ArrayList<java.lang.String>splitStringAtFirstNumber(java.lang.String val)java.util.ArrayList<java.lang.String>splitStringOnNumbers(java.lang.String val)method splitStringOnNumbers takes a String object and returns an ArrayList of substrings in which the original string has been split into different parts based on the amount of number substrings it has.java.util.ArrayList<java.lang.String>splitStringOnOperators()java.util.ArrayList<java.lang.String>splitStringOnVariables(java.lang.String val)method splitStringOnVariables takes a String object and returns an ArrayList of substrings in which the original string has been split into different parts based on the amount of Variable substrings it has.voidvalidateTokens()Identifies that the input is a valid one by checking that all tokens are either MNumber objects, Variable objects or MOperator objects.
-
Constructor Details
-
MatrixExpressionScanner
public MatrixExpressionScanner(java.lang.String scannerInput)- Parameters:
scannerInput- the input of this Scanner object
-
-
Method Details
-
setScannerInput
public void setScannerInput(java.lang.String scannerInput)- Parameters:
scannerInput- sets the input of this Scanner object
-
getScannerInput
public java.lang.String getScannerInput()- Returns:
- the input into the scanner.
-
setDelimiter
public void setDelimiter(java.lang.String delimiter)- Parameters:
delimiter- sets the delimiter to be used by this Scanner object
-
getDelimiter
public java.lang.String getDelimiter()- Returns:
- the delimiter to be used by this Scanner object
-
setFirstVarIndex
public void setFirstVarIndex(int firstVarIndex)- Parameters:
firstVarIndex- the index of occurence of the very first instance of a given token type.
-
getFirstVarIndex
public int getFirstVarIndex()- Returns:
- the index of occurence of the very first instance of a given token type.
-
setScanner
public void setScanner(java.util.ArrayList<java.lang.String> scanner)- Parameters:
scanner- sets the ArrayList object that holds the scanned output.
-
getScanner
public java.util.ArrayList<java.lang.String> getScanner()- Returns:
- the ArrayList object that holds the scanned output.
-
setFirstOpIndex
public void setFirstOpIndex(int firstOpIndex)- Parameters:
firstOpIndex- sets the index of the first MOperator object in the input
-
getFirstOpIndex
public int getFirstOpIndex()- Returns:
- the index of the first MOperator object in the input
-
setRunnable
public void setRunnable(boolean runnable)- Parameters:
runnable- sets whether object of this class are runnable on a calculating device or not.
-
isRunnable
public boolean isRunnable()- Returns:
- true if the object of this class is runnable on a calculating device.
-
setErrorList
public void setErrorList(java.util.ArrayList<java.lang.String> errorList)- Parameters:
errorList- sets the list of errors.
-
getErrorList
public java.util.ArrayList<java.lang.String> getErrorList()- Returns:
- the list of errors.
-
getFirstVariableInString
public java.lang.String getFirstVariableInString(java.lang.String val)Will retrieve the first occurence of a full Variable in a number String. e.g in 3ABC it will return ABC But in A,B,C it will return A Also it will store information about the index of discovery of the first variable in field firstIndex, and -1 in it if no variable is found- Parameters:
val- the String from which the first Variable object name is to be retrieved.- Returns:
- the first Variable object in the input string.
-
getIndexOfFirstVariable
public int getIndexOfFirstVariable()- Returns:
- the index where the first Variable was found and -1 if none is found
-
splitStringOnVariables
public java.util.ArrayList<java.lang.String> splitStringOnVariables(java.lang.String val)method splitStringOnVariables takes a String object and returns an ArrayList of substrings in which the original string has been split into different parts based on the amount of Variable substrings it has. e.g if val="2ABC+D+5.21q-$34" it will return [2,ABC,+,D,+,5.21,q,-,$34]- Parameters:
val-- Returns:
- An ArrayList of substrings consisting of Variable substrings and the other substrings of the input.
-
getFirstNumberSubstring
public java.lang.String getFirstNumberSubstring(java.lang.String val) throws java.lang.StringIndexOutOfBoundsExceptionmethod getFirstNumberSubstring takes a String object and returns the first number string in the String.- Parameters:
val- the string to analyze- Returns:
- the index of the first occurence of a number character in the sequence.
- Throws:
java.lang.StringIndexOutOfBoundsException
-
isNumber
public boolean isNumber(java.lang.String num)- Parameters:
num- The number string- Returns:
- true if it represents a valid number.
-
splitStringAtFirstNumber
public java.util.ArrayList<java.lang.String> splitStringAtFirstNumber(java.lang.String val)- Parameters:
val- the String to analyze- Returns:
- an ArrayList consisting of 2 or 3 parts. a. If a number substring starts the string,then it returns an ArrayList object containing the number substring and the part of the string after the number. e.g. for 231.62A+98B+sin45C, the method returns [231.62,A+98B+sin45C] b. If a number substring does not start the string but occurs later on in it, the method returns an ArrayList object containing (i.)the substring from index 0 up to, but not including the index where the first number occurs. (ii.)The number substring (iii.)The remaining part of the string after the number. The method will not be used directly by developers but will be used as a tool in math expression scanning.
-
splitStringOnNumbers
public java.util.ArrayList<java.lang.String> splitStringOnNumbers(java.lang.String val)method splitStringOnNumbers takes a String object and returns an ArrayList of substrings in which the original string has been split into different parts based on the amount of number substrings it has.- Parameters:
val- the string to analyze e.g if val="123.234+43.6",the output will be [123.234,+,43.6]- Returns:
- An ArrayList of substrings consisting of number substrings and the other substrings of the input.
- Throws:
java.lang.StringIndexOutOfBoundsException
-
getNumberStrings
public java.util.ArrayList<java.lang.String> getNumberStrings(java.lang.String val)method getNumberStrings takes a String object and returns an ArrayList of substrings of all numbers in the input String- Parameters:
val- the string to analyze e.g if val="123.234+43.6",the output will be [123.234,43.6]- Returns:
- An ArrayList of substrings consisting of number substrings and the other substrings of the input.
- Throws:
java.lang.StringIndexOutOfBoundsException
-
getFirstOperatorInString
public java.lang.String getFirstOperatorInString()method getFirstOperatorInString takes a String object and returns the the first occurence of an operator in the String.- Returns:
- the first occurence of an operator in the sequence.
- Throws:
java.lang.NullPointerException- if no operator is found in the string
-
getFirstIndexOfOperator
public int getFirstIndexOfOperator()- Returns:
- the index of first occurence of the operator.
-
getOperatorStrings
public java.util.ArrayList<java.lang.String> getOperatorStrings()- Returns:
- an ArrayList of all MOperator object names in the
-
splitStringOnOperators
public java.util.ArrayList<java.lang.String> splitStringOnOperators()- Returns:
- this string split on the operators.
-
splitListOnVariables
public java.util.List<java.lang.String> splitListOnVariables(java.util.List<java.lang.String> val)Convenience form of splitStringOnOperators that inserts the string to be split into a List object and effects the split right inside it. This is useful to the scanner method as it takes advantage of ArrayList method subList to get Strings in locations inside it and split them into multiple substrings of numbers and operators using this method. CAUTION!!!!! This method only allows the List to take contain one element at the beginning and that is the String to be split into numbers and operators.- Parameters:
val- the List object containing a single string value e.g 4+tan(12)- Returns:
- the the List object with the initial string split into component number and operator parts.
-
validateTokens
public void validateTokens()Identifies that the input is a valid one by checking that all tokens are either MNumber objects, Variable objects or MOperator objects. Then it registers any Variable object found and initializes it to zero. -
scanner
public java.util.ArrayList<java.lang.String> scanner()Utility method,more popularly used as a scanner into mathematical tokens of mathematical expressions. This method does not check expression variables against declared variables and is only useful in breaking down the input into scanned tokens of numbers,variables and operators. The overloaded one takes a VariableManager object that models the store of Variable objects in a computing application and checks if all variable names entered by the user have been declared.- Returns:
- an ArrayList containing a properly scanned version of the string such that all recognized number substrings,variable substrings and operator substrings have been resolved. To use this method as a scanner for math expressions all the programmer has to do is to take care of the signs where need be(e.g in -2.873*5R+sinh34.2, the scanned view will be [-,2.873,*,5,R,+,sinh,34.2]) To make sense of this, the programmer has to write minor code to concatenate the - and the 2.873 and so on.
-
scanner
public java.util.ArrayList<java.lang.String> scanner(MatrixVariableManager matrixvarman, VariableManager varMan)Utility method,more popularly used as a scanner into mathematical tokens of mathematical expressions- Parameters:
varMan- The store of all user variables already declared. The scanner will not allow the user to use any variables he/she/it has not declaredmatrixvarman- The store of all user matrix variables. The scanner references it here to ensure that nobidy uses a variable that does not been declared in the store.- Returns:
- an ArrayList containing a properly scanned version of the string such that all recognized number substrings,variable substrings and operator substrings have been resolved. To use this method as a scanner for math expressions all the programmer has to do is to take care of the signs where need be(e.g in -2.873*5R+sinh34.2, the scanned view will be [-,2.873,*,5,R,+,sinh,34.2]) To make sense of this, the programmer has to write minor code to concatenate the - and the 2.873 and so on.
-