use of org.opengis.filter.expression.Literal in project ddf by codice.
the class GeotoolsFilterAdapterImpl method visit.
public Object visit(PropertyIsGreaterThanOrEqualTo filter, Object delegate) {
ExpressionValues filterValues = getExpressions(filter, delegate);
String propertyName = filterValues.propertyName;
Object literal = filterValues.literal;
// Are property name and literal reversed?
if (filter.getExpression1() instanceof Literal) {
// convert literal >= property to property <= literal
Filter lessThanOrEqual = FF.lessOrEqual(FF.property(propertyName), FF.literal(literal));
return lessThanOrEqual.accept(this, delegate);
}
if (literal instanceof String) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, (String) literal);
} else if (literal instanceof Date) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, (Date) literal);
} else if (literal instanceof Integer) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Integer) literal).intValue());
} else if (literal instanceof Short) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Short) literal).shortValue());
} else if (literal instanceof Long) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Long) literal).longValue());
} else if (literal instanceof Float) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Float) literal).floatValue());
} else if (literal instanceof Double) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Double) literal).doubleValue());
} else if (literal instanceof Boolean) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, literal);
} else if (literal instanceof byte[]) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, literal);
} else {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, literal);
}
}
use of org.opengis.filter.expression.Literal in project ddf by codice.
the class GeotoolsFilterAdapterImpl method visit.
public Object visit(PropertyIsGreaterThan filter, Object delegate) {
ExpressionValues filterValues = getExpressions(filter, delegate);
String propertyName = filterValues.propertyName;
Object literal = filterValues.literal;
// Are property name and literal reversed?
if (filter.getExpression1() instanceof Literal) {
// convert literal > property to property < literal
Filter lessThan = FF.less(FF.property(propertyName), FF.literal(literal));
return lessThan.accept(this, delegate);
}
if (literal instanceof String) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, (String) literal);
} else if (literal instanceof Date) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, (Date) literal);
} else if (literal instanceof Integer) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Integer) literal).intValue());
} else if (literal instanceof Short) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Short) literal).shortValue());
} else if (literal instanceof Long) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Long) literal).longValue());
} else if (literal instanceof Float) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Float) literal).floatValue());
} else if (literal instanceof Double) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Double) literal).doubleValue());
} else if (literal instanceof Boolean) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, literal);
} else if (literal instanceof byte[]) {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, literal);
} else {
return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, literal);
}
}
use of org.opengis.filter.expression.Literal in project ddf by codice.
the class GeotoolsFilterAdapterImpl method visit.
public Object visit(PropertyIsLessThan filter, Object delegate) {
ExpressionValues filterValues = getExpressions(filter, delegate);
String propertyName = filterValues.propertyName;
Object literal = filterValues.literal;
// Are property name and literal reversed?
if (filter.getExpression1() instanceof Literal) {
// convert literal < property to property > literal
Filter greaterThan = FF.greater(FF.property(propertyName), FF.literal(literal));
return greaterThan.accept(this, delegate);
}
if (literal instanceof String) {
return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, (String) literal);
} else if (literal instanceof Date) {
return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, (Date) literal);
} else if (literal instanceof Integer) {
return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, ((Integer) literal).intValue());
} else if (literal instanceof Short) {
return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, ((Short) literal).shortValue());
} else if (literal instanceof Long) {
return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, ((Long) literal).longValue());
} else if (literal instanceof Float) {
return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, ((Float) literal).floatValue());
} else if (literal instanceof Double) {
return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, ((Double) literal).doubleValue());
} else if (literal instanceof Boolean) {
return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, literal);
} else if (literal instanceof byte[]) {
return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, literal);
} else {
return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, literal);
}
}
use of org.opengis.filter.expression.Literal in project ddf by codice.
the class FilterBuilderTest method withinGeoTest.
/**
*
*/
@Test
public void withinGeoTest() {
FilterBuilder builder = new GeotoolsFilterBuilder();
Filter filter = builder.attribute(Metacard.GEOGRAPHY).within().wkt(POINT_WKT);
filter.accept(new DefaultFilterVisitor() {
@Override
public Object visit(Within filter, Object data) {
Literal literalWrapper = (Literal) filter.getExpression2();
Geometry geometry = (Geometry) literalWrapper.evaluate(null);
geometry.getCentroid().getCoordinate();
return super.visit(filter, data);
}
}, null);
}
use of org.opengis.filter.expression.Literal in project ddf by codice.
the class FilterBuilderTest method afterDate.
@Test
public void afterDate() {
final Date date = new Date();
FilterVisitor visitor = spy(new DefaultFilterVisitor() {
});
FilterBuilder builder = new GeotoolsFilterBuilder();
Filter filter = builder.attribute(FOO_ATTRIBUTE).is().after().date(date);
filter.accept(visitor, null);
ArgumentCaptor<After> expressionArgument = ArgumentCaptor.forClass(After.class);
verify(visitor).visit(expressionArgument.capture(), anyObject());
ExpressionVisitor expVisitor = spy(new DefaultExpressionVisitor() {
});
expressionArgument.getValue().getExpression1().accept(expVisitor, null);
ArgumentCaptor<PropertyName> propertyNameArgument = ArgumentCaptor.forClass(PropertyName.class);
verify(expVisitor).visit(propertyNameArgument.capture(), anyObject());
assertEquals(FOO_ATTRIBUTE, propertyNameArgument.getValue().getPropertyName());
expressionArgument.getValue().getExpression2().accept(expVisitor, null);
ArgumentCaptor<Literal> literalArgument = ArgumentCaptor.forClass(Literal.class);
verify(expVisitor).visit(literalArgument.capture(), anyObject());
assertEquals(date, ((Instant) literalArgument.getValue().getValue()).getPosition().getDate());
}
Aggregations