Class GenericBracket
java.lang.Object
parser.GenericBracket
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
For < and > bracketsprivate int
static final int
For () bracketsprivate GenericBracket
objects of this class keep a record of their counterpart or complementing bracket.static final int
For {} bracketsprivate 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 boolean
If the particular bracket is an open bracket.static final int
For [] brackets -
Constructor Summary
ConstructorsConstructorDescriptionGenericBracket
(int bracketType, boolean open) Constructor of this class for creating its objects and initializing their names with either a ( or a ) and initialGenericBracket
(String name) -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
checkBracketStructure
(List<String> list, int start, int end) boolean
returns a List containing the contents of a bracket pair,including the bracket pair itself.int
static int
getComplementIndex
(GenericBracket bracket, boolean isOpenBracket, int start, String expr) static int
getComplementIndex
(GenericBracket brac, int start, ArrayList<String> scan) static int
getComplementIndex
(GenericBracket brac, int start, List<String> scan) getDomainContents
(ArrayList<String> scan) int
getIndex()
int
static boolean
hasBracketsInRange
(List<String> list, int start, int end) private static boolean
static boolean
isCloseBracket
(String bracket) boolean
isComplement
(GenericBracket brac) checks if the Bracket object argument below is the sane as the complement to this Bracket object.boolean
boolean
isOpen()
static boolean
isOpenBracket
(String bracket) boolean
static void
static int
prevIndexOf
(List list, int start, Object sought) void
setBracketType
(int bracketType) void
setComplement
(GenericBracket complement) void
setEvaluated
(boolean evaluated) void
setIndex
(int index) void
setOpen
(boolean open) private static boolean
validateBracketStructure
(List<String> scanner) method mapBrackets goes over an input equation and maps all positions that have corresponding brackets
-
Field Details
-
bracketType
private int bracketType -
CURLY_BRACE
public static final int CURLY_BRACEFor {} brackets- See Also:
-
SQUARE_BRACE
public static final int SQUARE_BRACEFor [] brackets- See Also:
-
CIRCULAR_BRACE
public static final int CIRCULAR_BRACEFor () brackets- See Also:
-
ANGULAR_BRACE
public static final int ANGULAR_BRACEFor < and > brackets- See Also:
-
open
private boolean openIf the particular bracket is an open bracket. If false, then it is a close bracket. -
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
-
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:open
- If true, this Bracket is an opening brace.
-
GenericBracket
- 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
- Returns:
- the string representation of this Bracket half.
-
getComplementBracketString
- Returns:
- the string representation of this Bracket half's complement.
-
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 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
- 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
-
isSBP
-
getComplementIndex
- Parameters:
brac
- TheGenericBracket
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:
brac
- TheGenericBracket
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
- TheGenericBracket
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
- 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 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
-
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
-
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.
-
prevIndexOf
- Parameters:
list
- the collection of objects that the search is to be carried out onstart
- the starting index of the search from where we search backwards for the object that index itself been not includedsought
- 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
-
main
-