/** * Gets the value of this property from the passed object. * * @param obj Object from which we need to extract a property value. */ public Object evaluate(Object obj) { return evaluate(obj, null); }
public void testSetupAndExtraction() throws Exception { // this should move out to a more configurable system run from scripts // but we can start with a set of hard coded tests SimpleFeature[] f = sampleFeatures(); AttributeExpressionImpl e1 = new AttributeExpressionImpl(schema, "value"); AttributeExpressionImpl e2 = new AttributeExpressionImpl(schema, "name"); assertEquals(12d, ((Integer) e1.evaluate(f[0])).doubleValue(), 0); assertEquals(3d, ((Integer) e1.evaluate(f[1])).doubleValue(), 0); assertEquals(15d, ((Integer) e1.evaluate(f[2])).doubleValue(), 0); assertEquals("first", (String) e2.evaluate(f[0])); assertEquals("second", (String) e2.evaluate(f[1])); } }
public void testSetupAndExtraction() throws Exception { // this should move out to a more configurable system run from scripts // but we can start with a set of hard coded tests SimpleFeature[] f = sampleFeatures(); AttributeExpressionImpl e1 = new AttributeExpressionImpl(schema, "value"); AttributeExpressionImpl e2 = new AttributeExpressionImpl(schema, "name"); assertEquals(12d, ((Integer) e1.evaluate(f[0])).doubleValue(), 0); assertEquals(3d, ((Integer) e1.evaluate(f[1])).doubleValue(), 0); assertEquals(15d, ((Integer) e1.evaluate(f[2])).doubleValue(), 0); assertEquals("first", (String) e2.evaluate(f[0])); assertEquals("second", (String) e2.evaluate(f[1])); } }
public void testTypeMissmatch() throws Exception { SimpleFeature[] f = sampleFeatures(); // the following are intentionaly backwards AttributeExpressionImpl e1 = new AttributeExpressionImpl(schema, "value"); AttributeExpressionImpl e2 = new AttributeExpressionImpl(schema, "name"); boolean pass = false; Object value = null; value = e1.evaluate(f[0]); if (value instanceof Integer) { pass = true; } assertTrue("String expresion returned an Integer", pass); pass = false; value = e2.evaluate(f[0]); if (value instanceof String) { pass = true; } assertTrue("Integer expresion returned a String", pass); }
public void testTypeMissmatch() throws Exception { SimpleFeature[] f = sampleFeatures(); // the following are intentionaly backwards AttributeExpressionImpl e1 = new AttributeExpressionImpl(schema, "value"); AttributeExpressionImpl e2 = new AttributeExpressionImpl(schema, "name"); boolean pass = false; Object value = null; value = e1.evaluate(f[0]); if (value instanceof Integer) { pass = true; } assertTrue("String expresion returned an Integer", pass); pass = false; value = e2.evaluate(f[0]); if (value instanceof String) { pass = true; } assertTrue("Integer expresion returned a String", pass); }
/** * Gets the value of this attribute from the passed feature. * * @param feature Feature from which to extract attribute value. */ public Object evaluate(SimpleFeature feature) { //NC - is exact copy of code anyway, don't need to keep changing both //this method can probably be removed all together return evaluate((Object) feature, null); }
/** * Gets the value of this property from the passed object. * * @param obj Object from which we need to extract a property value. */ public Object evaluate(Object obj) { return evaluate(obj, null); }
/** * Gets the value of this property from the passed object. * * @param obj Object from which we need to extract a property value. */ public Object evaluate(Object obj) { return evaluate(obj, null); }
public void testFeature() { SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName("test"); typeBuilder.setNamespaceURI("http://www.geotools.org/test"); typeBuilder.add("foo", Integer.class); typeBuilder.add("bar", Double.class); SimpleFeatureType type = typeBuilder.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); builder.add(Integer.valueOf(1)); builder.add(new Double(2.0)); SimpleFeature feature = builder.buildFeature("fid"); AttributeExpressionImpl ex = new AttributeExpressionImpl("foo"); assertEquals(Integer.valueOf(1), ex.evaluate(feature)); ex = new AttributeExpressionImpl("@id"); assertEquals("fid", ex.evaluate(feature)); } }
"eg:simpleAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(simpleAttribute, ex.evaluate(feature)); "eg:complexAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(complexAttribute, ex.evaluate(feature)); Object o = ex.evaluate(feature); assertTrue(o instanceof List); assertEquals(3, ((List) o).size()); o = ex.evaluate(feature); assertTrue(o instanceof List); assertEquals(3, ((List) o).size()); "eg:complexAttribute/eg:rootAttribute[1]", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(rootOne, ex.evaluate(feature)); ex = new AttributeExpressionImpl( "eg:complexAttribute/eg:rootAttribute[2]", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(rootTwo, ex.evaluate(feature)); "eg:complexAttribute/eg:rootAttribute[3]/eg:singleLeafAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(singleLeaf, ex.evaluate(feature));
"eg:simpleAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(simpleAttribute, ex.evaluate(feature)); "eg:complexAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(complexAttribute, ex.evaluate(feature)); Object o = ex.evaluate(feature); assertTrue(o instanceof List); assertEquals(3, ((List) o).size()); o = ex.evaluate(feature); assertTrue(o instanceof List); assertEquals(3, ((List) o).size()); "eg:complexAttribute/eg:rootAttribute[1]", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(rootOne, ex.evaluate(feature)); ex = new AttributeExpressionImpl( "eg:complexAttribute/eg:rootAttribute[2]", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(rootTwo, ex.evaluate(feature)); "eg:complexAttribute/eg:rootAttribute[3]/eg:singleLeafAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(singleLeaf, ex.evaluate(feature));
assertEquals(simpleAttribute, ex.evaluate(feature)); assertEquals(complexAttribute, ex.evaluate(feature)); Object o = ex.evaluate(feature); assertTrue( o instanceof List ); assertEquals(3, ((List) o).size()); o = ex.evaluate(feature); assertTrue( o instanceof List ); assertEquals(3, ((List) o).size()); assertEquals(rootOne, ex.evaluate(feature)); ex = new AttributeExpressionImpl("eg:complexAttribute/eg:rootAttribute[2]", new Hints( FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(rootTwo, ex.evaluate(feature)); "eg:complexAttribute/eg:rootAttribute[3]/eg:singleLeafAttribute", new Hints( FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(singleLeaf, ex.evaluate(feature)); "eg:complexAttribute/eg:rootAttribute[3]/eg:multiLeafAttribute", new Hints( FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(null, ex.evaluate(feature)); "eg:complexAttribute/eg:rootAttribute[2]/eg:multiLeafAttribute", new Hints( FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(leafOne, ex.evaluate(feature));
new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, GSMLNAMESPACES)); Object o = ex.evaluate(mf); assertNotNull(o); assertTrue(o instanceof PropertyDescriptor); new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, GSMLNAMESPACES)); o = ex.evaluate(mf); assertNotNull(o); assertTrue(o.equals (Types.typeName(XLINKNS, "href"))); new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, GSMLNAMESPACES)); o = ex.evaluate(mf); assertNull(o);