]> Creatis software - CreaPhase.git/blob - octave_packages/java-1.2.8/javaArray.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / java-1.2.8 / javaArray.m
1 ## Copyright (C) 2007 Michael Goffioul
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 ## GNU General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function file} {@var{a} =} javaArray (@var{class},@var{[M,N,...]})
18 ## @deftypefnx {Function file} {@var{a} =} javaArray (@var{class},@var{M},@var{N},...)
19 ##
20 ## Creates a Java array of size [@var{M},@var{N},...] with elements of
21 ## class @var{class}. @var{class} can be a Java object representing a class
22 ## or a string containing the fully qualified class name.
23 ##
24 ## The generated array is uninitialized, all elements are set to null
25 ## if @var{class} is a reference type, or to a default value (usually 0)
26 ## if @var{class} is a primitive type.
27 ##
28 ## @example
29 ##   a = javaArray ("java.lang.String", 2, 2);
30 ##   a(1,1) = "Hello";
31 ## @end example
32 ##
33 ## @end deftypefn
34
35 function [ ret ] = javaArray (class_name, varargin)
36
37   switch length (varargin)
38   case 0
39     error ("missing array size");
40   case 1
41     dims = varargin{1};
42   otherwise
43     dims = [varargin{:}];
44   endswitch
45
46   ret = java_invoke ("org.octave.ClassHelper", "createArray", class_name, dims);
47
48 endfunction