Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

QA check on FeatureCollection.accepts combined with utility method Da…

…taUtilities.visit( collection, visitor, progress )
  • Loading branch information...
commit a534e4507adb32d0b23481e47e235fe7224fd1b6 1 parent 9c9d5b7
Jody Garnett authored

Showing 18 changed files with 110 additions and 293 deletions. Show diff stats Hide diff stats

  1. 20  modules/extension/app-schema/app-schema/src/main/java/org/geotools/data/complex/MappingFeatureCollection.java
  2. 4  ...ension/app-schema/sample-data-access/src/main/java/org/geotools/data/SampleDataAccessFeatureCollection.java
  3. 12  modules/library/data/src/main/java/org/geotools/data/store/ContentFeatureSource.java
  4. 62  modules/library/main/src/main/java/org/geotools/data/DataUtilities.java
  5. 9  modules/library/main/src/main/java/org/geotools/data/collection/SpatialIndexFeatureCollection.java
  6. 23  modules/library/main/src/main/java/org/geotools/data/collection/TreeSetFeatureCollection.java
  7. 7  modules/library/main/src/main/java/org/geotools/data/memory/MemoryFeatureCollection.java
  8. 24  modules/library/main/src/main/java/org/geotools/data/store/DataFeatureCollection.java
  9. 26  modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureCollection.java
  10. 29  modules/library/main/src/main/java/org/geotools/feature/collection/AbstractFeatureCollection.java
  11. 23  modules/library/main/src/main/java/org/geotools/feature/collection/AdaptorFeatureCollection.java
  12. 25  modules/library/main/src/main/java/org/geotools/feature/collection/BaseFeatureCollection.java
  13. 28  modules/library/main/src/main/java/org/geotools/feature/collection/DecoratingFeatureCollection.java
  14. 27  modules/library/main/src/main/java/org/geotools/feature/collection/DecoratingSimpleFeatureCollection.java
  15. 23  modules/plugin/feature-pregeneralized/src/main/java/org/geotools/data/gen/PreGeneralizedFeatureCollection.java
  16. 4  modules/unsupported/geogit-versioned/src/main/java/org/geotools/data/geogit/GeoGitSimpleFeatureCollection.java
  17. 23  ...eogit-versioned/src/main/java/org/geotools/data/versioning/decorator/DefaultVersionedFeatureCollection.java
  18. 34  modules/unsupported/process-feature/src/main/java/org/geotools/process/vector/ProcessingCollection.java
20  ...es/extension/app-schema/app-schema/src/main/java/org/geotools/data/complex/MappingFeatureCollection.java
@@ -21,6 +21,7 @@
21 21
 import java.util.Collection;
22 22
 import java.util.Iterator;
23 23
 
  24
+import org.geotools.data.DataUtilities;
24 25
 import org.geotools.data.Query;
25 26
 import org.geotools.data.crs.ReprojectFeatureResults;
26 27
 import org.geotools.feature.CollectionListener;
@@ -78,24 +79,7 @@ public void setUnrolledFilter(Filter unrolledFilter) {
78 79
      *      org.opengis.util.ProgressListener)
79 80
      */
80 81
     public void accepts(FeatureVisitor visitor, ProgressListener progress) throws IOException {
81  
-        FeatureIterator iterator = null;
82  
-        if( progress == null ) progress = new NullProgressListener();
83  
-        try{
84  
-            progress.started();
85  
-            for( iterator = features(); !progress.isCanceled() && iterator.hasNext();){
86  
-                try {
87  
-                    Feature feature = iterator.next();
88  
-                    visitor.visit(feature);
89  
-                }
90  
-                catch( Exception erp ){
91  
-                    progress.exceptionOccurred( erp );
92  
-                }
93  
-            }            
94  
-        }
95  
-        finally {
96  
-            progress.complete();            
97  
-            iterator.close();
98  
-        }
  82
+        DataUtilities.visit(this, visitor, progress);
99 83
     }
100 84
 
101 85
     /**
4  ...ion/app-schema/sample-data-access/src/main/java/org/geotools/data/SampleDataAccessFeatureCollection.java
@@ -52,9 +52,7 @@
52 52
      *      org.opengis.util.ProgressListener)
53 53
      */
