01: // Copyright (c) 2002 Per M.A. Bothner and Brainfood Inc.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.kawa.functions;
05:
06: import gnu.lists.*;
07: import gnu.mapping.*;
08:
09: public class ArraySet extends ProcedureN {
10: public static final ArraySet arraySet = new ArraySet();
11:
12: public static void arraySet(Array array, Sequence index,
13: Object value) {
14: int dims = index.size();
15: int[] indexes = new int[dims];
16: for (int i = 0; i < dims; i++) {
17: indexes[i] = ((Number) index.get(i)).intValue();
18: }
19: array.set(indexes, value);
20: }
21:
22: public Object apply3(Object arg0, Object arg1, Object arg2)
23: throws Throwable {
24: if (arg1 instanceof Sequence) {
25: arraySet((Array) arg0, (Sequence) arg1, arg2);
26: return Values.empty;
27: } else
28: return super .apply3(arg0, arg1, arg2);
29: }
30:
31: public Object applyN(Object[] args) throws Throwable {
32: Array array = (Array) args[0];
33:
34: if (args.length == 3) {
35: Object arg1 = args[1];
36: if (arg1 instanceof Sequence) {
37: arraySet(array, (Sequence) arg1, args[2]);
38: return Values.empty;
39: }
40: }
41: int dim = args.length - 2;
42: int[] indexes = new int[dim];
43: for (int i = dim; --i >= 0;) {
44: indexes[i] = ((Number) args[i + 1]).intValue();
45: }
46: array.set(indexes, args[dim + 1]);
47: return Values.empty;
48: }
49: }
|