Package org.apache.poi.hssf.record.formula.eval

Examples of org.apache.poi.hssf.record.formula.eval.StringEval


  }
 
  public void testSimpleString() {
   
    ValueEval[] values = {
      new StringEval("Albert")
      new StringEval("Charles")
      new StringEval("Ed")
      new StringEval("Greg")
      new StringEval("Ian")
    };
   
    AreaEval ae = createAreaEval("A1:A5", values);
   
    // Note String comparisons are case insensitive
    confirmInt(3, invokeMatch(new StringEval("Ed"), ae, MATCH_LARGEST_LTE));
    confirmInt(3, invokeMatch(new StringEval("eD"), ae, MATCH_LARGEST_LTE));
    confirmInt(3, invokeMatch(new StringEval("Ed"), ae, MATCH_EXACT));
    confirmInt(3, invokeMatch(new StringEval("ed"), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new StringEval("Hugh"), ae, MATCH_LARGEST_LTE));
    assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Hugh"), ae, MATCH_EXACT));
  }
View Full Code Here


   
    ValueEval[] values = {
        new NumberEval(4)
        BoolEval.FALSE, 
        new NumberEval(5),
        new StringEval("Albert")
        BoolEval.FALSE, 
        BoolEval.TRUE, 
        new NumberEval(10)
        new StringEval("Charles")
        new StringEval("Ed")
        new NumberEval(10)
        new NumberEval(25)
        BoolEval.TRUE, 
        new StringEval("Ed")
    };
   
    AreaEval ae = createAreaEval("A1:A13", values);
   
    assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Aaron"), ae, MATCH_LARGEST_LTE));
   
    confirmInt(5, invokeMatch(BoolEval.FALSE, ae, MATCH_LARGEST_LTE));
    confirmInt(2, invokeMatch(BoolEval.FALSE, ae, MATCH_EXACT));
    confirmInt(3, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE));
    confirmInt(3, invokeMatch(new NumberEval(5), ae, MATCH_EXACT));
   
    confirmInt(8, invokeMatch(new StringEval("CHARLES"), ae, MATCH_EXACT));
   
    confirmInt(4, invokeMatch(new StringEval("Ben"), ae, MATCH_LARGEST_LTE));
   
    confirmInt(13, invokeMatch(new StringEval("ED"), ae, MATCH_LARGEST_LTE));
    confirmInt(9, invokeMatch(new StringEval("ED"), ae, MATCH_EXACT));
     
    confirmInt(13, invokeMatch(new StringEval("Hugh"), ae, MATCH_LARGEST_LTE));
    assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Hugh"), ae, MATCH_EXACT));
   
    confirmInt(11, invokeMatch(new NumberEval(30), ae, MATCH_LARGEST_LTE));
    confirmInt(12, invokeMatch(BoolEval.TRUE, ae, MATCH_LARGEST_LTE));
  }
View Full Code Here

* @author Josh Micich
*/
public final class TestRoundFuncs extends TestCase {
  public void testRounddownWithStringArg() {
   
    Eval strArg = new StringEval("abc");
    Eval[] args = { strArg, new NumberEval(2), };
    Eval result = new Rounddown().evaluate(args, -1, (short)-1);
    assertEquals(ErrorEval.VALUE_INVALID, result);
  }
View Full Code Here

    assertEquals(ErrorEval.VALUE_INVALID, result);
  }
 
  public void testRoundupWithStringArg() {
   
    Eval strArg = new StringEval("abc");
    Eval[] args = { strArg, new NumberEval(2), };
    Eval result = new Roundup().evaluate(args, -1, (short)-1);
    assertEquals(ErrorEval.VALUE_INVALID, result);
  }
View Full Code Here

        if (startNum > strBuff.length()) {
          strBuff.append(newStr);
        } else {
          strBuff.insert(startNum - 1, newStr);
        }
        retval = new StringEval(strBuff.toString());
      }
        }
    return retval;
    }
View Full Code Here

    }
    if(veRowColIndexArg instanceof BlankEval) {
      throw EvaluationException.invalidValue();
    }
    if(veRowColIndexArg instanceof StringEval) {
      StringEval se = (StringEval) veRowColIndexArg;
      String strVal = se.getStringValue();
      Double dVal = OperandResolver.parseDouble(strVal);
      if(dVal == null) {
        // String does not resolve to a number. Raise #VALUE! error.
        throw EvaluationException.invalidRef();
        // This includes text booleans "TRUE" and "FALSE".  They are not valid.
View Full Code Here

    protected StringLookupComparer(StringEval se) {
      super(se);
      _value = se.getStringValue();
    }
    protected CompareResult compareSameType(ValueEval other) {
      StringEval se = (StringEval) other;
      return CompareResult.valueOf(_value.compareToIgnoreCase(se.getStringValue()));
    }
View Full Code Here

      String str = OperandResolver.coerceValueToString(veval);
      str = str.trim();
      if(str.length() < 1) {
        return StringEval.EMPTY_INSTANCE;
      }
      return new StringEval(str);
    } catch (EvaluationException e) {
      return e.getErrorEval();
    }
  }
View Full Code Here

         
        if (retval == null) {
      if (numToReplace != REPLACE_ALL && numToReplace < 1) {
        retval = ErrorEval.VALUE_INVALID;
      } else if (searchStr.length() == 0) {
        retval = new StringEval(oldStr);
      } else {
        StringBuffer strBuff = new StringBuffer();
        int startIndex = 0;
        int nextMatch = -1;
        for (int leftToReplace = numToReplace;
          (leftToReplace > 0 || numToReplace == REPLACE_ALL)
            && (nextMatch = oldStr.indexOf(searchStr, startIndex)) != -1;
          leftToReplace--) {
          // store everything from end of last match to start of this match
          strBuff.append(oldStr.substring(startIndex, nextMatch));
          strBuff.append(newStr);
          startIndex = nextMatch + searchStr.length();
        }
        // store everything from end of last match to end of string
        if (startIndex < oldStr.length()) {
          strBuff.append(oldStr.substring(startIndex));
        }
        retval = new StringEval(strBuff.toString());
      }
        }
    return retval;
    }
View Full Code Here

    if (eval instanceof BoolEval) {
      BoolEval be = (BoolEval) eval;
      return CellValue.valueOf(be.getBooleanValue());
    }
    if (eval instanceof StringEval) {
      StringEval ne = (StringEval) eval;
      return new CellValue(ne.getStringValue());
    }
    if (eval instanceof ErrorEval) {
      return CellValue.getError(((ErrorEval)eval).getErrorCode());
    }
    throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")");
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.record.formula.eval.StringEval

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.