コード例 #1
0
ファイル: Countif.java プロジェクト: enricospataro/dynswc
 public boolean matches(ValueEval x) {
   double testValue;
   if (x instanceof StringEval) {
     // if the target(x) is a string, but parses as a number
     // it may still count as a match, only for the equality operator
     switch (getCode()) {
       case CmpOp.EQ:
       case CmpOp.NONE:
         break;
       case CmpOp.NE:
         // Always matches (inconsistent with above two cases).
         // for example '<>123' matches '123', '4', 'abc', etc
         return true;
       default:
         // never matches (also inconsistent with above three cases).
         // for example '>5' does not match '6',
         return false;
     }
     StringEval se = (StringEval) x;
     Double val = OperandResolver.parseDouble(se.getStringValue());
     if (val == null) {
       // x is text that is not a number
       return false;
     }
     return _value == val.doubleValue();
   } else if ((x instanceof NumberEval)) {
     NumberEval ne = (NumberEval) x;
     testValue = ne.getNumberValue();
   } else if ((x instanceof BlankEval)) {
     switch (getCode()) {
       case CmpOp.NE:
         // Excel counts blank values in range as not equal to any value. See Bugzilla 51498
         return true;
       default:
         return false;
     }
   } else {
     return false;
   }
   return evaluate(Double.compare(testValue, _value));
 }
コード例 #2
0
ファイル: Countif.java プロジェクト: enricospataro/dynswc
 public boolean matches(ValueEval x) {
   int testValue;
   if (x instanceof StringEval) {
     if (true) { // change to false to observe more intuitive behaviour
       // Note - Unlike with numbers, it seems that COUNTIF never matches
       // boolean values when the target(x) is a string
       return false;
     }
     @SuppressWarnings("unused")
     StringEval se = (StringEval) x;
     Boolean val = parseBoolean(se.getStringValue());
     if (val == null) {
       // x is text that is not a boolean
       return false;
     }
     testValue = boolToInt(val.booleanValue());
   } else if ((x instanceof BoolEval)) {
     BoolEval be = (BoolEval) x;
     testValue = boolToInt(be.getBooleanValue());
   } else if ((x instanceof BlankEval)) {
     switch (getCode()) {
       case CmpOp.NE:
         // Excel counts blank values in range as not equal to any value. See Bugzilla 51498
         return true;
       default:
         return false;
     }
   } else if ((x instanceof NumberEval)) {
     switch (getCode()) {
       case CmpOp.NE:
         // not-equals comparison of a number to boolean always returnes false
         return true;
       default:
         return false;
     }
   } else {
     return false;
   }
   return evaluate(testValue - _value);
 }
コード例 #3
0
ファイル: Countif.java プロジェクト: enricospataro/dynswc
  /** When the second argument is a string, many things are possible */
  private static I_MatchPredicate createGeneralMatchPredicate(StringEval stringEval) {
    String value = stringEval.getStringValue();
    CmpOp operator = CmpOp.getOperator(value);
    value = value.substring(operator.getLength());

    Boolean booleanVal = parseBoolean(value);
    if (booleanVal != null) {
      return new BooleanMatcher(booleanVal.booleanValue(), operator);
    }

    Double doubleVal = OperandResolver.parseDouble(value);
    if (doubleVal != null) {
      return new NumberMatcher(doubleVal.doubleValue(), operator);
    }
    ErrorEval ee = parseError(value);
    if (ee != null) {
      return new ErrorMatcher(ee.getErrorCode(), operator);
    }

    // else - just a plain string with no interpretation.
    return new StringMatcher(value, operator);
  }