54 54
     public void accepts(FeatureVisitor visitor, ProgressListener progress) throws IOException {
55  
-        for (Feature feature : this) {
56  
-            visitor.visit(feature);
57  
-        }
  55
+        DataUtilities.visit(this, visitor, progress);
58 56
     }
59 57
 
60 58
     /**
12  modules/library/data/src/main/java/org/geotools/data/store/ContentFeatureSource.java
@@ -682,13 +682,21 @@ public void accepts( Query query, org.opengis.feature.FeatureVisitor visitor,
682 682
             float position = 0;
683 683
             progress.started();
684 684
             while( reader.hasNext() ){
  685
+                SimpleFeature feature = null;
685 686
                 if (size > 0) progress.progress( position++/size );
686 687
                 try {
687  
-                    SimpleFeature feature = reader.next();
  688
+                    feature = reader.next();
688 689
                     visitor.visit(feature);
689 690
                 }
690  
-                catch( Exception erp ){
  691
+                catch( IOException erp ){
691 692
                     progress.exceptionOccurred( erp );
  693
+                    throw erp;
  694
+                }
  695
+                catch( Exception unexpected ){
  696
+                    progress.exceptionOccurred( unexpected );
  697
+                    String fid = feature == null ? "feature" : feature.getIdentifier().toString();
  698
+                    throw new IOException("Problem visiting " + query.getTypeName() + " visiting " + fid
  699
+                            + ":" + unexpected, unexpected);
692 700
                 }
693 701
             }
694 702
         }
62  modules/library/main/src/main/java/org/geotools/data/DataUtilities.java
@@ -91,6 +91,7 @@
91 91
 import org.geotools.resources.i18n.ErrorKeys;
92 92
 import org.geotools.resources.i18n.Errors;
93 93
 import org.geotools.util.Converters;
  94
+import org.geotools.util.NullProgressListener;
94 95
 import org.geotools.util.Utilities;
95 96
 import org.opengis.coverage.grid.GridCoverage;
96 97
 import org.opengis.feature.Feature;
@@ -117,6 +118,7 @@
117 118
 import org.opengis.referencing.FactoryException;
118 119
 import org.opengis.referencing.ReferenceIdentifier;
119 120
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
  121
+import org.opengis.util.ProgressListener;
120 122
 
121 123
 import com.vividsolutions.jts.geom.Coordinate;
122 124
 import com.vividsolutions.jts.geom.Envelope;
@@ -2649,8 +2651,9 @@ static AttributeDescriptor createAttribute(String typeSpec) throws SchemaExcepti
2649 2651
     }
2650 2652
 
2651 2653
     /**
2652  
-     * Manually count the number of features from the provided FeatureIterator
2653  
-     * 
  2654
+     * Manually count the number of features from the provided FeatureIterator.
  2655
+     * This implementation is intended for FeatureCollection implementors and test case
  2656
+     * verification. Client code should always call {@link FeatureCollection#size()}
2654 2657
      * @param collection
2655 2658
      * @return number of featuers in feature collection
2656 2659
      */
@@ -2674,6 +2677,8 @@ public static int count( FeatureIterator<?> iterator) {
2674 2677
     /**
2675 2678
      * Manually count the number of features in a feature collection using using {@link FeatureCollection#features()}.
2676 2679
      * 
  2680
+     * This implementation is intended for FeatureCollection implementors and test case
  2681
+     * verification. Client code should always call {@link FeatureCollection#size()}
2677 2682
      * @param collection
2678 2683
      * @return number of featuers in feature collection
2679 2684
      */
@@ -2696,7 +2701,10 @@ public static int count(
2696 2701
         }
2697 2702
     }
2698 2703
     /**
2699  
-     * Manually calculate the bounds from the provided FeatureIteator
  2704
+     * Manually calculate the bounds from the provided FeatureIteator.
  2705
+     * This implementation is intended for FeatureCollection implementors and test case
  2706
+     * verification. Client code should always call {@link FeatureCollection#getBounds()}.
  2707
+     * 
2700 2708
      * @param iterator
2701 2709
      * @return
2702 2710
      */
