volatility

This commit is contained in:
Denis Molony 2017-03-15 15:40:18 +11:00
parent cad2106c71
commit 7056f5c49d
5 changed files with 53 additions and 32 deletions

View File

@ -42,6 +42,12 @@ class Address implements Comparable<Address>
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)

View File

@ -30,7 +30,7 @@ class Cell extends AbstractValue implements Comparable<Cell>
this.address = address;
cellType = CellType.EMPTY;
isVolatile = true;
isVolatile = false;
}
boolean isCellType (CellType cellType)
@ -103,8 +103,7 @@ class Cell extends AbstractValue implements Comparable<Cell>
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<Cell>
@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<Cell>
{
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<Cell>
contents = "Empty";
}
return String.format ("[Cell:%5s %s]", address, contents);
return String.format ("[Cell:%5s %s %s]", address, contents,
isVolatile ? "volatile" : "fixed");
}
@Override

View File

@ -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++;
}
}

View File

@ -146,18 +146,32 @@ class Expression extends AbstractValue implements Iterable<Value>
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>
}
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<Value>
}
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<Value>
}
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)

View File

@ -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 ());
}
}