001 /** 002 * Implements the CFML Function arrayset 003 */ 004 package railo.runtime.functions.arrays; 005 006 import railo.runtime.PageContext; 007 import railo.runtime.exp.ExpressionException; 008 import railo.runtime.exp.PageException; 009 import railo.runtime.functions.BIF; 010 import railo.runtime.op.Caster; 011 import railo.runtime.op.Duplicator; 012 import railo.runtime.type.Array; 013 014 public final class ArraySet extends BIF { 015 016 private static final long serialVersionUID = -7804363479876538167L; 017 018 public static boolean call(PageContext pc , Array array, double from, double to, Object value) throws PageException { 019 int f=(int) from; 020 int t=(int) to; 021 if(f<1) 022 throw new ExpressionException("Second parameter of the function arraySet must be greater than zero; now ["+f+"]"); 023 if(f>t) 024 throw new ExpressionException("Third parameter of the function arraySet must be greater than the second parameter; now [second:"+f+", third:"+t+"]"); 025 if(array.getDimension()>1) 026 throw new ExpressionException("Function arraySet can only be used with a one-dimensional array; this array has "+array.getDimension()+" dimensions"); 027 for(int i=f;i<=t;i++) { 028 array.setE(i,Duplicator.duplicate(value,true)); 029 } 030 031 return true; 032 } 033 034 @Override 035 public Object invoke(PageContext pc, Object[] args) throws PageException { 036 return call(pc,Caster.toArray(args[0]),Caster.toDoubleValue(args[1]),Caster.toDoubleValue(args[2]),args[3]); 037 } 038 }