*/
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;
+ }
}
*/
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;
+ }
}
*/
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;
+ }
}
*/
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;
+ }
}
*/
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;
+ }
}
*/
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;
+ }
}
*/
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 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;
+ }
}