poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r479290 - in /jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions: Islogical.java Isnontext.java Isnumber.java Isref.java Istext.java Left.java Right.java
Date Sun, 26 Nov 2006 06:14:12 GMT
Author: amol
Date: Sat Nov 25 22:14:11 2006
New Revision: 479290

URL: http://svn.apache.org/viewvc?view=rev&rev=479290
Log:
initial version

Modified:
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Islogical.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isnontext.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isnumber.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isref.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Istext.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Left.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Right.java

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Islogical.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Islogical.java?view=diff&rev=479290&r1=479289&r2=479290
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Islogical.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Islogical.java
Sat Nov 25 22:14:11 2006
@@ -4,10 +4,38 @@
  */
 package org.apache.poi.hssf.record.formula.functions;
 
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.RefEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
 /**
- * @author 
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
  *
  */
-public class Islogical extends NotImplementedFunction {
+public class Islogical extends LogicalFunction {
 
+    public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+        Eval retval = BoolEval.FALSE;
+        
+        switch (operands.length) {
+        default:
+            retval = ErrorEval.VALUE_INVALID;
+            break;
+        case 1:
+            Eval eval = operands[0];
+            if (eval instanceof BoolEval) {
+                retval = BoolEval.TRUE;
+            }
+            else if (eval instanceof RefEval) {
+                Eval xlatedEval = xlateRefEval((RefEval) eval);
+                if (xlatedEval instanceof BoolEval) {
+                    retval = BoolEval.TRUE;
+                }
+            }
+        }
+        
+        return retval;
+    }
 }

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isnontext.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isnontext.java?view=diff&rev=479290&r1=479289&r2=479290
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isnontext.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isnontext.java
Sat Nov 25 22:14:11 2006
@@ -4,10 +4,37 @@
  */
 package org.apache.poi.hssf.record.formula.functions;
 
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.RefEval;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+
 /**
- * @author 
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
  *
  */
-public class Isnontext extends NotImplementedFunction {
-
+public class Isnontext extends LogicalFunction {
+    public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+        Eval retval = BoolEval.TRUE;
+        
+        switch (operands.length) {
+        default:
+            retval = ErrorEval.VALUE_INVALID;
+            break;
+        case 1:
+            Eval eval = operands[0];
+            if (eval instanceof StringEval) {
+                retval = BoolEval.FALSE;
+            }
+            else if (eval instanceof RefEval) {
+                Eval xlatedEval = xlateRefEval((RefEval) eval);
+                if (xlatedEval instanceof StringEval) {
+                    retval = BoolEval.FALSE;
+                }
+            }
+        }
+        
+        return retval;
+    }
 }

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isnumber.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isnumber.java?view=diff&rev=479290&r1=479289&r2=479290
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isnumber.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isnumber.java
Sat Nov 25 22:14:11 2006
@@ -4,10 +4,37 @@
  */
 package org.apache.poi.hssf.record.formula.functions;
 
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.RefEval;
+
 /**
- * @author 
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
  *
  */
-public class Isnumber extends NotImplementedFunction {
-
+public class Isnumber extends LogicalFunction {
+    public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+        Eval retval = BoolEval.FALSE;
+        
+        switch (operands.length) {
+        default:
+            retval = ErrorEval.VALUE_INVALID;
+            break;
+        case 1:
+            Eval eval = operands[0];
+            if (eval instanceof NumberEval) {
+                retval = BoolEval.TRUE;
+            }
+            else if (eval instanceof RefEval) {
+                Eval xlatedEval = xlateRefEval((RefEval) eval);
+                if (xlatedEval instanceof NumberEval) {
+                    retval = BoolEval.TRUE;
+                }
+            }
+        }
+        
+        return retval;
+    }
 }

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isref.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isref.java?view=diff&rev=479290&r1=479289&r2=479290
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isref.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Isref.java
Sat Nov 25 22:14:11 2006
@@ -4,10 +4,31 @@
  */
 package org.apache.poi.hssf.record.formula.functions;
 
+import org.apache.poi.hssf.record.formula.eval.AreaEval;
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.RefEval;
+
 /**
- * @author 
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
  *
  */
-public class Isref extends NotImplementedFunction {
-
+public class Isref implements Function {
+    public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+        Eval retval = BoolEval.FALSE;
+        
+        switch (operands.length) {
+        default:
+            retval = ErrorEval.VALUE_INVALID;
+            break;
+        case 1:
+            Eval eval = operands[0];
+            if (eval instanceof RefEval || eval instanceof AreaEval) {
+                retval = BoolEval.TRUE;
+            }
+        }
+        
+        return retval;
+    }
 }

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Istext.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Istext.java?view=diff&rev=479290&r1=479289&r2=479290
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Istext.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Istext.java
Sat Nov 25 22:14:11 2006
@@ -4,10 +4,37 @@
  */
 package org.apache.poi.hssf.record.formula.functions;
 
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.RefEval;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+
 /**
- * @author 
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
  *
  */
