Mercurial > hg > octave-lyh
annotate scripts/java/org/octave/ClassHelper.java @ 17328:ea23eb07f8ed
Add missing TeX symbols and fix few others (bug #39828).
* libinterp/corefcn/oct-tex-lexer.ll (ID): Allow digit characters.
* libinterp/corefcn/txt-eng.cc (symbol_names): Add "angle", "ast",
"sim", "Leftarrow" and "Rightarrow".
(symbol_codes): Likewise. Fix unicode values for symbols "langle" and
"rangle".
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Fri, 23 Aug 2013 11:47:04 -0400 |
parents | 6e39fe7992d9 |
children |
rev | line source |
---|---|
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
1 /* |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
2 |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
3 Copyright (C) 2007 Michael Goffioul |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
4 |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
5 This file is part of Octave. |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
6 |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or (at |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
10 your option) any later version. |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
11 |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
15 General Public License for more details. |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
16 |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
20 |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
21 */ |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 package org.octave; |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 import java.lang.reflect.*; |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 public class ClassHelper |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
29 private static OctClassLoader loader; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
31 static |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
32 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
33 ClassLoader l = ClassHelper.class.getClassLoader (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
34 loader = (l instanceof OctClassLoader ? (OctClassLoader) l : |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
35 new OctClassLoader (l)); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
36 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
39 /** |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
40 * Add the given path to the classpath. |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
41 * @param name String - path to addd to the classpath |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
42 * @return boolean - true if the given path exists and was added to the classpath. |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
43 * @throws Exception |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
44 */ |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
45 public static boolean addClassPath (String name) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
46 throws Exception |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
47 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
48 boolean found = false; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
49 java.io.File f = new java.io.File (name); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
50 if (f.exists ()) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
52 loader.addClassPath (name); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
53 found = true; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
55 return (found); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
56 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
59 // new -MH- |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
60 /** |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
61 * |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
62 * @param name String - path to remove from classpath. |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
63 * @return boolean - true if the given path existed in the classpath before it was removed. |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
64 * @throws Exception |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
65 */ |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
66 public static boolean removeClassPath (String name) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
67 throws Exception |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
68 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
69 boolean found = false; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
70 java.io.File f = new java.io.File (name); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
71 java.net.URL urlToRemove = f.toURI ().toURL (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
72 // save urls in current class path |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
73 java.net.URL[] urls = loader.getURLs (); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
75 // create a completely new class loader because java.net.URLClassLoader has no removeClassPath() method |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
76 ClassLoader l = ClassHelper.class.getClassLoader (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
77 loader = (l instanceof OctClassLoader ? (OctClassLoader) l : |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
78 new OctClassLoader (l)); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
80 // add the previous urls back, except for the one |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
81 for (int i = 0; i < urls.length; i++) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
83 java.net.URL url = urls[i]; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
84 if (!url.equals (urlToRemove)) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
85 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
86 loader.addURL (url); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
87 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
88 else |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
89 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 // path to remove |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 found = true; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
92 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 } |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
95 return (found); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
96 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
97 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
99 public static String getClassPath () |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
100 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
101 StringBuffer buf = new StringBuffer (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
102 String pathSep = System.getProperty ("path.separator"); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
103 java.net.URL[] urls = loader.getURLs (); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
105 for (int i = 0; i < urls.length; i++) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
107 try |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
108 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
109 java.io.File f = new java.io.File (urls[i].toURI ()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
110 if (buf.length () > 0) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
111 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
112 buf.append (pathSep); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
113 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
114 buf.append (f.toString ()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
115 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
116 catch (java.net.URISyntaxException ex) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
117 {} |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
119 return buf.toString (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
120 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
121 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
122 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
123 // new -MH- |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
124 // return list of methods for given class name |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
125 public static String getMethods (String classname) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
126 throws ClassNotFoundException |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
127 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
128 return (getMethods (Class.forName (classname))); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
129 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
130 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
131 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
132 // new -MH- |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
133 // return list of methods for given class instance |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
134 public static String getMethods (Object obj) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
135 throws ClassNotFoundException |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
136 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
137 return (getMethods (obj.getClass ())); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
138 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
139 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
140 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
141 // new -MH- |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
142 // return list of methods for given class |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
143 public static String getMethods (Class klass) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
144 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
145 StringBuffer sb = new StringBuffer (); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
146 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
147 Method theMethod[] = klass.getMethods (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
148 for (int i = 0; i < theMethod.length; i++) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
149 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
150 if (i > 0) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
151 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
152 sb.append (";"); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
153 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
154 sb.append (theMethod[i].getReturnType ().getCanonicalName ()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
155 sb.append (" "); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
156 sb.append (theMethod[i].getName ()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
157 sb.append ("("); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
158 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
159 Class theParameter[] = theMethod[i].getParameterTypes (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
160 for (int j = 0; j < theParameter.length; j++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
161 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
162 if (j > 0) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
163 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
164 sb.append (", "); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
165 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
166 sb.append (theParameter[j].getCanonicalName ()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
167 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
168 sb.append (")"); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
169 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
170 Class theExceptions[] = theMethod[i].getExceptionTypes (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
171 if (theExceptions.length > 0) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
172 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
173 sb.append (" throws "); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
174 for (int j = 0; j < theExceptions.length; j++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
175 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
176 if (j > 0) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
177 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
178 sb.append (", "); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
179 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
180 sb.append (theExceptions[j].getCanonicalName ()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
181 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
182 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
183 } |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
184 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
185 return (sb.toString ()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
186 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
187 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
188 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
189 // new -MH- |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
190 // return list of fields for given class |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
191 public static String getFields (Class klass) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
192 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
193 StringBuffer sb = new StringBuffer (); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
194 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
195 Field theField[] = klass.getFields (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
196 for (int i = 0; i < theField.length; i++) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
197 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
198 if (i > 0) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
199 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
200 sb.append (";"); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
201 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
202 sb.append (theField[i].toString ()); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
203 } |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
204 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
205 return (sb.toString ()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
206 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
207 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
208 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
209 // new -MH- |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
210 // return list of fields for given class name |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
211 public static String getFields (String classname) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
212 throws ClassNotFoundException |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
213 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
214 return (getFields (Class.forName (classname))); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
215 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
216 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
217 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
218 // new -MH- |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
219 // return list of fields for given class instance |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
220 public static String getFields (Object obj) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
221 throws ClassNotFoundException |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
222 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
223 return (getFields (obj.getClass ())); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
224 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
225 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
226 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
227 public static Method findMethod (Class cls, String name, Class[] argTypes) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
228 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
229 try |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
230 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
231 return cls.getMethod (name, argTypes); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
232 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
233 catch (Exception e) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
234 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
235 Method[] mList = cls.getMethods (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
236 Method m; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
237 for (int i = 0; i < mList.length; i++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
238 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
239 m = mList[i]; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
240 if (m.getName ().equals (name) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
241 && m.getParameterTypes ().length == argTypes.length |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
242 && isCallableFrom (m, argTypes)) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
243 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
244 return m; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
245 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
246 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
247 return null; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
248 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
249 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
250 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
251 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
252 public static Constructor findConstructor (Class cls, Class[] argTypes) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
253 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
254 try |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
255 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
256 return cls.getConstructor (argTypes); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
257 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
258 catch (Exception e) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
259 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
260 Constructor[] cList = cls.getConstructors (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
261 //System.out.println("# constructors: " + cList.length); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
262 Constructor c; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
263 for (int i = 0; i < cList.length; i++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
264 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
265 //System.out.println("Considering constructor: " + cList[i]); |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
266 c = cList[i]; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
267 if (c.getParameterTypes ().length == argTypes.length |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
268 && isCallableFrom (c, argTypes)) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
269 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
270 return c; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
271 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
272 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
273 return null; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
274 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
275 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
276 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
277 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
278 private static Object invokeMethod (Method m, Object target, Object[] args) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
279 throws Exception |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
280 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
281 try |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
282 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
283 return m.invoke (target, args); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
284 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
285 catch (IllegalAccessException ex) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
286 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
287 String mName = m.getName (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
288 Class[] pTypes = m.getParameterTypes (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
289 Class currClass = target.getClass (); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
290 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
291 while (currClass != null) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
292 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
293 try |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
294 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
295 Method meth = currClass.getMethod (mName, pTypes); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
296 if (!meth.equals (m)) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
297 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
298 return meth.invoke (target, args); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
299 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
300 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
301 catch (NoSuchMethodException ex2) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
302 {} |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
303 catch (IllegalAccessException ex2) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
304 {} |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
305 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
306 Class[] ifaceList = currClass.getInterfaces (); |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
307 for (int i = 0; i < ifaceList.length; i++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
308 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
309 try |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
310 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
311 Method meth = ifaceList[i].getMethod (mName, pTypes); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
312 return meth.invoke (target, args); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
313 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
314 catch (NoSuchMethodException ex2) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
315 {} |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
316 catch (IllegalAccessException ex2) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
317 {} |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
318 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
319 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
320 currClass = currClass.getSuperclass (); |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
321 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
322 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
323 throw ex; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
324 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
325 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
326 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
327 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
328 public static Object invokeMethod (Object target, String name, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
329 Object[] args, Class[] argTypes) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
330 throws Throwable |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
331 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
332 Method m = findMethod (target.getClass (), name, argTypes); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
333 if (m != null) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
334 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
335 try |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
336 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
337 Object result = invokeMethod (m, target, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
338 castArguments (args, argTypes, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
339 m.getParameterTypes ())); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
340 return result; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
341 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
342 catch (InvocationTargetException ex) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
343 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
344 throw ex.getCause (); |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
345 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
346 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
347 else |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
348 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
349 throw new NoSuchMethodException (name); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
350 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
351 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
352 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
353 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
354 public static Object invokeStaticMethod (String cls, String name, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
355 Object[] args, Class[] argTypes) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
356 throws Throwable |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
357 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
358 Method m = findMethod (Class.forName (cls, true, loader), name, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
359 argTypes); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
360 if (m != null) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
361 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
362 try |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
363 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
364 Object result = m.invoke (null, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
365 castArguments (args, argTypes, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
366 m.getParameterTypes ())); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
367 return result; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
368 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
369 catch (InvocationTargetException ex) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
370 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
371 throw ex.getCause (); |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
372 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
373 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
374 else |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
375 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
376 throw new NoSuchMethodException (name); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
377 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
378 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
379 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
380 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
381 public static Object invokeConstructor (String cls, Object[] args, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
382 Class[] argTypes) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
383 throws Throwable |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
384 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
385 Constructor c = findConstructor (Class.forName (cls, true, loader), |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
386 argTypes); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
387 if (c != null) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
388 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
389 try |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
390 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
391 Object result = c.newInstance (castArguments (args, argTypes, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
392 c.getParameterTypes ())); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
393 return result; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
394 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
395 catch (InvocationTargetException ex) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
396 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
397 throw ex.getCause (); |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
398 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
399 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
400 else |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
401 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
402 throw new NoSuchMethodException (cls); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
403 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
404 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
405 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
406 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
407 public static Object getField (Object target, String name) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
408 throws Throwable |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
409 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
410 try |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
411 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
412 Field f = target.getClass ().getField (name); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
413 return f.get (target); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
414 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
415 catch (NoSuchFieldException ex) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
416 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
417 try |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
418 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
419 return invokeMethod (target, name, new Object[0], new Class[0]); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
420 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
421 catch (NoSuchMethodException ex2) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
422 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
423 throw ex; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
424 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
425 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
426 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
427 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
428 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
429 public static Object getStaticField (String cls, String name) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
430 throws Throwable |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
431 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
432 try |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
433 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
434 Field f = Class.forName (cls, true, loader).getField (name); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
435 return f.get (null); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
436 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
437 catch (NoSuchFieldException ex) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
438 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
439 try |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
440 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
441 return invokeStaticMethod (cls, name, new Object[0], new Class[0]); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
442 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
443 catch (NoSuchMethodException ex2) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
444 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
445 throw ex; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
446 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
447 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
448 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
449 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
450 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
451 public static void setField (Object target, String name, Object value) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
452 throws Exception |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
453 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
454 Field f = target.getClass ().getField (name); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
455 f.set (target, castArgument (value, value.getClass (), f.getType ())); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
456 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
457 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
458 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
459 public static void setStaticField (String cls, String name, Object value) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
460 throws Exception |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
461 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
462 Field f = Class.forName (cls, true, loader).getField (name); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
463 f.set (null, castArgument (value, value.getClass (), f.getType ())); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
464 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
465 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
466 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
467 private static boolean isCallableFrom (Method m, Class[] argTypes) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
468 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
469 Class[] expTypes = m.getParameterTypes (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
470 for (int i = 0; i < argTypes.length; i++) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
471 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
472 if (!isCallableFrom (expTypes[i], argTypes[i])) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
473 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
474 return false; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
475 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
476 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
477 return true; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
478 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
479 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
480 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
481 private static boolean isCallableFrom (Constructor c, Class[] argTypes) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
482 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
483 Class[] expTypes = c.getParameterTypes (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
484 for (int i = 0; i < argTypes.length; i++) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
485 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
486 if (!isCallableFrom (expTypes[i], argTypes[i])) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
487 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
488 return false; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
489 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
490 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
491 return true; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
492 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
493 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
494 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
495 private static boolean isCallableFrom (Class expCls, Class argCls) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
496 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
497 //System.out.println("isCallableFrom: "+expCls.getCanonicalName() + " <=? " + argCls.getCanonicalName()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
498 if (argCls == null) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
499 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
500 return!expCls.isPrimitive (); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
501 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
502 else if (expCls.isAssignableFrom (argCls)) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
503 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
504 return true; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
505 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
506 else if ((isNumberClass (expCls) || isBooleanClass (expCls)) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
507 && isNumberClass (argCls)) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
508 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
509 return true; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
510 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
511 else if (isCharClass (expCls) && argCls.equals (Character.class)) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
512 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
513 /* |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
514 modified into a more strict check to avoid char to string matching |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
515 to avoid matching method signatureslike |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
516 java_method(char) with octave_call('a String') |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
517 Date: 28-08-2010 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
518 Author: Martin Hepperle |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
519 */ |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
520 return true; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
521 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
522 else if (isStringClass (expCls) && argCls.equals (String.class)) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
523 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
524 /* |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
525 added for strict String to String matching |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
526 java_method(String) with octave_call('a String') |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
527 but not |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
528 java_method(char) with octave_call('a String') |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
529 Date: 28-08-2010 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
530 Author: Martin Hepperle |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
531 */ |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
532 return true; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
533 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
534 else if (expCls.isArray () && argCls.isArray () |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
535 && isCallableFrom (expCls.getComponentType (), |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
536 argCls.getComponentType ())) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
537 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
538 return true; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
539 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
540 else if (expCls.equals (Object.class) && argCls.isPrimitive ()) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
541 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
542 return true; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
543 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
544 else |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
545 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
546 return false; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
547 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
548 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
549 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
550 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
551 private static boolean isNumberClass (Class cls) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
552 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
553 return (cls.equals (Integer.TYPE) || cls.equals (Integer.class) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
554 || cls.equals (Short.TYPE) || cls.equals (Short.class) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
555 || cls.equals (Long.TYPE) || cls.equals (Long.class) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
556 || cls.equals (Float.TYPE) || cls.equals (Float.class) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
557 || cls.equals (Double.TYPE) || cls.equals (Double.class)); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
558 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
559 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
560 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
561 private static boolean isBooleanClass (Class cls) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
562 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
563 return (cls.equals (Boolean.class) || cls.equals (Boolean.TYPE)); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
564 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
565 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
566 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
567 private static boolean isCharClass (Class cls) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
568 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
569 return (cls.equals (Character.class) || cls.equals (Character.TYPE)); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
570 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
571 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
572 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
573 /** |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
574 * Check whether the supplied class is a String class. |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
575 * |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
576 * Added for more strict char/string mathicng of method signatures |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
577 * Date: 28-08-2010 |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
578 * Author: Martin Hepperle |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
579 * @param cls Class - the class to check |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
580 * @return boolean - true if clas is of class java.lang.String |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
581 */ |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
582 private static boolean isStringClass (Class cls) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
583 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
584 return ( |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
585 cls.equals (String.class) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
586 ); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
587 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
588 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
589 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
590 private static Object[] castArguments (Object[] args, Class[] argTypes, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
591 Class[] expTypes) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
592 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
593 for (int i = 0; i < args.length; i++) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
594 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
595 args[i] = castArgument (args[i], argTypes[i], expTypes[i]); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
596 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
597 return args; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
598 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
599 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
600 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
601 private static Object castArgument (Object obj, Class type, Class expType) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
602 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
603 // System.out.println("expType:"+expType.getCanonicalName() + " <= type:" + type.getCanonicalName()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
604 if (type == null || expType.isAssignableFrom (type)) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
605 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
606 return obj; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
607 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
608 else if (isNumberClass (expType)) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
609 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
610 if (expType.equals (Integer.TYPE) || expType.equals (Integer.class)) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
611 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
612 return new Integer (((Number) obj).intValue ()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
613 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
614 else if (expType.equals (Double.TYPE) || expType.equals (Double.class)) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
615 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
616 return new Double (((Number) obj).doubleValue ()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
617 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
618 else if (expType.equals (Short.TYPE) || expType.equals (Short.class)) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
619 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
620 return new Short (((Number) obj).shortValue ()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
621 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
622 else if (expType.equals (Long.TYPE) || expType.equals (Long.class)) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
623 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
624 return new Long (((Number) obj).longValue ()); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
625 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
626 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
627 else if (isBooleanClass (expType)) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
628 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
629 return new Boolean (((Number) obj).intValue () != 0); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
630 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
631 else if (isCharClass (expType)) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
632 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
633 String s = obj.toString (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
634 if (s.length () != 1) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
635 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
636 throw new ClassCastException ("cannot cast " + s + " to character"); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
637 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
638 return new Character (s.charAt (0)); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
639 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
640 else if (expType.isArray () && type.isArray ()) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
641 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
642 return castArray (obj, type.getComponentType (), |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
643 expType.getComponentType ()); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
644 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
645 else if (type.isPrimitive ()) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
646 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
647 return obj; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
648 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
649 return null; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
650 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
651 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
652 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
653 private static Object castArray (Object obj, Class elemType, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
654 Class elemExpType) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
655 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
656 int len = Array.getLength (obj); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
657 Object result = Array.newInstance (elemExpType, len); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
658 for (int i = 0; i < len; i++) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
659 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
660 Array.set (result, i, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
661 castArgument (Array.get (obj, i), elemType, elemExpType)); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
662 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
663 return result; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
664 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
665 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
666 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
667 private static int getArrayClassNDims (Class cls) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
668 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
669 if (cls != null && cls.isArray ()) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
670 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
671 return (1 + getArrayClassNDims (cls.getComponentType ())); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
672 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
673 else |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
674 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
675 return 0; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
676 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
677 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
678 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
679 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
680 private static Class getArrayElemClass (Class cls) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
681 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
682 if (cls.isArray ()) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
683 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
684 return getArrayElemClass (cls.getComponentType ()); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
685 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
686 else |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
687 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
688 return cls; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
689 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
690 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
691 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
692 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
693 private static Object getArrayElements (Object array, int[][] idx, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
694 int offset, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
695 int ndims, Class elemType) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
696 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
697 if (offset >= ndims) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
698 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
699 Object elem = Array.get (array, idx[offset][0]); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
700 if (offset < idx.length - 1) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
701 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
702 return getArrayElements (elem, idx, offset + 1, ndims, elemType); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
703 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
704 else |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
705 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
706 return elem; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
707 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
708 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
709 else |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
710 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
711 Class compType = elemType.getComponentType (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
712 Object retval = Array.newInstance (compType, idx[offset].length); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
713 for (int i = 0; i < idx[offset].length; i++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
714 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
715 Object elem = Array.get (array, idx[offset][i]); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
716 if (offset < idx.length - 1) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
717 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
718 elem = getArrayElements (elem, idx, offset + 1, ndims, compType); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
719 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
720 Array.set (retval, i, elem); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
721 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
722 return retval; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
723 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
724 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
725 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
726 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
727 public static Object arraySubsref (Object obj, int[][] idx) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
728 throws Exception |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
729 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
730 if (!obj.getClass ().isArray ()) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
731 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
732 throw new IllegalArgumentException ("not a Java array"); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
733 } |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
734 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
735 if (idx.length == 1) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
736 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
737 if (idx[0].length == 1) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
738 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
739 return Array.get (obj, idx[0][0]); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
740 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
741 else |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
742 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
743 Object retval = Array.newInstance (obj.getClass (). |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
744 getComponentType (), |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
745 idx[0].length); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
746 for (int i = 0; i < idx[0].length; i++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
747 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
748 Array.set (retval, i, Array.get (obj, idx[0][i])); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
749 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
750 return retval; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
751 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
752 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
753 else |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
754 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
755 int[] dims = new int[idx.length]; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
756 for (int i = 0; i < idx.length; i++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
757 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
758 dims[i] = idx[i].length; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
759 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
760 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
761 if (dims.length != getArrayClassNDims (obj.getClass ())) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
762 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
763 throw new IllegalArgumentException ("index size mismatch"); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
764 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
765 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
766 /* resolve leading singletons */ |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
767 Object theObj = obj; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
768 int offset = 0; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
769 while (dims[offset] == 1) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
770 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
771 theObj = Array.get (theObj, idx[offset][0]); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
772 offset = offset + 1; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
773 if (offset >= dims.length) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
774 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
775 return theObj; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
776 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
777 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
778 if (offset > 0) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
779 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
780 int[][] new_idx = new int[idx.length - offset][]; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
781 System.arraycopy (idx, offset, new_idx, 0, idx.length - offset); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
782 return arraySubsref (theObj, new_idx); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
783 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
784 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
785 /* chop trailing singletons */ |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
786 int ndims = dims.length; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
787 while (ndims > 1 && dims[ndims - 1] == 1) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
788 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
789 ndims--; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
790 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
791 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
792 /* create result array */ |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
793 Class elemClass = theObj.getClass (); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
794 for (int i = 0; i <= (dims.length - ndims); i++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
795 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
796 elemClass = elemClass.getComponentType (); |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
797 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
798 Object retval = Array.newInstance (elemClass, dims[0]); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
799 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
800 /* fill-in array */ |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
801 for (int i = 0; i < idx[0].length; i++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
802 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
803 Object elem = getArrayElements (Array.get (theObj, idx[0][i]), |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
804 idx, 1, ndims, elemClass); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
805 Array.set (retval, i, elem); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
806 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
807 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
808 return retval; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
809 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
810 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
811 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
812 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
813 private static Object setArrayElements (Object array, int[][] idx, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
814 int offset, int ndims, Object rhs) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
815 throws Exception |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
816 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
817 if (offset >= ndims) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
818 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
819 if (offset < idx.length - 1) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
820 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
821 setArrayElements (Array.get (array, idx[offset][0]), idx, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
822 offset + 1, ndims, rhs); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
823 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
824 else |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
825 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
826 Array.set (array, idx[offset][0], rhs); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
827 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
828 return array; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
829 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
830 else |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
831 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
832 for (int i = 0; i < idx[offset].length; i++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
833 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
834 if (offset < idx.length - 1) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
835 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
836 setArrayElements (Array.get (array, idx[offset][i]), idx, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
837 offset + 1, ndims, Array.get (rhs, i)); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
838 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
839 else |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
840 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
841 Array.set (array, idx[offset][i], Array.get (rhs, i)); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
842 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
843 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
844 return array; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
845 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
846 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
847 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
848 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
849 public static Object arraySubsasgn (Object obj, int[][] idx, Object rhs) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
850 throws Exception |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
851 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
852 if (!obj.getClass ().isArray ()) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
853 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
854 throw new IllegalArgumentException ("not a Java array"); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
855 } |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
856 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
857 if (idx.length == 1) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
858 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
859 if (idx[0].length == 1) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
860 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
861 Array.set (obj, idx[0][0], rhs); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
862 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
863 else |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
864 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
865 for (int i = 0; i < idx[0].length; i++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
866 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
867 Array.set (obj, idx[0][i], Array.get (rhs, i)); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
868 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
869 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
870 return obj; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
871 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
872 else |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
873 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
874 int[] dims = new int[idx.length]; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
875 for (int i = 0; i < idx.length; i++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
876 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
877 dims[i] = idx[i].length; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
878 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
879 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
880 if (dims.length != getArrayClassNDims (obj.getClass ())) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
881 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
882 throw new IllegalArgumentException ("index size mismatch"); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
883 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
884 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
885 /* resolve leading singletons */ |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
886 Object theObj = obj; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
887 int offset = 0; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
888 while (dims[offset] == 1 && offset < (dims.length - 1)) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
889 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
890 theObj = Array.get (theObj, idx[offset][0]); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
891 offset = offset + 1; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
892 } |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
893 if (offset > 0) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
894 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
895 int[][] new_idx = new int[idx.length - offset][]; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
896 System.arraycopy (idx, offset, new_idx, 0, idx.length - offset); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
897 arraySubsasgn (theObj, new_idx, rhs); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
898 return obj; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
899 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
900 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
901 /* chop trailing singletons */ |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
902 int ndims = dims.length; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
903 while (ndims > 1 && dims[ndims - 1] == 1) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
904 { |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
905 ndims--; |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
906 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
907 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
908 for (int i = 0; i < idx[0].length; i++) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
909 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
910 setArrayElements (Array.get (theObj, idx[0][i]), idx, 1, ndims, |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
911 Array.get (rhs, i)); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
912 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
913 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
914 return obj; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
915 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
916 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
917 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
918 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
919 public static Object createArray (Object cls, int[] dims) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
920 throws Exception |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
921 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
922 Class theClass; |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
923 if (cls instanceof Class) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
924 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
925 theClass = (Class) cls; |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
926 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
927 else if (cls instanceof String) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
928 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
929 theClass = Class.forName ((String) cls, true, loader); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
930 } |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
931 else |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
932 { |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
933 throw new IllegalArgumentException ("invalid class specification " + |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
934 cls); |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
935 } |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
936 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
937 return Array.newInstance (theClass, dims); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
938 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
939 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
940 |
15753
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
941 public static Object createArray (Object cls, int length) |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
942 throws Exception |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
943 { |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
944 return createArray (cls, new int[] {length}); |
6e39fe7992d9
style fixes and copyright update for java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
945 } |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
946 } |