From f7e9854dc83d2765205f14b046f56077f23e205e Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Sun, 13 Mar 2016 14:59:19 +1100 Subject: [PATCH] tidying --- .../diskbrowser/visicalc/Condition.java | 42 ++++++++++--------- .../diskbrowser/visicalc/Expression.java | 1 + 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/com/bytezone/diskbrowser/visicalc/Condition.java b/src/com/bytezone/diskbrowser/visicalc/Condition.java index 954c171..c137657 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Condition.java +++ b/src/com/bytezone/diskbrowser/visicalc/Condition.java @@ -1,5 +1,6 @@ package com.bytezone.diskbrowser.visicalc; +// Predicate class Condition { private static final String[] comparators = { "<>", "<=", ">=", "=", "<", ">" }; @@ -7,11 +8,11 @@ class Condition private final Sheet parent; private String comparator; - private String cond; - private String value; + private String conditionText; + private String valueText; - private Expression expCond; - private Expression expValue; + private Expression conditionExpression; + private Expression valueExpression; public Condition (Sheet parent, String text) { @@ -22,8 +23,8 @@ class Condition int pos = text.indexOf (comp); if (pos > 0) { - cond = text.substring (0, pos); - value = text.substring (pos + comp.length ()); + conditionText = text.substring (0, pos); + valueText = text.substring (pos + comp.length ()); comparator = comp; break; } @@ -33,8 +34,8 @@ class Condition { if (text.startsWith ("@")) { - cond = text; - value = "1"; + conditionText = text; + valueText = "1"; comparator = "="; } else @@ -44,27 +45,27 @@ class Condition public boolean getResult () { - if (expCond == null) + if (conditionExpression == null) { - expCond = new Expression (parent, cond); - expValue = new Expression (parent, value); + conditionExpression = new Expression (parent, conditionText); + valueExpression = new Expression (parent, valueText); } - double condValue = expCond.getValue (); - double valueValue = expValue.getValue (); + double conditionResult = conditionExpression.getValue (); + double valueResult = valueExpression.getValue (); if (comparator.equals ("=")) - return condValue == valueValue; + return conditionResult == valueResult; else if (comparator.equals ("<>")) - return condValue != valueValue; + return conditionResult != valueResult; else if (comparator.equals ("<")) - return condValue < valueValue; + return conditionResult < valueResult; else if (comparator.equals (">")) - return condValue > valueValue; + return conditionResult > valueResult; else if (comparator.equals ("<=")) - return condValue <= valueValue; + return conditionResult <= valueResult; else if (comparator.equals (">=")) - return condValue >= valueValue; + return conditionResult >= valueResult; else System.out.printf ("Unexpected comparator result [%s]%n", comparator); @@ -74,6 +75,7 @@ class Condition @Override public String toString () { - return String.format ("[cond=%s, op=%s, value=%s]", cond, comparator, value); + return String.format ("[cond=%s, op=%s, value=%s]", conditionText, comparator, + valueText); } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/Expression.java b/src/com/bytezone/diskbrowser/visicalc/Expression.java index f83fe87..7dd2b92 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Expression.java +++ b/src/com/bytezone/diskbrowser/visicalc/Expression.java @@ -177,6 +177,7 @@ class Expression implements Value { System.out.printf ("**** Unbalanced brackets: left:%d, right:%d ****%n", leftBracket, rightBracket); + System.out.println (input); return "@ERROR()"; } return line;