@@ -2728,7 +2736,10 @@ public static ReferencedEnvelope bounds( FeatureIterator<?> iterator ){
2728 2736
     }
2729 2737
     /**
2730 2738
      * Manually calculates the bounds of a feature collection using {@link FeatureCollection#features()}.
2731  
-     * 
  2739
+     * <p>
  2740
+     * This implementation is intended for FeatureCollection implementors and test case
  2741
+     * verification. Client code should always call {@link FeatureCollection#getBounds()}.
  2742
+     *  
2732 2743
      * @param collection
2733 2744
      * @return bounds of features in feature collection
2734 2745
      */
@@ -2762,6 +2773,49 @@ public static ReferencedEnvelope bounds(
2762 2773
     }
2763 2774
 
2764 2775
     /**
  2776
+     * Manually visit each feature using {@link FeatureCollection#features()}.
  2777
+     * <p>
  2778
+     * This method is intended to assist FeatureCollection implementors, and used to verify test-case results. Client code should always call
  2779
+     * {@link FeatureCollection#accepts(FeatureVisitor, ProgressListener)}
  2780
+     * 
  2781
+     * @param collection
  2782
+     * @return bounds of features in feature collection
  2783
+     */
  2784
+    public static void visit(FeatureCollection<?, ?> collection, FeatureVisitor visitor,
  2785
+            ProgressListener progress) throws IOException {
  2786
+        FeatureIterator<?> iterator = null;
  2787
+        float size = progress != null ? collection.size() : 0;
  2788
+        if (progress == null) {
  2789
+            progress = new NullProgressListener();
  2790
+        }
  2791
+        try {
  2792
+            float position = 0;
  2793
+            progress.started();
  2794
+            iterator = collection.features();
  2795
+            while (!progress.isCanceled() && iterator.hasNext()) {
  2796
+                Feature feature = null;
  2797
+                try {
  2798
+                    feature = iterator.next();
  2799
+                    visitor.visit(feature);
  2800
+                    if (size > 0) {
  2801
+                        progress.progress(position++ / size);
  2802
+                    }
  2803
+                } catch (Exception erp) {
  2804
+                    progress.exceptionOccurred(erp);
  2805
+                    String fid = feature == null ? "feature" : feature.getIdentifier().toString();
  2806
+                    throw new IOException("Problem with " + collection.getID() + " visiting " + fid
  2807
+                            + ":" + erp, erp);
  2808
+                }
  2809
+            }
  2810
+        } finally {
  2811
+            progress.complete();
  2812
+            if (iterator != null) {
  2813
+                iterator.close();
  2814
+            }
  2815
+        }
  2816
+    }
  2817
+
  2818
