2ba8dd7bdfb45fa17c979d1bf36354f6dd75a99f
[yaz4j-moved-to-github.git] / src / main / java / org / yaz4j / ScanSet.java
1 package org.yaz4j;
2
3 import org.yaz4j.jni.SWIGTYPE_p_ZOOM_scanset_p;
4 import org.yaz4j.jni.SWIGTYPE_p_size_t;
5 import org.yaz4j.jni.yaz4jlib;
6
7 public class ScanSet {
8
9   //for GC ref-count
10   private Connection conn;
11   private SWIGTYPE_p_ZOOM_scanset_p scanSet;
12   private boolean disposed = false;
13
14   ScanSet(SWIGTYPE_p_ZOOM_scanset_p scanSet, Connection conn) {
15     this.scanSet = scanSet;
16     this.conn = conn;
17   }
18
19   public void finalize() {
20     _dispose();
21   }
22
23   public ScanTerm get(long index) {
24     SWIGTYPE_p_size_t occ = yaz4jlib.new_size_tp();
25     SWIGTYPE_p_size_t length = yaz4jlib.new_size_tp();
26     String term = yaz4jlib.ZOOM_scanset_term(scanSet, (long) index, occ, length);
27     long occurences = yaz4jlib.size_tp_value(occ);
28     yaz4jlib.delete_size_tp(occ);
29     yaz4jlib.delete_size_tp(length);
30     return new ScanTerm(term, occurences);
31   }
32
33   public long getSize() {
34     return yaz4jlib.ZOOM_scanset_size(scanSet);
35   }
36
37   void _dispose() {
38     if (!disposed) {
39       yaz4jlib.ZOOM_scanset_destroy(scanSet);
40       scanSet = null;
41       conn = null;
42       disposed = true;
43     }
44   }
45 }