boolean isNull(Expression expr) { if (expr == null) return true; if (expr == Expression.NIL) return true; if (expr instanceof Literal) { Literal literal = (Literal) expr; return literal.getValue() == null; } return false; // must be some other non null thing }
public LiteralBuilder reset(Literal original) { unset = false; literal = original.getValue(); return this; }
@Override public Object visit(Literal expression, Object extraData) { Class<?> targetType = null; if (extraData != null && extraData instanceof Class) { targetType = (Class<?>) extraData; } return encodeLiteral(expression.getValue(), targetType); }
private String getPropertyName(Expression expr) { String propertyName; if (expr instanceof Literal) { propertyName = String.valueOf(((Literal) expr).getValue()); } else if (expr instanceof PropertyName) { propertyName = ((PropertyName) expr).getPropertyName(); } else { throw new IllegalStateException("Not a property name expression: " + expr); } return propertyName; }
private void handleDashArrayLiteral(Literal literal, List<Expression> expressions) { Object value = literal.getValue(); if (value instanceof String) { handleDashArrayText((String) value, expressions); } else { expressions.add(literal); } }
@Override public Object visit(Literal literal, Object extraData) { // handle BigDate udt, encode it as a long if (extraData instanceof Class && BigDate.class.isAssignableFrom((Class<?>) extraData)) { if (literal.getValue() instanceof Date) { return super.visit( filterFactory.literal(((Date) literal.getValue()).getTime()), Long.class); } } return super.visit(literal, extraData); }
private Object buildExists(PropertyIsEqualTo filter, StringBuilder output) { Function function = (Function) filter.getExpression1(); List<Expression> parameters = function.getParameters(); Literal arg = (Literal) parameters.get(0); output.append(arg.getValue()); output.append(" EXISTS"); return output; }
public static PeriodNode createPeriodDateAndDuration( final Literal date, final Literal duration, FilterFactory filterFactory) { // compute last date from duration // Y M D and H M S Date firstDate = (Date) date.getValue(); String strDuration = (String) duration.getValue(); Date lastDate = DurationUtil.addDurationToDate(firstDate, strDuration); Literal literalLastDate = filterFactory.literal(lastDate); PeriodNode period = new PeriodNode(date, literalLastDate); return period; }
public static PeriodNode createPeriodDurationAndDate( final Literal duration, final Literal date, FilterFactory filterFactory) { // compute first date from duration Y M D and H M S Date lastDate = (Date) date.getValue(); String strDuration = (String) duration.getValue(); Date firstDate = DurationUtil.subtractDurationToDate(lastDate, strDuration); Literal literalFirstDate = filterFactory.literal(firstDate); PeriodNode period = new PeriodNode(literalFirstDate, date); return period; }
protected Envelope extractBboxForSpatialIndexQuery(BinarySpatialOperator filter) { org.opengis.filter.expression.Expression leftGeom = filter.getExpression1(); org.opengis.filter.expression.Expression rightGeom = filter.getExpression2(); Geometry g; if (leftGeom instanceof org.opengis.filter.expression.Literal) { g = (Geometry) ((org.opengis.filter.expression.Literal) leftGeom).getValue(); } else { g = (Geometry) ((org.opengis.filter.expression.Literal) rightGeom).getValue(); } return g.getEnvelopeInternal(); }
public Classifier getClassifier(Object context) { org.opengis.filter.expression.Expression expr = getParameters().get(1); if (expr instanceof Literal) { // this is not good practice! (but the other method doesn't work) Literal literal = (Literal) expr; return (Classifier) literal.getValue(); } return (Classifier) expr.evaluate(context, Classifier.class); }
public int popIntegerValue() throws CQLException { try { Literal expr = this.popLiteral(); Number number = (Number) expr.getValue(); return number.intValue(); } catch (ClassCastException cce) { throw new CQLException("Expected integer"); } }
@Override public BoundingBox getBounds() { Object value = ((Literal) getExpression2()).getValue(); if (value instanceof BoundingBox) { return (BoundingBox) value; } else { // create one return buildEnvelope(minx, maxx, miny, maxy, srs); } } }
public Object visit(Literal expression, Object extraData) { Object value = expression.getValue(); if (value instanceof Geometry) { value = reproject((Geometry) value, featureType.getCoordinateReferenceSystem()); } return getFactory(extraData).literal(value); }
@Override public void encode(ContentHandler output) throws Exception { Encoder encoder = new Encoder(new org.geotools.gml3.v3_2.GMLConfiguration()); encoder.setInline(true); encoder.encode( ((Literal) e).getValue(), org.geotools.gml3.v3_2.GML.AbstractGeometry, output); } };
/** Test of getGammaValue method, of class ContrastEnhancementImpl. */ public void testGetSetGammaValue() { // System.out.println("getGammaValue"); ContrastEnhancementImpl contrastEnhancementImpl = new ContrastEnhancementImpl(); double expected = 1.5; contrastEnhancementImpl.setGammaValue(filterFactory.literal(expected)); double actual = ((Double) ((Literal) contrastEnhancementImpl.getGammaValue()).getValue()) .doubleValue(); assertEquals(expected, actual, 0.1); }
public void testParse() throws Exception { FilterMockData.literal(document, document); Literal literal = (Literal) parse(); assertNotNull(literal); assertEquals("foo", literal.getValue()); }
@Test public void notEqualsTest() { // forward PropertyIsNotEqualTo source = ff.notEqual(ff.property("i"), ff.literal("10"), true); PropertyIsNotEqualTo bound = (PropertyIsNotEqualTo) source.accept(visitor, null); assertEquals(Integer.valueOf(10), ((Literal) bound.getExpression2()).getValue()); // flip it source = ff.notEqual(ff.literal("10"), ff.property("i"), true); bound = (PropertyIsNotEqualTo) source.accept(visitor, null); assertEquals(Integer.valueOf(10), ((Literal) bound.getExpression1()).getValue()); }