[37] | 1 | function mut = subsasgn(mut,index,v)
|
---|
| 2 |
|
---|
| 3 | % Written by Tom Minka
|
---|
| 4 | % (c) Microsoft Corporation. All rights reserved.
|
---|
| 5 |
|
---|
| 6 | subsasgnJava(mut.obj,index,v,mut.cl);
|
---|
| 7 |
|
---|
| 8 | function subsasgnJava(jv,index,v,cl)
|
---|
| 9 |
|
---|
| 10 | if nargin < 4
|
---|
| 11 | % class(jv) is expensive, so we do it only once
|
---|
| 12 | cl = class(jv);
|
---|
| 13 | end
|
---|
| 14 | if strcmp(cl,'java.util.Hashtable')
|
---|
| 15 | % don't bother checking the type
|
---|
| 16 | %if strcmp(index(1).type,'.')
|
---|
| 17 | f = index(1).subs;
|
---|
| 18 | if length(index) > 1
|
---|
| 19 | jv = jv.get(f);
|
---|
| 20 | if isempty(jv)
|
---|
| 21 | error(sprintf('Reference to non-existent field ''%s''.',f));
|
---|
| 22 | end
|
---|
| 23 | % recurse on remaining subscripts
|
---|
| 24 | subsasgnJava(jv,index(2:end),v);
|
---|
| 25 | else
|
---|
| 26 | if ~jv.containsKey(f)
|
---|
| 27 | % add a new field
|
---|
| 28 | jv.get('_fields').addElement(f);
|
---|
| 29 | end
|
---|
| 30 | jv.put(f,toJava(v));
|
---|
| 31 | end
|
---|
| 32 | return
|
---|
| 33 | elseif strcmp(cl,'java.lang.Double[][]') | strcmp(cl,'java.lang.Object[][]')
|
---|
| 34 | if length(index(1).subs) == 1
|
---|
| 35 | % convert single index to a full index
|
---|
| 36 | i = index(1).subs{1};
|
---|
| 37 | if length(i) > 1
|
---|
| 38 | error('a single array of indices is not supported');
|
---|
| 39 | end
|
---|
| 40 | s = sizeJava(jv);
|
---|
| 41 | index(1).subs = num2cell(ind2subv(s,i),1);
|
---|
| 42 | end
|
---|
| 43 | if strcmp(cl,'java.lang.Object[][]')
|
---|
| 44 | % cell array
|
---|
| 45 | if strcmp(index(1).type,'{}')
|
---|
| 46 | index(1).type = '()';
|
---|
| 47 | end
|
---|
| 48 | end
|
---|
| 49 | % fall through
|
---|
| 50 | elseif strcmp(cl,'java.util.Vector') | strcmp(cl,'java.util.BitSet')
|
---|
| 51 | % empty array
|
---|
| 52 | error('Index exceeds matrix dimensions.');
|
---|
| 53 | end
|
---|
| 54 | % use built-in subsasgn
|
---|
| 55 | subsasgn(jv,index,toJava(v));
|
---|