Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix pregeneralized

  • Loading branch information...
commit c8cfb082e7ee90e235ef04dc1ac774e2a6551a76 1 parent 43f4005
@jodygarnett jodygarnett authored
View
115 ...s/plugin/feature-pregeneralized/src/main/java/org/geotools/data/gen/PreGeneralizedFeatureCollection.java
@@ -62,9 +62,7 @@
protected String geomPropertyName, backendGeomPropertyName;
protected int[] indexMapping;
-
- List<CollectionListener> listeners = new ArrayList<CollectionListener>();
-
+
public PreGeneralizedFeatureCollection(
SimpleFeatureCollection backendCollection,
SimpleFeatureType featureType, int[] indexMapping, String geomPropertyName,
@@ -77,11 +75,6 @@ public PreGeneralizedFeatureCollection(
this.indexMapping = indexMapping;
}
- protected UnsupportedOperationException unsupported() {
- return new UnsupportedOperationException(
- "Cannot modify a pregeneralized feature collection");
- }
-
/*
* (non-Javadoc)
*
@@ -89,14 +82,15 @@ protected UnsupportedOperationException unsupported() {
* org.opengis.util.ProgressListener) Logic copied from DefaultFeatureCollection class
*/
public void accepts(FeatureVisitor visitor, ProgressListener progress) throws IOException {
- Iterator iterator = null;
+ SimpleFeatureIterator iterator = null;
if (progress == null)
progress = new NullProgressListener();
try {
float size = size();
float position = 0;
progress.started();
- for (iterator = iterator(); !progress.isCanceled() && iterator.hasNext(); progress
+
+ for (iterator = features(); !progress.isCanceled() && iterator.hasNext(); progress
.progress(position++ / size)) {
try {
SimpleFeature feature = (SimpleFeature) iterator.next();
@@ -107,60 +101,10 @@ public void accepts(FeatureVisitor visitor, ProgressListener progress) throws IO
}
} finally {
progress.complete();
- close(iterator);
+ iterator.close();
}
}
- public boolean add(SimpleFeature arg0) {
- throw unsupported();
-
- }
-
- public boolean addAll(Collection arg0) {
- throw unsupported();
-
- }
-
- public boolean addAll(FeatureCollection arg0) {
- throw unsupported();
-
- }
-
- public void addListener(CollectionListener listener) throws NullPointerException {
- listeners.add(listener);
-
- }
-
- public void clear() {
- throw unsupported();
- }
-
- public void close(FeatureIterator<SimpleFeature> it) {
- it.close();
-
- }
-
-
- public void close(Iterator it) {
- if (it==null) return;
-
- try { // check for a possible close method
- Method closeMethod = it.getClass().getMethod("close", new Class[]{});
-
- if (closeMethod!=null) {
- int mod = closeMethod.getModifiers();
- if (Modifier.isPublic(mod) && (Modifier.isStatic(mod)==false))
- closeMethod.invoke(it, new Object[]{});
- }
- } catch (SecurityException e) {
- return;
- } catch (NoSuchMethodException e) {
- return;
- } catch (Exception e) {
- throw new RuntimeException("Error calling close method for "+it.getClass().getName());
- }
- }
-
public boolean contains(Object feature) {
if (feature instanceof PreGeneralizedSimpleFeature)
return backendCollection.contains(((PreGeneralizedSimpleFeature) feature).feature);
@@ -205,55 +149,6 @@ public boolean isEmpty() {
}
- public Iterator<SimpleFeature> iterator() {
- final Iterator<SimpleFeature> iterator = backendCollection.iterator();
-
- return new Iterator<SimpleFeature>() {
-
- public boolean hasNext() {
- return iterator.hasNext();
- }
-
- public SimpleFeature next() {
- SimpleFeature feature = (SimpleFeature) iterator.next();
- return new PreGeneralizedSimpleFeature(featureType, indexMapping, feature,
- geomPropertyName, backendGeomPropertyName);
- }
-
- public void remove() {
- throw unsupported();
- }
- public void close() {
- backendCollection.close(iterator);
- }
- };
- }
-
- public void purge() {
- throw unsupported();
-
- }
-
- public boolean remove(Object arg0) {
- throw unsupported();
-
- }
-
- public boolean removeAll(Collection arg0) {
- throw unsupported();
-
- }
-
- public void removeListener(CollectionListener listener) throws NullPointerException {
- listeners.remove(listener);
-
- }
-
- public boolean retainAll(Collection arg0) {
- throw unsupported();
-
- }
-
public int size() {
return backendCollection.size();
}
View
54 modules/plugin/feature-pregeneralized/src/main/java/org/geotools/data/gen/tool/Toolbox.java
@@ -162,33 +162,37 @@ protected void generalizeShapeFile(File shapeFile, DataStore shapeDS, File targe
SimpleFeatureCollection fcoll = fs.getFeatures();
SimpleFeatureIterator it = fcoll.features();
- int countTotal = fcoll.size();
-
- List<FeatureWriter<SimpleFeatureType, SimpleFeature>> writers = new ArrayList<FeatureWriter<SimpleFeatureType, SimpleFeature>>();
- for (int i = 0; i < dataStores.length; i++) {
- writers.add(dataStores[i].getFeatureWriter(typeName, Transaction.AUTO_COMMIT));
- }
-
- int counter = 0;
- while (it.hasNext()) {
- SimpleFeature feature = it.next();
- for (int i = 0; i < distanceArray.length; i++) {
- FeatureWriter<SimpleFeatureType, SimpleFeature> w = writers.get(i);
- SimpleFeature genFeature = w.next();
- genFeature.setAttributes(feature.getAttributes());
- Geometry newGeom = TopologyPreservingSimplifier.simplify((Geometry) feature
- .getDefaultGeometry(), distanceArray[i]);
- genFeature.setDefaultGeometry(newGeom);
- w.write();
+ try {
+ int countTotal = fcoll.size();
+
+ List<FeatureWriter<SimpleFeatureType, SimpleFeature>> writers = new ArrayList<FeatureWriter<SimpleFeatureType, SimpleFeature>>();
+ for (int i = 0; i < dataStores.length; i++) {
+ writers.add(dataStores[i].getFeatureWriter(typeName, Transaction.AUTO_COMMIT));
+ }
+
+ int counter = 0;
+ while (it.hasNext()) {
+ SimpleFeature feature = it.next();
+ for (int i = 0; i < distanceArray.length; i++) {
+ FeatureWriter<SimpleFeatureType, SimpleFeature> w = writers.get(i);
+ SimpleFeature genFeature = w.next();
+ genFeature.setAttributes(feature.getAttributes());
+ Geometry newGeom = TopologyPreservingSimplifier.simplify((Geometry) feature
+ .getDefaultGeometry(), distanceArray[i]);
+ genFeature.setDefaultGeometry(newGeom);
+ w.write();
+ }
+ counter++;
+ showProgress(countTotal, counter);
+
+ }
+ for (FeatureWriter<SimpleFeatureType, SimpleFeature> w : writers){
+ w.close();
}
- counter++;
- showProgress(countTotal, counter);
-
}
- fcoll.close(it);
-
- for (FeatureWriter<SimpleFeatureType, SimpleFeature> w : writers)
- w.close();
+ finally {
+ it.close();
+ }
for (DataStore ds : dataStores) {
ds.dispose();
View
99 .../feature-pregeneralized/src/test/java/org/geotools/data/gen/AbstractPreGeneralizedFeatureSourceTest.java
@@ -321,11 +321,15 @@ protected void testGetFeatures(String configName) {
assertTrue("the_geom".equals(fCollection.getSchema().getGeometryDescriptor()
.getLocalName()));
SimpleFeatureIterator iterator = fCollection.features();
- while (iterator.hasNext()) {
- SimpleFeature f = iterator.next();
- checkPoints(f, 0.0);
+ try {
+ while (iterator.hasNext()) {
+ SimpleFeature f = iterator.next();
+ checkPoints(f, 0.0);
+ }
+ }
+ finally {
+ iterator.close();
}
- fCollection.close(iterator);
q.getHints().put(Hints.GEOMETRY_DISTANCE, 5.0);
fCollection = fs.getFeatures(q);
@@ -334,11 +338,15 @@ protected void testGetFeatures(String configName) {
assertTrue("the_geom".equals(fCollection.getSchema().getGeometryDescriptor()
.getLocalName()));
iterator = fCollection.features();
- while (iterator.hasNext()) {
- SimpleFeature f = iterator.next();
- checkPoints(f, 5.0);
+ try {
+ while (iterator.hasNext()) {
+ SimpleFeature f = iterator.next();
+ checkPoints(f, 5.0);
+ }
+ }
+ finally {
+ iterator.close();
}
- fCollection.close(iterator);
q.getHints().put(Hints.GEOMETRY_DISTANCE, 10.0);
fCollection = fs.getFeatures(q);
@@ -347,11 +355,15 @@ protected void testGetFeatures(String configName) {
assertTrue("the_geom".equals(fCollection.getSchema().getGeometryDescriptor()
.getLocalName()));
iterator = fCollection.features();
- while (iterator.hasNext()) {
- SimpleFeature f = iterator.next();
- checkPoints(f, 10.0);
+ try {
+ while (iterator.hasNext()) {
+ SimpleFeature f = iterator.next();
+ checkPoints(f, 10.0);
+ }
+ }
+ finally {
+ iterator.close();
}
- fCollection.close(iterator);
q.getHints().put(Hints.GEOMETRY_DISTANCE, 20.0);
fCollection = fs.getFeatures(q);
@@ -360,12 +372,15 @@ protected void testGetFeatures(String configName) {
assertTrue("the_geom".equals(fCollection.getSchema().getGeometryDescriptor()
.getLocalName()));
iterator = fCollection.features();
- while (iterator.hasNext()) {
- SimpleFeature f = iterator.next();
- checkPoints(f, 20.0);
+ try {
+ while (iterator.hasNext()) {
+ SimpleFeature f = iterator.next();
+ checkPoints(f, 20.0);
+ }
+ }
+ finally {
+ iterator.close();
}
- fCollection.close(iterator);
-
q.getHints().put(Hints.GEOMETRY_DISTANCE, 50.0);
fCollection = fs.getFeatures(q);
typeName = fCollection.getSchema().getTypeName();
@@ -373,12 +388,15 @@ protected void testGetFeatures(String configName) {
assertTrue("the_geom".equals(fCollection.getSchema().getGeometryDescriptor()
.getLocalName()));
iterator = fCollection.features();
- while (iterator.hasNext()) {
- SimpleFeature f = iterator.next();
- checkPoints(f, 0.0);
+ try {
+ while (iterator.hasNext()) {
+ SimpleFeature f = iterator.next();
+ checkPoints(f, 0.0);
+ }
+ }
+ finally {
+ iterator.close();
}
- fCollection.close(iterator);
-
}
} catch (Exception ex) {
Assert.fail(ex.getMessage());
@@ -411,32 +429,33 @@ protected void testGetFeatures2(String configName) {
assertTrue("GenStreams".equals(typeName));
assertTrue(fCollection.size() > 0);
assertFalse(fCollection.isEmpty());
- Iterator<SimpleFeature> iterator = fCollection.iterator();
- while (iterator.hasNext()) {
- SimpleFeature f = iterator.next();
- checkPoints(f, 0.0);
+ SimpleFeatureIterator iterator = fCollection.features();
+ try {
+ while (iterator.hasNext()) {
+ SimpleFeature f = iterator.next();
+ checkPoints(f, 0.0);
+ }
+ }
+ finally {
+ iterator.close();
}
- fCollection.close(iterator);
-
fCollection = fs.getFeatures(Filter.INCLUDE);
typeName = fCollection.getSchema().getTypeName();
assertTrue("GenStreams".equals(typeName));
assertTrue(fCollection.size() > 0);
assertFalse(fCollection.isEmpty());
- iterator = fCollection.iterator();
- while (iterator.hasNext()) {
- SimpleFeature f = iterator.next();
- checkPoints(f, 0.0);
- }
- boolean error = true;
+ iterator = fCollection.features();
try {
- iterator.remove();
- } catch (UnsupportedOperationException e) {
- error = false;
+ while (iterator.hasNext()) {
+
+ SimpleFeature f = iterator.next();
+ checkPoints(f, 0.0);
+ }
+ // iterator.remove() no longer provided
+ }
+ finally {
+ iterator.close();
}
- assertFalse(error);
- fCollection.close(iterator);
-
ds.dispose();
} catch (Exception ex) {
View
84 ...ugin/feature-pregeneralized/src/test/java/org/geotools/data/gen/PreGeneralizedFeatureCollectionTest.java
@@ -58,87 +58,7 @@ public void testNotSupportedFeatures() {
ex.printStackTrace();
Assert.fail();
}
-
- boolean error = true;
- try {
- fCollection.add(null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
- error = true;
- try {
- fCollection.addAll((Collection<SimpleFeature>) null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
- error = true;
- try {
- fCollection.addAll((SimpleFeatureCollection) null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
- error = true;
- try {
- fCollection.clear();
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
- // purge is depricated
- // error = true;
- // try {
- // fCollection.purge();
- // } catch (UnsupportedOperationException ex) {
- // error = false;
- // }
- // if (error) {
- // Assert.fail();
- // }
-
- error = true;
- try {
- fCollection.remove(null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
- error = true;
- try {
- fCollection.removeAll(null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
- error = true;
- try {
- fCollection.retainAll(null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
+
+ // the non-supported features
}
}
View
320 ...s/plugin/feature-pregeneralized/src/test/java/org/geotools/data/gen/PreGeneralizedSimpleFeatureTest.java
@@ -28,6 +28,7 @@
import org.geotools.data.gen.info.GeneralizationInfosProvider;
import org.geotools.data.gen.info.GeneralizationInfosProviderImpl;
import org.geotools.data.simple.SimpleFeatureCollection;
+import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.feature.NameImpl;
import org.junit.Assert;
import org.opengis.feature.Property;
@@ -62,73 +63,80 @@ public void testSimpleFeatureBasics() {
Assert.fail();
}
- Iterator<SimpleFeature> it = fCollection.iterator();
- SimpleFeature feature1 = it.next();
- SimpleFeature feature2 = it.next();
- // SimpleFeature feature3 = it.next();
-
- assertTrue(feature1 instanceof PreGeneralizedSimpleFeature);
-
- for (int i = 0; i < feature1.getType().getAttributeDescriptors().size(); i++) {
- Object value1 = feature1.getAttribute(i);
- Object value2 = feature1.getAttribute(feature1.getType().getAttributeDescriptors().get(
- i).getLocalName());
- assertTrue(value1 == value2);
+ SimpleFeatureIterator it = fCollection.features();
+ try {
+ SimpleFeature feature1 = it.next();
+
+ SimpleFeature feature2 = it.next();
+ // SimpleFeature feature3 = it.next();
+
+
+ assertTrue(feature1 instanceof PreGeneralizedSimpleFeature);
+
+ for (int i = 0; i < feature1.getType().getAttributeDescriptors().size(); i++) {
+ Object value1 = feature1.getAttribute(i);
+ Object value2 = feature1.getAttribute(feature1.getType().getAttributeDescriptors().get(
+ i).getLocalName());
+ assertTrue(value1 == value2);
+ }
+
+ assertNotNull(feature1.getAttribute("CAT_ID"));
+ assertNotNull(feature1.getAttribute(new NameImpl("CAT_ID")));
+ assertTrue(feature1.getAttributeCount() == 4);
+
+ assertFalse(feature1.equals(feature2));
+ assertTrue(feature1.equals(feature1));
+ assertFalse(feature1.hashCode() == feature2.hashCode());
+ assertTrue(feature1.hashCode() == feature1.hashCode());
+
+ assertFalse(feature1.getID().equals(feature2.getID()));
+
+ assertTrue(feature1.getBounds().equals(feature1.getBounds()));
+ assertFalse(feature1.getBounds().equals(feature2.getBounds()));
+
+ assertTrue(feature1.getDefaultGeometry().equals(feature1.getDefaultGeometry()));
+ assertFalse(feature1.getDefaultGeometry().equals(feature2.getDefaultGeometry()));
+
+ assertTrue(feature1.getDefaultGeometryProperty().getName().getLocalPart()
+ .equals("the_geom"));
+ assertTrue(feature1.getDefaultGeometryProperty().getName().equals(
+ feature2.getDefaultGeometryProperty().getName()));
+ assertFalse(feature1.getDefaultGeometryProperty().equals(
+ feature2.getDefaultGeometryProperty()));
+
+ assertTrue(feature1.getFeatureType().equals(feature2.getFeatureType()));
+ assertTrue(feature2.getFeatureType().getName().getLocalPart().equals("GenStreams"));
+
+ assertTrue(feature1.getIdentifier().equals(feature1.getIdentifier()));
+ assertFalse(feature1.getIdentifier().equals(feature2.getIdentifier()));
+
+ assertTrue(feature1.getProperties().size() == 4);
+ assertTrue(feature1.getProperty("CAT_ID").getValue()
+ .equals(feature1.getAttribute("CAT_ID")));
+ assertTrue(feature1.getProperty("the_geom").getValue().equals(
+ feature1.getAttribute("the_geom")));
+ // assertFalse(feature1.getProperty("CAT_ID").getValue().equals(feature2.getAttribute("CAT_ID"
+ // )));
+ assertFalse(feature1.getProperty("the_geom").getValue().equals(
+ feature2.getAttribute("the_geom")));
+
+ assertTrue(feature1.getProperties("CAT_ID").contains(feature1.getProperty("CAT_ID")));
+ assertFalse(feature2.getProperties("the_geom").contains(feature1.getProperty("the_geom")));
+
+ assertTrue(feature1.getProperties(new NameImpl("CAT_ID")).contains(
+ feature1.getProperty("CAT_ID")));
+ assertFalse(feature2.getProperties(new NameImpl("the_geom")).contains(
+ feature1.getProperty("the_geom")));
+
+ assertTrue(feature1.getType().equals(fCollection.getSchema()));
+ assertTrue(feature1.getValue().equals(feature1.getProperties()));
+
+ assertNotNull(feature1.getUserData());
+ }
+ finally {
+ it.close();
+ ds.dispose();
}
-
- assertNotNull(feature1.getAttribute("CAT_ID"));
- assertNotNull(feature1.getAttribute(new NameImpl("CAT_ID")));
- assertTrue(feature1.getAttributeCount() == 4);
-
- assertFalse(feature1.equals(feature2));
- assertTrue(feature1.equals(feature1));
- assertFalse(feature1.hashCode() == feature2.hashCode());
- assertTrue(feature1.hashCode() == feature1.hashCode());
-
- assertFalse(feature1.getID().equals(feature2.getID()));
-
- assertTrue(feature1.getBounds().equals(feature1.getBounds()));
- assertFalse(feature1.getBounds().equals(feature2.getBounds()));
-
- assertTrue(feature1.getDefaultGeometry().equals(feature1.getDefaultGeometry()));
- assertFalse(feature1.getDefaultGeometry().equals(feature2.getDefaultGeometry()));
-
- assertTrue(feature1.getDefaultGeometryProperty().getName().getLocalPart()
- .equals("the_geom"));
- assertTrue(feature1.getDefaultGeometryProperty().getName().equals(
- feature2.getDefaultGeometryProperty().getName()));
- assertFalse(feature1.getDefaultGeometryProperty().equals(
- feature2.getDefaultGeometryProperty()));
-
- assertTrue(feature1.getFeatureType().equals(feature2.getFeatureType()));
- assertTrue(feature2.getFeatureType().getName().getLocalPart().equals("GenStreams"));
-
- assertTrue(feature1.getIdentifier().equals(feature1.getIdentifier()));
- assertFalse(feature1.getIdentifier().equals(feature2.getIdentifier()));
-
- assertTrue(feature1.getProperties().size() == 4);
- assertTrue(feature1.getProperty("CAT_ID").getValue()
- .equals(feature1.getAttribute("CAT_ID")));
- assertTrue(feature1.getProperty("the_geom").getValue().equals(
- feature1.getAttribute("the_geom")));
- // assertFalse(feature1.getProperty("CAT_ID").getValue().equals(feature2.getAttribute("CAT_ID"
- // )));
- assertFalse(feature1.getProperty("the_geom").getValue().equals(
- feature2.getAttribute("the_geom")));
-
- assertTrue(feature1.getProperties("CAT_ID").contains(feature1.getProperty("CAT_ID")));
- assertFalse(feature2.getProperties("the_geom").contains(feature1.getProperty("the_geom")));
-
- assertTrue(feature1.getProperties(new NameImpl("CAT_ID")).contains(
- feature1.getProperty("CAT_ID")));
- assertFalse(feature2.getProperties(new NameImpl("the_geom")).contains(
- feature1.getProperty("the_geom")));
-
- assertTrue(feature1.getType().equals(fCollection.getSchema()));
- assertTrue(feature1.getValue().equals(feature1.getProperties()));
-
- assertNotNull(feature1.getUserData());
- ds.dispose();
}
public void testUnsupported() {
@@ -147,96 +155,100 @@ public void testUnsupported() {
Assert.fail();
}
- Iterator<SimpleFeature> it = fCollection.iterator();
- SimpleFeature feature1 = it.next();
-
- assertTrue(feature1 instanceof PreGeneralizedSimpleFeature);
-
- boolean error;
-
- error = true;
- try {
- feature1.setAttribute(0, null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
- try {
- feature1.setAttribute("CAT_ID", null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
- try {
- feature1.setAttribute(new NameImpl("CAT_ID"), null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
- try {
- feature1.setAttributes((List<Object>) null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
+ SimpleFeatureIterator it = fCollection.features();
try {
- feature1.setAttributes(new Object[0]);
- } catch (UnsupportedOperationException ex) {
- error = false;
+ SimpleFeature feature1 = it.next();
+
+ assertTrue(feature1 instanceof PreGeneralizedSimpleFeature);
+
+ boolean error;
+
+ error = true;
+ try {
+ feature1.setAttribute(0, null);
+ } catch (UnsupportedOperationException ex) {
+ error = false;
+ }
+ if (error) {
+ Assert.fail();
+ }
+
+ try {
+ feature1.setAttribute("CAT_ID", null);
+ } catch (UnsupportedOperationException ex) {
+ error = false;
+ }
+ if (error) {
+ Assert.fail();
+ }
+
+ try {
+ feature1.setAttribute(new NameImpl("CAT_ID"), null);
+ } catch (UnsupportedOperationException ex) {
+ error = false;
+ }
+ if (error) {
+ Assert.fail();
+ }
+
+ try {
+ feature1.setAttributes((List<Object>) null);
+ } catch (UnsupportedOperationException ex) {
+ error = false;
+ }
+ if (error) {
+ Assert.fail();
+ }
+
+ try {
+ feature1.setAttributes(new Object[0]);
+ } catch (UnsupportedOperationException ex) {
+ error = false;
+ }
+ if (error) {
+ Assert.fail();
+ }
+
+ try {
+ feature1.setDefaultGeometry(null);
+ } catch (UnsupportedOperationException ex) {
+ error = false;
+ }
+ if (error) {
+ Assert.fail();
+ }
+
+ try {
+ feature1.setDefaultGeometryProperty(null);
+ } catch (UnsupportedOperationException ex) {
+ error = false;
+ }
+ if (error) {
+ Assert.fail();
+ }
+
+ try {
+ feature1.setValue((Collection<Property>) null);
+ } catch (UnsupportedOperationException ex) {
+ error = false;
+ }
+ if (error) {
+ Assert.fail();
+ }
+
+ try {
+ feature1.setValue((Object) null);
+ } catch (UnsupportedOperationException ex) {
+ error = false;
+ }
+ if (error) {
+ Assert.fail();
+ }
+ }
+ finally {
+ it.close();
+ ds.dispose();
}
- if (error) {
- Assert.fail();
- }
-
- try {
- feature1.setDefaultGeometry(null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
- try {
- feature1.setDefaultGeometryProperty(null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
- try {
- feature1.setValue((Collection<Property>) null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
- try {
- feature1.setValue((Object) null);
- } catch (UnsupportedOperationException ex) {
- error = false;
- }
- if (error) {
- Assert.fail();
- }
-
- ds.dispose();
}
}
View
22 modules/plugin/feature-pregeneralized/src/test/java/org/geotools/data/gen/TestSetup.java
@@ -24,12 +24,10 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.geotools.TestData;
-import org.geotools.data.DefaultQuery;
import org.geotools.data.DefaultRepository;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.FeatureReader;
@@ -41,6 +39,7 @@
import org.geotools.data.memory.MemoryDataStore;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.shapefile.ShapefileDataStoreFactory;
+import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.feature.NameImpl;
import org.geotools.feature.simple.SimpleFeatureBuilder;
@@ -110,7 +109,7 @@ static public void initialize() {
// StreamsFeatureSource = ds.getFeatureSource(typeName);
Transaction t = new DefaultTransaction();
- Query query = new DefaultQuery(typeName, Filter.INCLUDE);
+ Query query = new Query(typeName, Filter.INCLUDE);
FeatureReader<SimpleFeatureType, SimpleFeature> reader = ds.getFeatureReader(query, t);
while (reader.hasNext()) {
@@ -299,12 +298,17 @@ static private void createShapeFilePyramd() throws IOException {
FeatureWriter<SimpleFeatureType, SimpleFeature> writer = ds.getFeatureWriter(ds
.getTypeNames()[0], Transaction.AUTO_COMMIT);
- Iterator<SimpleFeature> it = fs.getFeatures().iterator();
- while (it.hasNext()) {
- SimpleFeature f = it.next();
- SimpleFeature fNew = writer.next();
- fNew.setAttributes(f.getAttributes());
- writer.write();
+ SimpleFeatureIterator it = fs.getFeatures().features();
+ try {
+ while (it.hasNext()) {
+ SimpleFeature f = it.next();
+ SimpleFeature fNew = writer.next();
+ fNew.setAttributes(f.getAttributes());
+ writer.write();
+ }
+ }
+ finally {
+ it.close();
}
writer.close();
ds.dispose();
Please sign in to comment.
Something went wrong with that request. Please try again.