View Javadoc
1 /*** 2 * Operator.java 3 * 4 * $Author: mballesteros $ 5 * $Date: 2003/11/28 19:18:04 $ 6 * $Revision: 1.1 $ 7 */ 8 package net.sf.jec; 9 10 11 /*** Abstract class parent of every operator. An operator might nest another 12 * operator, resulting in a function composition: <code>OP1(x), OP2(OP1(x))</code><p> 13 * Thus, applying OP2 to an object 'x', implies appliying OP1 to 'x' and then 14 * OP2 to the result. 15 * @author mballesteros 16 */ 17 public abstract class Operator { 18 19 public static boolean showFunctionString = false; 20 21 /*** Nested operator 22 */ 23 protected Operator nestedOp; 24 25 protected Operator[] argOps; 26 27 /*** Creates a new operator that nest another operator 28 */ 29 public Operator() { 30 this.nestedOp = null; 31 } 32 33 /*** Creates a new operator that nest another operator 34 */ 35 public Operator(Operator nestedOp) { 36 this.nestedOp = nestedOp; 37 } 38 39 /*** Sets the operator's nested operator 40 */ 41 public void setNestedOperator(Operator nestedOp) { 42 this.nestedOp = nestedOp; 43 } 44 45 public void setArgumentOperators(Operator[] argOps) { 46 this.argOps = argOps; 47 } 48 49 public String toString() { 50 return showFunctionString? toFunctionString() : toExpressionString(); 51 } 52 53 /*** Returns a function representation String for this operator 54 */ 55 public abstract String toFunctionString(); 56 57 /*** Returns an expression String representation for this operator 58 */ 59 public abstract String toExpressionString(); 60 61 /*** 62 */ 63 public final Object apply(Object rootCtx, Object ctx) 64 throws EvaluationException { 65 if (nestedOp != null && ctx != null) ctx = nestedOp.apply(rootCtx, ctx); 66 return directMap(rootCtx, ctx); 67 } 68 69 /*** Returns the associated value to the given context and root context 70 * @param rootCtx The root context, needed for operators that require 71 * expression evaluation from root point. Example: Indexer operators 72 * @param ctx The current context where the operator will work over 73 */ 74 protected abstract Object directMap(Object rootCtx, Object ctx) 75 throws EvaluationException; 76 }

This page was automatically generated by Maven