3eaea9495c1e43035032fa7860a81843fda3fffa
[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     //for GC ref-count
9     private Connection conn;
10     private SWIGTYPE_p_ZOOM_scanset_p scanSet;
11     private boolean disposed = false;
12
13     ScanSet(SWIGTYPE_p_ZOOM_scanset_p scanSet, Connection conn) {
14         this.scanSet = scanSet;
15         this.conn = conn;
16     }
17
18     public void finalize() {
19         _dispose();
20     }
21
22     public ScanTerm get(long index) {
23         SWIGTYPE_p_size_t occ = yaz4jlib.new_size_tp();
24         SWIGTYPE_p_size_t length = yaz4jlib.new_size_tp();
25         String term = yaz4jlib.ZOOM_scanset_term(scanSet, (long) index, occ, length);
26         long occurences = yaz4jlib.size_tp_value(occ);
27         yaz4jlib.delete_size_tp(occ);
28         yaz4jlib.delete_size_tp(length);
29         return new ScanTerm(term, occurences);
30     }
31
32     public long getSize() {
33         return yaz4jlib.ZOOM_scanset_size(scanSet);
34     }
35
36     void _dispose() {
37         if (!disposed) {
38             yaz4jlib.ZOOM_scanset_destroy(scanSet);
39             scanSet = null;
40             conn = null;
41             disposed = true;
42         }
43     }
44 }