File: GObject.java

package info (click to toggle)
lasso 2.4.1-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 25,856 kB
  • ctags: 14,480
  • sloc: ansic: 66,107; xml: 23,958; sh: 11,365; python: 7,474; makefile: 1,526; java: 444; php: 325; perl: 117
file content (49 lines) | stat: -rw-r--r-- 1,551 bytes parent folder | download | duplicates (7)
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
47
48
49
package com.entrouvert.lasso;
import java.util.*;

class GObject {
        private long cptr;

        protected GObject(long ptr) {
                if (ptr == 0) {
                    throw new RuntimeException("Error creating " + getClass().getName());
                }
                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);
        }
}