Package parser

Class GenericBracket

java.lang.Object
parser.GenericBracket

public class GenericBracket extends Object
  • Field Details

    • bracketType

      private int bracketType
    • CURLY_BRACE

      public static final int CURLY_BRACE
      For {} brackets
      See Also:
    • SQUARE_BRACE

      public static final int SQUARE_BRACE
      For [] brackets
      See Also:
    • CIRCULAR_BRACE

      public static final int CIRCULAR_BRACE
      For () brackets
      See Also:
    • ANGULAR_BRACE

      public static final int ANGULAR_BRACE
      For < and > brackets
      See Also:
    • open

      private boolean open
      If the particular bracket is an open bracket. If false, then it is a close bracket.
    • index

      private int index
      The index of the bracket in the ArrayList containing the scanned function
    • complement

      private GenericBracket complement
      objects of this class keep a record of their counterpart or complementing bracket.
    • evaluated

      private boolean evaluated
      Return true if the contents of the bracket have been evaluated
  • Constructor Details

    • GenericBracket

      public GenericBracket(int bracketType, boolean open)
      Constructor of this class for creating its objects and initializing their names with either a ( or a ) and initial
      Parameters:
      bracketType - One of:
      1. CURLY_BRACE
      2. SQUARE_BRACE
      3. CIRCULAR_BRACE
      4. ANGULAR_BRACE
      open - If true, this Bracket is an opening brace.
    • GenericBracket

      public GenericBracket(String name)
      Parameters:
      name - The bracket string. One of {,},(,),[,],<,>
  • Method Details

    • setEvaluated

      public void setEvaluated(boolean evaluated)
      Parameters:
      evaluated - set whether or not this bracket's contents have been evaluated
    • isEvaluated

      public boolean isEvaluated()
      Returns:
      true if this bracket's contents have been evaluated
    • getIndex

      public int getIndex()
      Returns:
      the index of this Bracket object in a scanned function
    • setIndex

      public void setIndex(int index)
      Parameters:
      index - the ne w index to assign to this Bracket object in a scanned Function
    • getBracketString

      public String getBracketString()
      Returns:
      the string representation of this Bracket half.
    • getComplementBracketString

      public String getComplementBracketString()
      Returns:
      the string representation of this Bracket half's complement.
    • getComplement

      public GenericBracket getComplement()
      Returns:
      the Bracket object which is the complement of this Bracket object
    • setComplement

      public void setComplement(GenericBracket complement)
      Parameters:
      complement - sets the Bracket object which is to be the complement to this one in the scanned Function
    • isComplement

      public boolean isComplement(GenericBracket brac)
      checks if the Bracket object argument below is the sane as the complement to this Bracket object.
      Parameters:
      brac - The GenericBracket object whose identity is to be checked whether or not it complements this GenericBracket object.
      Returns:
      true if the parameter is the complement to this one.
    • setBracketType

      public void setBracketType(int bracketType)
    • getBracketType

      public int getBracketType()
    • isOpen

      public boolean isOpen()
    • setOpen

      public void setOpen(boolean open)
    • encloses

      public boolean encloses(Bracket brac)
      Parameters:
      brac - the bracket to be checked if or not it is enclosed by this bracket and its complement.
      Returns:
      true if the bracket is enclosed by this bracket and its counterpart.
    • getNumberOfInternalBrackets

      public int getNumberOfInternalBrackets(ArrayList<Bracket> brac)
      Parameters:
      brac - an ArrayList object containing all brackets found in a function
      Returns:
      the number of bracket pairs contained between this Bracket object and its complement
    • isSBP

      public boolean isSBP(ArrayList<String> scan)
      Parameters:
      scan - The ArrayList object containing the scanned function.
      Returns:
      true if this Bracket object forms with its complement, a single bracket pair that is a bracket pair containing no other bracket pairs.
    • getComplementIndex

      public static int getComplementIndex(GenericBracket brac, int start, ArrayList<String> scan)
      Parameters:
      brac - The GenericBracket object whose complement we seek is a closing bracket i.e )
      start - the index of the given bracket.
      scan - the ArrayList containing the scanned function.
      Returns:
      the index of the enclosing or complement bracket of this bracket object
    • getComplementIndex

      public static int getComplementIndex(GenericBracket brac, int start, List<String> scan)
      Parameters:
      brac - The GenericBracket object whose complement we seek.
      start - the index of the given bracket.
      scan - the ArrayList containing the scanned function.
      Returns:
      the index of the enclosing or complement bracket of this bracket object
    • getComplementIndex

      public static int getComplementIndex(GenericBracket bracket, boolean isOpenBracket, int start, String expr)
      Parameters:
      bracket - The GenericBracket object whose complement we seek.
      isOpenBracket - boolean variable that should be true if this bracket object whose complement we seek is an opening bracket i.e (, and should be set to false if this bracket object whose complement we seek is a closing bracket i.e )
      start - the index of the given bracket.
      expr - the function string containing the brackets.
      Returns:
      the index of the enclosing or complement bracket of this bracket object
    • checkBracketStructure

      public static boolean checkBracketStructure(List<String> list, int start, int end)
      Parameters:
      list - The list containing the scanned math expression.
      start - The point in the list where this algorithm should start checking the bracket syntax.(inclusive)
      end - The point in the list where this algorithm should stop checking the bracket syntax.(inclusive)
      Returns:
      true if the bracket syntax of the scanned expression in the given range is valid or the expression in the given range is devoid of brackets.
    • hasBracketsInRange

      public static boolean hasBracketsInRange(List<String> list, int start, int end)
      Parameters:
      list - The list containing the scanned math expression.
      start - The point in the list where this algorithm should start checking for brackets.(inclusive)
      end - The point in the list where this algorithm should stop checking for brackets.(inclusive)
      Returns:
      true if the scanned expression contains brackets in the given range.
    • isOpenBracket

      public static boolean isOpenBracket(String bracket)
      Parameters:
      bracket - The String object.
      Returns:
      true if the String object represents an open bracket
    • isCloseBracket

      public static boolean isCloseBracket(String bracket)
      Parameters:
      bracket - The String object.
      Returns:
      true if the String object represents a close bracket
    • getDomainContents

      public String getDomainContents(ArrayList<String> scan)
      Parameters:
      scan - The ArrayList object containing the scanned function.
      Returns:
      The contents of this bracket and its complement as a string, the bracket and its complement are also returned. e.g in 5+(2+3-sin2).. This method will return (2+3-sin2).
    • getBracketDomainContents

      public ArrayList<String> getBracketDomainContents(ArrayList<String> scan)
      returns a List containing the contents of a bracket pair,including the bracket pair itself.
      Parameters:
      scan - the ArrayList containing the scanner output for a Function
      Returns:
      the bracket pair and its contents.
    • validateBracketStructure

      private static boolean validateBracketStructure(List<String> scanner)
      method mapBrackets goes over an input equation and maps all positions that have corresponding brackets
      Parameters:
      scanner - The ArrayList object that contains the scanned math function.
      Returns:
      true if the structure of the bracket is valid.
    • prevIndexOf

      public static int prevIndexOf(List list, int start, Object sought)
      Parameters:
      list - the collection of objects that the search is to be carried out on
      start - the starting index of the search from where we search backwards for the object that index itself been not included
      sought - the object that we seek
      Returns:
      the index of the first occurrence of the object behind index start or -1 if the object is not found.
    • isBracket

      private static boolean isBracket(String get)
    • main

      public static void main(String[] args)