1 4 package gnu.kawa.functions; 5 import gnu.lists.*; 6 import gnu.mapping.*; 7 8 public class ArraySet extends ProcedureN 9 { 10 public static final ArraySet arraySet = new ArraySet(); 11 12 public static void arraySet(Array array, Sequence index, Object value) 13 { 14 int dims = index.size(); 15 int[] indexes = new int[dims]; 16 for (int i = 0; i < dims; i++) 17 { 18 indexes[i] = ((Number ) index.get(i)).intValue(); 19 } 20 array.set(indexes, value); 21 } 22 23 public Object apply3 (Object arg0, Object arg1, Object arg2) 24 throws Throwable 25 { 26 if (arg1 instanceof Sequence) 27 { 28 arraySet((Array) arg0, (Sequence) arg1, arg2); 29 return Values.empty; 30 } 31 else 32 return super.apply3(arg0, arg1, arg2); 33 } 34 35 public Object applyN (Object [] args) 36 throws Throwable 37 { 38 Array array = (Array) args[0]; 39 40 if (args.length == 3) 41 { 42 Object arg1 = args[1]; 43 if (arg1 instanceof Sequence) 44 { 45 arraySet(array, (Sequence) arg1, args[2]); 46 return Values.empty; 47 } 48 } 49 int dim = args.length-2; 50 int[] indexes = new int[dim]; 51 for (int i = dim; --i >= 0; ) 52 { 53 indexes[i] = ((Number ) args[i+1]).intValue(); 54 } 55 array.set(indexes, args[dim+1]); 56 return Values.empty; 57 } 58 } 59 | Popular Tags |