poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r797238 - in /poi/trunk/src/java/org/apache/poi: hssf/record/formula/eval/ConcatEval.java ss/formula/OperationEvaluatorFactory.java
Date Thu, 23 Jul 2009 21:45:56 GMT
Author: josh
Date: Thu Jul 23 21:45:56 2009
New Revision: 797238

URL: http://svn.apache.org/viewvc?rev=797238&view=rev
Log:
Converted ConcatEval to singleton

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/ConcatEval.java
    poi/trunk/src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/ConcatEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/ConcatEval.java?rev=797238&r1=797237&r2=797238&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/ConcatEval.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/ConcatEval.java Thu Jul 23
21:45:56 2009
@@ -17,47 +17,44 @@
 
 package org.apache.poi.hssf.record.formula.eval;
 
-import org.apache.poi.hssf.record.formula.ConcatPtg;
-
 /**
  * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- *  
  */
 public final class ConcatEval implements OperationEval {
 
-    private ConcatPtg delegate;
+	public static final OperationEval instance = new ConcatEval();
 
-    public ConcatEval(ConcatPtg ptg) {
-        delegate = ptg;
-    }
-
-    public Eval evaluate(Eval[] args, int srcRow, short srcCol) {
-    	if(args.length != 2) {
-    		return ErrorEval.VALUE_INVALID;
-    	}
-        StringBuffer sb = new StringBuffer();
-        try {
-			for (int i = 0; i < 2; i++) { 
-			    
-			    ValueEval ve = OperandResolver.getSingleValue(args[i], srcRow, srcCol);
-			    if (ve instanceof StringValueEval) {
-			        StringValueEval sve = (StringValueEval) ve;
-			        sb.append(sve.getStringValue());
-			    } else if (ve == BlankEval.INSTANCE) {
-			        // do nothing
-			    } else {
-			        throw new RuntimeException("Unexpected value type (" 
-			        		+ ve.getClass().getName() + ")");
-			    }
+	private ConcatEval() {
+		// enforce singleton
+	}
+
+	public Eval evaluate(Eval[] args, int srcRow, short srcCol) {
+		if(args.length != 2) {
+			return ErrorEval.VALUE_INVALID;
+		}
+		StringBuffer sb = new StringBuffer();
+		try {
+			for (int i = 0; i < 2; i++) {
+
+				ValueEval ve = OperandResolver.getSingleValue(args[i], srcRow, srcCol);
+				if (ve instanceof StringValueEval) {
+					StringValueEval sve = (StringValueEval) ve;
+					sb.append(sve.getStringValue());
+				} else if (ve == BlankEval.INSTANCE) {
+					// do nothing
+				} else {
+					throw new RuntimeException("Unexpected value type ("
+							+ ve.getClass().getName() + ")");
+				}
 			}
 		} catch (EvaluationException e) {
 			return e.getErrorEval();
 		}
-        
-        return new StringEval(sb.toString());
-    }
-
-    public int getNumberOfOperands() {
-        return delegate.getNumberOfOperands();
-    }
+
+		return new StringEval(sb.toString());
+	}
+
+	public int getNumberOfOperands() {
+		return 2;
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java?rev=797238&r1=797237&r2=797238&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java Thu Jul 23
21:45:56 2009
@@ -84,6 +84,7 @@
 		m.put(LessThanPtg.class, LessThanEval.instance);
 		m.put(NotEqualPtg.class, NotEqualEval.instance);
 
+		m.put(ConcatPtg.class, ConcatEval.instance);
 		m.put(AddPtg.class, AddEval.instance);
 		m.put(DividePtg.class, DivideEval.instance);
 		m.put(MultiplyPtg.class, MultiplyEval.instance);
@@ -112,16 +113,13 @@
 		if (result != null) {
 			return  result;
 		}
-		
+
 		if (ptgClass == FuncPtg.class) {
 			return new FuncVarEval((FuncPtg)ptg);
 		}
 		if (ptgClass == FuncVarPtg.class) {
 			return new FuncVarEval((FuncVarPtg)ptg);
 		}
-		if (ptgClass == ConcatPtg.class) {
-			return new ConcatEval((ConcatPtg)ptg);
-		}
 		throw new RuntimeException("Unexpected operation ptg class (" + ptgClass.getName() + ")");
 	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message