public Add add(Expression expr1, Expression expr2) { return new AddImpl(expr1, expr2); }
public Object evaluate(Object feature) throws IllegalArgumentException { ensureOperandsSet(); double leftDouble = Filters.number(getExpression1().evaluate(feature)); double rightDouble = Filters.number(getExpression2().evaluate(feature)); return number(leftDouble + rightDouble); }
public void testEvaluateAsString() { Object result = add.evaluate(null, String.class); assertEquals("3.0", result); } }
/** * Override of hashCode method. * * @return a hash code value for this add expression. */ public int hashCode() { int result = 23; result = (37 * result) + getExpression1().hashCode(); result = (37 * result) + getExpression2().hashCode(); return result; }
public String toString() { return "(" + getExpression1().toString() + "+" + getExpression2().toString() + ")"; } }
protected void setUp() throws Exception { FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); Expression e1 = ff.literal(1); Expression e2 = ff.literal(2); add = new AddImpl(e1, e2); }
public Object evaluate(Object feature) throws IllegalArgumentException { ensureOperandsSet(); double leftDouble = Filters.number( getExpression1().evaluate(feature) ); double rightDouble = Filters.number( getExpression2().evaluate(feature) ); return number(leftDouble + rightDouble); }
/** * Compares this expression to the specified object. Returns true if the * * @param obj - the object to compare this expression against. * @return true if specified object is equal to this expression; false otherwise. */ public boolean equals(Object obj) { if (obj instanceof AddImpl) { AddImpl other = (AddImpl) obj; return Utilities.equals(getExpression1(), other.getExpression1()) && Utilities.equals(getExpression2(), other.getExpression2()); } else { return false; } } /**
public void testEvaluateAsInteger() { Object result = add.evaluate(null, Integer.class); assertEquals(Integer.valueOf(3), result); }
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) { } }
public Object evaluate(Object feature) throws IllegalArgumentException { ensureOperandsSet(); double leftDouble = Filters.number( getExpression1().evaluate(feature) ); double rightDouble = Filters.number( getExpression2().evaluate(feature) ); return number(leftDouble + rightDouble); }
/** * Override of hashCode method. * * @return a hash code value for this add expression. */ public int hashCode() { int result = 23; result = (37 * result) + getExpression1().hashCode(); result = (37 * result) + getExpression2().hashCode(); return result; }
public void testEvaluate() { Object result = add.evaluate(null); assertEquals(new Double(3), result); }
switch (convertType) { case ExpressionType.MATH_ADD: curExprssn = new AddImpl(null, null); break; case ExpressionType.MATH_SUBTRACT:
public String toString() { return "(" + getExpression1().toString() + "+" + getExpression2().toString()+ ")"; } }
public Add add(Expression expr1, Expression expr2) { return new AddImpl(expr1,expr2); }
/** * Override of hashCode method. * * @return a hash code value for this add expression. */ public int hashCode() { int result = 23; result = (37 * result) + getExpression1().hashCode(); result = (37 * result) + getExpression2().hashCode(); return result; }
public Add add(Expression expr1, Expression expr2) { return new AddImpl(expr1,expr2); }
public String toString() { return "(" + getExpression1().toString() + "+" + getExpression2().toString()+ ")"; } }
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()); } }