From 7056f5c49dd4ebd9488591ef0b6c834b755f33b3 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Wed, 15 Mar 2017 15:40:18 +1100 Subject: [PATCH] volatility --- .../diskbrowser/visicalc/Address.java | 6 +++ .../bytezone/diskbrowser/visicalc/Cell.java | 25 ++++++------ .../bytezone/diskbrowser/visicalc/Count.java | 10 ++--- .../diskbrowser/visicalc/Expression.java | 38 +++++++++++++++---- .../bytezone/diskbrowser/visicalc/Sheet.java | 6 +-- 5 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/com/bytezone/diskbrowser/visicalc/Address.java b/src/com/bytezone/diskbrowser/visicalc/Address.java index edbdd26..88b0b24 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Address.java +++ b/src/com/bytezone/diskbrowser/visicalc/Address.java @@ -42,6 +42,12 @@ class Address implements Comparable
set (address.substring (0, 2), address.substring (2)); } + public boolean matches (String addressText) + { + Address address = new Address (addressText); + return this.rowMatches (address) && this.columnMatches (address); + } + private void set (String sCol, String sRow) { if (sCol.length () == 1) diff --git a/src/com/bytezone/diskbrowser/visicalc/Cell.java b/src/com/bytezone/diskbrowser/visicalc/Cell.java index 09fcb96..7673544 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Cell.java +++ b/src/com/bytezone/diskbrowser/visicalc/Cell.java @@ -30,7 +30,7 @@ class Cell extends AbstractValue implements Comparable this.address = address; cellType = CellType.EMPTY; - isVolatile = true; + isVolatile = false; } boolean isCellType (CellType cellType) @@ -103,8 +103,7 @@ class Cell extends AbstractValue implements Comparable expressionText = command; value = new Expression (parent, this, expressionText).reduce (); cellType = CellType.VALUE; - - isVolatile = value.isVolatile (); + isVolatile = true; } catch (IllegalArgumentException e) { @@ -200,20 +199,14 @@ class Cell extends AbstractValue implements Comparable @Override public ValueType getValueType () { - if (cellType == CellType.EMPTY) - return ValueType.NA; - - if (cellType == CellType.LABEL || cellType == CellType.REPEATING_CHARACTER) - return ValueType.VALUE; - - return value.getValueType (); + return cellType == CellType.VALUE ? value.getValueType () : ValueType.VALUE; } @Override public String getText () { if (cellType == CellType.EMPTY) - return ""; + return "MPT"; if (cellType == CellType.LABEL) return "LBL"; @@ -236,8 +229,11 @@ class Cell extends AbstractValue implements Comparable { if (cellType == CellType.VALUE) { - value.calculate (); - isVolatile = value.isVolatile (); + if (isVolatile) + { + value.calculate (); + isVolatile = value.isVolatile (); + } } } @@ -301,7 +297,8 @@ class Cell extends AbstractValue implements Comparable contents = "Empty"; } - return String.format ("[Cell:%5s %s]", address, contents); + return String.format ("[Cell:%5s %s %s]", address, contents, + isVolatile ? "volatile" : "fixed"); } @Override diff --git a/src/com/bytezone/diskbrowser/visicalc/Count.java b/src/com/bytezone/diskbrowser/visicalc/Count.java index 140cd60..7dc00b5 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Count.java +++ b/src/com/bytezone/diskbrowser/visicalc/Count.java @@ -1,5 +1,7 @@ package com.bytezone.diskbrowser.visicalc; +import com.bytezone.diskbrowser.visicalc.Cell.CellType; + class Count extends Function { private final ExpressionList list; @@ -26,15 +28,9 @@ class Count extends Function { v.calculate (); - if (v instanceof Cell && v.isValueType (ValueType.NA)) + if (v instanceof Cell && ((Cell) v).isCellType (CellType.EMPTY)) continue; - if (!v.isValueType (ValueType.VALUE)) - { - valueType = v.getValueType (); - return; - } - value++; } } diff --git a/src/com/bytezone/diskbrowser/visicalc/Expression.java b/src/com/bytezone/diskbrowser/visicalc/Expression.java index 76368c8..b770673 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Expression.java +++ b/src/com/bytezone/diskbrowser/visicalc/Expression.java @@ -146,18 +146,32 @@ class Expression extends AbstractValue implements Iterable System.out.println ("nothing to calculate: " + text); return; } - System.out.printf (" calc %-6s %s%n", cell.getAddressText (), text); + + // System.out.printf (" calc %-6s %s%n", cell.getAddressText (), text); if (!isVolatile) return; boolean currentVolatile = false; - // System.out.printf ("exp %s is currently %svolatile%n", text, - // isVolatile ? " " : "not "); + + // boolean debug = cell.getAddress ().matches ("C8"); + boolean debug = false; + if (debug) + { + System.out.println (this); + System.out.printf ("(1) exp %s is currently %svolatile%n", text, + isVolatile ? " " : "not "); + } try { Value thisValue = values.get (0); thisValue.calculate (); + if (debug) + { + System.out.println (this); + System.out.printf ("(2) exp %s is currently %svolatile%n", thisValue.getText (), + thisValue.isVolatile () ? " " : "not "); + } value = 0; if (!thisValue.isValueType (ValueType.VALUE)) @@ -167,8 +181,6 @@ class Expression extends AbstractValue implements Iterable } value = thisValue.getValue (); - // System.out.printf ("exp %s is currently %svolatile%n", thisValue.getText (), - // thisValue.isVolatile () ? " " : "not "); if (!currentVolatile) currentVolatile = thisValue.isVolatile (); @@ -188,8 +200,12 @@ class Expression extends AbstractValue implements Iterable } double nextValue = thisValue.getValue (); - // System.out.printf ("exp %s is currently %svolatile%n", thisValue.getText (), - // thisValue.isVolatile () ? " " : "not "); + if (debug) + { + System.out.println (this); + System.out.printf ("(3.%d) exp %s is currently %svolatile%n", i, + thisValue.getText (), thisValue.isVolatile () ? " " : "not "); + } if (!currentVolatile) currentVolatile = thisValue.isVolatile (); @@ -230,7 +246,13 @@ class Expression extends AbstractValue implements Iterable } isVolatile = currentVolatile; - // System.out.println (currentVolatile); + if (debug) + { + System.out.println (this); + System.out.printf ("(4) exp %s is currently %svolatile%n", text, + isVolatile ? " " : "not "); + System.out.println (); + } } private String balanceBrackets (String input) diff --git a/src/com/bytezone/diskbrowser/visicalc/Sheet.java b/src/com/bytezone/diskbrowser/visicalc/Sheet.java index be4b861..e3556d3 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Sheet.java +++ b/src/com/bytezone/diskbrowser/visicalc/Sheet.java @@ -166,7 +166,7 @@ public class Sheet } // might have to keep recalculating until nothing changes?? - System.out.println ("\n*********** Calculating\n"); + // System.out.println ("\n*********** Calculating\n"); calculate (recalculationOrder); // System.out.println ("\n*********** Calculating\n"); // calculate (recalculationOrder); @@ -179,9 +179,9 @@ public class Sheet for (Cell cell : cells.values ()) if (cell.isCellType (CellType.VALUE)) { - System.out.printf ("%5d start %s%n", count, cell.getAddressText ()); + // System.out.printf ("%5d start %s%n", count, cell.getAddressText ()); cell.calculate (); - System.out.printf ("%5d stop %s%n", count++, cell.getAddressText ()); + // System.out.printf ("%5d stop %s%n", count++, cell.getAddressText ()); } }