hellojava 0.0.2-java → 0.0.4-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/ext/hellojava/JavaCallTest.java +12 -0
- data/ext/hellojava/JavaCallTest2.java +20 -0
- data/lib/hellojava.rb +78 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85d5257583e5e4c9fe0f8cfdc6670731efc2c60a615f69c4f4aebb6cec3d072a
|
4
|
+
data.tar.gz: f52eaef3c17a67b13a7ba569f11a94ab06947073b22f82e753e2127bf653ad41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c7e85c556980fbdae896014869b9dd7e2cbe811ab2912fc40fd555c85d39e3a6b2063378df5ba4d798adc87948f4a40fc8220aa711c64784f5a263c802ef010
|
7
|
+
data.tar.gz: d6fc7296259986a9bb8e32205cdf1dcfc28b3160decb7da3ed1ffc10213a2c34e49bd8ba1d945f20fb6174b0d2ceafee53c29575547a486421a00953d4471164
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import java.util.ArrayList;
|
2
|
+
|
1
3
|
public class JavaCallTest {
|
2
4
|
public static String str1() {
|
3
5
|
return "str1";
|
@@ -5,5 +7,15 @@ public class JavaCallTest {
|
|
5
7
|
public String str2() {
|
6
8
|
return "str2";
|
7
9
|
}
|
10
|
+
public static void sub1(String fname, double[][] vals) {
|
11
|
+
System.out.printf("fname:%s size:%d\n", fname, vals.length);
|
12
|
+
for (int i = 0; i < vals.length; i++) {
|
13
|
+
System.out.printf("vals[%d] size:%d\n", i, vals[i].length);
|
14
|
+
for (int j = 0; j < vals[i].length; j++) {
|
15
|
+
System.out.printf(" %f", vals[i][j]);
|
16
|
+
}
|
17
|
+
System.out.println();
|
18
|
+
}
|
19
|
+
}
|
8
20
|
}
|
9
21
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import java.util.function.Function;
|
2
|
+
import java.util.function.Consumer;
|
3
|
+
import java.util.function.Predicate;
|
4
|
+
import java.util.function.Supplier;
|
5
|
+
|
6
|
+
public class JavaCallTest2 {
|
7
|
+
public static void funcType1(String str, Consumer<String> func) {
|
8
|
+
System.out.println("funcType1 in");
|
9
|
+
func.accept(str);
|
10
|
+
}
|
11
|
+
public static String funcType2(Supplier<String> func) {
|
12
|
+
System.out.println("funcType2 in");
|
13
|
+
return func.get();
|
14
|
+
}
|
15
|
+
public static double funcType3(double[] vals, Function<double[], Double> func) {
|
16
|
+
System.out.println("funcType3 in");
|
17
|
+
return func.apply(vals);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
data/lib/hellojava.rb
CHANGED
@@ -2,8 +2,10 @@ require 'java'
|
|
2
2
|
require 'hellojava.jar'
|
3
3
|
java_import 'java.lang.System'
|
4
4
|
java_import 'JavaCallTest'
|
5
|
+
java_import 'JavaCallTest2'
|
5
6
|
java_import 'Hoge'
|
6
7
|
|
8
|
+
# jrubyからjavaの呼び出し
|
7
9
|
module HelloJavaLib
|
8
10
|
# Systemクラス使用
|
9
11
|
#
|
@@ -38,10 +40,86 @@ module HelloJavaLib
|
|
38
40
|
p calc.add
|
39
41
|
return
|
40
42
|
end
|
43
|
+
# 引数に二次元配列の場合
|
44
|
+
#
|
45
|
+
# @overload func_d(fname, vals)
|
46
|
+
# @param [String] fname 文字列
|
47
|
+
# @param [Array] vals 二次元の配列(double[][])
|
48
|
+
# @return [void]
|
49
|
+
# @example
|
50
|
+
# vals = [
|
51
|
+
# [12.3, 22.5, 33.7, 44.6],
|
52
|
+
# [12.3, 22.5, 33.7, 44.6, 55.8],
|
53
|
+
# ]
|
54
|
+
# HelloJavaLib::func_d("fname.jpg", vals)
|
55
|
+
# =>
|
56
|
+
# fname:fname.jpg size:2
|
57
|
+
# vals[0] size:4
|
58
|
+
# 12.300000 22.500000 33.700000 44.600000
|
59
|
+
# vals[1] size:5
|
60
|
+
# 12.300000 22.500000 33.700000 44.600000 55.800000
|
61
|
+
def func_d(fname, vals)
|
62
|
+
JavaCallTest.sub1(
|
63
|
+
fname, vals.to_java(Java::double[])
|
64
|
+
);
|
65
|
+
return
|
66
|
+
end
|
67
|
+
# 引数に関数型の場合
|
68
|
+
class FuncTypes
|
69
|
+
class << self
|
70
|
+
# @overload func_type1(str, &func)
|
71
|
+
# @param [String] str 文字列
|
72
|
+
# @param [block] func 関数型(引数:文字列, 戻り値:なし)
|
73
|
+
# @return [void]
|
74
|
+
# @example
|
75
|
+
# HelloJavaLib::FuncTypes.func_type1("Hello") {|s|
|
76
|
+
# p s + "!!"
|
77
|
+
# next
|
78
|
+
# }
|
79
|
+
# =>
|
80
|
+
# funcType1 in
|
81
|
+
# "Hello!!"
|
82
|
+
def func_type1(str, &func)
|
83
|
+
JavaCallTest2.funcType1(str, func)
|
84
|
+
return
|
85
|
+
end
|
86
|
+
# @overload func_type2(&func)
|
87
|
+
# @param [block] func 関数型(引数:なし, 戻り値:文字列)
|
88
|
+
# @return [void]
|
89
|
+
# @example
|
90
|
+
# HelloJavaLib::FuncTypes.func_type2() {
|
91
|
+
# next "Hello"
|
92
|
+
# }
|
93
|
+
# =>
|
94
|
+
# funcType2 in
|
95
|
+
# "Hello"
|
96
|
+
def func_type2(&func)
|
97
|
+
p JavaCallTest2.funcType2(func)
|
98
|
+
return
|
99
|
+
end
|
100
|
+
# @overload func_type3(vals, &func)
|
101
|
+
# @param [Array] vals double型の配列(duble[])
|
102
|
+
# @param [block] func 関数型(引数:double[], 戻り値:double)
|
103
|
+
# @return [void]
|
104
|
+
# @example
|
105
|
+
# vals = [11, 22, 33, 44]
|
106
|
+
# HelloJavaLib::FuncTypes.func_type3(vals) {|xi|
|
107
|
+
# next xi.sum(0.0) / xi.length
|
108
|
+
# }
|
109
|
+
# =>
|
110
|
+
# funcType3 in
|
111
|
+
# 27.5
|
112
|
+
def func_type3(vals, &func)
|
113
|
+
p JavaCallTest2.funcType3(vals.to_java(Java::double), func)
|
114
|
+
return
|
115
|
+
end
|
41
116
|
|
117
|
+
end
|
118
|
+
end
|
42
119
|
module_function :func_a
|
43
120
|
module_function :func_b
|
44
121
|
module_function :func_c
|
122
|
+
module_function :func_d
|
45
123
|
|
46
124
|
end
|
47
125
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hellojava
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- siranovel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- ext/hellojava/Calc.java
|
65
65
|
- ext/hellojava/Hoge.java
|
66
66
|
- ext/hellojava/JavaCallTest.java
|
67
|
+
- ext/hellojava/JavaCallTest2.java
|
67
68
|
- lib/hellojava.rb
|
68
69
|
homepage: http://github.com/siranovel/stdy4act
|
69
70
|
licenses:
|