mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-06-15 19:29:45 +00:00
privacy
This commit is contained in:
parent
2b9db288d4
commit
2bbe143296
|
@ -2,22 +2,20 @@ package com.bytezone.diskbrowser.visicalc;
|
||||||
|
|
||||||
public class Abs extends Function
|
public class Abs extends Function
|
||||||
{
|
{
|
||||||
Expression source;
|
private final Expression source;
|
||||||
|
|
||||||
Abs (Sheet parent, String text)
|
Abs (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 ()
|
||||||
{
|
{
|
||||||
if (source == null)
|
source.calculate ();
|
||||||
{
|
|
||||||
source = new Expression (parent, functionText);
|
|
||||||
values.add (source);
|
|
||||||
source.calculate ();
|
|
||||||
}
|
|
||||||
|
|
||||||
value = Math.abs (source.getValue ());
|
value = Math.abs (source.getValue ());
|
||||||
valueType = source.getValueType ();
|
valueType = source.getValueType ();
|
||||||
|
|
|
@ -89,7 +89,7 @@ public abstract class AbstractValue implements Value
|
||||||
else if (this instanceof Condition)
|
else if (this instanceof Condition)
|
||||||
{
|
{
|
||||||
text.append (
|
text.append (
|
||||||
String.format ("| Condition : %-69s |%n", ((Condition) this).fullText));
|
String.format ("| Condition : %-69s |%n", ((Condition) this).getFullText ()));
|
||||||
for (Value v : (Condition) this)
|
for (Value v : (Condition) this)
|
||||||
text.append (((AbstractValue) v).getValueText (depth + 1));
|
text.append (((AbstractValue) v).getValueText (depth + 1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,10 @@ class Address implements Comparable<Address>
|
||||||
private static final int MAX_ROWS = 255;
|
private static final int MAX_ROWS = 255;
|
||||||
private static final int MAX_COLUMNS = 64;
|
private static final int MAX_COLUMNS = 64;
|
||||||
|
|
||||||
int row, column;
|
private int row, column;
|
||||||
int rowKey;
|
private int rowKey;
|
||||||
int columnKey;
|
private int columnKey;
|
||||||
String text;
|
private String text;
|
||||||
|
|
||||||
public Address (String column, String row)
|
public Address (String column, String row)
|
||||||
{
|
{
|
||||||
|
@ -65,6 +65,26 @@ class Address implements Comparable<Address>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean rowMatches (Address other)
|
||||||
|
{
|
||||||
|
return row == other.row;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean columnMatches (Address other)
|
||||||
|
{
|
||||||
|
return column == other.column;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getRow ()
|
||||||
|
{
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getColumn ()
|
||||||
|
{
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
|
||||||
Address nextRow ()
|
Address nextRow ()
|
||||||
{
|
{
|
||||||
Address next = new Address (column, row + 1);
|
Address next = new Address (column, row + 1);
|
||||||
|
@ -90,6 +110,16 @@ class Address implements Comparable<Address>
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getRowKey ()
|
||||||
|
{
|
||||||
|
return rowKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getColumnKey ()
|
||||||
|
{
|
||||||
|
return columnKey;
|
||||||
|
}
|
||||||
|
|
||||||
public String getDetails ()
|
public String getDetails ()
|
||||||
{
|
{
|
||||||
return String.format ("Row:%3d Col:%3d rKey:%5d cKey:%5d", row, column, rowKey,
|
return String.format ("Row:%3d Col:%3d rKey:%5d cKey:%5d", row, column, rowKey,
|
||||||
|
|
|
@ -5,11 +5,12 @@ import java.util.List;
|
||||||
|
|
||||||
class And extends Function
|
class And extends Function
|
||||||
{
|
{
|
||||||
List<Condition> conditions = new ArrayList<Condition> ();
|
private final List<Condition> conditions = new ArrayList<Condition> ();
|
||||||
|
|
||||||
public And (Sheet parent, String text)
|
public And (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
|
|
||||||
String list[] = text.split (",");
|
String list[] = text.split (",");
|
||||||
for (String s : list)
|
for (String s : list)
|
||||||
conditions.add (new Condition (parent, s));
|
conditions.add (new Condition (parent, s));
|
||||||
|
|
|
@ -7,6 +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 (parent, text);
|
range = new Range (parent, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ public class Average extends Function
|
||||||
for (Address address : range)
|
for (Address address : range)
|
||||||
{
|
{
|
||||||
Cell cell = parent.getCell (address);
|
Cell cell = parent.getCell (address);
|
||||||
if (cell == null || cell.isValueType (ValueType.NA))
|
if (cell.isValueType (ValueType.NA))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!cell.isValueType (ValueType.VALUE))
|
if (!cell.isValueType (ValueType.VALUE))
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||||
|
|
||||||
public Cell (Sheet parent, Address address)
|
public Cell (Sheet parent, Address address)
|
||||||
{
|
{
|
||||||
super ("Cell " + address.text);
|
super ("Cell " + address.getText ());
|
||||||
|
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.address = address;
|
this.address = address;
|
||||||
|
@ -88,13 +88,13 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||||
if (false)
|
if (false)
|
||||||
{
|
{
|
||||||
System.out.println ("****** Hardcoded values ******");
|
System.out.println ("****** Hardcoded values ******");
|
||||||
if (address.rowKey == 67)
|
if (address.getRowKey () == 67)
|
||||||
expressionText = "1000";
|
expressionText = "1000";
|
||||||
else if (address.rowKey == 131)
|
else if (address.getRowKey () == 131)
|
||||||
expressionText = "10.5";
|
expressionText = "10.5";
|
||||||
else if (address.rowKey == 195)
|
else if (address.getRowKey () == 195)
|
||||||
expressionText = "12";
|
expressionText = "12";
|
||||||
else if (address.rowKey == 259)
|
else if (address.getRowKey () == 259)
|
||||||
expressionText = "8";
|
expressionText = "8";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,15 +102,15 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||||
if (false)
|
if (false)
|
||||||
{
|
{
|
||||||
System.out.println ("****** Hardcoded values ******");
|
System.out.println ("****** Hardcoded values ******");
|
||||||
if (address.rowKey == 66)
|
if (address.getRowKey () == 66)
|
||||||
expressionText = "10";
|
expressionText = "10";
|
||||||
else if (address.rowKey == 130)
|
else if (address.getRowKey () == 130)
|
||||||
expressionText = "30";
|
expressionText = "30";
|
||||||
else if (address.rowKey == 194)
|
else if (address.getRowKey () == 194)
|
||||||
expressionText = "65";
|
expressionText = "65";
|
||||||
else if (address.rowKey == 258)
|
else if (address.getRowKey () == 258)
|
||||||
expressionText = "1000";
|
expressionText = "1000";
|
||||||
else if (address.rowKey == 386)
|
else if (address.getRowKey () == 386)
|
||||||
expressionText = "15";
|
expressionText = "15";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +118,13 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||||
if (false)
|
if (false)
|
||||||
{
|
{
|
||||||
System.out.println ("****** Hardcoded values ******");
|
System.out.println ("****** Hardcoded values ******");
|
||||||
if (address.rowKey == 67)
|
if (address.getRowKey () == 67)
|
||||||
expressionText = "9375";
|
expressionText = "9375";
|
||||||
else if (address.rowKey == 131)
|
else if (address.getRowKey () == 131)
|
||||||
expressionText = "4500";
|
expressionText = "4500";
|
||||||
else if (address.rowKey == 195)
|
else if (address.getRowKey () == 195)
|
||||||
expressionText = "24";
|
expressionText = "24";
|
||||||
else if (address.rowKey == 259)
|
else if (address.getRowKey () == 259)
|
||||||
expressionText = "11.9";
|
expressionText = "11.9";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,10 +173,10 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||||
@Override
|
@Override
|
||||||
public ValueType getValueType ()
|
public ValueType getValueType ()
|
||||||
{
|
{
|
||||||
// if (value == null)
|
|
||||||
// calculate ();
|
|
||||||
if (cellType == CellType.EMPTY)
|
if (cellType == CellType.EMPTY)
|
||||||
return ValueType.NA;
|
return ValueType.NA;
|
||||||
|
if (cellType == CellType.LABEL || cellType == CellType.REPEATING_CHARACTER)
|
||||||
|
return ValueType.VALUE;
|
||||||
|
|
||||||
return value.getValueType ();
|
return value.getValueType ();
|
||||||
}
|
}
|
||||||
|
@ -184,8 +184,6 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||||
@Override
|
@Override
|
||||||
public String getText ()
|
public String getText ()
|
||||||
{
|
{
|
||||||
// if (value == null)
|
|
||||||
// calculate ();
|
|
||||||
if (cellType == CellType.EMPTY)
|
if (cellType == CellType.EMPTY)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
|
@ -195,16 +193,15 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||||
@Override
|
@Override
|
||||||
public boolean isValueType (ValueType type)
|
public boolean isValueType (ValueType type)
|
||||||
{
|
{
|
||||||
// if (value == null || value.getValueType () != ValueType.VALUE)
|
// if (cellType == CellType.LABEL || cellType == CellType.REPEATING_CHARACTER)
|
||||||
// calculate ();
|
// return type == ValueType.VALUE;
|
||||||
if (cellType == CellType.LABEL || cellType == CellType.REPEATING_CHARACTER)
|
//
|
||||||
return type == ValueType.VALUE;
|
// if (cellType == CellType.EMPTY)
|
||||||
|
// return type == ValueType.NA;
|
||||||
if (cellType == CellType.EMPTY)
|
//
|
||||||
return type == ValueType.NA;
|
// assert value != null : "bollocks " + address;
|
||||||
|
// return value.isValueType (type);
|
||||||
assert value != null : "bollocks " + address;
|
return type == getValueType ();
|
||||||
return value.isValueType (type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCellType (CellType type)
|
public boolean isCellType (CellType type)
|
||||||
|
|
|
@ -2,10 +2,10 @@ package com.bytezone.diskbrowser.visicalc;
|
||||||
|
|
||||||
public class Choose extends Function
|
public class Choose extends Function
|
||||||
{
|
{
|
||||||
protected final Range range;
|
private final Range range;
|
||||||
String sourceText;
|
private final String sourceText;
|
||||||
String rangeText;
|
private final String rangeText;
|
||||||
Number source;
|
private final Number source;
|
||||||
|
|
||||||
Choose (Sheet parent, String text)
|
Choose (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
|
@ -13,8 +13,10 @@ public class Choose extends Function
|
||||||
|
|
||||||
int pos = text.indexOf (',');
|
int pos = text.indexOf (',');
|
||||||
sourceText = text.substring (8, pos);
|
sourceText = text.substring (8, pos);
|
||||||
|
source = new Number (sourceText);
|
||||||
rangeText = text.substring (pos + 1, text.length () - 1);
|
rangeText = text.substring (pos + 1, text.length () - 1);
|
||||||
range = new Range (parent, rangeText);
|
range = new Range (parent, rangeText);
|
||||||
source = new Number (sourceText);
|
|
||||||
|
values.add (source);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ class Condition extends AbstractValue implements Iterable<Value>
|
||||||
private String comparator;
|
private String comparator;
|
||||||
private String conditionText;
|
private String conditionText;
|
||||||
private String valueText;
|
private String valueText;
|
||||||
protected String fullText;
|
private final String fullText;
|
||||||
|
|
||||||
private Expression conditionExpression;
|
private Expression conditionExpression;
|
||||||
private Expression valueExpression;
|
private Expression valueExpression;
|
||||||
|
@ -30,6 +30,10 @@ class Condition extends AbstractValue implements Iterable<Value>
|
||||||
{
|
{
|
||||||
conditionText = text.substring (0, pos);
|
conditionText = text.substring (0, pos);
|
||||||
valueText = text.substring (pos + comp.length ());
|
valueText = text.substring (pos + comp.length ());
|
||||||
|
conditionExpression = new Expression (parent, conditionText);
|
||||||
|
valueExpression = new Expression (parent, valueText);
|
||||||
|
values.add (conditionExpression);
|
||||||
|
values.add (valueExpression);
|
||||||
comparator = comp;
|
comparator = comp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -53,17 +57,8 @@ class Condition extends AbstractValue implements Iterable<Value>
|
||||||
{
|
{
|
||||||
value = 0;
|
value = 0;
|
||||||
|
|
||||||
if (conditionExpression == null)
|
conditionExpression.calculate ();
|
||||||
{
|
valueExpression.calculate ();
|
||||||
conditionExpression = new Expression (parent, conditionText);
|
|
||||||
valueExpression = new Expression (parent, valueText);
|
|
||||||
|
|
||||||
conditionExpression.calculate ();
|
|
||||||
valueExpression.calculate ();
|
|
||||||
|
|
||||||
values.add (conditionExpression);
|
|
||||||
values.add (valueExpression);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conditionExpression.isValueType (ValueType.ERROR)
|
if (conditionExpression.isValueType (ValueType.ERROR)
|
||||||
|| valueExpression.isValueType (ValueType.ERROR))
|
|| valueExpression.isValueType (ValueType.ERROR))
|
||||||
|
@ -88,6 +83,11 @@ class Condition extends AbstractValue implements Iterable<Value>
|
||||||
System.out.printf ("Unexpected comparator result [%s]%n", comparator);
|
System.out.printf ("Unexpected comparator result [%s]%n", comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getFullText ()
|
||||||
|
{
|
||||||
|
return fullText;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString ()
|
public String toString ()
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +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 (parent, text);
|
range = new Range (parent, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +20,8 @@ class Count extends Function
|
||||||
for (Address address : range)
|
for (Address address : range)
|
||||||
{
|
{
|
||||||
Cell cell = parent.getCell (address);
|
Cell cell = parent.getCell (address);
|
||||||
if (cell == null || cell.isValueType (ValueType.NA))
|
|
||||||
|
if (cell.isValueType (ValueType.NA))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!cell.isValueType (ValueType.VALUE))
|
if (!cell.isValueType (ValueType.VALUE))
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Expression extends AbstractValue implements Iterable<Value>
|
||||||
private final List<String> operators = new ArrayList<String> ();
|
private final List<String> operators = new ArrayList<String> ();
|
||||||
private final List<String> signs = new ArrayList<String> ();
|
private final List<String> signs = new ArrayList<String> ();
|
||||||
|
|
||||||
private String text;
|
private final String text;
|
||||||
|
|
||||||
public Expression (Sheet parent, String text)
|
public Expression (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
|
@ -93,9 +93,8 @@ class Expression extends AbstractValue implements Iterable<Value>
|
||||||
Cell cell = parent.getCell (addressText);
|
Cell cell = parent.getCell (addressText);
|
||||||
if (cell == null)
|
if (cell == null)
|
||||||
{
|
{
|
||||||
// should this (or parent) create a new empty cell?
|
assert false : "Impossible";
|
||||||
// cell = parent.addCell (addressText);
|
// values.add (new Number ("0"));
|
||||||
values.add (new Number ("0"));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
values.add (parent.getCell (addressText));
|
values.add (parent.getCell (addressText));
|
||||||
|
@ -155,17 +154,16 @@ class Expression extends AbstractValue implements Iterable<Value>
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Value thisValue = values.get (0);
|
Value thisValue = values.get (0);
|
||||||
if (thisValue != null) // || thisValue.getValueType () != ValueType.VALUE)
|
thisValue.calculate ();
|
||||||
thisValue.calculate ();
|
|
||||||
|
|
||||||
value = 0;
|
value = 0;
|
||||||
if (!thisValue.isValueType (ValueType.VALUE))
|
if (thisValue.isValueType (ValueType.ERROR))
|
||||||
{
|
{
|
||||||
valueType = thisValue.getValueType ();
|
valueType = thisValue.getValueType ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = thisValue.getValue ();
|
value = thisValue.getValue (); // NA returns zero
|
||||||
|
|
||||||
String sign = signs.get (0);
|
String sign = signs.get (0);
|
||||||
if (sign.equals ("(-)"))
|
if (sign.equals ("(-)"))
|
||||||
|
@ -174,17 +172,15 @@ 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);
|
||||||
if (thisValue != null) // || thisValue.getValueType () != ValueType.VALUE)
|
thisValue.calculate ();
|
||||||
thisValue.calculate ();
|
|
||||||
|
|
||||||
if (!thisValue.isValueType (ValueType.VALUE))
|
if (thisValue.isValueType (ValueType.ERROR))
|
||||||
// if (thisValue.isValueType (ValueType.ERROR))
|
|
||||||
{
|
{
|
||||||
valueType = thisValue.getValueType ();
|
valueType = thisValue.getValueType ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double nextValue = thisValue.getValue ();
|
double nextValue = thisValue.getValue (); // NA returns zero
|
||||||
|
|
||||||
sign = signs.get (i);
|
sign = signs.get (i);
|
||||||
if (sign.equals ("(-)"))
|
if (sign.equals ("(-)"))
|
||||||
|
|
|
@ -6,6 +6,11 @@ public class Format
|
||||||
{
|
{
|
||||||
private static final DecimalFormat nf = new DecimalFormat ("#####0.00");
|
private static final DecimalFormat nf = new DecimalFormat ("#####0.00");
|
||||||
|
|
||||||
|
private Format ()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static String format (Value value, char formatChar, int colWidth)
|
static String format (Value value, char formatChar, int colWidth)
|
||||||
{
|
{
|
||||||
double actualValue = value.getValue ();
|
double actualValue = value.getValue ();
|
||||||
|
|
|
@ -6,8 +6,8 @@ class If extends Function
|
||||||
private final String textTrue;
|
private final String textTrue;
|
||||||
private final String textFalse;
|
private final String textFalse;
|
||||||
|
|
||||||
private Expression expTrue;
|
private final Expression expTrue;
|
||||||
private Expression expFalse;
|
private final Expression expFalse;
|
||||||
|
|
||||||
public If (Sheet parent, String text)
|
public If (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
|
@ -21,6 +21,11 @@ class If extends Function
|
||||||
|
|
||||||
textTrue = functionText.substring (pos1 + 1, pos2);
|
textTrue = functionText.substring (pos1 + 1, pos2);
|
||||||
textFalse = functionText.substring (pos2 + 1);
|
textFalse = functionText.substring (pos2 + 1);
|
||||||
|
|
||||||
|
expTrue = new Expression (parent, textTrue);
|
||||||
|
values.add (expTrue);
|
||||||
|
expFalse = new Expression (parent, textFalse);
|
||||||
|
values.add (expFalse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -31,12 +36,6 @@ class If extends Function
|
||||||
|
|
||||||
if (condition.getValue () == 1)
|
if (condition.getValue () == 1)
|
||||||
{
|
{
|
||||||
if (expTrue == null)
|
|
||||||
{
|
|
||||||
expTrue = new Expression (parent, textTrue);
|
|
||||||
values.add (expTrue);
|
|
||||||
}
|
|
||||||
|
|
||||||
expTrue.calculate ();
|
expTrue.calculate ();
|
||||||
|
|
||||||
if (!expTrue.isValueType (ValueType.VALUE))
|
if (!expTrue.isValueType (ValueType.VALUE))
|
||||||
|
@ -46,12 +45,6 @@ class If extends Function
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (expFalse == null)
|
|
||||||
{
|
|
||||||
expFalse = new Expression (parent, textFalse);
|
|
||||||
values.add (expFalse);
|
|
||||||
}
|
|
||||||
|
|
||||||
expFalse.calculate ();
|
expFalse.calculate ();
|
||||||
|
|
||||||
if (!expFalse.isValueType (ValueType.VALUE))
|
if (!expFalse.isValueType (ValueType.VALUE))
|
||||||
|
|
|
@ -7,13 +7,15 @@ class IsError extends Function
|
||||||
public IsError (Sheet parent, String text)
|
public IsError (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
|
|
||||||
|
cell = parent.getCell (functionText);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public void calculate ()
|
||||||
{
|
{
|
||||||
if (cell == null)
|
// if (cell == null)
|
||||||
cell = parent.getCell (functionText);
|
// cell = parent.getCell (functionText);
|
||||||
|
|
||||||
value = cell == null ? 1 : cell.isValueType (ValueType.ERROR) ? 1 : 0;
|
value = cell == null ? 1 : cell.isValueType (ValueType.ERROR) ? 1 : 0;
|
||||||
valueType = ValueType.VALUE;
|
valueType = ValueType.VALUE;
|
||||||
|
|
|
@ -2,18 +2,20 @@ package com.bytezone.diskbrowser.visicalc;
|
||||||
|
|
||||||
public class IsNa extends Function
|
public class IsNa extends Function
|
||||||
{
|
{
|
||||||
Expression expression;
|
Value expression;
|
||||||
|
|
||||||
IsNa (Sheet parent, String text)
|
IsNa (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
|
|
||||||
|
expression = new Expression (parent, functionText).reduce ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public void calculate ()
|
||||||
{
|
{
|
||||||
if (expression == null)
|
// if (expression == null)
|
||||||
expression = new Expression (parent, functionText);
|
// expression = new Expression (parent, functionText);
|
||||||
|
|
||||||
expression.calculate ();
|
expression.calculate ();
|
||||||
value = expression.getValue ();
|
value = expression.getValue ();
|
||||||
|
|
|
@ -2,10 +2,10 @@ package com.bytezone.diskbrowser.visicalc;
|
||||||
|
|
||||||
class Lookup extends Function
|
class Lookup extends Function
|
||||||
{
|
{
|
||||||
protected final Range range;
|
private final String sourceText;
|
||||||
String sourceText;
|
private final String rangeText;
|
||||||
String rangeText;
|
private final Expression source;
|
||||||
Expression source;
|
private final Range range;
|
||||||
|
|
||||||
public Lookup (Sheet parent, String text)
|
public Lookup (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
|
@ -14,9 +14,10 @@ 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);
|
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 (parent, rangeText);
|
range = new Range (parent, rangeText);
|
||||||
|
|
||||||
|
values.add (source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -47,7 +48,6 @@ 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
|
||||||
|
@ -57,9 +57,7 @@ class Lookup extends Function
|
||||||
|
|
||||||
if (parent.cellExists (adjacentAddress))
|
if (parent.cellExists (adjacentAddress))
|
||||||
{
|
{
|
||||||
Cell adjacentCell = parent.getCell (adjacentAddress);
|
value = parent.getCell (adjacentAddress).getValue ();
|
||||||
if (adjacentCell != null)
|
|
||||||
value = adjacentCell.getValue ();
|
|
||||||
valueType = ValueType.VALUE;
|
valueType = ValueType.VALUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -7,6 +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 (parent, text);
|
range = new Range (parent, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ class Max extends Function
|
||||||
for (Address address : range)
|
for (Address address : range)
|
||||||
{
|
{
|
||||||
Cell cell = parent.getCell (address);
|
Cell cell = parent.getCell (address);
|
||||||
if (cell == null || cell.isValueType (ValueType.NA))
|
if (cell.isValueType (ValueType.NA))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!cell.isValueType (ValueType.VALUE))
|
if (!cell.isValueType (ValueType.VALUE))
|
||||||
|
|
|
@ -7,6 +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 (parent, text);
|
range = new Range (parent, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ class Min extends Function
|
||||||
for (Address address : range)
|
for (Address address : range)
|
||||||
{
|
{
|
||||||
Cell cell = parent.getCell (address);
|
Cell cell = parent.getCell (address);
|
||||||
if (cell == null || cell.isValueType (ValueType.NA))
|
if (cell.isValueType (ValueType.NA))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!cell.isValueType (ValueType.VALUE))
|
if (!cell.isValueType (ValueType.VALUE))
|
||||||
|
|
|
@ -11,6 +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 (parent, text);
|
range = new Range (parent, text);
|
||||||
|
|
||||||
// int pos = text.indexOf (',');
|
// int pos = text.indexOf (',');
|
||||||
|
@ -29,7 +30,7 @@ public class Npv extends Function
|
||||||
for (Address address : range)
|
for (Address address : range)
|
||||||
{
|
{
|
||||||
Cell cell = parent.getCell (address);
|
Cell cell = parent.getCell (address);
|
||||||
if (cell == null || cell.isValueType (ValueType.NA))
|
if (cell.isValueType (ValueType.NA))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!cell.isValueType (ValueType.VALUE))
|
if (!cell.isValueType (ValueType.VALUE))
|
||||||
|
|
|
@ -5,11 +5,12 @@ import java.util.List;
|
||||||
|
|
||||||
class Or extends Function
|
class Or extends Function
|
||||||
{
|
{
|
||||||
List<Condition> conditions = new ArrayList<Condition> ();
|
private final List<Condition> conditions = new ArrayList<Condition> ();
|
||||||
|
|
||||||
public Or (Sheet parent, String text)
|
public Or (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
|
|
||||||
String list[] = text.split (",");
|
String list[] = text.split (",");
|
||||||
for (String s : list)
|
for (String s : list)
|
||||||
conditions.add (new Condition (parent, s));
|
conditions.add (new Condition (parent, s));
|
||||||
|
|
|
@ -5,6 +5,8 @@ class Pi extends Function
|
||||||
Pi (Sheet parent, String text)
|
Pi (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
|
|
||||||
value = Math.PI;
|
value = Math.PI;
|
||||||
|
valueType = ValueType.VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,9 +13,9 @@ class Range implements Iterable<Address>
|
||||||
Pattern.compile ("([A-B]?[A-Z])([0-9]{1,3})\\.\\.\\.([A-B]?[A-Z])([0-9]{1,3})");
|
Pattern.compile ("([A-B]?[A-Z])([0-9]{1,3})\\.\\.\\.([A-B]?[A-Z])([0-9]{1,3})");
|
||||||
private static final Pattern addressList = Pattern.compile ("\\(([^,]+(,[^,]+)*)\\)");
|
private static final Pattern addressList = Pattern.compile ("\\(([^,]+(,[^,]+)*)\\)");
|
||||||
|
|
||||||
Address from, to;
|
private Address from, to;
|
||||||
List<Address> range = new ArrayList<Address> ();
|
private final List<Address> range = new ArrayList<Address> ();
|
||||||
Sheet parent;
|
private final Sheet parent;
|
||||||
|
|
||||||
public Range (Sheet parent, String rangeText)
|
public Range (Sheet parent, String rangeText)
|
||||||
{
|
{
|
||||||
|
@ -57,13 +57,13 @@ class Range implements Iterable<Address>
|
||||||
range.add (from);
|
range.add (from);
|
||||||
Address tempFrom = from;
|
Address tempFrom = from;
|
||||||
|
|
||||||
if (from.row == to.row)
|
if (from.rowMatches (to))
|
||||||
while (from.compareTo (to) < 0)
|
while (from.compareTo (to) < 0)
|
||||||
{
|
{
|
||||||
from = from.nextColumn ();
|
from = from.nextColumn ();
|
||||||
range.add (from);
|
range.add (from);
|
||||||
}
|
}
|
||||||
else if (from.column == to.column)
|
else if (from.columnMatches (to))
|
||||||
while (from.compareTo (to) < 0)
|
while (from.compareTo (to) < 0)
|
||||||
{
|
{
|
||||||
from = from.nextRow ();
|
from = from.nextRow ();
|
||||||
|
@ -79,14 +79,14 @@ class Range implements Iterable<Address>
|
||||||
{
|
{
|
||||||
Address first = range.get (0);
|
Address first = range.get (0);
|
||||||
Address last = range.get (range.size () - 1);
|
Address last = range.get (range.size () - 1);
|
||||||
return first.row == last.row;
|
return first.rowMatches (last);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isVertical ()
|
boolean isVertical ()
|
||||||
{
|
{
|
||||||
Address first = range.get (0);
|
Address first = range.get (0);
|
||||||
Address last = range.get (range.size () - 1);
|
Address last = range.get (range.size () - 1);
|
||||||
return first.column == last.column;
|
return first.columnMatches (last);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -148,11 +148,11 @@ class Range implements Iterable<Address>
|
||||||
{
|
{
|
||||||
StringBuilder text = new StringBuilder ();
|
StringBuilder text = new StringBuilder ();
|
||||||
for (Address address : range)
|
for (Address address : range)
|
||||||
text.append (address.text + ",");
|
text.append (address.getText () + ",");
|
||||||
if (text.length () > 0)
|
if (text.length () > 0)
|
||||||
text.deleteCharAt (text.length () - 1);
|
text.deleteCharAt (text.length () - 1);
|
||||||
return text.toString ();
|
return text.toString ();
|
||||||
}
|
}
|
||||||
return String.format (" %s -> %s", from.text, to.text);
|
return String.format (" %s -> %s", from.getText (), to.getText ());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -199,7 +199,7 @@ public class Sheet
|
||||||
if (m.find ())
|
if (m.find ())
|
||||||
{
|
{
|
||||||
Address address = new Address (m.group (1), m.group (2));
|
Address address = new Address (m.group (1), m.group (2));
|
||||||
currentCell = rowOrderCells.get (address.rowKey);
|
currentCell = rowOrderCells.get (address.getRowKey ());
|
||||||
|
|
||||||
int pos = line.indexOf (':'); // end of cell address
|
int pos = line.indexOf (':'); // end of cell address
|
||||||
line = line.substring (pos + 1); // remove address from line
|
line = line.substring (pos + 1); // remove address from line
|
||||||
|
@ -224,7 +224,7 @@ public class Sheet
|
||||||
if (line.charAt (2) == 'C' && line.charAt (3) == 'C')
|
if (line.charAt (2) == 'C' && line.charAt (3) == 'C')
|
||||||
{
|
{
|
||||||
int width = Integer.parseInt (line.substring (4));
|
int width = Integer.parseInt (line.substring (4));
|
||||||
columnWidths.put (currentCell.getAddress ().column, width);
|
columnWidths.put (currentCell.getAddress ().getColumn (), width);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
System.out.printf ("Unknown Global:[%s]%n", line);
|
System.out.printf ("Unknown Global:[%s]%n", line);
|
||||||
|
@ -262,11 +262,11 @@ public class Sheet
|
||||||
private void addCell (Cell cell)
|
private void addCell (Cell cell)
|
||||||
{
|
{
|
||||||
// System.out.printf ("Adding: %s%n", cell);
|
// System.out.printf ("Adding: %s%n", cell);
|
||||||
rowOrderCells.put (cell.getAddress ().rowKey, cell);
|
rowOrderCells.put (cell.getAddress ().getRowKey (), cell);
|
||||||
columnOrderCells.put (cell.getAddress ().columnKey, cell);
|
columnOrderCells.put (cell.getAddress ().getColumnKey (), cell);
|
||||||
|
|
||||||
highestRow = Math.max (highestRow, cell.getAddress ().row);
|
highestRow = Math.max (highestRow, cell.getAddress ().getRow ());
|
||||||
highestColumn = Math.max (highestColumn, cell.getAddress ().column);
|
highestColumn = Math.max (highestColumn, cell.getAddress ().getColumn ());
|
||||||
}
|
}
|
||||||
|
|
||||||
Cell getCell (String addressText)
|
Cell getCell (String addressText)
|
||||||
|
@ -276,7 +276,7 @@ public class Sheet
|
||||||
|
|
||||||
Cell getCell (Address address)
|
Cell getCell (Address address)
|
||||||
{
|
{
|
||||||
Cell cell = rowOrderCells.get (address.rowKey);
|
Cell cell = rowOrderCells.get (address.getRowKey ());
|
||||||
if (cell == null)
|
if (cell == null)
|
||||||
{
|
{
|
||||||
// System.out.printf ("cell not found, creating: %s%n", address);
|
// System.out.printf ("cell not found, creating: %s%n", address);
|
||||||
|
@ -288,7 +288,7 @@ public class Sheet
|
||||||
|
|
||||||
boolean cellExists (Address address)
|
boolean cellExists (Address address)
|
||||||
{
|
{
|
||||||
return rowOrderCells.get (address.rowKey) != null;
|
return rowOrderCells.get (address.getRowKey ()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size ()
|
public int size ()
|
||||||
|
@ -397,7 +397,7 @@ public class Sheet
|
||||||
Address cellAddress = cell.getAddress ();
|
Address cellAddress = cell.getAddress ();
|
||||||
|
|
||||||
// insert newlines for empty rows
|
// insert newlines for empty rows
|
||||||
while (lastRow < cellAddress.row)
|
while (lastRow < cellAddress.getRow ())
|
||||||
{
|
{
|
||||||
++lastRow;
|
++lastRow;
|
||||||
lastColumn = 0;
|
lastColumn = 0;
|
||||||
|
@ -408,7 +408,7 @@ public class Sheet
|
||||||
}
|
}
|
||||||
|
|
||||||
// pad out empty columns
|
// pad out empty columns
|
||||||
while (lastColumn < cellAddress.column)
|
while (lastColumn < cellAddress.getColumn ())
|
||||||
{
|
{
|
||||||
int width = columnWidth;
|
int width = columnWidth;
|
||||||
if (columnWidths.containsKey (lastColumn))
|
if (columnWidths.containsKey (lastColumn))
|
||||||
|
@ -420,8 +420,8 @@ public class Sheet
|
||||||
++lastColumn;
|
++lastColumn;
|
||||||
|
|
||||||
int colWidth = columnWidth;
|
int colWidth = columnWidth;
|
||||||
if (columnWidths.containsKey (cellAddress.column))
|
if (columnWidths.containsKey (cellAddress.getColumn ()))
|
||||||
colWidth = columnWidths.get (cellAddress.column);
|
colWidth = columnWidths.get (cellAddress.getColumn ());
|
||||||
|
|
||||||
text.append (cell.getText (colWidth, globalFormat));
|
text.append (cell.getText (colWidth, globalFormat));
|
||||||
}
|
}
|
||||||
|
@ -432,13 +432,13 @@ public class Sheet
|
||||||
int last = -1;
|
int last = -1;
|
||||||
for (Cell cell : columnOrderCells.values ())
|
for (Cell cell : columnOrderCells.values ())
|
||||||
{
|
{
|
||||||
if (last < cell.getAddress ().column)
|
if (last < cell.getAddress ().getColumn ())
|
||||||
{
|
{
|
||||||
String columnName = Address.getCellName (1, cell.getAddress ().column);
|
String columnName = Address.getCellName (1, cell.getAddress ().getColumn ());
|
||||||
columnName = columnName.substring (0, columnName.length () - 1);
|
columnName = columnName.substring (0, columnName.length () - 1);
|
||||||
text.append ("\n *** Column " + columnName
|
text.append ("\n *** Column " + columnName
|
||||||
+ " ***\n\n");
|
+ " ***\n\n");
|
||||||
last = cell.getAddress ().column;
|
last = cell.getAddress ().getColumn ();
|
||||||
}
|
}
|
||||||
text.append (cell.getDebugText ());
|
text.append (cell.getDebugText ());
|
||||||
text.append ("\n");
|
text.append ("\n");
|
||||||
|
|
|
@ -7,6 +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 (parent, text);
|
range = new Range (parent, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +20,8 @@ class Sum extends Function
|
||||||
for (Address address : range)
|
for (Address address : range)
|
||||||
{
|
{
|
||||||
Cell cell = parent.getCell (address);
|
Cell cell = parent.getCell (address);
|
||||||
if (cell == null || cell.isValueType (ValueType.NA))
|
|
||||||
|
if (cell.isValueType (ValueType.NA))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!cell.isValueType (ValueType.VALUE))
|
if (!cell.isValueType (ValueType.VALUE))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user