View Javadoc
1 /*** 2 * CountOperator.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.Collection; 11 import java.util.Map; 12 13 import net.sf.jec.EvaluationException; 14 15 16 /*** CountOperator counts the amount of elements in the context collection. It 17 * doesn't take any argument operator. 18 * 19 * @author mballesteros 20 */ 21 public class CountOperator extends GroupOperator { 22 23 /*** Creates a new CountOperator 24 */ 25 public CountOperator() { } 26 27 /*** Returns a function representation String for this operator 28 */ 29 public String toFunctionString() { 30 return "Count(" + (nestedOp == null? "" : nestedOp.toString()) + ")"; 31 } 32 33 /*** Returns an expression String representation for this operator 34 */ 35 public String toExpressionString() { 36 return (nestedOp == null? "" : nestedOp.toString()) + ".count()"; 37 } 38 39 /*** Returns the associated value to the given context and root context 40 * @param rootCtx The root context, needed for operators that require 41 * expression evaluation from root point. Example: Indexer operators 42 * @param ctx The current context where the operator will work over 43 */ 44 protected Object directMap(Object rootCtx, Object ctx) 45 throws EvaluationException { 46 if (ctx instanceof Collection) { 47 return new Integer( ((Collection)ctx).size() ); 48 } else if (ctx instanceof Map) { 49 return applyToGroup(rootCtx, (Map)ctx ); 50 } else { 51 return null; 52 } 53 } 54 }

This page was automatically generated by Maven