Class MBracket
java.lang.Object
parser.Operator
math.matrix.expressParser.MOperator
math.matrix.expressParser.MBracket
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate MBracket
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 MOperator
COL_JOIN, DET, DET_BRACE, INV, operators, ROW_JOIN, TRI_MATRIX, UNIT
Fields inherited from class 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, OR, PERMUTATION, PLUS, POWER, REMAINDER, ROOT, SEMI_COLON, SPACE, SQUARE, STORE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionnon-static version of the above method.static MBracket
createTwinBracket
(MBracket 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.boolean
returns a List containing the contents of a bracket pair,including the bracket pair itself.static int
getComplementIndex
(boolean isOpenBracket, int start, ArrayList<String> scan) int
getIndex()
getName()
int
static boolean
isCloseBracket
(String bracket) boolean
isComplement
(MBracket brac) checks if the MBracket object argument below is the sane as the complement to this MBracket object.boolean
static boolean
isOpenBracket
(String bracket) void
setComplement
(MBracket complement) void
setEvaluated
(boolean evaluated) void
setIndex
(int index) void
Methods inherited from class MOperator
getPrecedence, isAssignmentOperator, isBinaryOperator, isBracket, isClosingBrace, isClosingBracket, isColJoin, isColon, isCube, isDet, isDetHalfSymbol, isInverse, isMul, isOpeningBrace, isOpeningBracket, isOperatorString, isPlusOrMinus, isPower, isRowJoin, isSquare, isTri, isUnaryPostOperator, isUnaryPreOperator, isUnit, validateAll
Methods inherited from class Operator
isAtOperator, isComma, isConstantStoreCommand, isCubeRoot, isEqualsOperator, isExitCommand, isFactorial, isLogicOperator, isMulOrDiv, isMulOrDivOrRemOrPermOrCombOrPow, isPermOrComb, isRemainder, isSemiColon, isSquareRoot, isStoreCommand
-
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
-
MBracket
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 MBracket objects. If we create another MBracket array, say array moreBracs and copy the objects in bracs into moreBracs.Now, both bracs and moreBracs will hold references to these MBracket 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 MBracket 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 MBracket object. The one above creates a twin for the specified bracket object.- Returns:
- a MBracket 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 MBracket object in a scanned function
-
setIndex
public void setIndex(int index) - Parameters:
index
- the ne w index to assign to this MBracket object in a scanned Function
-
getName
-
setName
-
getComplement
- Returns:
- the MBracket object which is the complement of this MBracket object
-
setComplement
- Parameters:
complement
- sets the MBracket object which is to be the complement to this one in the scanned Function
-
isComplement
checks if the MBracket object argument below is the sane as the complement to this MBracket object.- Parameters:
brac
- The MBracket object whose identity is to be checked whether or not it complements this MBracket 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
-
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
-
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
-
getBracketDomainContents
-