/** * Check if the given symbol is a <code>SymbolNode</code> and test if the names are equal. * * @param symbol1 * @param symbol2Name * @return */ public boolean isSymbol(SymbolNode symbol1, String symbol2Name) { if (fRelaxedSyntax) { return symbol1.getString().equalsIgnoreCase(symbol2Name); } return symbol1.getString().equals(symbol2Name); }
/** * Check if the given symbol is a <code>SymbolNode</code> and test if the names are equal. * * @param symbol1 * @param symbol2 * @return */ public boolean isSymbol(SymbolNode symbol1, SymbolNode symbol2) { if (fRelaxedSyntax) { return symbol1.getString().equalsIgnoreCase(symbol2.getString()); } return symbol1.equals(symbol2); }
/** * Internal helper using the mathclipse framework. * * @param aSymbolNodeA The node A to be processed. * @param aSymbolNodeB The node B to be processed. * @param aFunctionNodeC The node C to be processed. * * @return The {@link Criteria} (tree) extracted from the provided nodes. * * @throws ParseException Thrown in case there were problems working with * the given node. */ private Criteria toCriteria( SymbolNode aSymbolNodeA, SymbolNode aSymbolNodeB, FunctionNode aFunctionNodeC ) throws ParseException { if ( aSymbolNodeA.getString().equalsIgnoreCase( NODE ) ) { Criteria theCriteria = toCriteria( aFunctionNodeC ); if ( aSymbolNodeB.getString().equalsIgnoreCase( NOT ) ) { return not( theCriteria ); } } throw new ParseException( "Unable to parse: \"" + aSymbolNodeA.getString() + "\", \"" + aSymbolNodeB.getString() + "\" and/or \"" + aFunctionNodeC.getString() + "\"", 0 ); }
/** * Internal helper using the mathclipse framework. * * @param aSymbolNodeA The node A to be processed. * @param aFunctionNodeB The node B to be processed. * @param aSymbolNodeC The node C to be processed. * * @return The {@link Criteria} (tree) extracted from the provided nodes. * * @throws ParseException Thrown in case there were problems working with * the given node. */ private Criteria toCriteria( SymbolNode aSymbolNodeA, FunctionNode aFunctionNodeB, SymbolNode aSymbolNodeC ) throws ParseException { if ( aSymbolNodeA.getString().equalsIgnoreCase( NODE ) ) { Criteria theCriteria = toCriteria( aFunctionNodeB ); if ( aSymbolNodeC.getString().equalsIgnoreCase( OR ) ) { return or( theCriteria ); } else if ( aSymbolNodeC.getString().equalsIgnoreCase( AND ) ) { return and( theCriteria ); } else if ( aSymbolNodeC.getString().equalsIgnoreCase( INTERSECT ) ) { return intersectWith( theCriteria ); } else if ( aSymbolNodeC.getString().equalsIgnoreCase( NOT ) ) { return not( theCriteria ); } } throw new ParseException( "Unable to parse: \"" + aSymbolNodeA.getString() + "\", \"" + aFunctionNodeB.getString() + "\" and/or \"" + aSymbolNodeC.getString() + "\"", 0 ); }
String theUnEscapedKey = toUnEscapedKey( aSymbolNodeB.getString() ); Object theUnEscapedValue = toUnEscapedValue( aSymbolNodeC.getString() ); if ( aSymbolNodeA.getString().equalsIgnoreCase( EQUAL_WITH ) ) { return equalWith( theUnEscapedKey, theUnEscapedValue ); else if ( aSymbolNodeA.getString().equalsIgnoreCase( NOT_EQUAL_WITH ) ) { return notEqualWith( theUnEscapedKey, theUnEscapedValue ); else if ( aSymbolNodeA.getString().equalsIgnoreCase( GREATER_THAN ) ) { return greaterThan( theUnEscapedKey, theUnEscapedValue ); else if ( aSymbolNodeA.getString().equalsIgnoreCase( GREATER_OR_EQUAL_THAN ) ) { return greaterOrEqualThan( theUnEscapedKey, theUnEscapedValue ); else if ( aSymbolNodeA.getString().equalsIgnoreCase( LESS_THAN ) ) { return lessThan( theUnEscapedKey, theUnEscapedValue ); else if ( aSymbolNodeA.getString().equalsIgnoreCase( LESS_OR_EQUAL_THAN ) ) { return lessOrEqualThan( theUnEscapedKey, theUnEscapedValue ); throw new ParseException( toUnEscapedKey( "Unable to parse: " + aSymbolNodeA.getString() ) + "\", \"" + theUnEscapedKey + "\" and/or \"" + theUnEscapedValue + "\"", 0 );
/** * Internal helper using the mathclipse framework. * * @param aSymbolNodeA The node A to be processed. * @param aFunctionNodeB The node B to be processed. * @param aFunctionNodeC The node C to be processed. * * @return The {@link Criteria} (tree) extracted from the provided nodes. * * @throws ParseException Thrown in case there were problems working with * the given node. */ private Criteria toCriteria( SymbolNode aSymbolNodeA, FunctionNode aFunctionNodeB, FunctionNode aFunctionNodeC ) throws ParseException { if ( aSymbolNodeA.getString().equalsIgnoreCase( NODE ) ) { Criteria theCriteriaB = toCriteria( aFunctionNodeB ); Criteria theCriteriaC = toCriteria( aFunctionNodeC ); if ( theCriteriaB instanceof CriteriaNode ) { CriteriaNode theCriteriaNode = (CriteriaNode) theCriteriaB; theCriteriaNode.addChild( theCriteriaC ); return theCriteriaNode; } } throw new ParseException( "Unable to parse: \"" + aSymbolNodeA.getString() + "\", \"" + aFunctionNodeB.getString() + "\" and/or \"" + aFunctionNodeC.getString() + "\"", 0 ); }
public Complex evaluate(IEvaluator<Complex, ComplexVariable> engine, FunctionNode function) { if (function.size() != 3) { throw new ArithmeticException("SetFunction#evaluate(DoubleEvaluator,FunctionNode) needs 2 arguments: " + function.toString()); } if (!(function.getNode(1) instanceof SymbolNode)) { throw new ArithmeticException("SetFunction#evaluate(DoubleEvaluator,FunctionNode) symbol required on the left hand side: " + function.toString()); } String variableName = ((SymbolNode) function.getNode(1)).getString(); Complex result = engine.evaluateNode(function.getNode(2)); ComplexVariable dv = engine.getVariable(variableName); if (dv == null) { dv = new ComplexVariable(result); } else { dv.setValue(result); } engine.defineVariable(variableName, dv); return result; } }
public double evaluate(DoubleEvaluator engine, FunctionNode function) { if (function.size() != 3) { throw new ArithmeticException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) needs 2 arguments: " + function.toString()); } if (!(function.getNode(1) instanceof SymbolNode)) { throw new ArithmeticException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) symbol required on the left hand side: " + function.toString()); } String variableName = ((SymbolNode) function.getNode(1)).getString(); double result = engine.evaluateNode(function.getNode(2)); IDoubleValue dv = engine.getVariable(variableName); if (dv == null) { dv = new DoubleVariable(result); } else { dv.setValue(result); } engine.defineVariable(variableName, dv); return result; } }
/** * Evaluate. * * @param engine the engine * @param function the function * @return the double */ @Override public double evaluate( DoubleEvaluator engine, FunctionNode function ) { if ( function.size() != 3 ) { throw new ArithmeticException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) needs 2 arguments: " + function.toString() ); } if ( !(function.getNode( 1 ) instanceof SymbolNode) ) { throw new ArithmeticException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) symbol required on the left hand side: " + function.toString() ); } String variableName = ((SymbolNode) function.getNode( 1 )).getString(); double result = engine.evaluateNode( function.getNode( 2 ) ); IDoubleValue dv = engine.getVariable( variableName ); if ( dv == null ) { dv = new DoubleVariable( result ); } else { dv.setValue( result ); } engine.defineVariable( variableName, dv ); return result; } }
/** * Evaluate. * * @param engine the engine * @param function the function * @return the complex */ @Override public Complex evaluate( IEvaluator<Complex, ComplexVariable> engine, FunctionNode function ) { if ( function.size() != 3 ) { throw new ArithmeticException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) needs 2 arguments: " + function.toString() ); } if ( !(function.getNode( 1 ) instanceof SymbolNode) ) { throw new ArithmeticException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) symbol required on the left hand side: " + function.toString() ); } String variableName = ((SymbolNode) function.getNode( 1 )).getString(); Complex result = engine.evaluateNode( function.getNode( 2 ) ); ComplexVariable dv = engine.getVariable( variableName ); if ( dv == null ) { dv = new ComplexVariable( result ); } else { dv.setValue( result ); } engine.defineVariable( variableName, dv ); return result; } }
@Override public double evaluate(DoubleEvaluator engine, FunctionNode function) { if (function.size() != 3) { throw new ArithmeticMathException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) needs 2 arguments: " + function.toString()); } if (!(function.getNode(1) instanceof SymbolNode)) { throw new ArithmeticMathException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) symbol required on the left hand side: " + function.toString()); } String variableName = ((SymbolNode) function.getNode(1)).getString(); double result = engine.evaluateNode(function.getNode(2)); IDoubleValue dv = engine.getVariable(variableName); if (dv == null) { dv = new DoubleVariable(result); } else { dv.setValue(result); } engine.defineVariable(variableName, dv); return result; } }