Package math.matrix.expressParser
Class MmathScanner
java.lang.Object
math.matrix.expressParser.MmathScanner
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
The character used to identify that an expression like sin 1 means see sin and 1 as separate tokens.Contains a list of Variable objects used that are not declared.private int
Sets the first occurence of a Variable object in this Scanner object.private int
Sets the first occurence of a Variable object in this Scanner object.private boolean
Contains the scanned expressionprivate String
The math expression to be scanned. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
method getFirstNumberSubstring takes a String object and returns the first number string in the String.method getFirstOperatorInString takes a String object and returns the the first occurence of an operator in the String.int
Will retrieve the first occurence of a full Variable in a number String.int
int
getNumberStrings
(String val) method getNumberStrings takes a String object and returns an ArrayList of substrings of all numbers in the input Stringboolean
boolean
private void
Removes commas from the ArrayList object that contains the scanned function.scanner()
Utility method,more popularly used as a scanner into mathematical tokens of mathematical expressions.scanner
(VariableManager varMan) Utility method,more popularly used as a scanner into mathematical tokens of mathematical expressionsvoid
setDelimiter
(String delimiter) void
setErrorList
(ArrayList<String> errorList) void
setFirstOpIndex
(int firstOpIndex) void
setFirstVarIndex
(int firstVarIndex) void
setRunnable
(boolean runnable) void
setScanner
(ArrayList<String> scanner) void
setScannerInput
(String scannerInput) splitListOnVariables
(List<String> val) Convenience form of splitStringOnOperators that inserts the string to be split into a List object and effects the split right inside it.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.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.void
Identifies that the input is a valid one by checking that all tokens are either MNumber objects, Variable objects or MOperator objects.
-
Field Details
-
errorList
Contains a list of Variable objects used that are not declared. -
runnable
private boolean runnable -
scannerInput
The math expression to be scanned. -
delimiter
The character used to identify that an expression like sin 1 means see sin and 1 as separate tokens. -
firstVarIndex
private int firstVarIndexSets the first occurence of a Variable object in this Scanner object. -
firstOpIndex
private int firstOpIndexSets the first occurence of a Variable object in this Scanner object. -
scanner
Contains the scanned expression
-
-
Constructor Details
-
MmathScanner
- Parameters:
scannerInput
- the input of this Scanner object
-
-
Method Details
-
setScannerInput
- Parameters:
scannerInput
- sets the input of this Scanner object
-
getScannerInput
- Returns:
- the input into the scanner.
-
setDelimiter
- Parameters:
delimiter
- sets the delimiter to be used by this Scanner object
-
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
- Parameters:
scanner
- sets the ArrayList object that holds the scanned output.
-
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
- Parameters:
errorList
- sets the list of errors.
-
getErrorList
- Returns:
- the list of errors.
-
removeCommas
private void removeCommas()Removes commas from the ArrayList object that contains the scanned function. -
getFirstVariableInString
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
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
method 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:
StringIndexOutOfBoundsException
-
isNumber
- Parameters:
num
- The number string- Returns:
- true if it represents a valid number.
-
splitStringAtFirstNumber
- 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
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:
StringIndexOutOfBoundsException
-
getNumberStrings
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:
StringIndexOutOfBoundsException
-
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:
NullPointerException
- if no operator is found in the string
-
getFirstIndexOfOperator
public int getFirstIndexOfOperator()- Returns:
- the index of first occurence of the operator.
-
getOperatorStrings
- Returns:
- an ArrayList of all MOperator object names in the
-
splitStringOnOperators
- Returns:
- this string split on the operators.
-
splitListOnVariables
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
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
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 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.
-