blob: a7815a72c6db3ae810368a37a05fea16568e3fbb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package com.entrouvert.lasso;
import java.util.*;
class GObject {
private long cptr;
protected GObject(long ptr) {
cptr = ptr;
}
protected Map arrayToMap(Object[] arr) {
Map map = new HashMap();
if (arr == null)
return map;
if (arr.length % 2 != 0)
throw new IllegalArgumentException("arr must of an even size");
int i;
for (i=0;i<arr.length;i+=2) {
map.put(arr[i],arr[i+1]);
}
return map;
}
protected void mapToArray(Map map, Object[] arr) {
int s = map.size();
if (map == null)
return;
Iterator it;
it = map.entrySet().iterator();
int i = 0;
while (it.hasNext() && i < 2*s) {
Map.Entry e = (Map.Entry)it.next();
arr[i++] = (Object)e.getKey();
arr[i++] = (Object)e.getValue();
}
}
protected void listToArray(List list, Object[] arr) {
Iterator it = list.iterator();
int s = arr.length;
int i = 0;
while (it.hasNext() && i < s) {
arr[i++] = (Object)it.next();
}
}
protected void finalize() throws Throwable {
LassoJNI.destroy(cptr);
}
}
|