3e230461c4d53340b8f4b789c7736d8fdcbb63b9
[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_int;
5 import org.yaz4j.jni.yaz4jlib;
6
7 public class ScanSet
8 {
9         private SWIGTYPE_p_ZOOM_scanset_p scanSet = null ;
10         private Connection connection;
11         private boolean disposed = false;
12         
13         ScanSet(SWIGTYPE_p_ZOOM_scanset_p scanSet, Connection connection)
14         {
15                 this.connection = connection;
16                 this.scanSet = scanSet;
17         }
18
19         public void finalize()
20         {
21                 Dispose();
22         }
23
24         public ScanTerm get(long index)
25         {
26                 SWIGTYPE_p_int occ = yaz4jlib.new_intp();
27                 SWIGTYPE_p_int length = yaz4jlib.new_intp();
28                 String term = yaz4jlib.ZOOM_scanset_term( scanSet, (long)index, occ, length ) ;
29                 int occurences = yaz4jlib.intp_value(occ);
30                 yaz4jlib.delete_intp(occ);
31                 yaz4jlib.delete_intp(length);
32                 return new ScanTerm(term, occurences);
33         }
34
35         public long getSize()
36         {
37                 return yaz4jlib.ZOOM_scanset_size(scanSet);
38         }
39
40         public void Dispose()
41         {
42                 if (! disposed)
43                 {
44                         yaz4jlib.ZOOM_scanset_destroy(scanSet);
45                         connection = null;
46                         scanSet = null;
47                         disposed = true;
48                 }
49         }
50 }