1 | function v = subsref(mut,index)
|
---|
2 |
|
---|
3 | % Written by Tom Minka
|
---|
4 | % (c) Microsoft Corporation. All rights reserved.
|
---|
5 |
|
---|
6 | v = subsrefJava(mut.obj,index,mut.cl);
|
---|
7 |
|
---|
8 | function v = subsrefJava(jv,index,cl)
|
---|
9 |
|
---|
10 | if nargin < 3
|
---|
11 | % class(jv) is expensive, so we do it only once
|
---|
12 | cl = class(jv);
|
---|
13 | end
|
---|
14 | wantcell = 0;
|
---|
15 | if strcmp(cl,'java.util.Hashtable')
|
---|
16 | % don't bother checking the type
|
---|
17 | %if strcmp(index(1).type,'.')
|
---|
18 | f = index(1).subs;
|
---|
19 | v = jv.get(f);
|
---|
20 | if isempty(v)
|
---|
21 | error(sprintf('Reference to non-existent field ''%s''.',f));
|
---|
22 | end
|
---|
23 | elseif strcmp(cl,'java.lang.Double[][]') | strcmp(cl,'java.lang.Object[][]')
|
---|
24 | if length(index(1).subs) == 1
|
---|
25 | % convert single index to a full index
|
---|
26 | i = index(1).subs{1};
|
---|
27 | if length(i) > 1
|
---|
28 | error('a single array of indices is not supported');
|
---|
29 | end
|
---|
30 | s = sizeJava(jv);
|
---|
31 | index(1).subs = num2cell(ind2subv(s,i),1);
|
---|
32 | end
|
---|
33 | if strcmp(cl,'java.lang.Object[][]')
|
---|
34 | % cell array
|
---|
35 | if strcmp(index(1).type,'{}')
|
---|
36 | index(1).type = '()';
|
---|
37 | else
|
---|
38 | % type is '()' for a cell array
|
---|
39 | wantcell = 1;
|
---|
40 | % if the subscript has more than one element, the result will already
|
---|
41 | % be a cell array
|
---|
42 | for i = index(1).subs
|
---|
43 | if length(i{1}) > 1
|
---|
44 | wantcell = 0;
|
---|
45 | break
|
---|
46 | end
|
---|
47 | end
|
---|
48 | end
|
---|
49 | end
|
---|
50 | v = subsref(jv,index(1));
|
---|
51 | elseif strcmp(cl,'java.util.Vector') | strcmp(cl,'java.util.BitSet')
|
---|
52 | % empty array
|
---|
53 | error('Index exceeds matrix dimensions.');
|
---|
54 | else
|
---|
55 | % use built-in subsref
|
---|
56 | v = subsref(jv,index(1));
|
---|
57 | end
|
---|
58 | if length(index) > 1
|
---|
59 | % recurse on remaining subscripts
|
---|
60 | v = subsrefJava(v,index(2:end));
|
---|
61 | else
|
---|
62 | v = fromJava(v);
|
---|
63 | if wantcell
|
---|
64 | v = {v};
|
---|
65 | end
|
---|
66 | end
|
---|
67 |
|
---|