- private SWIGTYPE_p_ZOOM_scanset_p scanSet = null;
- private Connection connection;
- private boolean disposed = false;
+ //for GC ref-count
+ private Connection conn;
+ private SWIGTYPE_p_ZOOM_scanset_p scanSet;
+ private boolean disposed = false;
+ private long size = 0;
- ScanSet(SWIGTYPE_p_ZOOM_scanset_p scanSet, Connection connection) {
- this.connection = connection;
- this.scanSet = scanSet;
- }
+ ScanSet(SWIGTYPE_p_ZOOM_scanset_p scanSet, Connection conn) {
+ this.scanSet = scanSet;
+ size = yaz4jlib.ZOOM_scanset_size(scanSet);
+ this.conn = conn;
+ }
- public ScanTerm get(long index) {
- SWIGTYPE_p_size_t occ = yaz4jlib.new_size_tp();
- SWIGTYPE_p_size_t length = yaz4jlib.new_size_tp();
- String term = yaz4jlib.ZOOM_scanset_term(scanSet, (long) index, occ, length);
- long occurences = yaz4jlib.size_tp_value(occ);
- yaz4jlib.delete_size_tp(occ);
- yaz4jlib.delete_size_tp(length);
- return new ScanTerm(term, occurences);
- }
+ public ScanTerm get(long index) {
+ SWIGTYPE_p_size_t occ = yaz4jlib.new_size_tp();
+ SWIGTYPE_p_size_t length = yaz4jlib.new_size_tp();
+ String term = yaz4jlib.ZOOM_scanset_term(scanSet, (long) index, occ, length);
+ long occurences = yaz4jlib.size_tp_value(occ);
+ yaz4jlib.delete_size_tp(occ);
+ yaz4jlib.delete_size_tp(length);
+ return new ScanTerm(term, occurences);
+ }
+ }
+
+ @Override
+ public Iterator<ScanTerm> iterator() {
+ return new Iterator<ScanTerm>() {
+ private long cur;
+ @Override
+ public boolean hasNext() {
+ return cur < size;
+ }
+
+ @Override
+ public ScanTerm next() {
+ return get(cur++);
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("remove operation not supported");
+ }
+ };
+ }