Skip to content
Browse files

Fix app-schema - but why all these terrible implementations of size

  • Loading branch information...
1 parent 889cec8 commit 645aa472a6fe1e52906da64055a4a2965d25200f @jodygarnett jodygarnett committed Oct 29, 2012
View
10 ...extension/app-schema/app-schema/src/test/java/org/geotools/data/complex/BoreholeTest.java
@@ -320,8 +320,14 @@ public void testDataStore() throws Exception {
private int size(FeatureCollection<FeatureType, Feature> features) {
int size = 0;
- for (Iterator i = features.iterator(); i.hasNext(); i.next()) {
- size++;
+ FeatureIterator<Feature> i = features.features();
+ try {
+ for (; i.hasNext(); i.next()) {
+ size++;
+ }
+ }
+ finally {
+ i.close();
}
return size;
}
View
10 ...extension/app-schema/app-schema/src/test/java/org/geotools/data/complex/GeoSciMLTest.java
@@ -248,8 +248,14 @@ public void testFeatureSourceHonoursQueryNamespace() throws Exception {
private int size(FeatureCollection<FeatureType, Feature> features) {
int size = 0;
- for (Iterator i = features.iterator(); i.hasNext(); i.next()) {
- size++;
+ FeatureIterator<Feature> i = features.features();
+ try {
+ for (; i.hasNext(); i.next()) {
+ size++;
+ }
+ }
+ finally {
+ i.close();
}
return size;
}
View
11 ...nsion/app-schema/app-schema/src/test/java/org/geotools/data/complex/GeologicUnitTest.java
@@ -35,6 +35,7 @@
import org.geotools.data.complex.config.FeatureTypeRegistry;
import org.geotools.data.complex.config.XMLConfigDigester;
import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.FeatureIterator;
import org.geotools.feature.Types;
import org.geotools.test.AppSchemaTestSupport;
import org.geotools.xml.SchemaIndex;
@@ -184,8 +185,14 @@ public void testGetFeatures() throws Exception {
private int size(FeatureCollection<FeatureType, Feature> features) {
int size = 0;
- for (Iterator i = features.iterator(); i.hasNext(); i.next()) {
- size++;
+ FeatureIterator<Feature> i = features.features();
+ try {
+ for (; i.hasNext(); i.next()) {
+ size++;
+ }
+ }
+ finally {
+ i.close();
}
return size;
}
View
43 ...app-schema/src/test/java/org/geotools/data/complex/filter/UnmappingFilterVisitorTest.java
@@ -48,6 +48,7 @@
import org.geotools.data.memory.MemoryDataStore;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.FeatureIterator;
import org.geotools.feature.NameImpl;
import org.geotools.feature.TypeBuilder;
import org.geotools.feature.Types;
@@ -185,7 +186,7 @@ private FeatureTypeMapping createSampleDerivedAttributeMappings() throws Excepti
attMappings.add(new AttributeMapping(null, strConcat, XPath.steps(targetFeature,
"concatenated", namespaces)));
- FeatureSource simpleSource = mapping.getSource();
+ FeatureSource<?,?> simpleSource = mapping.getSource();
FeatureTypeMapping mapping = new FeatureTypeMapping(simpleSource, targetFeature,
attMappings, namespaces);
return mapping;
@@ -207,9 +208,10 @@ public void testUnrollFidMappedToAttribute() throws Exception {
.getFeatures(unrolled);
assertEquals(1, getCount(results));
- Iterator<SimpleFeature> features = results.iterator();
+ FeatureIterator<SimpleFeature> features = results.features();
SimpleFeature unmappedFeature = (SimpleFeature) features.next();
- results.close(features);
+ features.close();
+
assertNotNull(unmappedFeature);
Object object = unmappedFeature.getProperty("station_no").getValue();
assertEquals(fid, object);
@@ -240,24 +242,26 @@ public void testUnrollFid() throws Exception {
.getFeatures(unrolled);
assertEquals(1, getCount(results));
- Iterator<SimpleFeature> features = results.iterator();
+ FeatureIterator<SimpleFeature> features = results.features();
SimpleFeature unmappedFeature = (SimpleFeature) features.next();
- results.close(features);
+
+ features.close();
+
assertNotNull(unmappedFeature);
Object object = unmappedFeature.getProperty("station_no").getValue();
assertEquals(fid1, object);
}
- private int getCount(FeatureCollection features) {
- Iterator iterator = features.iterator();
+ private int getCount(FeatureCollection<?,?> features) {
+ FeatureIterator<?> iterator = features.features();
int count = 0;
try {
while (iterator.hasNext()) {
iterator.next();
count++;
}
} finally {
- features.close(iterator);
+ iterator.close();
}
return count;
}
@@ -307,11 +311,17 @@ private void checkUnrollIdExpression(Expression idExpression) throws Exception {
}
featureMapping.setIdentifierExpression(idExpression);
this.visitor = new UnmappingFilterVisitor(this.mapping);
- FeatureCollection<SimpleFeatureType,SimpleFeature> content = mapping.getSource()
- .getFeatures();
- Iterator iterator = content.iterator();
- Feature sourceFeature = (Feature) iterator.next();
- content.close(iterator);
+
+ // retrieve a single sample feature
+ FeatureCollection<?,?> content = mapping.getSource().getFeatures();
+ FeatureIterator<?> iterator = content.features();
+ Feature sourceFeature = null;
+ try {
+ sourceFeature = iterator.next();
+ }
+ finally {
+ iterator.close();
+ }
String fid = sourceFeature.getIdentifier().toString();
Id fidFilter = ff.id(Collections.singleton(ff.featureId(fid)));
Filter unrolled = (Filter) fidFilter.accept(visitor, null);
@@ -321,9 +331,10 @@ private void checkUnrollIdExpression(Expression idExpression) throws Exception {
FeatureCollection<SimpleFeatureType,SimpleFeature> results = mapping.getSource()
.getFeatures(unrolled);
assertEquals(1, getCount(results));
- iterator = results.iterator();
+ iterator = results.features();
SimpleFeature unmappedFeature = (SimpleFeature) iterator.next();
- results.close(iterator);
+ iterator.close();
+
assertEquals(fid, unmappedFeature.getID());
}
@@ -682,7 +693,7 @@ public void testLogicFilter() throws Exception {
testLogicFilter(Or.class);
}
- private void testLogicFilter(Class filterType) throws Exception {
+ private void testLogicFilter(Class<?> filterType) throws Exception {
BinaryLogicOperator complexLogicFilter;
PropertyIsGreaterThan resultFilter = ff.greater(ff.property("measurement/result"), ff
.literal(new Integer(5)));
View
42 modules/extension/app-schema/app-schema/src/test/java/org/geotools/filter/BBoxTest.java
@@ -29,6 +29,7 @@
import org.geotools.data.DataAccessFinder;
import org.geotools.data.FeatureSource;
import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.FeatureIterator;
import org.geotools.feature.Types;
import org.geotools.test.AppSchemaTestSupport;
import org.junit.BeforeClass;
@@ -91,12 +92,16 @@ public void testBBoxWithPropertyName() throws Exception {
BBOX filter = ff.bbox(ff.property("gsml:shape"), -1.1, 52.5, -1.1, 52.6, null);
FeatureCollection<FeatureType, Feature> features = fSource.getFeatures(filter);
assertEquals(2, size(features));
- Iterator<Feature> iterator = features.iterator();
- Feature f = iterator.next();
- assertEquals(f.getIdentifier().toString(), "mf1");
- f = iterator.next();
- assertEquals(f.getIdentifier().toString(), "mf3");
-
+ FeatureIterator<Feature> iterator = features.features();
+ try {
+ Feature f = iterator.next();
+ assertEquals(f.getIdentifier().toString(), "mf1");
+ f = iterator.next();
+ assertEquals(f.getIdentifier().toString(), "mf3");
+ }
+ finally {
+ iterator.close();
+ }
// prove that it would fail when property name is not a geometry attribute
filter = ff.bbox(ff.property("gml:name[1]"), -1.2, 52.5, -1.1, 52.6, null);
features = fSource.getFeatures(filter);
@@ -116,17 +121,28 @@ public void testBBoxWithNoPropertyName() throws IOException {
BBOX filter = ff.bbox(ff.property(""), -1.1, 52.5, -1.1, 52.6, null);
FeatureCollection<FeatureType, Feature> features = fSource.getFeatures(filter);
assertEquals(2, size(features));
- Iterator<Feature> iterator = features.iterator();
- Feature f = iterator.next();
- assertEquals(f.getIdentifier().toString(), "mf1");
- f = iterator.next();
- assertEquals(f.getIdentifier().toString(), "mf3");
+ FeatureIterator<Feature> iterator = features.features();
+ try {
+ Feature f = iterator.next();
+ assertEquals(f.getIdentifier().toString(), "mf1");
+ f = iterator.next();
+ assertEquals(f.getIdentifier().toString(), "mf3");
+ }
+ finally {
+ iterator.close();
+ }
}
private int size(FeatureCollection<FeatureType, Feature> features) {
int size = 0;
- for (Iterator i = features.iterator(); i.hasNext(); i.next()) {
- size++;
+ FeatureIterator<Feature> i = features.features();
+ try {
+ for (; i.hasNext(); i.next()) {
+ size++;
+ }
+ }
+ finally {
+ i.close();
}
return size;
}
View
90 ...extension/app-schema/app-schema/src/test/java/org/geotools/filter/VocabFunctionsTest.java
@@ -29,6 +29,7 @@
import org.geotools.data.FeatureSource;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.FeatureIterator;
import org.geotools.feature.Types;
import org.geotools.gml3.bindings.GML3EncodingUtils;
import org.geotools.test.AppSchemaTestSupport;
@@ -119,26 +120,37 @@ public void testRecodeFunction() throws IOException {
put("sc.3", "c");
}
};
- Iterator<Feature> features = exCollection.iterator();
- while (features.hasNext()) {
- Feature feature = features.next();
- String fId = feature.getIdentifier().getID();
- String recodedName = VALUE_MAP.get(fId);
- // gml[3]: <OCQL>Recode(STRING, 'string_one', 'a', 'string_two', 'b', 'string_three',
- // 'c')</OCQL>
- ComplexAttribute complexAttribute = (ComplexAttribute) ff.property("gml:name[3]")
- .evaluate(feature);
- String value = Converters.convert(GML3EncodingUtils.getSimpleContent(complexAttribute),
- String.class);
- assertEquals(recodedName, value);
+ FeatureIterator<Feature> features = exCollection.features();
+ try {
+ while (features.hasNext()) {
+ Feature feature = features.next();
+ String fId = feature.getIdentifier().getID();
+ String recodedName = VALUE_MAP.get(fId);
+ // gml[3]: <OCQL>Recode(STRING, 'string_one', 'a', 'string_two', 'b', 'string_three',
+ // 'c')</OCQL>
+ ComplexAttribute complexAttribute = (ComplexAttribute) ff.property("gml:name[3]")
+ .evaluate(feature);
+ String value = Converters.convert(GML3EncodingUtils.getSimpleContent(complexAttribute),
+ String.class);
+ assertEquals(recodedName, value);
+ }
+ }
+ finally {
+ features.close();
}
- exCollection.close(features);
}
private int size(FeatureCollection<FeatureType, Feature> features) {
+ // return features.size(); // JG: why are you not doing this?
int size = 0;
- for (Iterator i = features.iterator(); i.hasNext(); i.next()) {
- size++;
+ FeatureIterator<Feature> i = features.features();
+ try {
+ for (; i.hasNext(); i.next()) {
+ size++;
+ }
+ }
+ finally {
+ i.close();
}
return size;
}
@@ -155,15 +167,19 @@ public void testCategorizeFunction() {
put("sc.3", "a valid value");
}
};
- Iterator<Feature> features = exCollection.iterator();
- while (features.hasNext()) {
- Feature feature = features.next();
- String fId = feature.getIdentifier().getID();
- Property attribute = feature.getProperty("someAttribute");
- // <OCQL>Categorize(getID(), 'missing value', 2, 'a valid value')</OCQL>
- assertEquals(attribute.getValue(), VALUE_MAP.get(fId));
+ FeatureIterator<Feature> features = exCollection.features();
+ try {
+ while (features.hasNext()) {
+ Feature feature = features.next();
+ String fId = feature.getIdentifier().getID();
+ Property attribute = feature.getProperty("someAttribute");
+ // <OCQL>Categorize(getID(), 'missing value', 2, 'a valid value')</OCQL>
+ assertEquals(attribute.getValue(), VALUE_MAP.get(fId));
+ }
+ }
+ finally {
+ features.close();
}
- exCollection.close(features);
}
/**
@@ -210,19 +226,23 @@ public void testVocabFunctionInMappingFile() {
put("sc.3", "urn:cgi:classifier:CGI:SimpleLithology:2008:sediment");
}
};
- Iterator<Feature> features = exCollection.iterator();
- while (features.hasNext()) {
- Feature feature = features.next();
- String fId = feature.getIdentifier().getID();
- // gml[2]: <OCQL>Vocab(URN_ID,
- // 'src/test/java/org/geotools/filter/test-data/minoc_lithology_mapping.properties')</OCQL>
- ComplexAttribute complexAttribute = (ComplexAttribute) ff.property("gml:name[2]")
- .evaluate(feature);
- String value = Converters.convert(GML3EncodingUtils.getSimpleContent(complexAttribute),
- String.class);
- assertEquals(VALUE_MAP.get(fId), value);
+ FeatureIterator<Feature> features = exCollection.features();
+ try {
+ while (features.hasNext()) {
+ Feature feature = features.next();
+ String fId = feature.getIdentifier().getID();
+ // gml[2]: <OCQL>Vocab(URN_ID,
+ // 'src/test/java/org/geotools/filter/test-data/minoc_lithology_mapping.properties')</OCQL>
+ ComplexAttribute complexAttribute = (ComplexAttribute) ff.property("gml:name[2]")
+ .evaluate(feature);
+ String value = Converters.convert(GML3EncodingUtils.getSimpleContent(complexAttribute),
+ String.class);
+ assertEquals(VALUE_MAP.get(fId), value);
+ }
+ }
+ finally {
+ features.close();
}
- exCollection.close(features);
}
}

0 comments on commit 645aa47

Please sign in to comment.
Something went wrong with that request. Please try again.