View Javadoc
1 /*** 2 * SelectOperator.java 3 * 4 * $Author: mballesteros $ 5 * $Date: 2003/11/28 19:18:03 $ 6 * $Revision: 1.1 $ 7 */ 8 package net.sf.jec.namedop; 9 10 import java.util.ArrayList; 11 import java.util.Collection; 12 import java.util.Iterator; 13 import java.util.List; 14 15 import net.sf.jec.EvaluationException; 16 import net.sf.jec.Operator; 17 18 19 /*** SelectOperator operates over a Collection, selecting those elements that 20 * evaluate into 'true' when the boolean operator argument is applied. 21 * 22 * @author mballesteros 23 */ 24 public class SelectOperator extends Operator { 25 26 /*** Creates a new SelectOperator 27 */ 28 public SelectOperator() { } 29 30 /*** Returns a function representation String for this operator 31 */ 32 public String toFunctionString() { 33 return ""; 34 } 35 36 /*** Returns an expression String representation for this operator 37 */ 38 public String toExpressionString() { 39 return ""; 40 } 41 42 43 /*** Returns the associated value to the given context and root context 44 * @param rootCtx The root context, needed for operators that require 45 * expression evaluation from root point. Example: Indexer operators 46 * @param ctx The current context where the operator will work over 47 */ 48 protected Object directMap(Object rootCtx, Object ctx) throws EvaluationException { 49 if (ctx instanceof Collection) { 50 List out = new ArrayList(); 51 Object obj; 52 Iterator it = ((Collection)ctx).iterator(); 53 while (it.hasNext()) { 54 obj = it.next(); 55 if ( argOps[0].apply(rootCtx, obj) == Boolean.TRUE ) out.add(obj); 56 } 57 return out; 58 } else { 59 return null; 60 } 61 } 62 }

This page was automatically generated by Maven