hellojava 0.0.3-java → 0.0.5-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cffd381d1e1109af675b8cb94187962e67b6dbf3ea6042eb97b5a9f073eb3ec
4
- data.tar.gz: 46b0dd75a091b2102b8749a13b9875d9cc6ca0dbb5de8e8a29c14d9c983bff75
3
+ metadata.gz: cd8720bbd199d2a6550935f31fcb287c4a34c56989c37423e21b75e0a2c105fc
4
+ data.tar.gz: c7d9b01cfc2c859b8b22d2ee96d1a0aa4104bec9426d12c9d771aa9cb995235b
5
5
  SHA512:
6
- metadata.gz: 38a4c1b06b61727bd80a75ef5304acbc07f3fd97f3cfd3ab18172e8d7386fe56d44e919dd0b02e25eac5525a600bf0f4ee39db60fbb406b0f72b55798c0edd63
7
- data.tar.gz: 564535daf02d2b576adcd9a7af2baa000d0226b2ac1368bc2676a799bb8e07271e1a047c7d5e53c87d0cca1ff7dc0f12a9cebaa1ee4a22378d7dbe34f96abb22
6
+ metadata.gz: 97a9371b1ea24d09271d19ea2e3a3d89c170a997370ef1c0e52dbcb653f0b316113b1b9e6990f318871f99be6d83f4a9e4fb16fe31980117a412f7383b3dc440
7
+ data.tar.gz: d51e36fb15912e52fa54d3859b1e826f9470833eec0b422a887c8f49ef262451ddbed1d86ccd7725ccb66cb389607c55eb410068ca04d3d5c081f5e1c6bf3487
data/CHANGELOG.md CHANGED
@@ -2,10 +2,23 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.0.5] - 2023-12-31
6
+
7
+ ### Added
8
+ - Add parameter test of Hash Type.
9
+
10
+ ### change
11
+ - chg function name from func_d to func_v.
12
+
13
+ ## [0.0.4] - 2023-11-03
14
+
15
+ ### Added
16
+ - Add parameter test of function type.
17
+
5
18
  ## [0.0.3] - 2023-10-21
6
19
 
7
20
  ### Added
8
- - Add test parameter of A two-dimensional array
21
+ - Add parameter test of A two-dimensional array.
9
22
 
10
23
  ## [0.0.2] - 2023-09-27
11
24
 
@@ -1,4 +1,5 @@
1
1
  import java.util.ArrayList;
2
+ import java.util.Map;
2
3
 
3
4
  public class JavaCallTest {
4
5
  public static String str1() {
@@ -16,6 +17,17 @@ public class JavaCallTest {
16
17
  }
17
18
  System.out.println();
18
19
  }
19
- }
20
+ }
21
+ public static void hash(Map<String, double[]> vals) {
22
+ System.out.println("hash in");
23
+ for(Map.Entry<String, double[]> entry : vals.entrySet()) {
24
+ System.out.print(entry.getKey());
25
+ double[] v = entry.getValue();
26
+ for(int i = 0; i < v.length; i++) {
27
+ System.out.printf(" %f", v[i]);
28
+ }
29
+ System.out.println();
30
+ }
31
+ }
20
32
  }
21
33
 
@@ -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,11 @@ 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'
7
+ java_import 'java.util.HashMap'
6
8
 
9
+ # jrubyからjavaの呼び出し
7
10
  module HelloJavaLib
8
11
  # Systemクラス使用
9
12
  #
@@ -40,7 +43,7 @@ module HelloJavaLib
40
43
  end
41
44
  # 引数に二次元配列の場合
42
45
  #
43
- # @overload func_d(fname, vals)
46
+ # @overload func_v(fname, vals)
44
47
  # @param [String] fname 文字列
45
48
  # @param [Array] vals 二次元の配列(double[][])
46
49
  # @return [void]
@@ -49,23 +52,97 @@ module HelloJavaLib
49
52
  # [12.3, 22.5, 33.7, 44.6],
50
53
  # [12.3, 22.5, 33.7, 44.6, 55.8],
51
54
  # ]
52
- # HelloJavaLib::func_d("fname.jpg", vals)
55
+ # HelloJavaLib::func_v("fname.jpg", vals)
53
56
  # =>
