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 024import lucee.runtime.PageContext; 025import lucee.runtime.exp.FunctionException; 026import lucee.runtime.exp.PageException; 027import lucee.runtime.functions.BIF; 028import lucee.runtime.functions.closure.Filter; 029import lucee.runtime.op.Caster; 030import lucee.runtime.type.Array; 031import lucee.runtime.type.UDF; 032import lucee.runtime.type.util.ListUtil; 033import lucee.runtime.type.util.StringListData; 034 035 036public final class ListFilter extends BIF { 037 038 private static final long serialVersionUID = 2182867537570796564L; 039 040 public static String call(PageContext pc , String list, UDF filter) throws PageException { 041 return call(pc, list, filter, ",", false,true, false, 20); 042 } 043 044 public static String call(PageContext pc , String list, UDF filter,String delimiter) throws PageException { 045 return call(pc, list, filter, delimiter, false,true, false, 20); 046 } 047 048 public static String call(PageContext pc , String list, UDF filter,String delimiter 049 , boolean includeEmptyFields) throws PageException { 050 return call(pc, list, filter, delimiter, includeEmptyFields,true, false, 20); 051 } 052 053 public static String call(PageContext pc , String list, UDF filter,String delimiter 054 , boolean includeEmptyFields, boolean multiCharacterDelimiter) throws PageException { 055 return call(pc, list, filter, delimiter, includeEmptyFields,multiCharacterDelimiter, false, 20); 056 } 057 058 public static String call(PageContext pc , String list, UDF filter,String delimiter 059 , boolean includeEmptyFields, boolean multiCharacterDelimiter, boolean parallel) throws PageException { 060 return call(pc, list, filter, delimiter, includeEmptyFields,multiCharacterDelimiter, parallel, 20); 061 } 062 063 public static String call(PageContext pc , String list, UDF filter,String delimiter 064 , boolean includeEmptyFields, boolean multiCharacterDelimiter, boolean parallel, double maxThreads) throws PageException { 065 066 return ListUtil.arrayToList( 067 (Array)Filter.call(pc, new StringListData(list,delimiter,includeEmptyFields,multiCharacterDelimiter), filter, parallel, maxThreads), delimiter); 068 } 069 070 071 @Override 072 public Object invoke(PageContext pc, Object[] args) throws PageException { 073 074 if(args.length==2) 075 return call(pc, Caster.toString(args[0]), Caster.toFunction(args[1])); 076 if(args.length==3) 077 return call(pc, Caster.toString(args[0]), Caster.toFunction(args[1]),Caster.toString(args[2])); 078 if(args.length==4) 079 return call(pc, Caster.toString(args[0]), Caster.toFunction(args[1]),Caster.toString(args[2]),Caster.toBooleanValue(args[3])); 080 if(args.length==5) 081 return call(pc, Caster.toString(args[0]), Caster.toFunction(args[1]),Caster.toString(args[2]),Caster.toBooleanValue(args[3]), Caster.toBooleanValue(args[4])); 082 if(args.length==6) 083 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])); 084 if(args.length==7) 085 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])); 086 087 throw new FunctionException(pc, "ListFilter", 2, 7, args.length); 088 } 089}