diff --git a/src/com/bytezone/diskbrowser/visicalc/AbstractValue.java b/src/com/bytezone/diskbrowser/visicalc/AbstractValue.java index 265e247..086c190 100644 --- a/src/com/bytezone/diskbrowser/visicalc/AbstractValue.java +++ b/src/com/bytezone/diskbrowser/visicalc/AbstractValue.java @@ -1,8 +1,14 @@ package com.bytezone.diskbrowser.visicalc; +import java.util.ArrayList; +import java.util.List; + public abstract class AbstractValue implements Value { protected final String typeText; + protected double value; + protected ValueType valueType = ValueType.VALUE; + protected List values = new ArrayList (); public AbstractValue (String typeText) { @@ -14,4 +20,36 @@ public abstract class AbstractValue implements Value { return typeText; } + + @Override + public ValueType getValueType () + { + return valueType; + } + + @Override + public boolean isValueType (ValueType type) + { + return valueType == type; + } + + @Override + public double getValue () + { + return value; + } + + @Override + public String getText () + { + switch (valueType) + { + case NA: + return "NA"; + case ERROR: + return "Error"; + default: + return ""; + } + } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/Cell.java b/src/com/bytezone/diskbrowser/visicalc/Cell.java index 0e3fbd0..89366bd 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Cell.java +++ b/src/com/bytezone/diskbrowser/visicalc/Cell.java @@ -10,12 +10,11 @@ class Cell extends AbstractValue implements Comparable private final Sheet parent; private CellType cellType; private final Format format = new Format (); + private String expressionText; private String repeatingText; private String repeat = ""; private String label; - - private String expressionText; private Value value; enum CellType @@ -84,6 +83,8 @@ class Cell extends AbstractValue implements Comparable // FUTURE.VC if (false) + { + System.out.println ("****** Hardcoded values ******"); if (address.rowKey == 67) expressionText = "1000"; else if (address.rowKey == 131) @@ -92,9 +93,12 @@ class Cell extends AbstractValue implements Comparable expressionText = "12"; else if (address.rowKey == 259) expressionText = "8"; + } // IRA.VC - if (true) + if (false) + { + System.out.println ("****** Hardcoded values ******"); if (address.rowKey == 66) expressionText = "10"; else if (address.rowKey == 130) @@ -105,9 +109,12 @@ class Cell extends AbstractValue implements Comparable expressionText = "1000"; else if (address.rowKey == 386) expressionText = "15"; + } // CARLOAN.VC if (false) + { + System.out.println ("****** Hardcoded values ******"); if (address.rowKey == 67) expressionText = "9375"; else if (address.rowKey == 131) @@ -116,6 +123,7 @@ class Cell extends AbstractValue implements Comparable expressionText = "24"; else if (address.rowKey == 259) expressionText = "11.9"; + } } // format cell value for output @@ -193,8 +201,10 @@ class Cell extends AbstractValue implements Comparable expressionText = ""; Expression expression = new Expression (parent, expressionText); - value = expression.size () == 1 ? expression.get (0) : expression; + // value = expression.size () == 1 ? expression.get (0) : expression; + value = expression.reduce (); } + value.calculate (); return this; @@ -228,8 +238,6 @@ class Cell extends AbstractValue implements Comparable text.append (String.format ("| VALUE : %-69s |%n", expressionText)); if (value == null) text.append (String.format ("| Value : %-69s |%n", "null")); - // else if (value instanceof Expression) - // text.append (getExpressionComponents ((Expression) value, 1)); else text.append (getValueText (value, 0)); break; @@ -257,31 +265,19 @@ class Cell extends AbstractValue implements Comparable String.format ("| %-10s : %-69s |%n", typeText, value.getValueType ())); if (value instanceof Expression) - text.append (getExpressionComponents ((Expression) value, depth + 1)); + { + text.append ( + String.format ("| Expression : %-69s |%n", ((Expression) value).fullText ())); + for (Value v : (Expression) value) + text.append (getValueText (v, depth + 1)); + } else if (value instanceof Function) - text.append (getFunctionComponents ((Function) value, depth + 1)); - - return text.toString (); - } - - private String getExpressionComponents (Expression expression, int depth) - { - StringBuilder text = new StringBuilder (); - - text.append (String.format ("| Expression : %-69s |%n", expression.fullText ())); - for (Value value : expression) - text.append (getValueText (value, depth)); - - return text.toString (); - } - - private String getFunctionComponents (Function function, int depth) - { - StringBuilder text = new StringBuilder (); - - text.append (String.format ("| Function : %-69s |%n", function.fullText)); - for (Value value : function) - text.append (getValueText (value, depth)); + { + text.append ( + String.format ("| Function : %-69s |%n", ((Function) value).fullText)); + for (Value v : (Function) value) + text.append (getValueText (v, depth + 1)); + } return text.toString (); } diff --git a/src/com/bytezone/diskbrowser/visicalc/Condition.java b/src/com/bytezone/diskbrowser/visicalc/Condition.java index e663893..06fbdff 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Condition.java +++ b/src/com/bytezone/diskbrowser/visicalc/Condition.java @@ -3,7 +3,7 @@ package com.bytezone.diskbrowser.visicalc; import com.bytezone.diskbrowser.visicalc.Value.ValueType; // Predicate -class Condition +class Condition //extends AbstractValue { private static final String[] comparators = { "<>", "<=", ">=", "=", "<", ">" }; @@ -18,8 +18,8 @@ class Condition public Condition (Sheet parent, String text) { + // super ("Condition"); this.parent = parent; - // System.out.println (text); for (String comp : comparators) { diff --git a/src/com/bytezone/diskbrowser/visicalc/Expression.java b/src/com/bytezone/diskbrowser/visicalc/Expression.java index dce2c18..e3316bf 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Expression.java +++ b/src/com/bytezone/diskbrowser/visicalc/Expression.java @@ -29,12 +29,10 @@ class Expression extends AbstractValue implements Iterable // [.3*(B4+B7+B8+B9)] // [+N12+(P12*(.2*K12+K9-O12))] - private final List values = new ArrayList (); + // private final List values = new ArrayList (); private final List operators = new ArrayList (); private final List signs = new ArrayList (); - private ValueType valueType = ValueType.VALUE; - private double value; private String text; public Expression (Sheet parent, String text) @@ -128,6 +126,13 @@ class Expression extends AbstractValue implements Iterable System.out.printf ("Nothing[%s]%n", text); } + Value reduce () + { + if (values.size () == 1 && signs.get (0).equals ("(+)")) + return values.get (0); + return this; + } + int size () { return values.size (); @@ -210,48 +215,6 @@ class Expression extends AbstractValue implements Iterable return this; } - @Override - public ValueType getValueType () - { - return valueType; - } - - @Override - public boolean isValueType (ValueType type) - { - return valueType == type; - } - - @Override - public double getValue () - { - return value; - } - - @Override - public String getText () - { - if (valueType == null && values.size () > 0) - calculate (); - - if (valueType == null) - { - System.out.printf ("null valuetype in exp [%s]%n", text); - System.out.println (values.size ()); - } - switch (valueType) - { - case NA: - return "NA"; - case ERROR: - return "Error"; - // case NAN: - // return "NaN"; - default: - return "???"; - } - } - private String checkBrackets (String input) { String line = input.trim (); diff --git a/src/com/bytezone/diskbrowser/visicalc/Function.java b/src/com/bytezone/diskbrowser/visicalc/Function.java index ff2b800..3a2ec32 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Function.java +++ b/src/com/bytezone/diskbrowser/visicalc/Function.java @@ -1,8 +1,6 @@ package com.bytezone.diskbrowser.visicalc; -import java.util.ArrayList; import java.util.Iterator; -import java.util.List; // http://www.bricklin.com/history/refcard1.htm // Functions: @@ -33,10 +31,7 @@ abstract class Function extends AbstractValue implements Iterable protected String functionText; protected String fullText; - protected ValueType valueType; - protected double value; - - protected List values = new ArrayList (); + // protected List values = new ArrayList (); static Function getInstance (Sheet parent, String text) { @@ -118,40 +113,6 @@ abstract class Function extends AbstractValue implements Iterable } } - @Override - public ValueType getValueType () - { - return valueType; - } - - @Override - public boolean isValueType (ValueType type) - { - return valueType == type; - } - - @Override - public double getValue () - { - return value; - } - - @Override - public String getText () - { - switch (valueType) - { - case NA: - return "NA"; - case ERROR: - return "Error"; - // case NAN: - // return "NaN"; - default: - return ""; - } - } - @Override public Iterator iterator () { diff --git a/src/com/bytezone/diskbrowser/visicalc/If.java b/src/com/bytezone/diskbrowser/visicalc/If.java index f193548..7008752 100644 --- a/src/com/bytezone/diskbrowser/visicalc/If.java +++ b/src/com/bytezone/diskbrowser/visicalc/If.java @@ -12,7 +12,6 @@ class If extends Function public If (Sheet parent, String text) { super (parent, text); - // System.out.println (text); int pos1 = functionText.indexOf (','); int pos2 = functionText.indexOf (',', pos1 + 1); diff --git a/src/com/bytezone/diskbrowser/visicalc/Number.java b/src/com/bytezone/diskbrowser/visicalc/Number.java index fc24b3c..e57115b 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Number.java +++ b/src/com/bytezone/diskbrowser/visicalc/Number.java @@ -2,9 +2,6 @@ package com.bytezone.diskbrowser.visicalc; class Number extends AbstractValue { - private double value; - private ValueType valueType; - public Number (String text) { super ("Constant"); @@ -12,7 +9,6 @@ class Number extends AbstractValue try { value = Double.parseDouble (text); - valueType = ValueType.VALUE; } catch (NumberFormatException e) { @@ -21,49 +17,15 @@ class Number extends AbstractValue } } - @Override - public boolean isValueType (ValueType type) - { - return valueType == type; - } - @Override public String toString () { return String.format ("Number: %f", value); } - @Override - public double getValue () - { - return value; - } - - @Override - public String getText () - { - switch (valueType) - { - case NA: - return "NA"; - case ERROR: - return "Error"; - // case NAN: - // return "NaN"; - default: - return ""; - } - } - @Override public Value calculate () { return this; } - - @Override - public ValueType getValueType () - { - return valueType; - } } \ No newline at end of file