List of usage examples for org.apache.poi.ss.util NumberComparer compare
public static int compare(double a, double b)
From source file:nl.eur.ese.spreadsheettest.DStarRunner.java
License:Apache License
/** * Test whether a value matches a numeric condition. * @param valueEval Value to check./*from w w w . ja va 2 s. c om*/ * @param op Comparator to use. * @param condition Value to check against. * @return whether the condition holds. * @throws EvaluationException If it's impossible to turn the condition into a number. */ private static boolean testNumericCondition(ValueEval valueEval, operator op, String condition) throws EvaluationException { // Construct double from ValueEval. if (!(valueEval instanceof NumericValueEval)) return false; double value = ((NumericValueEval) valueEval).getNumberValue(); // Construct double from condition. double conditionValue = 0.0; try { int intValue = Integer.parseInt(condition); conditionValue = intValue; } catch (NumberFormatException e) { // It's not an int. try { conditionValue = Double.parseDouble(condition); } catch (NumberFormatException e2) { // It's not a double. throw new EvaluationException(ErrorEval.VALUE_INVALID); } } int result = NumberComparer.compare(value, conditionValue); switch (op) { case largerThan: return result > 0; case largerEqualThan: return result >= 0; case smallerThan: return result < 0; case smallerEqualThan: return result <= 0; case equal: return result == 0; } return false; // Can not be reached. }