-public class Istext extends NotImplementedFunction {
-
+public class Istext extends LogicalFunction {
+    public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+        Eval retval = BoolEval.FALSE;
+        
+        switch (operands.length) {
+        default:
+            retval = ErrorEval.VALUE_INVALID;
+            break;
+        case 1:
+            Eval eval = operands[0];
+            if (eval instanceof StringEval) {
+                retval = BoolEval.TRUE;
+            }
+            else if (eval instanceof RefEval) {
+                Eval xlatedEval = xlateRefEval((RefEval) eval);
+                if (xlatedEval instanceof StringEval) {
+                    retval = BoolEval.TRUE;
+                }
+            }
+        }
+        
+        return retval;
+    }
 }

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Left.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Left.java?view=diff&rev=479290&r1=479289&r2=479290
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Left.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Left.java
Sat Nov 25 22:14:11 2006
@@ -4,10 +4,88 @@
  */
 package org.apache.poi.hssf.record.formula.functions;
 
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.RefEval;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
 /**
- * @author 
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
  *
  */
-public class Left extends NotImplementedFunction {
+public class Left extends TextFunction {
 
+    public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+        Eval retval = ErrorEval.VALUE_INVALID;
+        int index = 1;
+        switch (operands.length) {
+        default:
+            break;
+        case 2:
+            Eval indexEval = operands[1];
+            index = evaluateAsInteger(indexEval);
+            if (index < 0) {
+                break;
+            }
+        case 1:
+            ValueEval veval = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
+            String str = null;
+            if (veval instanceof StringEval) {
+                StringEval stringEval = (StringEval) veval;
+                str = stringEval.getStringValue();
+            }
+            else if (veval instanceof BoolEval) {
+                BoolEval beval = (BoolEval) veval;
+                str = beval.getBooleanValue() ? "TRUE" : "FALSE";
+            }
+            else if (veval instanceof NumberEval) {
+                NumberEval neval = (NumberEval) veval;
+                str = neval.getStringValue();
+            }
+            if (null != str) {
+                str = str.substring(0, Math.min(str.length(), index));
+                retval = new StringEval(str);
+            }
+        }
+        return retval;
+    }
+    
+    protected int evaluateAsInteger(Eval eval) {
+        int numval = -1;
+        if (eval instanceof NumberEval) {
+            NumberEval neval = (NumberEval) eval;
+            double d = neval.getNumberValue();
+            numval = (int) d;
+        }
+        else if (eval instanceof StringEval) {
+            StringEval seval = (StringEval) eval;
+            String s = seval.getStringValue();
+            try { 
+                double d = Double.parseDouble(s);
+                numval = (int) d;
+            } 
+            catch (Exception e) {
+            }
+        }
+        else if (eval instanceof BoolEval) {
+            BoolEval beval = (BoolEval) eval;
+            numval = beval.getBooleanValue() ? 1 : 0;
+        }
+        else if (eval instanceof RefEval) {
+            numval = evaluateAsInteger(xlateRefEval((RefEval) eval));
+        }
+        return numval;
+    }
+    
+    protected Eval xlateRefEval(RefEval reval) {
+        Eval retval = reval.getInnerValueEval();
+        
+        if (retval instanceof RefEval) {
+            retval = xlateRefEval((RefEval) retval);
+        }
+        return retval;
+    }
 }

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Right.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Right.java?view=diff&rev=479290&r1=479289&r2=479290
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Right.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Right.java
Sat Nov 25 22:14:11 2006
@@ -4,10 +4,89 @@
  */
 package org.apache.poi.hssf.record.formula.functions;
 
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.RefEval;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
 /**
- * @author 
+ * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
  *
  */
-public class Right extends NotImplementedFunction {
+public class Right extends TextFunction {
 
+    public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+        Eval retval = ErrorEval.VALUE_INVALID;
+        int index = 1;
+        switch (operands.length) {
+        default:
+            break;
+        case 2:
+            Eval indexEval = operands[1];
+            index = evaluateAsInteger(indexEval);
+            if (index < 0) {
+                break;
+            }
+        case 1:
+            ValueEval veval = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
+            String str = null;
+            if (veval instanceof StringEval) {
+                StringEval stringEval = (StringEval) veval;
+                str = stringEval.getStringValue();
+            }
+            else if (veval instanceof BoolEval) {
+                BoolEval beval = (BoolEval) veval;
+                str = beval.getBooleanValue() ? "TRUE" : "FALSE";
+            }
+            else if (veval instanceof NumberEval) {
+                NumberEval neval = (NumberEval) veval;
+                str = neval.getStringValue();
+            }
+            if (null != str) {
+                int strlen = str.length();
+                str = str.substring(Math.max(0, strlen-index));
+                retval = new StringEval(str);
+            }
+        }
+        return retval;
+    }
+    
+    protected int evaluateAsInteger(Eval eval) {
+        int numval = -1;
+        if (eval instanceof NumberEval) {
+            NumberEval neval = (NumberEval) eval;
+            double d = neval.getNumberValue();
+            numval = (int) d;
+        }
+        else if (eval instanceof StringEval) {
+            StringEval seval = (StringEval) eval;
+            String s = seval.getStringValue();
+            try { 
+                double d = Double.parseDouble(s);
+                numval = (int) d;
+            } 
+            catch (Exception e) {
+            }
+        }
+        else if (eval instanceof BoolEval) {
+            BoolEval beval = (BoolEval) eval;
+            numval = beval.getBooleanValue() ? 1 : 0;
+        }
+        else if (eval instanceof RefEval) {
+            numval = evaluateAsInteger(xlateRefEval((RefEval) eval));
+        }
+        return numval;
+    }
+    
+    protected Eval xlateRefEval(RefEval reval) {
+        Eval retval = reval.getInnerValueEval();
+        
+        if (retval instanceof RefEval) {
+            retval = xlateRefEval((RefEval) retval);
+        }
+        return retval;
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Mime
View raw message