Package com.singularsys.jep.walkers
Class TestingVisitor
java.lang.Object
com.singularsys.jep.walkers.TestingVisitor
- All Implemented Interfaces:
GenericVisitor<Boolean,Predicate<Node>, JepException>
public class TestingVisitor
extends Object
implements GenericVisitor<Boolean,Predicate<Node>,JepException>
A visitor than can test all nodes in a tree against a set of predicates.
First a visitor is constructed and then the
test(Node) method
is called to test an expression.
This visitor checks all operators and functions have assigned pfmc's.
TestingVisitor tv = new TestingVisitor(
n -> n instanceof ASTOpNode
? n.getPFMC()!=null
: true,
n -> n instanceof ASTFunNode
? n.getPFMC()!=null
: true
);
This visitor checks all literal constants are Doubles
TestingVisitor tv = new TestingVisitor(
n -> n instanceof ASTConstant
? n.getValue() instanceof Double
: true);
This visitor checks the assumption that PFMC of an operator node matches the PFMC of the operator.
TestingVisitor tv = new TestingVisitor(
n -> n instanceof ASTOpNode
? n.getOperator().getPFMC() == n.getPFMC()
: true);
- Since:
- Jep 4.1
-
Constructor Summary
ConstructorsConstructorDescriptionTestingVisitor(Predicate<Node>... preds) Constructor with a set of Predicate to use in test -
Method Summary
Modifier and TypeMethodDescriptionCreate an Exception of the correct type.booleanTest using the set of Predicates given in the constructorbooleanTest using a supplied Predicatevisit(ASTConstant node, Predicate<Node> data) Visit a constant nodevisit(ASTFunNode node, Predicate<Node> data) Visit a function nodeVisit an operator nodevisit(ASTVarNode node, Predicate<Node> data) Visit a variable nodeMethods 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
-
Constructor Details
-
TestingVisitor
Constructor with a set of Predicate to use in test- Parameters:
preds- zero or more Predicates
-
-
Method Details
-
test
Test using the set of Predicates given in the constructor- Parameters:
n- root node to test- Returns:
- true if all test pass for all nodes, false otherwise
- Throws:
JepException
-
test
Test using a supplied Predicate- Parameters:
n- root node to testpred- predicate to test- Returns:
- Throws:
JepException
-
visit
Description copied from interface:GenericVisitorVisit a constant node- Specified by:
visitin interfaceGenericVisitor<Boolean,Predicate<Node>, JepException> - Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
JepException
-
visit
Description copied from interface:GenericVisitorVisit a function node- Specified by:
visitin interfaceGenericVisitor<Boolean,Predicate<Node>, JepException> - Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
JepException
-
visit
Description copied from interface:GenericVisitorVisit a variable node- Specified by:
visitin interfaceGenericVisitor<Boolean,Predicate<Node>, JepException> - Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
JepException
-
visit
Description copied from interface:GenericVisitorVisit an operator node- Specified by:
visitin interfaceGenericVisitor<Boolean,Predicate<Node>, JepException> - Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
JepException
-
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<Boolean,Predicate<Node>, JepException> - Parameters:
s- error message- Returns:
- an Exception
-