54
57
  # fname:fname.jpg size:2
55
58
  # vals[0] size:4
56
59
  # 12.300000 22.500000 33.700000 44.600000
57
60
  # vals[1] size:5
58
61
  # 12.300000 22.500000 33.700000 44.600000 55.800000
59
- def func_d(fname, vals)
60
- p JavaCallTest.sub1(
62
+ def func_v(fname, vals)
63
+ JavaCallTest.sub1(
61
64
  fname, vals.to_java(Java::double[])
62
65
  );
63
66
  return
64
67
  end
68
+ # 引数にHashの場合
69
+ #
70
+ # @overload func_h(vals)
71
+ # @param [Hash] vals Hash(String, double[])
72
+ # @return [void]
73
+ # @example
74
+ # vals = {
75
+ # "dt1" => [12.3, 22.5, 33.7, 44.6],
76
+ # "dt2" => [12.3, 22.5, 33.7, 44.6, 55.8],
77
+ # }
78
+ # HelloJavaLib::func_h(vals)
79
+ # =>
80
+ # hash in
81
+ # dt1 12.300000 22.500000 33.700000 44.600000
82
+ # dt2 12.300000 22.500000 33.700000 44.600000 55.800000
83
+ def func_h(vals)
84
+ o = HashMap.new
85
+ vals.each{|k, v|
86
+ o[k] = v.to_java(Java::double)
87
+ }
88
+ JavaCallTest.hash(o)
89
+ end
90
+ # 引数に関数型の場合
91
+ class FuncTypes
92
+ class << self
93
+ # @overload func_type1(str, &func)
94
+ # @param [String] str 文字列
95
+ # @param [block] func 関数型(引数:文字列, 戻り値:なし)
96
+ # @return [void]
97
+ # @example
98
+ # HelloJavaLib::FuncTypes.func_type1("Hello") {|s|
99
+ # p s + "!!"
100
+ # next
101
+ # }
102
+ # =>
103
+ # funcType1 in
104
+ # "Hello!!"
105
+ def func_type1(str, &func)
106
+ JavaCallTest2.funcType1(str, func)
107
+ return
108
+ end
109
+ # @overload func_type2(&func)
110
+ # @param [block] func 関数型(引数:なし, 戻り値:文字列)
111
+ # @return [void]
112
+ # @example
113
+ # HelloJavaLib::FuncTypes.func_type2() {
114
+ # next "Hello"
115
+ # }
116
+ # =>
117
+ # funcType2 in
118
+ # "Hello"
119
+ def func_type2(&func)
120
+ p JavaCallTest2.funcType2(func)
121
+ return
122
+ end
123
+ # @overload func_type3(vals, &func)
124
+ # @param [Array] vals double型の配列(duble[])
125
+ # @param [block] func 関数型(引数:double[], 戻り値:double)
126
+ # @return [void]
127
+ # @example
128
+ # vals = [11, 22, 33, 44]
129
+ # HelloJavaLib::FuncTypes.func_type3(vals) {|xi|
130
+ # next xi.sum(0.0) / xi.length
131
+ # }
132
+ # =>
133
+ # funcType3 in
134
+ # 27.5
135
+ def func_type3(vals, &func)
136
+ p JavaCallTest2.funcType3(vals.to_java(Java::double), func)
137
+ return
138
+ end
139
+
140
+ end
141
+ end
65
142
  module_function :func_a
66
143
  module_function :func_b
67
144
  module_function :func_c
68
- module_function :func_d
69
-
145
+ module_function :func_v
146
+ module_function :func_h
70
147
  end
71
148
 
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.3
4
+ version: 0.0.5
5
5
  platform: java
6
6
  authors:
7
7
  - siranovel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-21 00:00:00.000000000 Z
11
+ date: 2023-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -20,8 +20,8 @@ dependencies:
20
20
  - !ruby/object:Gem::Version
21
21
  version: 12.3.3
22
22
  name: rake
23
- prerelease: false
24
23
  type: :development
24
+ prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
@@ -40,8 +40,8 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: 1.2.5
42
42
  name: rake-compiler
43
- prerelease: false
44
43
  type: :development
44
+ prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
@@ -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: