Class MatrixExpressionScanner

java.lang.Object
math.matrix.expressParser.MatrixExpressionScanner

public class MatrixExpressionScanner extends Object
  • Field Details

    • errorList

      private ArrayList<String> errorList
      Contains a list of Variable objects used that are not declared.
    • runnable

      private boolean runnable
    • scannerInput

      private String scannerInput
      The math expression to be scanned.
    • delimiter

      private String delimiter
      The character used to identify that an expression like sin 1 means see sin and 1 as separate tokens.
    • firstVarIndex

      private int firstVarIndex
      Sets the first occurence of a Variable object in this Scanner object.
    • firstOpIndex

      private int firstOpIndex
      Sets the first occurence of a Variable object in this Scanner object.
    • scanner

      private ArrayList<String> scanner
      Contains the scanned expression
  • Constructor Details

    • MatrixExpressionScanner

      public MatrixExpressionScanner(String scannerInput)
      Parameters:
      scannerInput - the input of this Scanner object
  • Method Details

    • setScannerInput

      public void setScannerInput(String scannerInput)
      Parameters:
      scannerInput - sets the input of this Scanner object
    • getScannerInput

      public String getScannerInput()
      Returns:
      the input into the scanner.
    • setDelimiter

      public void setDelimiter(String delimiter)
      Parameters:
      delimiter - sets the delimiter to be used by this Scanner object
    • getDelimiter

      public 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(ArrayList<String> scanner)
      Parameters:
      scanner - sets the ArrayList object that holds the scanned output.
    • getScanner

      public ArrayList<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(ArrayList<String> errorList)
      Parameters:
      errorList - sets the list of errors.
    • getErrorList

      public ArrayList<String> getErrorList()
      Returns:
      the list of errors.
    • removeCommas

      private void removeCommas()
      Removes commas from the ArrayList object that contains the scanned function.
    • getFirstVariableInString

      public String getFirstVariableInString(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 ArrayList<String> splitStringOnVariables(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 String getFirstNumberSubstring(String val) throws StringIndexOutOfBoundsException
      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

      public boolean isNumber(String num)
      Parameters:
      num - The number string
      Returns:
      true if it represents a valid number.
    • splitStringAtFirstNumber

      public ArrayList<String> splitStringAtFirstNumber(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 ArrayList<String> splitStringOnNumbers(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:
      StringIndexOutOfBoundsException
    • getNumberStrings

      public ArrayList<String> getNumberStrings(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:
      StringIndexOutOfBoundsException
    • getFirstOperatorInString

      public 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:
      NullPointerException - if no operator is found in the string
    • getFirstIndexOfOperator

      public int getFirstIndexOfOperator()
      Returns:
      the index of first occurence of the operator.
    • getOperatorStrings

      public ArrayList<String> getOperatorStrings()
      Returns:
      an ArrayList of all MOperator object names in the
    • splitStringOnOperators

      public ArrayList<String> splitStringOnOperators()
      Returns:
      this string split on the operators.
    • splitListOnVariables

      public List<String> 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. 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 ArrayList<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 ArrayList<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 declared
      matrixvarman - 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.