001    /**
002     * Implements the CFML Function arrayappend
003     */
004    package railo.runtime.functions.arrays;
005    
006    import railo.runtime.PageContext;
007    import railo.runtime.exp.PageException;
008    import railo.runtime.functions.BIF;
009    import railo.runtime.op.Caster;
010    import railo.runtime.op.Decision;
011    import railo.runtime.type.Array;
012    
013    /**
014     * implementation of the Function arrayAppend
015     */
016    public final class ArrayAppend extends BIF {
017            
018            private static final long serialVersionUID = 5989673419120862625L;
019    
020    
021            public static boolean call(PageContext pc , Array array, Object object) throws PageException {
022                    return call(pc, array, object, false);
023            }
024            
025            /**
026             * @param pc
027             * @param array
028             * @param object
029             * @return has appended
030             * @throws PageException
031             */
032            public static boolean call(PageContext pc , Array array, Object object, boolean merge) throws PageException {
033                    if(merge && Decision.isCastableToArray(object)) {
034                            Object[] appends = Caster.toNativeArray(object);
035                            for(int i=0;i<appends.length;i++){
036                                    array.append(appends[i]);
037                            }
038                    }
039                    else
040                            array.append(object);
041                    return true;
042            }
043            
044            @Override
045            public Object invoke(PageContext pc, Object[] args) throws PageException {
046                    if(args.length==2) return call(pc,Caster.toArray(args[0]),args[1]);
047                    return call(pc,Caster.toArray(args[0]),args[1],Caster.toBooleanValue(args[2]));
048            }
049    }