01: package org.geotools.data.store;
02:
03: import java.util.Iterator;
04:
05: /**
06: * Iterator wrapper which caps the number of returned features;
07: *
08: * @author Justin Deoliveira, The Open Planning Project
09: *
10: */
11: public class MaxFeaturesIterator implements Iterator {
12:
13: Iterator delegate;
14: long max;
15: long counter;
16:
17: public MaxFeaturesIterator(Iterator delegate, long max) {
18: this .delegate = delegate;
19: this .max = max;
20: counter = 0;
21: }
22:
23: public Iterator getDelegate() {
24: return delegate;
25: }
26:
27: public void remove() {
28: delegate.remove();
29: }
30:
31: public boolean hasNext() {
32: return delegate.hasNext() && counter < max;
33: }
34:
35: public Object next() {
36: if (counter++ <= max) {
37: return delegate.next();
38: }
39:
40: return null;
41: }
42:
43: }
|