mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-01-11 04:29:45 +00:00
always add cells
This commit is contained in:
parent
7451194aaf
commit
2b9db288d4
@ -16,6 +16,7 @@ public class Abs extends Function
|
|||||||
{
|
{
|
||||||
source = new Expression (parent, functionText);
|
source = new Expression (parent, functionText);
|
||||||
values.add (source);
|
values.add (source);
|
||||||
|
source.calculate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
value = Math.abs (source.getValue ());
|
value = Math.abs (source.getValue ());
|
||||||
|
@ -7,7 +7,7 @@ public class Average extends Function
|
|||||||
public Average (Sheet parent, String text)
|
public Average (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
range = new Range (text);
|
range = new Range (parent, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -81,6 +81,7 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
|||||||
{
|
{
|
||||||
expressionText = command;
|
expressionText = command;
|
||||||
cellType = CellType.VALUE;
|
cellType = CellType.VALUE;
|
||||||
|
value = new Expression (parent, expressionText).reduce ();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUTURE.VC
|
// FUTURE.VC
|
||||||
@ -144,7 +145,10 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
|||||||
|
|
||||||
case VALUE:
|
case VALUE:
|
||||||
if (!isValueType (ValueType.VALUE))
|
if (!isValueType (ValueType.VALUE))
|
||||||
return Format.justify (value.getText (), colWidth, 'R');
|
{
|
||||||
|
char fmt = cellFormat != ' ' ? cellFormat : globalFormat;
|
||||||
|
return Format.justify (value.getText (), colWidth, fmt);
|
||||||
|
}
|
||||||
|
|
||||||
char formatChar = cellFormat != ' ' ? cellFormat : globalFormat;
|
char formatChar = cellFormat != ' ' ? cellFormat : globalFormat;
|
||||||
return " " + Format.format (value, formatChar, colWidth - 1);
|
return " " + Format.format (value, formatChar, colWidth - 1);
|
||||||
@ -158,8 +162,10 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
|||||||
@Override
|
@Override
|
||||||
public double getValue ()
|
public double getValue ()
|
||||||
{
|
{
|
||||||
if (value == null)
|
// if (value == null)
|
||||||
calculate ();
|
// calculate ();
|
||||||
|
if (cellType != CellType.VALUE)
|
||||||
|
return 0;
|
||||||
|
|
||||||
return value.getValue ();
|
return value.getValue ();
|
||||||
}
|
}
|
||||||
@ -167,14 +173,21 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
|||||||
@Override
|
@Override
|
||||||
public ValueType getValueType ()
|
public ValueType getValueType ()
|
||||||
{
|
{
|
||||||
|
// if (value == null)
|
||||||
|
// calculate ();
|
||||||
|
if (cellType == CellType.EMPTY)
|
||||||
|
return ValueType.NA;
|
||||||
|
|
||||||
return value.getValueType ();
|
return value.getValueType ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getText ()
|
public String getText ()
|
||||||
{
|
{
|
||||||
if (value == null)
|
// if (value == null)
|
||||||
calculate ();
|
// calculate ();
|
||||||
|
if (cellType == CellType.EMPTY)
|
||||||
|
return "";
|
||||||
|
|
||||||
return value.getText ();
|
return value.getText ();
|
||||||
}
|
}
|
||||||
@ -182,9 +195,15 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
|||||||
@Override
|
@Override
|
||||||
public boolean isValueType (ValueType type)
|
public boolean isValueType (ValueType type)
|
||||||
{
|
{
|
||||||
if (value == null)
|
// if (value == null || value.getValueType () != ValueType.VALUE)
|
||||||
calculate ();
|
// calculate ();
|
||||||
|
if (cellType == CellType.LABEL || cellType == CellType.REPEATING_CHARACTER)
|
||||||
|
return type == ValueType.VALUE;
|
||||||
|
|
||||||
|
if (cellType == CellType.EMPTY)
|
||||||
|
return type == ValueType.NA;
|
||||||
|
|
||||||
|
assert value != null : "bollocks " + address;
|
||||||
return value.isValueType (type);
|
return value.isValueType (type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,20 +215,15 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
|||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public void calculate ()
|
||||||
{
|
{
|
||||||
if (value != null && value.isValueType (ValueType.VALUE))
|
// if (value != null && value.isValueType (ValueType.VALUE))
|
||||||
return;
|
// return;
|
||||||
|
//
|
||||||
|
// if (expressionText == null)
|
||||||
|
// expressionText = "";
|
||||||
|
|
||||||
if (value == null)
|
// value = new Expression (parent, expressionText).reduce ();
|
||||||
{
|
if (value != null)
|
||||||
if (expressionText == null)
|
value.calculate ();
|
||||||
expressionText = "";
|
|
||||||
|
|
||||||
value = new Expression (parent, expressionText).reduce ();
|
|
||||||
}
|
|
||||||
|
|
||||||
value.calculate ();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDebugText ()
|
public String getDebugText ()
|
||||||
|
@ -14,7 +14,7 @@ public class Choose extends Function
|
|||||||
int pos = text.indexOf (',');
|
int pos = text.indexOf (',');
|
||||||
sourceText = text.substring (8, pos);
|
sourceText = text.substring (8, pos);
|
||||||
rangeText = text.substring (pos + 1, text.length () - 1);
|
rangeText = text.substring (pos + 1, text.length () - 1);
|
||||||
range = new Range (rangeText);
|
range = new Range (parent, rangeText);
|
||||||
source = new Number (sourceText);
|
source = new Number (sourceText);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ class Count extends Function
|
|||||||
public Count (Sheet parent, String text)
|
public Count (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
range = new Range (text);
|
range = new Range (parent, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,9 +74,9 @@ class Expression extends AbstractValue implements Iterable<Value>
|
|||||||
bracketText.substring (1, bracketText.length () - 1)));
|
bracketText.substring (1, bracketText.length () - 1)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '#':
|
case '#': // no idea
|
||||||
System.out.printf ("Hash character [%s] in [%s]%n", ch, line);
|
System.out.printf ("Hash character [%s] in [%s]%n", ch, line);
|
||||||
ptr++; // no idea
|
ptr++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -93,8 +93,9 @@ class Expression extends AbstractValue implements Iterable<Value>
|
|||||||
Cell cell = parent.getCell (addressText);
|
Cell cell = parent.getCell (addressText);
|
||||||
if (cell == null)
|
if (cell == null)
|
||||||
{
|
{
|
||||||
System.out.println ("adding NA");
|
// should this (or parent) create a new empty cell?
|
||||||
values.add (Function.getInstance (parent, "@NA"));
|
// cell = parent.addCell (addressText);
|
||||||
|
values.add (new Number ("0"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
values.add (parent.getCell (addressText));
|
values.add (parent.getCell (addressText));
|
||||||
@ -154,17 +155,18 @@ class Expression extends AbstractValue implements Iterable<Value>
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Value thisValue = values.get (0);
|
Value thisValue = values.get (0);
|
||||||
thisValue.calculate ();
|
if (thisValue != null) // || thisValue.getValueType () != ValueType.VALUE)
|
||||||
|
thisValue.calculate ();
|
||||||
|
|
||||||
value = 0;
|
value = 0;
|
||||||
if (thisValue.isValueType (ValueType.VALUE))
|
if (!thisValue.isValueType (ValueType.VALUE))
|
||||||
value = thisValue.getValue ();
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
valueType = thisValue.getValueType ();
|
valueType = thisValue.getValueType ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value = thisValue.getValue ();
|
||||||
|
|
||||||
String sign = signs.get (0);
|
String sign = signs.get (0);
|
||||||
if (sign.equals ("(-)"))
|
if (sign.equals ("(-)"))
|
||||||
value *= -1;
|
value *= -1;
|
||||||
@ -172,17 +174,18 @@ class Expression extends AbstractValue implements Iterable<Value>
|
|||||||
for (int i = 1; i < values.size (); i++)
|
for (int i = 1; i < values.size (); i++)
|
||||||
{
|
{
|
||||||
thisValue = values.get (i);
|
thisValue = values.get (i);
|
||||||
thisValue.calculate ();
|
if (thisValue != null) // || thisValue.getValueType () != ValueType.VALUE)
|
||||||
|
thisValue.calculate ();
|
||||||
|
|
||||||
double nextValue = 0;
|
if (!thisValue.isValueType (ValueType.VALUE))
|
||||||
if (thisValue.isValueType (ValueType.VALUE))
|
// if (thisValue.isValueType (ValueType.ERROR))
|
||||||
nextValue = thisValue.getValue ();
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
valueType = thisValue.getValueType ();
|
valueType = thisValue.getValueType ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double nextValue = thisValue.getValue ();
|
||||||
|
|
||||||
sign = signs.get (i);
|
sign = signs.get (i);
|
||||||
if (sign.equals ("(-)"))
|
if (sign.equals ("(-)"))
|
||||||
nextValue *= -1;
|
nextValue *= -1;
|
||||||
|
@ -2,17 +2,21 @@ package com.bytezone.diskbrowser.visicalc;
|
|||||||
|
|
||||||
public class Int extends Function
|
public class Int extends Function
|
||||||
{
|
{
|
||||||
|
Expression source;
|
||||||
|
|
||||||
Int (Sheet parent, String text)
|
Int (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
|
|
||||||
|
source = new Expression (parent, functionText);
|
||||||
|
values.add (source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public void calculate ()
|
||||||
{
|
{
|
||||||
Expression exp = new Expression (parent, functionText);
|
source.calculate ();
|
||||||
value = (int) exp.getValue ();
|
value = (int) source.getValue ();
|
||||||
valueType = exp.getValueType ();
|
valueType = source.getValueType ();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,26 +13,29 @@ class Lookup extends Function
|
|||||||
|
|
||||||
int pos = text.indexOf (',');
|
int pos = text.indexOf (',');
|
||||||
sourceText = text.substring (8, pos);
|
sourceText = text.substring (8, pos);
|
||||||
|
source = new Expression (parent, sourceText);
|
||||||
|
values.add (source);
|
||||||
rangeText = text.substring (pos + 1, text.length () - 1);
|
rangeText = text.substring (pos + 1, text.length () - 1);
|
||||||
range = new Range (rangeText);
|
range = new Range (parent, rangeText);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public void calculate ()
|
||||||
{
|
{
|
||||||
if (source == null)
|
|
||||||
{
|
|
||||||
source = new Expression (parent, sourceText);
|
|
||||||
values.add (source);
|
|
||||||
}
|
|
||||||
|
|
||||||
source.calculate ();
|
source.calculate ();
|
||||||
|
|
||||||
if (!source.isValueType (ValueType.VALUE))
|
if (!source.isValueType (ValueType.VALUE))
|
||||||
{
|
{
|
||||||
valueType = source.getValueType ();
|
valueType = source.getValueType ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (range.size () == 0)
|
||||||
|
{
|
||||||
|
valueType = ValueType.NA;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
double sourceValue = source.getValue ();
|
double sourceValue = source.getValue ();
|
||||||
Address target = null;
|
Address target = null;
|
||||||
|
|
||||||
@ -44,15 +47,26 @@ class Lookup extends Function
|
|||||||
target = address;
|
target = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// System.out.printf ("*****-----**** %s%n", target);
|
||||||
if (target == null)
|
if (target == null)
|
||||||
valueType = ValueType.NA;
|
valueType = ValueType.NA;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Address adjacentAddress =
|
Address adjacentAddress =
|
||||||
range.isVertical () ? target.nextColumn () : target.nextRow ();
|
range.isVertical () ? target.nextColumn () : target.nextRow ();
|
||||||
Cell adjacentCell = parent.getCell (adjacentAddress);
|
|
||||||
value = adjacentCell.getValue ();
|
if (parent.cellExists (adjacentAddress))
|
||||||
valueType = ValueType.VALUE;
|
{
|
||||||
|
Cell adjacentCell = parent.getCell (adjacentAddress);
|
||||||
|
if (adjacentCell != null)
|
||||||
|
value = adjacentCell.getValue ();
|
||||||
|
valueType = ValueType.VALUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value = 0;
|
||||||
|
valueType = ValueType.VALUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ class Max extends Function
|
|||||||
public Max (Sheet parent, String text)
|
public Max (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
range = new Range (text);
|
range = new Range (parent, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,7 +7,7 @@ class Min extends Function
|
|||||||
public Min (Sheet parent, String text)
|
public Min (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
range = new Range (text);
|
range = new Range (parent, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,7 +11,7 @@ public class Npv extends Function
|
|||||||
Npv (Sheet parent, String text)
|
Npv (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
range = new Range (text);
|
range = new Range (parent, text);
|
||||||
|
|
||||||
// int pos = text.indexOf (',');
|
// int pos = text.indexOf (',');
|
||||||
// valueText = text.substring (8, pos);
|
// valueText = text.substring (8, pos);
|
||||||
|
@ -15,24 +15,41 @@ class Range implements Iterable<Address>
|
|||||||
|
|
||||||
Address from, to;
|
Address from, to;
|
||||||
List<Address> range = new ArrayList<Address> ();
|
List<Address> range = new ArrayList<Address> ();
|
||||||
|
Sheet parent;
|
||||||
|
|
||||||
public Range (String rangeText)
|
public Range (Sheet parent, String rangeText)
|
||||||
{
|
{
|
||||||
|
this.parent = parent;
|
||||||
setRange (rangeText);
|
setRange (rangeText);
|
||||||
|
|
||||||
|
createCells ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Range (Address from, Address to)
|
public Range (Sheet parent, Address from, Address to)
|
||||||
{
|
{
|
||||||
this.from = from;
|
this.from = from;
|
||||||
this.to = to;
|
this.to = to;
|
||||||
|
this.parent = parent;
|
||||||
|
|
||||||
addRange ();
|
addRange ();
|
||||||
|
|
||||||
|
createCells ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Range (String[] cells)
|
public Range (Sheet parent, String[] cells)
|
||||||
{
|
{
|
||||||
|
this.parent = parent;
|
||||||
|
|
||||||
for (String s : cells)
|
for (String s : cells)
|
||||||
range.add (new Address (s));
|
range.add (new Address (s));
|
||||||
|
|
||||||
|
createCells ();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createCells ()
|
||||||
|
{
|
||||||
|
for (Address address : range)
|
||||||
|
parent.getCell (address);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addRange ()
|
private void addRange ()
|
||||||
@ -54,6 +71,7 @@ class Range implements Iterable<Address>
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw new InvalidParameterException ();
|
throw new InvalidParameterException ();
|
||||||
|
|
||||||
from = tempFrom;
|
from = tempFrom;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +95,17 @@ class Range implements Iterable<Address>
|
|||||||
return range.iterator ();
|
return range.iterator ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int size ()
|
||||||
|
{
|
||||||
|
int total = 0;
|
||||||
|
|
||||||
|
for (Address address : range)
|
||||||
|
if (parent.getCell (address) != null)
|
||||||
|
++total;
|
||||||
|
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
private void setRange (String text)
|
private void setRange (String text)
|
||||||
{
|
{
|
||||||
Matcher m = rangePattern.matcher (text);
|
Matcher m = rangePattern.matcher (text);
|
||||||
|
@ -164,6 +164,7 @@ public class Sheet
|
|||||||
ptr += length + 1; // +1 for end-of-line token
|
ptr += length + 1; // +1 for end-of-line token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println ("** Start of calculation **");
|
||||||
// might have to keep recalculating until nothing changes??
|
// might have to keep recalculating until nothing changes??
|
||||||
if (recalculation == 'A') // auto
|
if (recalculation == 'A') // auto
|
||||||
{
|
{
|
||||||
@ -260,6 +261,7 @@ public class Sheet
|
|||||||
|
|
||||||
private void addCell (Cell cell)
|
private void addCell (Cell cell)
|
||||||
{
|
{
|
||||||
|
// System.out.printf ("Adding: %s%n", cell);
|
||||||
rowOrderCells.put (cell.getAddress ().rowKey, cell);
|
rowOrderCells.put (cell.getAddress ().rowKey, cell);
|
||||||
columnOrderCells.put (cell.getAddress ().columnKey, cell);
|
columnOrderCells.put (cell.getAddress ().columnKey, cell);
|
||||||
|
|
||||||
@ -274,7 +276,19 @@ public class Sheet
|
|||||||
|
|
||||||
Cell getCell (Address address)
|
Cell getCell (Address address)
|
||||||
{
|
{
|
||||||
return rowOrderCells.get (address.rowKey);
|
Cell cell = rowOrderCells.get (address.rowKey);
|
||||||
|
if (cell == null)
|
||||||
|
{
|
||||||
|
// System.out.printf ("cell not found, creating: %s%n", address);
|
||||||
|
cell = new Cell (this, address);
|
||||||
|
addCell (cell);
|
||||||
|
}
|
||||||
|
return cell;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean cellExists (Address address)
|
||||||
|
{
|
||||||
|
return rowOrderCells.get (address.rowKey) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size ()
|
public int size ()
|
||||||
|
@ -7,7 +7,7 @@ class Sum extends Function
|
|||||||
public Sum (Sheet parent, String text)
|
public Sum (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
range = new Range (text);
|
range = new Range (parent, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user