+    /**
2765 2819
      * Changes the ending (e.g. ".sld") of a {@link URL}
2766 2820
      * 
2767 2821
      * @param url
9  modules/library/main/src/main/java/org/geotools/data/collection/SpatialIndexFeatureCollection.java
@@ -134,20 +134,27 @@ public void accepts(final FeatureVisitor visitor, ProgressListener listener) thr
134 134
         final ProgressListener progress = listener != null ? listener : new NullProgressListener();
135 135
         progress.started();
136 136
         final float size = (float) size();
  137
+        final IOException problem[] = new IOException[1];
137 138
         index.query(everything, new ItemVisitor() {
138 139
             float count = 0f;
139 140
 
140 141
             public void visitItem(Object item) {
  142
+                SimpleFeature feature = null;
141 143
                 try {
142  
-                    SimpleFeature feature = (SimpleFeature) item;
  144
+                    feature = (SimpleFeature) item;
143 145
                     visitor.visit(feature);
144 146
                 } catch (Throwable t) {
145 147
                     progress.exceptionOccurred(t);
  148
+                    String fid = feature == null ? "feature" : feature.getIdentifier().toString();
  149
+                    problem[0] = new IOException("Problem visiting " + fid + ":" + t, t);
146 150
                 } finally {
147 151
                     progress.progress(count / size);
148 152
                 }
149 153
             }
150 154
         });
  155
+        if( problem[0] != null ){
  156
+            throw problem[0];
  157
+        }
151 158
         progress.complete();
152 159
     }
153 160
 
23  modules/library/main/src/main/java/org/geotools/data/collection/TreeSetFeatureCollection.java
@@ -633,27 +633,8 @@ public SimpleFeatureCollection collection() throws IOException {
633 633
     }
634 634
 
635 635
     public void accepts(org.opengis.feature.FeatureVisitor visitor,
636  
-            org.opengis.util.ProgressListener progress) {
637  
-        Iterator iterator = null;
638  
-        if (progress == null)
639  
-            progress = new NullProgressListener();
640  
-        try {
641  
-            float size = size();
642  
-            float position = 0;
643  
-            progress.started();
644  
-            for (iterator = iterator(); !progress.isCanceled() && iterator.hasNext(); progress
645  
-                    .progress(position++ / size)) {
646  
-                try {
647  
-                    SimpleFeature feature = (SimpleFeature) iterator.next();
648  
-                    visitor.visit(feature);
649  
-                } catch (Exception erp) {
650  
-                    progress.exceptionOccurred(erp);
651  
-                }
652  
-            }
653  
-        } finally {
654  
-            progress.complete();
655  
-            close(iterator);
656  
-        }
  636
+            org.opengis.util.ProgressListener progress) throws IOException {
  637
+        DataUtilities.visit( this, visitor, progress );
657 638
     }
658 639
 
659 640
     /**
7  modules/library/main/src/main/java/org/geotools/data/memory/MemoryFeatureCollection.java
@@ -21,12 +21,11 @@
21 21
 import java.util.NoSuchElementException;
22 22
 import java.util.TreeMap;
23 23
 
  24
+import org.geotools.data.DataUtilities;
24 25
 import org.geotools.data.simple.SimpleFeatureIterator;
25 26
 import org.geotools.feature.collection.AbstractFeatureCollection;
26 27
 import org.geotools.feature.collection.RandomFeatureAccess;
27  
-import org.geotools.feature.visitor.BoundsVisitor;
28 28
 import org.geotools.geometry.jts.ReferencedEnvelope;
29  
-import org.geotools.util.NullProgressListener;
30 29
 import org.opengis.feature.simple.SimpleFeature;
31 30
 import org.opengis.feature.simple.SimpleFeatureType;
32 31
 
@@ -125,9 +124,7 @@ public SimpleFeature removeFeatureMember(String id) {
125 124
      */
126 125
     @Override
127 126
     public ReferencedEnvelope getBounds() {
128  
-        BoundsVisitor bounds = new BoundsVisitor();
129  
-        accepts(bounds, new NullProgressListener());
130  
-        return bounds.getBounds();
  127
+        return DataUtilities.bounds( features() );
131 128
     }
132 129
 
133 130
 	@Override
24  modules/library/main/src/main/java/org/geotools/data/store/DataFeatureCollection.java
@@ -27,6 +27,7 @@
27 27
 import java.util.logging.Level;
28 28
 import java.util.logging.Logger;
29 29
 
  30
+import org.geotools.data.DataUtilities;
30 31
 import org.geotools.data.FeatureReader;
31 32
 import org.geotools.data.FeatureWriter;
32 33
 import org.geotools.data.collection.DelegateFeatureReader;
