001 /** 002 * Implements the CFML Function arrayMerge 003 * Merge 2 arrays 004 */ 005 package railo.runtime.functions.arrays; 006 007 import railo.runtime.PageContext; 008 import railo.runtime.exp.PageException; 009 import railo.runtime.functions.BIF; 010 import railo.runtime.op.Caster; 011 import railo.runtime.type.Array; 012 import railo.runtime.type.ArrayImpl; 013 014 015 public final class ArrayMerge extends BIF { 016 017 private static final long serialVersionUID = -391473381762154998L; 018 019 public static Array call(PageContext pc , Array arr1, Array arr2) throws PageException { 020 return call(pc,arr1,arr2,false); 021 } 022 public static Array call(PageContext pc , Array arr1, Array arr2, boolean leaveIndex) throws PageException { 023 if(leaveIndex) { 024 Array arr = new ArrayImpl(); 025 set(arr,arr2); 026 set(arr,arr1); 027 return arr; 028 } 029 030 Array arr = new ArrayImpl(); 031 append(arr,arr1); 032 append(arr,arr2); 033 return arr; 034 035 } 036 037 @Override 038 public Object invoke(PageContext pc, Object[] args) throws PageException { 039 if(args.length==2)return call(pc,Caster.toArray(args[0]),Caster.toArray(args[1])); 040 return call(pc,Caster.toArray(args[0]),Caster.toArray(args[1]), Caster.toBooleanValue(args[2])); 041 } 042 043 044 045 public static void set(Array target,Array source) throws PageException { 046 int[] srcKeys=source.intKeys(); 047 for(int i=0;i<srcKeys.length;i++) { 048 target.setE(srcKeys[i],source.getE(srcKeys[i])); 049 } 050 } 051 052 public static void append(Array target,Array source) throws PageException { 053 int[] srcKeys=source.intKeys(); 054 for(int i=0;i<srcKeys.length;i++) { 055 target.append(source.getE(srcKeys[i])); 056 } 057 } 058 059 }