001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019/** 020 * Implements the CFML Function arrayavg 021 */ 022package lucee.runtime.functions.list; 023 024 025import lucee.runtime.PageContext; 026import lucee.runtime.exp.FunctionException; 027import lucee.runtime.exp.PageException; 028import lucee.runtime.functions.BIF; 029import lucee.runtime.functions.closure.Each; 030import lucee.runtime.op.Caster; 031import lucee.runtime.type.UDF; 032import lucee.runtime.type.util.StringListData; 033 034public final class ListEach extends BIF { 035 036 private static final long serialVersionUID = -2271260656749514177L; 037 038 039 public static String call(PageContext pc , String list, UDF udf) throws PageException { 040 return _call(pc, list, udf,",",false, true, false, 20); 041 } 042 043 public static String call(PageContext pc , String list, UDF udf,String delimiter) throws PageException { 044 return _call(pc, list, udf,delimiter,false, true,false, 20); 045 } 046 047 public static String call(PageContext pc , String list, UDF udf,String delimiter, boolean includeEmptyFields) throws PageException { 048 return _call(pc, list, udf,delimiter,includeEmptyFields,true, false, 20); 049 } 050 public static String call(PageContext pc , String list, UDF udf,String delimiter, boolean includeEmptyFields,boolean multiCharacterDelimiter) throws PageException { 051 return _call(pc, list, udf,delimiter,includeEmptyFields,multiCharacterDelimiter, false, 20); 052 } 053 054 public static String call(PageContext pc , String list, UDF udf,String delimiter, boolean includeEmptyFields,boolean multiCharacterDelimiter, boolean parallel) throws PageException { 055 return _call(pc, list, udf,delimiter,includeEmptyFields,multiCharacterDelimiter, parallel, 20); 056 } 057 058 public static String call(PageContext pc , String list, UDF udf,String delimiter, boolean includeEmptyFields,boolean multiCharacterDelimiter, boolean parallel, double maxThreads) throws PageException { 059 return _call(pc, list, udf,delimiter,includeEmptyFields,multiCharacterDelimiter, parallel, (int)maxThreads); 060 } 061 private static String _call(PageContext pc , String list, UDF udf,String delimiter, boolean includeEmptyFields, boolean multiCharacterDelimiter, boolean parallel, int maxThreads) throws PageException { 062 StringListData data=new StringListData(list,delimiter,includeEmptyFields,multiCharacterDelimiter); 063 064 return Each.call(pc, data, udf, parallel, maxThreads); 065 } 066 067 @Override 068 public Object invoke(PageContext pc, Object[] args) throws PageException { 069 070 if(args.length==2) 071 return call(pc, Caster.toString(args[0]), Caster.toFunction(args[1])); 072 if(args.length==3) 073 return call(pc, Caster.toString(args[0]), Caster.toFunction(args[1]),Caster.toString(args[2])); 074 if(args.length==4) 075 return call(pc, Caster.toString(args[0]), Caster.toFunction(args[1]),Caster.toString(args[2]),Caster.toBooleanValue(args[3])); 076 if(args.length==5) 077 return call(pc, Caster.toString(args[0]), Caster.toFunction(args[1]),Caster.toString(args[2]),Caster.toBooleanValue(args[3]), Caster.toBooleanValue(args[4])); 078 if(args.length==6) 079 return call(pc, Caster.toString(args[0]), Caster.toFunction(args[1]),Caster.toString(args[2]),Caster.toBooleanValue(args[3]), Caster.toBooleanValue(args[4]), Caster.toBooleanValue(args[5])); 080 if(args.length==7) 081 return call(pc, Caster.toString(args[0]), Caster.toFunction(args[1]),Caster.toString(args[2]),Caster.toBooleanValue(args[3]), Caster.toBooleanValue(args[4]), Caster.toBooleanValue(args[5]), Caster.toDoubleValue(args[6])); 082 083 throw new FunctionException(pc, "ListEach", 2, 7, args.length); 084 } 085}