Class DimensionVisitor
- java.lang.Object
-
- com.singularsys.extensions.matrix.DimensionVisitor
-
- All Implemented Interfaces:
JepComponent
,ParserVisitor
,java.io.Serializable
- Direct Known Subclasses:
DDimensionVisitor
public class DimensionVisitor extends java.lang.Object implements ParserVisitor, JepComponent
Annotates nodes with the dimension of the vector or matrix.Warning messages are sometimes generated. This list can be accessed using
getWarnings()
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Node.HookKey
DIM_KEY
A Key to use with Nodes and Variables to store the dimensions.protected Jep
jep
protected OperatorTableI
ot
-
Constructor Summary
Constructors Constructor Description DimensionVisitor()
Should only be used as when theinit(Jep)
will be called.DimensionVisitor(Jep jep1)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Dimensions
calcVariableDimensionsByValue(Variable var)
Calculate and sets the dimensions of a variable using its valuestatic Dimensions
getDimByValue(java.lang.Object val)
Find the dimensions of a given value.Dimensions
getDimensions(Node node)
Get the dimensions of a node.Dimensions
getDimensions(Variable var)
Get the dimensions of a variable.JepComponent
getLightWeightInstance()
Gets a light-weight instance suitable for using in multiple threads.java.util.List<java.lang.String>
getWarnings()
The list of warnings when a variable has changed dimension.void
init(Jep jep1)
Initialize the component.void
setVariableDimensions(Variable var, Dimensions dim)
Sets the dimensions of a variable to give value.Dimensions
visit(XVariable var)
If the variable has an equation visit that equation to find the dimensions and set the variables dimension.Dimensions
visit(ASTConstant node, java.lang.Object data)
Dimensions
visit(ASTFunNode node, java.lang.Object data)
Dimensions
visit(ASTOpNode node, java.lang.Object data)
Dimensions
visit(ASTVarNode node, java.lang.Object data)
Dimensions
visit(Node node)
Annotate every node in the tree.protected Dimensions
visitAssign(ASTOpNode node, java.lang.Object data)
-
-
-
Field Detail
-
DIM_KEY
public static final Node.HookKey DIM_KEY
A Key to use with Nodes and Variables to store the dimensions.
-
jep
protected Jep jep
-
ot
protected OperatorTableI ot
-
-
Method Detail
-
getDimByValue
public static final Dimensions getDimByValue(java.lang.Object val)
Find the dimensions of a given value. Handles 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 SCALER.
-
setVariableDimensions
public void setVariableDimensions(Variable var, Dimensions dim)
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
public Dimensions calcVariableDimensionsByValue(Variable var)
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:
java.lang.NullPointerException
- if the variable does not have a value
-
visit
public Dimensions visit(XVariable var) throws ParseException
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
public Dimensions getDimensions(Variable var)
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
public Dimensions getDimensions(Node node)
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
public Dimensions visit(Node node) throws ParseException
Annotate every node in the tree.- Parameters:
node
- root node of the expression- Returns:
- dimensions of the root node
- Throws:
ParseException
-
visit
public Dimensions visit(ASTConstant node, java.lang.Object data) throws ParseException
- Specified by:
visit
in interfaceParserVisitor
- Throws:
ParseException
-
visit
public Dimensions visit(ASTVarNode node, java.lang.Object data) throws ParseException
- Specified by:
visit
in interfaceParserVisitor
- Throws:
ParseException
-
visitAssign
protected Dimensions visitAssign(ASTOpNode node, java.lang.Object data) throws ParseException
- Throws:
ParseException
-
visit
public Dimensions visit(ASTFunNode node, java.lang.Object data) throws ParseException
- Specified by:
visit
in interfaceParserVisitor
- Throws:
ParseException
-
visit
public Dimensions visit(ASTOpNode node, java.lang.Object data) throws ParseException
- Specified by:
visit
in interfaceParserVisitor
- Throws:
ParseException
-
getWarnings
public java.util.List<java.lang.String> getWarnings()
The list of warnings when a variable has changed dimension.- Returns:
-
init
public void init(Jep jep1)
Description copied from interface:JepComponent
Initialize the component. This methods 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:
init
in interfaceJepComponent
- Parameters:
jep1
- the current Jep instance
-
getLightWeightInstance
public JepComponent getLightWeightInstance()
Description copied from interface:JepComponent
Gets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstance
in interfaceJepComponent
- Returns:
- either an new instance, null or 'this'.
-
-