Module: HelloJavaLib

Defined in:
lib/hellojava.rb

Overview

jrubyからjavaの呼び出し

Defined Under Namespace

Classes: FuncTypes

Class Method Summary collapse

Class Method Details

.func_avoid

Systemクラス使用

Examples:

HelloJavaLib::func_a()   => 'Hello, JRuby'

This method returns an undefined value.



17
18
19
# File 'lib/hellojava.rb', line 17

def func_a()
    System.out.println("Hello, JRuby")
end

.func_bvoid

標準クラス以外の使用

Examples:

HelloJavaLib::func_b()   => 'str1'

This method returns an undefined value.



26
27
28
29
# File 'lib/hellojava.rb', line 26

def func_b()
    p JavaCallTest.str1
    return
end

.func_c(value1, value2) ⇒ void

戻り値がオブジェクトの場合

Examples:

HelloJavaLib::func_c(1, 2)   => 3

This method returns an undefined value.

Parameters:

  • value1 (int)

    value1の値

  • value2 (int)

    value2の値



38
39
40
41
42
43
# File 'lib/hellojava.rb', line 38

def func_c(value1, value2)
    hoge = Hoge.new
    calc = hoge.getCalc(value1, value2)
    p calc.add
    return
end

.func_h(vals) ⇒ void

引数にHashの場合

Examples:

vals = {
         "dt1" => [12.3, 22.5, 33.7, 44.6],
         "dt2" => [12.3, 22.5, 33.7, 44.6, 55.8],
       }
HelloJavaLib::func_h(vals)
=>
 hash in
 dt1 12.300000 22.500000 33.700000 44.600000
 dt2 12.300000 22.500000 33.700000 44.600000 55.800000

This method returns an undefined value.

Parameters:

  • vals (Hash)

    Hash(String, double[])



83
84
85
86
87
88
89
# File 'lib/hellojava.rb', line 83

def func_h(vals)
    o = HashMap.new
    vals.each{|k, v|
        o[k] = v.to_java(Java::double)
    }
    JavaCallTest.hash(o)
end

.func_v(fname, vals) ⇒ void

引数に二次元配列の場合

Examples:

vals = [
         [12.3, 22.5, 33.7, 44.6],
         [12.3, 22.5, 33.7, 44.6, 55.8],
       ]
HelloJavaLib::func_v("fname.jpg", vals) 
=>
 fname:fname.jpg size:2
 vals[0] size:4
 12.300000 22.500000 33.700000 44.600000
 vals[1] size:5
 12.300000 22.500000 33.700000 44.600000 55.800000

This method returns an undefined value.

Parameters:



62
63
64
65
66
67
# File 'lib/hellojava.rb', line 62

def func_v(fname, vals)
    JavaCallTest.sub1(
      fname, vals.to_java(Java::double[])
    );
    return
end