return ((Geometry) this.literal).equalsExact(expLit.evaluate(null, Geometry.class)); } else if (expressionType == ExpressionType.LITERAL_INTEGER) { return ((Integer) this.literal).equals(expLit.evaluate(null, Integer.class)); } else if (expressionType == ExpressionType.LITERAL_STRING) { return ((String) this.literal).equals(expLit.evaluate(null, String.class)); } else if (expressionType == ExpressionType.LITERAL_DOUBLE) { return ((Double) this.literal).equals(expLit.evaluate(null, Double.class)); } else if (expressionType == ExpressionType.LITERAL_LONG) { return ((Long) this.literal).equals(expLit.evaluate(null, Long.class)); } else { Object other = expLit.evaluate(null, this.literal.getClass()); if (other != null) { return other.equals(this.literal); Object converted = this.evaluate(null, other.getClass()); if (converted != null) { return converted.equals(other); String str1 = (String) this.evaluate(null, String.class); String str2 = (String) expLit.evaluate(null, String.class); return str1 != null && str2 != null && str1.equals(str2);
@Override public void setValue(Object aValue) { this.value = null; this.expression = null; if (aValue instanceof Double) { this.value = (Double) aValue; } else if (aValue instanceof LiteralExpressionImpl) { LiteralExpressionImpl literal = (LiteralExpressionImpl) aValue; value = literal.evaluate(value, Double.class); } else if ((aValue instanceof AttributeExpressionImpl) || (aValue instanceof FunctionExpressionImpl) || (aValue instanceof MathExpressionImpl)) { this.expression = (Expression) aValue; } }
@Override public void setValue(Object aValue) { this.value = null; this.expression = null; if (aValue instanceof Boolean) { this.value = (Boolean) aValue; } else if (aValue instanceof LiteralExpressionImpl) { LiteralExpressionImpl literal = (LiteralExpressionImpl) aValue; value = literal.evaluate(value, Boolean.class); } else if ((aValue instanceof AttributeExpressionImpl) || (aValue instanceof FunctionExpressionImpl) || (aValue instanceof MathExpressionImpl)) { this.expression = (Expression) aValue; } }
@Override public void setValue(Object aValue) { this.value = null; this.expression = null; if (aValue instanceof Long) { this.value = (Long) aValue; } else if (aValue instanceof LiteralExpressionImpl) { LiteralExpressionImpl literal = (LiteralExpressionImpl) aValue; value = literal.evaluate(value, Long.class); } else if ((aValue instanceof AttributeExpressionImpl) || (aValue instanceof FunctionExpressionImpl) || (aValue instanceof MathExpressionImpl)) { this.expression = (Expression) aValue; } }
@Override public void setValue(Object aValue) { this.value = null; this.expression = null; if (aValue instanceof Number) { this.value = (Number) aValue; } else if (aValue instanceof LiteralExpressionImpl) { LiteralExpressionImpl literal = (LiteralExpressionImpl) aValue; value = literal.evaluate(value, Number.class); } else if ((aValue instanceof AttributeExpressionImpl) || (aValue instanceof FunctionExpressionImpl) || (aValue instanceof MathExpressionImpl)) { this.expression = (Expression) aValue; } }
@Override public void setValue(Object aValue) { this.value = null; this.expression = null; if (aValue instanceof Integer) { this.value = (Integer) aValue; } else if (aValue instanceof LiteralExpressionImpl) { LiteralExpressionImpl literal = (LiteralExpressionImpl) aValue; value = literal.evaluate(value, Integer.class); } else if ((aValue instanceof AttributeExpressionImpl) || (aValue instanceof FunctionExpressionImpl) || (aValue instanceof MathExpressionImpl)) { this.expression = (Expression) aValue; } }
/** * Gets the value of this literal. * * @param feature Required by the interface but not used. * * @return the literal held by this expression. Ignores the passed in * feature. The literal held by this expression is almost invariably * a java.lang.String (so that no leading-zeros are lost during a string-> * Class conversion. This method will attempt to form the internal * String into a Integer, Double or BigInteger, before failing and * defaulting to a String. To speed things up significantly, use the * evaluate(Object, Class) method so that we don't have to guess * at what you expect back from this evaluate method! * * @throws IllegalArgumentException Feature does not match declared schema. */ public Object evaluate(SimpleFeature feature) throws IllegalArgumentException { return evaluate((Object)feature); }
public void testLiteralExpression() { LiteralExpressionImpl literal; literal = new LiteralExpressionImpl(1.0D); assertEquals(ExpressionType.LITERAL_DOUBLE, Filters.getExpressionType(literal)); assertEquals(new Double(1.0D), literal.evaluate((Feature) null)); GeometryFactory gf = new GeometryFactory(); literal = new LiteralExpressionImpl(gf.createPoint(new Coordinate(0, 0))); assertEquals(ExpressionType.LITERAL_GEOMETRY, Filters.getExpressionType(literal)); Geometry value = (Geometry) literal.evaluate((Feature) null); assertTrue(gf.createPoint(new Coordinate(0, 0)).equalsExact(value)); literal = new LiteralExpressionImpl(1); assertEquals(ExpressionType.LITERAL_INTEGER, Filters.getExpressionType(literal)); assertEquals(Integer.valueOf(1), literal.evaluate((Feature) null)); literal = new LiteralExpressionImpl(1L); assertEquals(ExpressionType.LITERAL_LONG, Filters.getExpressionType(literal)); assertEquals(Long.valueOf(1), literal.evaluate((Feature) null)); literal = new LiteralExpressionImpl("string value"); assertEquals(ExpressionType.LITERAL_STRING, Filters.getExpressionType(literal)); assertEquals("string value", literal.evaluate((Feature) null)); literal = new LiteralExpressionImpl(new Date(0)); assertEquals(ExpressionType.LITERAL_UNDECLARED, Filters.getExpressionType(literal)); assertEquals(new Date(0), literal.evaluate((Feature) null)); literal = new LiteralExpressionImpl(null); assertEquals(ExpressionType.LITERAL_UNDECLARED, Filters.getExpressionType(literal)); assertNull(literal.evaluate((Feature) null)); }
@Override public void setValue(Object aValue) { this.value = null; this.expression = null; if (aValue instanceof Float) { this.value = (Float) aValue; } else if (aValue instanceof Double) { this.value = ((Double) aValue).floatValue(); } else if (aValue instanceof LiteralExpressionImpl) { LiteralExpressionImpl literal = (LiteralExpressionImpl) aValue; value = literal.evaluate(value, Float.class); } else if ((aValue instanceof AttributeExpressionImpl) || (aValue instanceof FunctionExpressionImpl) || (aValue instanceof MathExpressionImpl)) { this.expression = (Expression) aValue; } }
@Override public void setValue(Object aValue) { this.value = null; this.expression = null; if (aValue != null) { if (aValue instanceof String) { this.value = (String) aValue; } else if (aValue instanceof LiteralExpressionImpl) { LiteralExpressionImpl literal = (LiteralExpressionImpl) aValue; value = literal.evaluate(value, String.class); } else if ((aValue instanceof AttributeExpressionImpl) || (aValue instanceof FunctionExpressionImpl) || (aValue instanceof MathExpressionImpl)) { this.expression = (Expression) aValue; } else { this.value = aValue.toString(); } } }
@Override public void setValue(Object aValue) { this.value = null; this.expression = null; if (aValue != null) { if (aValue instanceof String) { this.value = (String) aValue; } else if (aValue instanceof LiteralExpressionImpl) { LiteralExpressionImpl literal = (LiteralExpressionImpl) aValue; value = literal.evaluate(value, String.class); } else if ((aValue instanceof AttributeExpressionImpl) || (aValue instanceof FunctionExpressionImpl) || (aValue instanceof MathExpressionImpl)) { this.expression = (Expression) aValue; } else { this.value = aValue.toString(); } } }
return ((Geometry) this.literal).equals((Geometry) expLit.evaluate(null, Geometry.class)); } else if (expressionType == LITERAL_INTEGER) { return ((Integer) this.literal).equals((Integer) expLit.evaluate(null, Integer.class)); } else if (expressionType == LITERAL_STRING) { return ((String) this.literal).equals((String) expLit.evaluate(null, String.class)); } else if (expressionType == LITERAL_DOUBLE) { return ((Double) this.literal).equals((Double) expLit.evaluate(null, Double.class)); } else { return true;
return ((Geometry) this.literal).equalsExact((Geometry) expLit.evaluate(null, Geometry.class)); } else if (expressionType == LITERAL_INTEGER) { return ((Integer) this.literal).equals((Integer) expLit.evaluate(null, Integer.class)); } else if (expressionType == LITERAL_STRING) { return ((String) this.literal).equals((String) expLit.evaluate(null, String.class)); } else if (expressionType == LITERAL_DOUBLE) { return ((Double) this.literal).equals((Double) expLit.evaluate(null, Double.class)); } else if (expressionType == LITERAL_LONG) { return ((Long) this.literal).equals((Long) expLit.evaluate(null, Long.class)); } else { return true;
public Object evaluate(Object feature) { //hrm. Well, now that' we're always storing the internals of //Literals as strings, we need to be slightly smart about how we //return what's inside. Some (err, lots) of code relies on this //method to return an instance of the correct TYPE. I guess we should //try and be somewhat smart about this. //ASSERTION: literal is always a string. // caching, don't try to reparse over and over the same literal if(parsedValue != null) return parsedValue; // actual parsing if (literal == null || !(literal instanceof String)) { parsedValue = literal; } else { String s = (String) literal; // check if it's a number try { BigDecimal bd = new BigDecimal(s); // check if it has a decimal part if(bd.scale() > 0) { double d = bd.doubleValue(); // if too big for double, it will become infinite if(!Double.isInfinite(d)) parsedValue = new Double(d); else