@@ -453,27 +454,8 @@ public boolean retainAll( Collection arg0 ) {
453 454
     public void clear() {        
454 455
     }
455 456
     
456  
-    public void accepts(org.opengis.feature.FeatureVisitor visitor, org.opengis.util.ProgressListener progress) {
457  
-    	Iterator iterator = null;
458  
-        if (progress == null) progress = new NullProgressListener();
459  
-        try{
460  
-            float size = size();
461  
-            float position = 0;            
462  
-            progress.started();
463  
-        	for( iterator = iterator(); !progress.isCanceled() && iterator.hasNext(); progress.progress( 100.0f * position++ / size )){
464  
-                try {
465  
-                    SimpleFeature feature = (SimpleFeature) iterator.next();
466  
-                    visitor.visit(feature);
467  
-                }
468  
-                catch( Exception erp ){
469  
-                    progress.exceptionOccurred( erp );
470  
-                }
471  
-	        }            
472  
-        }
473  
-        finally {
474  
-            progress.complete();            
475  
-        	close( iterator );
476  
-        }
  457
+    public void accepts(org.opengis.feature.FeatureVisitor visitor, org.opengis.util.ProgressListener progress) throws IOException {
  458
+        DataUtilities.visit(this, visitor, progress);
477 459
     }
478 460
     
479 461
     /**
26  modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureCollection.java
@@ -30,6 +30,7 @@
30 30
 import java.util.logging.Logger;
31 31
 
32 32
 import org.geotools.data.DataSourceException;
  33
+import org.geotools.data.DataUtilities;
33 34
 import org.geotools.data.FeatureReader;
34 35
 import org.geotools.data.simple.SimpleFeatureCollection;
35 36
 import org.geotools.data.simple.SimpleFeatureIterator;
@@ -596,29 +597,8 @@ public Set fids() {
596 597
         return Collections.unmodifiableSet( contents.keySet() );
597 598
     }
598 599
 
599  
-    public void accepts(org.opengis.feature.FeatureVisitor visitor, org.opengis.util.ProgressListener progress) {
600  
-    	FeatureIterator<?> iterator = null;
601  
-        if (progress == null) progress = new NullProgressListener();
602  
-        try{
603  
-            float size = size();
604  
-            float position = 0;            
605  
-            progress.started();
606  
-            for( iterator = features(); !progress.isCanceled() && iterator.hasNext(); progress.progress( position++/size )){
607  
-                try {
608  
-                    SimpleFeature feature = (SimpleFeature) iterator.next();
609  
-                    visitor.visit(feature);
610  
-                }
611  
-                catch( Exception erp ){
612  
-                    progress.exceptionOccurred( erp );
613  
-                }
614  
-            }            
615  
-        }
616  
-        finally {
617  
-            progress.complete();
618  
-            if( iterator != null){
619  
-                iterator.close();
620  
-            }
621  
-        }	
  600
+    public void accepts(org.opengis.feature.FeatureVisitor visitor, org.opengis.util.ProgressListener progress) throws IOException {
  601
+        DataUtilities.visit(this, visitor, progress);	
622 602
     }
623 603
 
624 604
     /**
29  modules/library/main/src/main/java/org/geotools/feature/collection/AbstractFeatureCollection.java
@@ -16,14 +16,15 @@
16 16
  */
17 17
 package org.geotools.feature.collection;
18 18
 
  19
+import java.io.IOException;
19 20
 import java.util.Collection;
20 21
 import java.util.Iterator;
21 22
 
  23
+import org.geotools.data.DataUtilities;
22 24
 import org.geotools.data.simple.SimpleFeatureCollection;
23 25
 import org.geotools.data.simple.SimpleFeatureIterator;
24 26
 import org.geotools.feature.FeatureIterator;
25 27
 import org.geotools.geometry.jts.ReferencedEnvelope;
26  
-import org.geotools.util.NullProgressListener;
27 28
 import org.opengis.feature.simple.SimpleFeature;
28 29
 import org.opengis.feature.simple.SimpleFeatureType;
29 30
 import org.opengis.filter.Filter;
@@ -221,30 +222,8 @@ public boolean isEmpty() {
221 222
         }
222 223
     }
223 224
 
224  
-	public void accepts(org.opengis.feature.FeatureVisitor visitor, org.opengis.util.ProgressListener progress) {
225  
-    	Iterator<SimpleFeature> iterator = null;
226  
-    	if( progress == null ) progress = new NullProgressListener();
227  
-        try{
228  
-            float size = size();
229  
-            float position = 0;            
230  
-            progress.started();
231  
-            for( iterator = iterator(); !progress.isCanceled() && iterator.hasNext();){
232  
-                if (size > 0) progress.progress( position++/size );
233  
-                try {
234  
-                    SimpleFeature feature = (SimpleFeature) iterator.next();
235  
-                    visitor.visit(feature);
236  
-                }
237  
-                catch( Exception erp ){
238  
-                    progress.exceptionOccurred( erp );
239  
-                }
240  
-            }            
241  
-        }
242  
-        finally {
243  
-            progress.complete();
244  
-            if( iterator instanceof FeatureIterator){
245  
-        		((FeatureIterator<?>)iterator).close();
246  
-        	}
247  
-        }
  225
+    public void accepts(org.opengis.feature.FeatureVisitor visitor, org.opengis.util.ProgressListener progress) throws IOException {
  226
+        DataUtilities.visit(this, visitor, progress);
248 227
     }
249 228
     
250 229
     //
23  modules/library/main/src/main/java/org/geotools/feature/collection/AdaptorFeatureCollection.java
@@ -24,6 +24,7 @@
24 24
 import java.util.List;
25 25
 import java.util.Set;
26 26
 
  27
+import org.geotools.data.DataUtilities;
27 28
 import org.geotools.data.simple.SimpleFeatureCollection;
28 29
 import org.geotools.data.simple.SimpleFeatureIterator;
29 30
 import org.geotools.feature.CollectionListener;
@@ -87,27 +88,7 @@ public void closeIterator( SimpleFeatureIterator close ) {
87 88
      * @throws IOException 
88 89
      */
89 90
     public void accepts(FeatureVisitor visitor, ProgressListener progress ) throws IOException {
90  
-        Iterator<SimpleFeature> iterator = null;
91  
-        if( progress == null ) progress = new NullProgressListener();
92  
-        try{
93  
-            float size = size();
94  
-            float position = 0;            
95  
-            progress.started();
96  
-            for( iterator = iterator(); !progress.isCanceled() && iterator.hasNext();){
97  
-                if (size > 0) progress.progress( position++/size );
98  
-                try {
99  
-                    SimpleFeature feature = iterator.next();
100  
-                    visitor.visit(feature);
101  
-                }
102  
-                catch( Exception erp ){
103  
-                    progress.exceptionOccurred( erp );
104  
-                }
105  
-            }            
106  
-        }
107  
-        finally {
108  
-            progress.complete();            
109  
-            close( iterator );
110  
-        }
  91
+        DataUtilities.visit(this, visitor, progress);
111 92
     }
112 93
         
113 94
     //
25  modules/library/main/src/main/java/org/geotools/feature/collection/BaseFeatureCollection.java
@@ -198,30 +198,7 @@ public boolean isEmpty() {
198 198
 
199 199
     public void accepts(org.opengis.feature.FeatureVisitor visitor,
200 200
             org.opengis.util.ProgressListener progress) throws IOException {
201  
-        FeatureIterator<F> iterator = null;
202  
-        if (progress == null)
203  
-            progress = new NullProgressListener();
204  
-        try {
205  
-            float size = size();
206  
-            float position = 0;
207  
-            progress.started();
208  
-            for (iterator = features(); !progress.isCanceled() && iterator.hasNext();) {
209  
-                try {
210  
-                    Feature feature = (Feature) iterator.next();
211  
-                    visitor.visit(feature);
212  
-                } catch (Exception erp) {
213  
-                    progress.exceptionOccurred(erp);
214  
-                }
215  
-                if (size > 0){
216  
-                    progress.progress(position++ / size);
217  
-                }
218  
-            }
219  
-        } finally {
220  
-            progress.complete();
221  
-            if( iterator != null ){
222  
-                iterator.close();
223  
-            }
224  
-        }
  201
+        DataUtilities.visit(this, visitor, progress);
225 202
     }
226 203
 
227 204
     //
28  modules/library/main/src/main/java/org/geotools/feature/collection/DecoratingFeatureCollection.java
@@ -16,8 +16,10 @@
16 16
  */
17 17
 package org.geotools.feature.collection;
18 18
 
  19
+import java.io.IOException;
19 20
 import java.util.Collection;
20 21
 
  22
+import org.geotools.data.DataUtilities;
21 23
 import org.geotools.feature.FeatureCollection;
22 24
 import org.geotools.feature.FeatureIterator;
23 25
 import org.geotools.geometry.jts.ReferencedEnvelope;
@@ -50,30 +52,8 @@ protected DecoratingFeatureCollection(FeatureCollection<T, F> delegate) {
50 52
     }
51 53
 
52 54
     public void accepts(org.opengis.feature.FeatureVisitor visitor,
53  
-            org.opengis.util.ProgressListener progress) {
54  
-        FeatureIterator<F> it = features();
55  
-
56  
-        try {
57  
-            Exception exception = null;
58  
-            while (it.hasNext()) {
59  
-                try {
60  
-                    visitor.visit(it.next());
61  
-                } catch (Exception e) {
62  
-                    if (exception != null)
63  
-                        exception = e;
64  
-                }
65  
-            }
66  
-
67  
-            if (exception != null) {
68  
-                if (exception instanceof RuntimeException) {
69  
-                    throw (RuntimeException) exception;
70  
-                } else {
71  
-                    throw new RuntimeException(exception);
72  
-                }
73  
-            }
74  
-        } finally {
75  
-        	it.close();
76  
-        }
  55
+            org.opengis.util.ProgressListener progress) throws IOException {
  56
+        DataUtilities.visit(this, visitor, progress);
77 57
     }
78 58
     
79 59
     public boolean contains(Object o) {
27  modules/library/main/src/main/java/org/geotools/feature/collection/DecoratingSimpleFeatureCollection.java
@@ -16,6 +16,7 @@
16 16
  */
17 17
 package org.geotools.feature.collection;
18 18
 
  19
+import java.io.IOException;
19 20
 import java.util.Collection;
20 21
 
21 22
 import org.geotools.data.DataUtilities;
@@ -55,30 +56,8 @@ protected DecoratingSimpleFeatureCollection(SimpleFeatureCollection delegate) {
55 56
     }
56 57
 
57 58
     public void accepts(org.opengis.feature.FeatureVisitor visitor,
58  
-            org.opengis.util.ProgressListener progress) {
59  
-        SimpleFeatureIterator it = features();
60  
-
61  
-        try {
62  
-            Exception exception = null;
63  
-            while (it.hasNext()) {
64  
-                try {
65  
-                    visitor.visit(it.next());
66  
-                } catch (Exception e) {
67  
-                    if (exception != null)
68  
-                        exception = e;
69  
-                }
70  
-            }
71  
-
72  
-            if (exception != null) {
73  
-                if (exception instanceof RuntimeException) {
74  
-                    throw (RuntimeException) exception;
75  
-                } else {
76  
-                    throw new RuntimeException(exception);
77  
-                }
78  
-            }
79  
-        } finally {
80  
-            it.close();
81  
-        }
  59
+            org.opengis.util.ProgressListener progress) throws IOException {
  60
+        DataUtilities.visit(this, visitor, progress);
82 61
     }
83 62
     
84 63
 
23  ...s/plugin/feature-pregeneralized/src/main/java/org/geotools/data/gen/PreGeneralizedFeatureCollection.java
@@ -26,6 +26,7 @@
26 26
 import java.util.Iterator;
27 27
 import java.util.List;
28 28
 
  29
+import org.geotools.data.DataUtilities;
29 30
 import org.geotools.data.simple.SimpleFeatureCollection;
30 31
 import org.geotools.data.simple.SimpleFeatureIterator;
31 32
 import org.geotools.feature.CollectionListener;
@@ -82,27 +83,7 @@ public PreGeneralizedFeatureCollection(
82 83
      *      org.opengis.util.ProgressListener) Logic copied from DefaultFeatureCollection class
83 84
      */
84 85
     public void accepts(FeatureVisitor visitor, ProgressListener progress) throws IOException {
85  
-        SimpleFeatureIterator iterator = null;
86  
-        if (progress == null)
87  
-            progress = new NullProgressListener();
88  
-        try {
89  
-            float size = size();
90  
-            float position = 0;
91  
-            progress.started();
92  
-            
93  
-            for (iterator = features(); !progress.isCanceled() && iterator.hasNext(); progress
94  
-                    .progress(position++ / size)) {
95  
-                try {
96  
-                    SimpleFeature feature = (SimpleFeature) iterator.next();
97  
-                    visitor.visit(feature);
98  
-                } catch (Exception erp) {
99  
-                    progress.exceptionOccurred(erp);
100  
-                }
101  
-            }
102  
-        } finally {
103  
-            progress.complete();
104  
-            iterator.close();
105  
-        }
  86
+        DataUtilities.visit(this, visitor, progress);
106 87
     }
107 88
 
108 89
     public boolean contains(Object feature) {
4  ...s/unsupported/geogit-versioned/src/main/java/org/geotools/data/geogit/GeoGitSimpleFeatureCollection.java
@@ -31,6 +31,7 @@
31 31
 import org.geogit.storage.ObjectDatabase;
32 32
 import org.geogit.storage.ObjectReader;
33 33
 import org.geogit.storage.WrappedSerialisingFactory;
  34
+import org.geotools.data.DataUtilities;
34 35
 import org.geotools.data.simple.SimpleFeatureCollection;
35 36
 import org.geotools.data.simple.SimpleFeatureIterator;
36 37
 import org.geotools.factory.Hints;
@@ -448,8 +449,7 @@ protected SimpleFeature computeNext() {
448 449
     @Override
449 450
     public void accepts(FeatureVisitor visitor, ProgressListener progress)
450 451
             throws IOException {
451  
-        // TODO Auto-generated method stub
452  
-
  452
+        DataUtilities.visit(this, visitor, progress);
453 453
     }
454 454
 
455 455
     /**
23  ...it-versioned/src/main/java/org/geotools/data/versioning/decorator/DefaultVersionedFeatureCollection.java
@@ -319,27 +319,8 @@ public Set fids() {
319 319
         return Collections.unmodifiableSet( contents.keySet() );
320 320
     }
321 321
 
322  
-    public void accepts(org.opengis.feature.FeatureVisitor visitor, org.opengis.util.ProgressListener progress) {
323  
-        FeatureIterator<SimpleFeature> iterator = null;
324  
-        if (progress == null) progress = new NullProgressListener();
325  
-        try{
326  
-            float size = size();
327  
-            float position = 0;            
328  
-            progress.started();
329  
-            for( iterator = features(); !progress.isCanceled() && iterator.hasNext(); progress.progress( position++/size )){
330  
-                try {
331  
-                    SimpleFeature feature = (SimpleFeature) iterator.next();
332  
-                    visitor.visit(feature);
333  
-                }
334  
-                catch( Exception erp ){
335  
-                    progress.exceptionOccurred( erp );
336  
-                }
337  
-            }            
338  
-        }
339  
-        finally {
340  
-            progress.complete();  
341  
-            iterator.close();
342  
-        }       
  322
+    public void accepts(org.opengis.feature.FeatureVisitor visitor, org.opengis.util.ProgressListener progress) throws IOException {
  323
+        DataUtilities.visit(this, visitor, progress);       
343 324
     }
344 325
 
345 326
     /**
34  modules/unsupported/process-feature/src/main/java/org/geotools/process/vector/ProcessingCollection.java
@@ -63,39 +63,7 @@ public ProcessingCollection() {
63 63
      */
64 64
     @Override
65 65
     public abstract FeatureIterator<F> features();
66  
-
67  
-    @Override
68  
-    public void accepts(FeatureVisitor visitor, ProgressListener progress) throws IOException {
69  
-        FeatureIterator<F> iterator = null;
70  
-        float size = progress != null ? size() : 0;
71  
-        if (progress == null) {
72  
-            progress = new NullProgressListener();
73  
-        }
74  
-        try {
75  
-            float position = 0;
76  
-            progress.started();
77  
-            iterator = features();
78  
-            while (!progress.isCanceled() && iterator.hasNext()) {
79  
-                try {
80  
-                    F feature = iterator.next();
81  
-                    visitor.visit(feature);
82  
-                    if (size > 0) {
83  
-                        progress.progress(position++ / size);
84  
-                    }
85  
-                } catch (Exception erp) {
86  
-                    progress.exceptionOccurred(erp);
87  
-                    throw new IOException("Error occurred while iterating over features", erp);
88  
-                }
89  
-            }
90  
-        } finally {
91  
-            progress.complete();
92  
-            if( iterator != null ){
93  
-            	iterator.close();
94  
-            }
95  
-        }
96  
-
97  
-    }
98  
-
  66
+    
99 67
     /**
100 68
      * The bounds of features in the output. If the bounds are not known in advance once can call the
101 69
      * getFeatureBounds() which will build it from the features as they are returned from the feature

0 notes on commit a534e45

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