Package parser
Class GenericBracket
java.lang.Object
parser.GenericBracket
public class GenericBracket
extends java.lang.Object
- Author:
- JIBOYE, OLUWAGBEMIRO OLAOLUWA
-
Field Summary
Fields Modifier and Type Field Description static intANGULAR_BRACEFor < and > bracketsstatic intCIRCULAR_BRACEFor () bracketsstatic intCURLY_BRACEFor {} bracketsstatic intSQUARE_BRACEFor [] brackets -
Constructor Summary
Constructors Constructor Description GenericBracket(int bracketType, boolean open)Constructor of this class for creating its objects and initializing their names with either a ( or a ) and initialGenericBracket(java.lang.String name) -
Method Summary
Modifier and Type Method Description static booleancheckBracketStructure(java.util.List<java.lang.String> list, int start, int end)booleanencloses(Bracket brac)java.util.ArrayList<java.lang.String>getBracketDomainContents(java.util.ArrayList<java.lang.String> scan)returns a List containing the contents of a bracket pair,including the bracket pair itself.java.lang.StringgetBracketString()intgetBracketType()GenericBracketgetComplement()java.lang.StringgetComplementBracketString()static intgetComplementIndex(GenericBracket bracket, boolean isOpenBracket, int start, java.lang.String expr)static intgetComplementIndex(GenericBracket brac, int start, java.util.ArrayList<java.lang.String> scan)static intgetComplementIndex(GenericBracket brac, int start, java.util.List<java.lang.String> scan)java.lang.StringgetDomainContents(java.util.ArrayList<java.lang.String> scan)intgetIndex()intgetNumberOfInternalBrackets(java.util.ArrayList<Bracket> brac)static booleanhasBracketsInRange(java.util.List<java.lang.String> list, int start, int end)static booleanisCloseBracket(java.lang.String bracket)booleanisComplement(GenericBracket brac)checks if the Bracket object argument below is the sane as the complement to this Bracket object.booleanisEvaluated()booleanisOpen()static booleanisOpenBracket(java.lang.String bracket)booleanisSBP(java.util.ArrayList<java.lang.String> scan)static voidmain(java.lang.String[] args)static intprevIndexOf(java.util.List list, int start, java.lang.Object sought)voidsetBracketType(int bracketType)voidsetComplement(GenericBracket complement)voidsetEvaluated(boolean evaluated)voidsetIndex(int index)voidsetOpen(boolean open)
-
Field Details
-
CURLY_BRACE
public static final int CURLY_BRACEFor {} brackets- See Also:
- Constant Field Values
-
SQUARE_BRACE
public static final int SQUARE_BRACEFor [] brackets- See Also:
- Constant Field Values
-
CIRCULAR_BRACE
public static final int CIRCULAR_BRACEFor () brackets- See Also:
- Constant Field Values
-
ANGULAR_BRACE
public static final int ANGULAR_BRACEFor < and > brackets- See Also:
- Constant Field Values
-
-
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
public GenericBracket(java.lang.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 java.lang.String getBracketString()- Returns:
- the string representation of this Bracket half.
-
getComplementBracketString
public java.lang.String 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
- 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(java.util.ArrayList<java.lang.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, java.util.ArrayList<java.lang.String> scan)- Parameters:
brac- TheGenericBracketobject 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, java.util.List<java.lang.String> scan)- Parameters:
brac- TheGenericBracketobject 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, java.lang.String expr)- Parameters:
bracket- TheGenericBracketobject 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(java.util.List<java.lang.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(java.util.List<java.lang.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(java.lang.String bracket)- Parameters:
bracket- The String object.- Returns:
- true if the String object represents an open bracket
-
isCloseBracket
public static boolean isCloseBracket(java.lang.String bracket)- Parameters:
bracket- The String object.- Returns:
- true if the String object represents a close bracket
-
getDomainContents
public java.lang.String getDomainContents(java.util.ArrayList<java.lang.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 java.util.ArrayList<java.lang.String> getBracketDomainContents(java.util.ArrayList<java.lang.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.
-
prevIndexOf
public static int prevIndexOf(java.util.List list, int start, java.lang.Object sought)- 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.
-
main
public static void main(java.lang.String[] args)
-