X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2FCellValueVisitor.java;h=0fa6ce0a599e65ec0132077c77d716502cd84c8a;hp=022326248c39bacdf395e484f06de8220410893a;hb=55ca14c;hpb=3b5069d0d30e7de27f73d88d5e89d29052291a34 diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java index 022326248..0fa6ce0a5 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java @@ -183,21 +183,20 @@ public class CellValueVisitor implements AstValueVisitor { if(rightVal==null) rightResult = rightTemp.toString(); else rightResult = rightVal; } - - if ((leftResult instanceof String) || (rightResult instanceof String)) { + if ((leftResult instanceof String) && (rightResult instanceof String)) { String leftString = (leftResult.toString()).toLowerCase(); String rightString = (rightResult.toString()).toLowerCase(); if("<".equals(astRelation.op.trim())) return leftString.compareTo(rightString) < 0; else if(">".equals(astRelation.op.trim())) return leftString.compareTo(rightString) > 0; - // empty string should equal zero (TODO: this is a hack, the proper fix should be somewhere earlier so other cases would work as well) - else if("=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) == 0 || emptyAndZero(leftString, rightString) || emptyAndZero(rightString, leftString); + else if("=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) == 0; else if("<>".equals(astRelation.op.trim())) return leftString.compareTo(rightString) != 0 ; else if("<=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) <= 0 ; else if(">=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) >= 0 ; else throw new IllegalStateException(); } else { - Number leftNumber = SpreadsheetGraphUtils.asNumber(leftResult); - Number rightNumber = SpreadsheetGraphUtils.asNumber(rightResult); + Number leftNumber = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(leftResult); + Number rightNumber = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(rightResult); + if(leftNumber==null || rightNumber==null) return false; if("<".equals(astRelation.op.trim())) return leftNumber.doubleValue() < rightNumber.doubleValue(); else if(">".equals(astRelation.op.trim())) return leftNumber.doubleValue() > rightNumber.doubleValue(); else if("=".equals(astRelation.op.trim())) return leftNumber.doubleValue() == rightNumber.doubleValue(); @@ -208,15 +207,6 @@ public class CellValueVisitor implements AstValueVisitor { } } - private static boolean emptyAndZero(String a, String b) { - try { - return a.isEmpty() && (Double.parseDouble(b) == 0); - } - catch (NumberFormatException e) { - return false; - } - } - Object leftValueWithPrefix(Object result, AstValue value, String prefix, boolean forceNumber) { if(result == null) { Object obj = value.accept(this);