((MathExpressionImpl) curExprssn).setExpression1(expFactory.create()); currentState = "rightValue"; expFactory = new ExpressionSAXParser(schema); LOGGER.finer("just added left value: " + currentState); } else if (currentState.equals("rightValue")) { ((MathExpressionImpl) curExprssn).setExpression2(expFactory.create()); currentState = "complete"; expFactory = null;
/** * Gets the left or first expression. * * @throws IllegalFilterException */ public void setExpression1(org.opengis.filter.expression.Expression expression) { if (isGeometryExpression(Filters.getExpressionType(expression))) { throw new IllegalFilterException( "Attempted to add Geometry expression to math expression."); } this.leftValue = expression; }
public void testIncompleteMathExpression() throws IllegalFilterException { Expression testAttribute1 = new LiteralExpressionImpl(Integer.valueOf(4)); MathExpressionImpl mathTest = new AddImpl(null, null); mathTest.setExpression1(testAttribute1); try { mathTest.evaluate(testFeature); fail("math expressions should not work if right hand side is not set"); } catch (IllegalArgumentException ife) { } mathTest = new AddImpl(null, null); mathTest.setExpression2(testAttribute1); try { mathTest.evaluate(testFeature); fail("math expressions should not work if left hand side is not set"); } catch (IllegalArgumentException ife) { } }
parameterList.add(mathExpression.getExpression1()); parameterList.add(mathExpression.getExpression2());
/** * Adds the 'right' value to this expression. * * @param rightValue Expression to add to this expression. * * @throws IllegalFilterException Attempting to add non-math expression. * * @deprecated use {@link #setExpression2(org.opengis.filter.expression.Expression)} */ public final void addRightValue(Expression rightValue) throws IllegalFilterException { setExpression2(rightValue); }
/** * Adds the 'left' value to this expression. * * @param leftValue Expression to add to this expression. * * @throws IllegalFilterException Attempting to add non-math expression. * * @deprecated use {@link #setExpression1(org.opengis.filter.expression.Expression)} */ public final void addLeftValue(Expression leftValue) throws IllegalFilterException { setExpression1(leftValue); }
/** * Gets the right expression. * * @return the expression on the right of the comparison. * * @deprecated use {@link #getExpression2()}. */ public final Expression getRightValue() { return (Expression) getExpression2(); }
/** * Gets the left or first expression. * * @deprecated use {@link #getExpression1()}. */ public final Expression getLeftValue() { return (Expression)getExpression1(); }
/** * Sets the math expression. * * @param expression the new math expression */ private void setMathExpression(Expression expression) { MathExpressionImpl mathsExpression = (MathExpressionImpl) expression; String expressionText = Localisation.getString(ExpressionPanelv2.class, "ExpressionPanelv2.expression"); ExpressionNode childNode1 = new ExpressionNode(); childNode1.setType(Number.class); childNode1.setName(expressionText + " 1"); childNode1.setExpression(mathsExpression.getExpression1()); this.insert(childNode1, this.getChildCount()); ExpressionNode childNode2 = new ExpressionNode(); childNode2.setType(Number.class); childNode2.setName(expressionText + " 2"); childNode2.setExpression(mathsExpression.getExpression2()); this.insert(childNode2, this.getChildCount()); }
/** * Adds the 'right' value to this expression. * * @param rightValue Expression to add to this expression. * * @throws IllegalFilterException Attempting to add non-math expression. * * @deprecated use {@link #setExpression2(org.opengis.filter.expression.Expression)} */ public final void addRightValue(Expression rightValue) throws IllegalFilterException { setExpression2(rightValue); }
/** * Adds the 'left' value to this expression. * * @param leftValue Expression to add to this expression. * * @throws IllegalFilterException Attempting to add non-math expression. * * @deprecated use {@link #setExpression1(org.opengis.filter.expression.Expression)} */ public final void addLeftValue(Expression leftValue) throws IllegalFilterException { setExpression1(leftValue); }
/** * Gets the right expression. * * @return the expression on the right of the comparison. * * @deprecated use {@link #getExpression2()}. */ public final Expression getRightValue() { return (Expression) getExpression2(); }
/** * Gets the left or first expression. * * @deprecated use {@link #getExpression1()}. */ public final Expression getLeftValue() { return (Expression)getExpression1(); }
public void testExpressionMath() { try { MathExpressionImpl testMath1; MathExpressionImpl testMath2; testExp1 = new LiteralExpressionImpl(new Double(5)); testExp2 = new LiteralExpressionImpl(new Double(5)); testMath1 = new AddImpl(null, null); testMath1.setExpression1(testExp1); testMath1.setExpression2(testExp2); testMath2 = new AddImpl(null, null); testMath2.setExpression1(testExp2); testMath2.setExpression2(testExp1); assertTrue(testMath1.equals(testMath2)); testExp3 = new LiteralExpressionImpl(Integer.valueOf(4)); testExp4 = new LiteralExpressionImpl(Integer.valueOf(4)); testMath2.setExpression1(testExp3); assertTrue(!testMath1.equals(testMath2)); testMath1.setExpression1(testExp4); assertTrue(testMath1.equals(testMath2)); testMath1 = new SubtractImpl(null, null); testMath1.setExpression1(testExp4); testMath1.setExpression1(testExp2); assertTrue(!testMath1.equals(testMath2)); assertTrue(!testMath1.equals("Random Object that happens to be a string")); } catch (IllegalFilterException e) { LOGGER.warning("bad filter: " + e.getMessage()); } }
mathTest.setExpression1(testAttribute1); mathTest.setExpression2(testAttribute2); assertEquals(Integer.valueOf(6), mathTest.evaluate(testObject, Integer.class)); mathTest.setExpression1(testAttribute1); mathTest.setExpression2(testAttribute2); assertEquals(Integer.valueOf(2), mathTest.evaluate(testObject, Integer.class)); mathTest.setExpression1(testAttribute1); mathTest.setExpression2(testAttribute2); assertEquals(Integer.valueOf(8), mathTest.evaluate(testObject, Integer.class)); mathTest.setExpression1(testAttribute1); mathTest.setExpression2(testAttribute2); assertEquals(new Double(2), mathTest.evaluate(testObject));
/** * Gets the second expression. * * @throws IllegalFilterException */ public void setExpression2(org.opengis.filter.expression.Expression expression) { // Check to see if this is a valid math expression before adding. if (isGeometryExpression(Filters.getExpressionType(expression))) { throw new IllegalFilterException( "Attempted to add Geometry expression to math expression."); } this.rightValue = expression; }
/** * Adds the maths expression. * * @param node the node * @param mathExpression the math expression * @return the expression */ private Expression addMathsExpression(ExpressionNode node, MathExpressionImpl mathExpression) { ExpressionNode leftChildNode = (ExpressionNode) node.getChildAt(0); mathExpression.setExpression1(addExpression(leftChildNode)); ExpressionNode rightChildNode = (ExpressionNode) node.getChildAt(1); mathExpression.setExpression2(addExpression(rightChildNode)); return mathExpression; }
mathTest.setExpression1(testAttribute1); mathTest.setExpression2(testAttribute2); LOGGER.fine( "math test: " + testAttribute2.evaluate(testFeature) + " = " + mathTest.evaluate(testFeature)); assertEquals(Integer.valueOf(6), mathTest.evaluate(testFeature, Integer.class)); mathTest.setExpression1(testAttribute1); mathTest.setExpression2(testAttribute2); LOGGER.fine( "math test: " + testAttribute2.evaluate(testFeature) + " = " + mathTest.evaluate(testFeature)); assertEquals(Integer.valueOf(2), mathTest.evaluate(testFeature, Integer.class)); mathTest.setExpression1(testAttribute1); mathTest.setExpression2(testAttribute2); LOGGER.fine( "math test: " + testAttribute2.evaluate(testFeature) + " = " + mathTest.evaluate(testFeature)); assertEquals(Integer.valueOf(8), mathTest.evaluate(testFeature, Integer.class));
/** * Gets the second expression. * * @throws IllegalFilterException */ public void setExpression2(org.opengis.filter.expression.Expression expression) { Expression rightValue = (Expression)expression; //Check to see if this is a valid math expression before adding. if (isGeometryExpression(rightValue.getType()) ) { throw new IllegalFilterException( "Attempted to add Geometry expression to math expression."); } this.rightValue = rightValue; }
MathExpressionImpl mathExpression = (MathExpressionImpl) localExpression; ExpressionNode leftChildNode = (ExpressionNode) node.getChildAt(0); mathExpression.setExpression1(addExpression(leftChildNode)); ExpressionNode rightChildNode = (ExpressionNode) node.getChildAt(1); mathExpression.setExpression2(addExpression(rightChildNode));