@Test public void testCanceled() throws Exception { DefaultProgressListener listener = new DefaultProgressListener(); listener.setCanceled(true); MarkFeatureIterator iterator = MarkFeatureIterator.create(zroads.getFeatures(), 1000, listener); assertNull(iterator); }
public static MarkFeatureIterator create( FeatureCollection fc, int maxFeaturesInMemory, ProgressListener listener) throws IOException { List<Feature> features = new ArrayList<>(); int count = 0; if (listener == null) { listener = new DefaultProgressListener(); } try (FeatureIterator fi = fc.features()) { while (fi.hasNext()) { if (listener.isCanceled()) { return null; } Feature f = fi.next(); features.add(f); count++; if (count >= maxFeaturesInMemory) { if (fc.getSchema() instanceof SimpleFeatureType) { return new DiskMarkFeatureIterator( features, fi, (SimpleFeatureType) fc.getSchema(), listener); } else { throw new IllegalArgumentException( "Cannot offload to disk complex features " + "and reached the max number of feature in memory: " + maxFeaturesInMemory); } } } return new MemoryMarkFeatureIterator(features); } }
MarkFeatureIterator implements FeatureIterator<Feature> { public static MarkFeatureIterator create( FeatureCollection fc, int maxFeaturesInMemory, ProgressListener listener) throws IOException { List<Feature> features = new ArrayList<>(); int count = 0; if (listener == null) { listener = new DefaultProgressListener(); } try (FeatureIterator fi = fc.features()) { while (fi.hasNext()) { if (listener.isCanceled()) { return null; } Feature f = fi.next(); features.add(f); count++; if (count >= maxFeaturesInMemory) { if (fc.getSchema() instanceof SimpleFeatureType) { return new DiskMarkFeatureIterator( features, fi, (SimpleFeatureType) fc.getSchema(), listener); } else { throw new IllegalArgumentException( "Cannot offload to disk complex features " + "and reached the max number of feature in memory: " + maxFeaturesInMemory); } } } return new MemoryMarkFeatureIterator(features); } } }
MarkFeatureIterator implements FeatureIterator<Feature> { public static MarkFeatureIterator create( FeatureCollection fc, int maxFeaturesInMemory, ProgressListener listener) throws IOException { List<Feature> features = new ArrayList<>(); int count = 0; if (listener == null) { listener = new DefaultProgressListener(); } try (FeatureIterator fi = fc.features()) { while (fi.hasNext()) { if (listener.isCanceled()) { return null; } Feature f = fi.next(); features.add(f); count++; if (count >= maxFeaturesInMemory) { if (fc.getSchema() instanceof SimpleFeatureType) { return new DiskMarkFeatureIterator( features, fi, (SimpleFeatureType) fc.getSchema(), listener); } else { throw new IllegalArgumentException( "Cannot offload to disk complex features " + "and reached the max number of feature in memory: " + maxFeaturesInMemory); } } } return new MemoryMarkFeatureIterator(features); } }  }
MarkFeatureIterator implements FeatureIterator<Feature> { public static MarkFeatureIterator create( FeatureCollection fc, int maxFeaturesInMemory, ProgressListener listener) throws IOException { List<Feature> features = new ArrayList<>(); int count = 0; if (listener == null) { listener = new DefaultProgressListener(); } try (FeatureIterator fi = fc.features()) { while (fi.hasNext()) { if (listener.isCanceled()) { return null; } Feature f = fi.next(); features.add(f); count++; if (count >= maxFeaturesInMemory) { if (fc.getSchema() instanceof SimpleFeatureType) { return new DiskMarkFeatureIterator( features, fi, (SimpleFeatureType) fc.getSchema(), listener); } else { throw new IllegalArgumentException( "Cannot offload to disk complex features " + "and reached the max number of feature in memory: " + maxFeaturesInMemory); } } } return new MemoryMarkFeatureIterator(features); } }  static MarkFeatureIterator create(
            FeatureCollection fc, int maxFeaturesInMemory, ProgressListener listener); abstract void mark(); abstract void reset(); }
MarkFeatureIterator implements FeatureIterator<Feature> { public static MarkFeatureIterator create( FeatureCollection fc, int maxFeaturesInMemory, ProgressListener listener) throws IOException { List<Feature> features = new ArrayList<>(); int count = 0; if (listener == null) { listener = new DefaultProgressListener(); } try (FeatureIterator fi = fc.features()) { while (fi.hasNext()) { if (listener.isCanceled()) { return null; } Feature f = fi.next(); features.add(f); count++; if (count >= maxFeaturesInMemory) { if (fc.getSchema() instanceof SimpleFeatureType) { return new DiskMarkFeatureIterator( features, fi, (SimpleFeatureType) fc.getSchema(), listener); } else { throw new IllegalArgumentException( "Cannot offload to disk complex features " + "and reached the max number of feature in memory: " + maxFeaturesInMemory); } } } return new MemoryMarkFeatureIterator(features); } }  static MarkFeatureIterator create(
            FeatureCollection fc, int maxFeaturesInMemory, ProgressListener listener); abstract void mark(); abstract void reset();  }