@Override public <T> T evaluate(Object object, Class<T> context) { // Selection of the first expression Expression clazzExpression = parameters.get(0); // Getting the defined class Class clazz = clazzExpression.evaluate(object, Class.class); // Checking the result boolean result = false; // If the input class is Object, the function always returns true if (clazz != null) { if (clazz == Object.class) { result = true; } else { // Otherwise the function checks if the class is an instance of the // input class result = clazz.isAssignableFrom(object.getClass()); } } // Finally the result is converted to the defined context class return Converters.convert(result, context); }
/** * Uses {@link Converters} to parse the provided text into the correct values to create a * feature. * * @param type FeatureType * @param fid Feature ID for new feature * @param text Text representation of values * @return newly created feature * @throws IllegalAttributeException */ public static SimpleFeature parse(SimpleFeatureType type, String fid, String[] text) throws IllegalAttributeException { Object[] attributes = new Object[text.length]; for (int i = 0; i < text.length; i++) { AttributeType attType = type.getDescriptor(i).getType(); attributes[i] = Converters.convert(text[i], attType.getBinding()); } return SimpleFeatureBuilder.build(type, attributes, fid); }
private void doSetAttribute(AttributeDescriptor d, Object o) { if (d instanceof GeometryDescriptor) { MongoUtil.setDBOValue( featureDBO, mapper.getGeometryPath(), mapper.toObject((Geometry) o)); } else { MongoUtil.setDBOValue( featureDBO, mapper.getPropertyPath(d.getLocalName()), Converters.convert(o, d.getType().getBinding())); } }
throws IllegalArgumentException { if (value == null) { if (descriptor.isNillable()) { return descriptor.getDefaultValue(); Class target = descriptor.getType().getBinding(); if (!target.isAssignableFrom(value.getClass())) { Object converted = Converters.convert(value, target); if (converted != null) { return converted;
public void modifyFeatures(AttributeDescriptor[] type, Object[] values, Filter filter) throws IOException { SimpleFeatureType original = typeMap.getOriginalFeatureType(); // map back attribute types and values to the original values AttributeDescriptor[] originalTypes = new AttributeDescriptor[type.length]; Object[] originalValues = new Object[values.length]; for (int i = 0; i < values.length; i++) { originalTypes[i] = original.getDescriptor(type[i].getName()); if (values[i] != null) { Class<?> target = originalTypes[i].getType().getBinding(); originalValues[i] = Converters.convert(values[i], target); if (originalValues[i] == null) throw new IOException("Could not map back " + values[i] + " to type " + target); } } featureStore() .modifyFeatures(originalTypes, originalValues, store.retypeFilter(filter, typeMap)); }
double data0 = workingPoints.get(0).data.evaluate(object, Double.class); double data1 = workingPoints.get(1).data.evaluate(object, Double.class); workingPoints.add( 0, new InterpPoint(ff2.literal(2 * data0 - data1), workingPoints.get(0).value)); segment++; double data0 = workingPoints.get(segment).data.evaluate(object, Double.class); double data1 = workingPoints.get(segment - 1).data.evaluate(object, Double.class); workingPoints.add( new InterpPoint( ff2.literal(2 * data0 - data1), workingPoints.get(segment).value)); return Converters.convert(interpolated, context);
/** * returns the value asociated with <code>key</code> on the set of key/value pairs of this * request reader * * @param key DOCUMENT ME! * @return DOCUMENT ME! */ protected String getValue(String key) { return Converters.convert(kvpPairs.get(key), String.class); }
Double value = lookupExp.evaluate(object, Double.class); if (value == null) { value = Converters.convert(object, Double.class); convertedValues = new Object[values.length]; for (int i = 0; i < convertedValues.length; i++) { convertedValues[i] = values[i].evaluate(object, context); return (T) convertedValues[valIdx]; } else { return values[valIdx].evaluate(object, context); isIncludedInThreshold = ff.greater(lookupExp, threshholdExp); } else { isIncludedInThreshold = ff.greaterOrEqual(lookupExp, threshholdExp);
/** * Allows this Attribute to convert an argument to its prefered storage type. If no parsing is * possible, returns the original value. If a parse is attempted, yet fails (i.e. a poor decimal * format) throw the Exception. This is mostly for use internally in Features, but implementors * should simply follow the rules to be safe. * * @param value the object to attempt parsing of. * @return <code>value</code> converted to the preferred storage of this <code>AttributeType * </code>. If no parsing was possible then the same object is returned. * @throws IllegalArgumentException if parsing is attempted and is unsuccessful. */ protected Object parse(Object value) throws IllegalArgumentException { if (value != null) { Class target = getType().getBinding(); if (!target.isAssignableFrom(value.getClass())) { // attempt to convert Object converted = Converters.convert(value, target); if (converted != null) { value = converted; } } } return value; } }
public void testAfterInstant() throws Exception { Date date = convert("2002-12-03 10:00:00AM", Date.class); DefaultInstant instant = new DefaultInstant(new DefaultPosition(date)); Expression literal = filterFac.literal(instant); Expression prop = filterFac.property(timestampFType.getAttributeDescriptors().get(0).getLocalName()); PropertyIsEqualTo filter = filterFac.equals(prop, literal); encoder.setFeatureType(timestampFType); encoder.encode(filter); LOGGER.fine("testAttr is a Timestamp " + filter + " -> " + output.getBuffer().toString()); assertEquals(output.getBuffer().toString(), "WHERE testAttr = '2002-12-03 10:00:00.0'"); }
@Override public Object visit(PropertyIsBetween filter, Object extraData) { BasicDBObject output = asDBObject(extraData); String propName = convert(filter.getExpression().accept(this, null), String.class); Object lower = filter.getLowerBoundary().accept(this, getValueType(filter.getExpression())); Object upper = filter.getUpperBoundary().accept(this, getValueType(filter.getExpression())); BasicDBObject dbo = new BasicDBObject(); dbo.put("$gte", lower); dbo.put("$lte", upper); output.put(propName, dbo); return output; }
@Override public Object getDefaultValue( ResourceInfo resource, String dimensionName, DimensionInfo dimension, Class clz) { String attrName = dimension.getAttribute(); Class<?> attrType = String.class; if (resource instanceof FeatureTypeInfo) { List<AttributeTypeInfo> attrTypes; try { attrTypes = ((FeatureTypeInfo) resource).attributes(); for (AttributeTypeInfo attr : attrTypes) { if (attr.getName().equals(attrName)) { attrType = attr.getBinding(); break; } } } catch (IOException e) { } } final FeatureCalc nearest = new NearestVisitor(ff.property(dimension.getAttribute()), this.toMatch); CalcResult res = getCalculatedResult((FeatureTypeInfo) resource, dimension, nearest); if (res.equals(CalcResult.NULL_RESULT)) { return null; } else { return Converters.convert(res.getValue(), clz); } }
/** * Processed the {@link ConverterFactory} extension point. * * @return A collection of converter factories. * @since 2.4 */ static ConverterFactory[] factories() { if (factories == null) { Collection<ConverterFactory> factoryCollection = getConverterFactories(GeoTools.getDefaultHints()); factories = (ConverterFactory[]) factoryCollection.toArray( new ConverterFactory[factoryCollection.size()]); } return factories; } }
/** * Returns a set of all available {@link ConverterFactory}'s which can handle convert from the * source to destination class. * * <p>This method essentially returns all factories in which the following returns non null. * * <pre> * factory.createConverter( source, target ); * </pre> * * @since 2.5 */ public static Set<ConverterFactory> getConverterFactories(Class<?> source, Class<?> target) { HashSet<ConverterFactory> factories = new HashSet<ConverterFactory>(); for (ConverterFactory factory : factories()) { if (factory.createConverter(source, target, null) != null) { factories.add(factory); } } return factories; }
public void setAttribute(int index, Object value) throws IndexOutOfBoundsException { // first do conversion Object converted = Converters.convert( value, getFeatureType().getDescriptor(index).getType().getBinding()); // if necessary, validation too if (validating) Types.validate(featureType.getDescriptor(index), converted); // finally set the value into the feature values[index] = converted; }
public static SimpleFeature feature(SimpleFeatureType fType, String fid, Node node) throws Exception { SimpleFeatureBuilder b = new SimpleFeatureBuilder(fType); int attributeCount = fType.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { AttributeDescriptor att = fType.getDescriptor(i); AttributeType attType = att.getType(); Object attValue = node.getChildValue(att.getLocalName()); if ((attValue != null) && !attType.getBinding().isAssignableFrom(attValue.getClass())) { // type mismatch, to try convert Object converted = Converters.convert(attValue, attType.getBinding()); if (converted != null) { attValue = converted; } } b.add(attValue); } // create the feature return b.buildFeature(fid); }
if (attType.isNillable()) { return null; // it was an explicit "<null>" try { Geometry geometry = wktReader.read(stringValue); value = Converters.convert(geometry, attType.getType().getBinding()); } catch (ParseException e) { value = Converters.convert(stringValue, attType.getType().getBinding());
polySymb.getStroke().setWidth(filterFactory.literal(size)); polySymb.getOptions().put(PolygonSymbolizer.GRAPHIC_MARGIN_KEY, "15"); PolygonSymbolizer rescaledPolySymb = (PolygonSymbolizer) visitor.getCopy(); double rescaledSize = rescaledPolySymb.getStroke().getWidth().evaluate(null, Double.class); .get(TextSymbolizer.GRAPHIC_MARGIN_KEY) .split("\\s+"); int rescaledGraphicMargin = Converters.convert(splitted[0], Integer.class).intValue(); assertEquals(expectedGraphicMargin, rescaledGraphicMargin); } catch (Exception e2) {