Package parser
Class Bracket
java.lang.Object
parser.Operator
parser.Bracket
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Bracket
objects of this class keep a record of their counterpart or complementing bracket.private boolean
Return true if the contents of the bracket have been evaluatedprivate int
The index of the bracket in the ArrayList containing the scanned functionprivate String
the name of the bracket i.e "(" or ")"Fields inherited from class parser.Operator
AND, ASSIGN, AT, CLOSE_CIRC_BRAC, CLOSE_SQUARE_BRAC, COLON, COMBINATION, COMMA, CONST, CUBE, CUBE_ROOT, DIVIDE, EN_DASH, EQUALS, EXIT, FACTORIAL, GREATER_OR_EQUALS, GREATER_THAN, INVERSE, LESS_OR_EQUALS, LESS_THAN, MINUS, MULTIPLY, OPEN_CIRC_BRAC, OPEN_SQUARE_BRAC, operators, OR, PERMUTATION, PLUS, POWER, REMAINDER, ROOT, SEMI_COLON, SPACE, SQUARE, STORE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
checkBracketStructure
(List<String> list, int start, int end) non-static version of the above method.static Bracket
createTwinBracket
(Bracket brac) Used to create similar objects that are not equal The object created by this class is similar to the parameter because it contains the same data as the parameter.domainTokenAt
(List<String> scanner, int index) boolean
returns a List containing the contents of a bracket pair,including the bracket pair itself.static int
getComplementIndex
(boolean isOpenBracket, int start, String expr) static int
getComplementIndex
(boolean isOpenBracket, int start, ArrayList<String> scan) static int
getComplementIndex
(boolean isOpenBracket, int start, List<String> scan) getDomainContents
(ArrayList<String> scan) int
getIndex()
getName()
int
static boolean
hasBracketsInRange
(List<String> list, int start, int end) static boolean
isCloseBracket
(String bracket) boolean
isComplement
(Bracket brac) checks if the Bracket object argument below is the sane as the complement to this Bracket object.boolean
static boolean
isOpenBracket
(String bracket) boolean
void
multiplyContentsByMinusOne
(List<String> scanner) void
setComplement
(Bracket complement) void
setEvaluated
(boolean evaluated) void
setIndex
(int index) void
boolean
private static boolean
validateBracketStructure
(List<String> scanner) method mapBrackets goes over an input equation and maps all positions that have corresponding bracketsMethods inherited from class parser.Operator
getPrecedence, isAssignmentOperator, isAtOperator, isBinaryOperator, isBracket, isClosingBrace, isClosingBracket, isColon, isComma, isConstantStoreCommand, isCube, isCubeRoot, isEqualsOperator, isExitCommand, isFactorial, isInverse, isLogicOperator, isMulOrDiv, isMulOrDivOrRemOrPermOrCombOrPow, isOpeningBrace, isOpeningBracket, isOperatorString, isPermOrComb, isPlusOrMinus, isPower, isRemainder, isSemiColon, isSquare, isSquareRoot, isStoreCommand, isUnaryPostOperator, isUnaryPreOperator, validateAll
-
Field Details
-
name
the name of the bracket i.e "(" or ")" -
index
private int indexThe index of the bracket in the ArrayList containing the scanned function -
complement
objects of this class keep a record of their counterpart or complementing bracket. -
evaluated
private boolean evaluatedReturn true if the contents of the bracket have been evaluated
-
-
Constructor Details
-
Bracket
Constructor of this class for creating its objects and initializing their names with either a ( or a ) and initial- Parameters:
op
-
-
-
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
-
createTwinBracket
Used to create similar objects that are not equal The object created by this class is similar to the parameter because it contains the same data as the parameter. However,its address in memory is different because it refers to an entirely different object of the same class,but having similar attributes. How can this method be of any use? Imagine an Array of Brackets say array bracs filled with Bracket objects. If we create another Bracket array, say array moreBracs and copy the objects in bracs into moreBracs.Now, both bracs and moreBracs will hold references to these Bracket objects in memory.Java will not create new, similar objects at another address in memory and store in the new array. The command was most likely moreBracs=bracs; or in a loop, it would look like: for(int i=0;i<bracs.length;i++){ moreBracs=bracs[i]; } These statements will only ensure that both arrays will hold a reference to the same objects in memory,i.e RAM. Hence whenever an unsuspecting coder modifies the contents of bracs, thinking He/She has a backup in moreBracs,Java is effecting the modification on the objects referred to by moreBracs, too.This can cause a serious logical error in applications. To stop this, we use this method in this way: for(int i=0;i<bracs.length;i++){ moreBracs[i]=createTwinBracket(bracs[i]); } Note that this can be applied to all storage objects too e.g Collection objects and so on.- Parameters:
brac
- The object whose twin we wish to create.- Returns:
- a Bracket object that manifests exactly the same attributes as brac but is a distinct object from brac.
-
createTwinBracket
non-static version of the above method. This one creates a twin for this Bracket object. The one above creates a twin for the specified bracket object.- Returns:
- a Bracket object that manifests exactly the same attributes as brac but is a distinct object from brac.
-
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
-
getName
-
setName
-
getComplement
- Returns:
- the Bracket object which is the complement of this Bracket object
-
setComplement
- Parameters:
complement
- sets the Bracket object which is to be the complement to this one in the scanned Function
-
isComplement
checks if the Bracket object argument below is the sane as the complement to this Bracket object.- Parameters:
brac
- The Bracket object whose identity is to be checked whether or not it complements this Bracket object.- Returns:
- true if the parameter is the complement to this one.
-
encloses
- 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
- 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
- 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
- Parameters:
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.scan
- the ArrayList containing the scanned function.- Returns:
- the index of the enclosing or complement bracket of this bracket object
-
getComplementIndex
- Parameters:
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.scan
- the ArrayList containing the scanned function.- Returns:
- the index of the enclosing or complement bracket of this bracket object
-
getComplementIndex
- Parameters:
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
- 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
- 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 no brackets in the given range.
-
isOpenBracket
- Parameters:
bracket
- The String object.- Returns:
- true if the String object represents an open bracket
-
isCloseBracket
- Parameters:
bracket
- The String object.- Returns:
- true if the String object represents a close bracket
-
simpleBracketPairHasVariables
- Parameters:
scan
- The ArrayList containing the scanned function inside which this Bracket exists.- Returns:
- true if between this Bracket and its complement, a Variable object is found.
-
getDomainContents
- 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
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
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.
-
multiplyContentsByMinusOne
- Parameters:
scanner
- The ArrayList containing the scanner output for a Function Multiplies the contents of this List by -1.
-
domainTokenAt
- Parameters:
scanner
- The ArrayList containing the scanner output for a Functionindex
- The index at which the token is to be retrieved. The first and elements are compulsorily always an open bracket and a close bracket respectively.
-