1 | import java.util.*;
|
---|
2 |
|
---|
3 | public class Test {
|
---|
4 |
|
---|
5 | int myint = 123;
|
---|
6 | double mydouble = 3.14159265;
|
---|
7 | String mystring = "my string";
|
---|
8 | static String ourstring = "our string";
|
---|
9 | static boolean embedded = false;
|
---|
10 | int array[] = {1,2,3};
|
---|
11 | Vector v;
|
---|
12 |
|
---|
13 | public Test() {
|
---|
14 |
|
---|
15 |
|
---|
16 | v = new Vector();
|
---|
17 | v.addElement("Hello");
|
---|
18 | printfields();
|
---|
19 | Vector x = perlTryVec(v);
|
---|
20 | x.addElement("World");
|
---|
21 | Vector y = perlTryVec(x);
|
---|
22 | if (!embedded) System.err.println("Thank you, perlTryVec!");
|
---|
23 |
|
---|
24 | if (!embedded) System.err.println(retchars());
|
---|
25 | if (!embedded) System.err.println("Thank you, retchars!");
|
---|
26 |
|
---|
27 | String[] s = retstrings();
|
---|
28 | if (!embedded) System.err.println(s[0] + s[1] + s[2] + s[3]);
|
---|
29 | if (!embedded) System.err.println("Thank you, retstrings!");
|
---|
30 |
|
---|
31 | Object[] o = retobjects(v, x, y);
|
---|
32 | if (!embedded) System.err.println(o[1]);
|
---|
33 | if (!embedded) System.err.println(o[3]);
|
---|
34 | if (!embedded) System.err.println(o[4]);
|
---|
35 | if (!embedded) System.err.println("Thank you, retobjects!");
|
---|
36 |
|
---|
37 | passarray(s);
|
---|
38 |
|
---|
39 | if (!embedded) System.err.println(s[0] + s[1] + s[2] + s[3]);
|
---|
40 | if (!embedded) System.err.println("Thank you, passarray!");
|
---|
41 |
|
---|
42 | printfields();
|
---|
43 | if (!embedded) System.err.println("Thank you, printfields!");
|
---|
44 | setfields();
|
---|
45 | if (!embedded) System.err.println("Thank you, setfields!");
|
---|
46 | printfields();
|
---|
47 | if (!embedded) System.err.println("Thank you, printfields!");
|
---|
48 | }
|
---|
49 |
|
---|
50 | perl Vector perlTryVec(Vector v) throws RuntimeException {{
|
---|
51 | print "v is: $v\n";
|
---|
52 | print "v isa: ", ref $v,"\n";
|
---|
53 |
|
---|
54 | print "In perlTryVec() - Vector size is: ", $v->size([],['int']), "\n";
|
---|
55 | @foo = times;
|
---|
56 | $size ||= getmeth('size', [], ['int']);
|
---|
57 | for ($i = 10000; $i; --$i) {
|
---|
58 | $x = $v->$size();
|
---|
59 | }
|
---|
60 | @bar = times;
|
---|
61 | printf "%5.2fu %5.2fs\n", $bar[0] - $foo[0], $bar[1] - $foo[1];
|
---|
62 | return $v;
|
---|
63 | }}
|
---|
64 |
|
---|
65 | perl char[] retchars() {{
|
---|
66 | print "In retchars()\n";
|
---|
67 | return [65,66,67];
|
---|
68 | }}
|
---|
69 |
|
---|
70 | perl String[] retstrings() {{
|
---|
71 | print "In retstrings()\n";
|
---|
72 | return [1,2,3,"many"];
|
---|
73 | }}
|
---|
74 |
|
---|
75 | perl Object[] retobjects(Vector v, Vector x, Vector y) {{
|
---|
76 | print "In retstrings()\n";
|
---|
77 | return [$v, $x, $y, "this is only a test", 123];
|
---|
78 | }}
|
---|
79 |
|
---|
80 | perl void passarray(String[] s) {{
|
---|
81 | print "In passarray()\n";
|
---|
82 | print "s = $s\n";
|
---|
83 | $t = GetObjectArrayElement($s,3);
|
---|
84 | print "t = $t\n";
|
---|
85 | $x = GetStringUTFChars($t);
|
---|
86 | print "$x\n";
|
---|
87 | $t = SetObjectArrayElement($s,3,NewStringUTF("infinity"));
|
---|
88 | }}
|
---|
89 |
|
---|
90 | perl void printfields() {{
|
---|
91 |
|
---|
92 | $| = 1;
|
---|
93 | eval {print $self->v->toString____s(), "\n";};
|
---|
94 | print $@ if $@;
|
---|
95 |
|
---|
96 | print $self->myint, "\n";
|
---|
97 | print $self->mydouble, "\n";
|
---|
98 | print $self->mystring, "\n";
|
---|
99 | print JPL::Test->ourstring, "\n";
|
---|
100 |
|
---|
101 | @nums = GetIntArrayElements($self->array());
|
---|
102 | print "@nums\n";
|
---|
103 |
|
---|
104 | @nums = unpack("i*", scalar GetIntArrayElements($self->array()));
|
---|
105 | print "@nums\n";
|
---|
106 | }}
|
---|
107 |
|
---|
108 | perl void setfields() {{
|
---|
109 | $self->myint(321);
|
---|
110 | $self->mydouble(2.7182918);
|
---|
111 | $self->mystring("MY STRING!!!");
|
---|
112 | JPL::Test->ourstring("OUR STRING!!!");
|
---|
113 | }}
|
---|
114 |
|
---|
115 | public static void main(String[] argv) {
|
---|
116 | if (java.lang.reflect.Array.getLength(argv) > 0 &&
|
---|
117 | argv[0].equals("-nothanks"))
|
---|
118 | embedded = true;
|
---|
119 | Test f = new Test();
|
---|
120 | if (!embedded) System.err.println("Thank you, Test!");
|
---|
121 | }
|
---|
122 | }
|
---|