Class DimensionVisitor
java.lang.Object
com.singularsys.extensions.matrix.DimensionVisitor
- All Implemented Interfaces:
GenericVisitor<Dimensions,,DimensionVisitor.NodeChecker, ParseException> JepComponent,Serializable
- Direct Known Subclasses:
DDimensionVisitor
public class DimensionVisitor
extends Object
implements GenericVisitor<Dimensions,DimensionVisitor.NodeChecker,ParseException>, JepComponent
Annotates nodes with the dimension of the vector or matrix.
Warning messages are sometimes generated. This list can be accessed using
getWarnings()
Since Jep 4.1, extension 2.2, this now implements GenericVisitor
some method signatures have changed to be more specific.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceClass to check conditions on a nodestatic classChecks nodes to see if the variable matches one in the supplied list -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Node.HookKeyA Key to use with Nodes and Variables to store the dimensions.protected Jepprotected OperatorTableI -
Constructor Summary
ConstructorsConstructorDescriptionShould only be used as when theinit(Jep)will be called.DimensionVisitor(Jep jep) Standalone constructor with a supplied Jep instance -
Method Summary
Modifier and TypeMethodDescriptionCalculate and sets the dimensions of a variable using its valuestatic DimensionsgetDimByValue(Object val) Find the dimensions of a given value.static DimensionsgetDimensions(Node node) Get the dimensions of a node.static DimensionsgetDimensions(Variable var) Get the dimensions of a variable.Gets a light-weight instance suitable for using in multiple threads.The list of warnings when a variable has changed dimension.voidInitialize the component.makeException(String message) Create an Exception of the correct type.static voidsetVariableDimensions(Variable var, Dimensions dim) Sets the dimensions of a variable to give value.If the variable has an equation visit that equation to find the dimensions and set the variables dimension.visit(ASTConstant node, DimensionVisitor.NodeChecker data) Visit a constant nodevisit(ASTFunNode node, DimensionVisitor.NodeChecker data) Visit a function nodevisit(ASTOpNode node, DimensionVisitor.NodeChecker data) Visit an operator nodevisit(ASTVarNode node, DimensionVisitor.NodeChecker data) Visit a variable node.Annotate every node in the tree.protected DimensionsvisitAssign(ASTOpNode node, Object data) Visit an assignment operator.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.singularsys.jep.GenericVisitor
makeException, visit, visitChildren
-
Field Details
-
DIM_KEY
A Key to use with Nodes and Variables to store the dimensions. -
jep
-
ot
-
-
Constructor Details
-
DimensionVisitor
public DimensionVisitor()Should only be used as when theinit(Jep)will be called. -
DimensionVisitor
Standalone constructor with a supplied Jep instance- Parameters:
jep- Jep instance
-
-
Method Details
-
calcDims
- Throws:
ParseException
-
getDimByValue
Find the dimensions of a given value. Handles the cases when the value is of typesMatrixI,VectorI, one and two-dimensional java.util.Vectors.- Parameters:
val- value- Returns:
- dimensions of object, unknown types returns SCALAR.
-
setVariableDimensions
Sets the dimensions of a variable to give value. Can be used in a situation when a variable is defined without a value being set for exampleVariable var = jep.addVariable("v"); dimensionVisitor.setVariableDimensions(var,Dimensions.THREE);- Parameters:
var-dim-- Since:
- Jep 4.0/Extensions 2.1
-
calcVariableDimensionsByValue
Calculate and sets the dimensions of a variable using its value- Parameters:
var- the variable, it is assumed it does not have a null value- Returns:
- the dimensions of its value
- Throws:
NullPointerException- if the variable does not have a value
-
visit
If the variable has an equation visit that equation to find the dimensions and set the variables dimension.- Parameters:
var- the variable- Returns:
- the calculated dimension
- Throws:
ParseException- if the variable does not have an equation- Since:
- Jep 4.0/Extensions 2.1
-
getDimensions
Get the dimensions of a variable.- Parameters:
var- the variable- Returns:
- the dimensions or null if it has not been set
- Since:
- Jep 4.0/Extensions 2.1
-
getDimensions
Get the dimensions of a node. For use in a static context use(Dimensions) node.getHook(DimensionVisitor.DIM_KEY);- Parameters:
node- the node- Returns:
- the dimensions or null if it has not been previously calculated
- Since:
- Jep 4.0/Extensions 2.1
-
visit
Annotate every node in the tree.- Parameters:
node- root node of the expression- Returns:
- dimensions of the root node
- Throws:
ParseException
-
visit
Description copied from interface:GenericVisitorVisit a constant node- Specified by:
visitin interfaceGenericVisitor<Dimensions,DimensionVisitor.NodeChecker, ParseException> - Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
ParseException
-
visit
Visit a variable node.- Specified by:
visitin interfaceGenericVisitor<Dimensions,DimensionVisitor.NodeChecker, ParseException> - Parameters:
node- the variable nodedata- aDimensionVisitor.NodeCheckerto check if the variable appears on the LHS of an assignment- Returns:
- the dimensions of the variable
- Throws:
ParseException- if the variable matches the LHS variable
-
visit
Description copied from interface:GenericVisitorVisit a function node- Specified by:
visitin interfaceGenericVisitor<Dimensions,DimensionVisitor.NodeChecker, ParseException> - Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
ParseException
-
visit
Description copied from interface:GenericVisitorVisit an operator node- Specified by:
visitin interfaceGenericVisitor<Dimensions,DimensionVisitor.NodeChecker, ParseException> - Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
ParseException
-
visitAssign
Visit an assignment operator. Will add the LHS variable to theDimensionVisitor.VariableNodeChecker. Sets the dimension of the LHS variable to the dimension of the RHS.- Parameters:
node- the node with an assignment operatordata- aDimensionVisitor.VariableNodeCheckerto check if the variable appears on the LHS of an assignment- Returns:
- dimensions of the RHS
- Throws:
ParseException- in the LHS variable appears on the RHS
-
getWarnings
The list of warnings when a variable has changed dimension.- Returns:
-
init
Description copied from interface:JepComponentInitialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.- Specified by:
initin interfaceJepComponent- Parameters:
jep1- the current Jep instance
-
getLightWeightInstance
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- either a new instance, null or 'this'.
-
makeException
Description copied from interface:GenericVisitorCreate an Exception of the correct type. A typical implementation is@Override public JepException makeException(String message) { return new JepException(message); }- Specified by:
makeExceptionin interfaceGenericVisitor<Dimensions,DimensionVisitor.NodeChecker, ParseException> - Parameters:
message- error message- Returns:
- an Exception
-