This commit is contained in:
Denis Molony 2016-08-01 11:50:43 +10:00
parent 82d8201180
commit 40db75e96a

View File

@ -13,12 +13,10 @@ class Cell implements Comparable<Cell>, Value
private char repeatingChar; private char repeatingChar;
private String repeat = ""; private String repeat = "";
private String label; private String label;
private String expressionText; private String expressionText;
private Value value; private Value value;
private ValueType valueType;
enum CellType enum CellType
{ {
@ -30,8 +28,8 @@ class Cell implements Comparable<Cell>, Value
this.parent = parent; this.parent = parent;
this.address = address; this.address = address;
cellType = CellType.VALUE; // default to VALUE, formatting may change it cellType = CellType.VALUE; // default to VALUE, formatting may change it
valueType = ValueType.VALUE; value = new Number ("0.0");
} }
void format (String format) void format (String format)
@ -182,7 +180,7 @@ class Cell implements Comparable<Cell>, Value
@Override @Override
public ValueType getValueType () public ValueType getValueType ()
{ {
return valueType; return value.getValueType ();
} }
@Override @Override
@ -192,36 +190,10 @@ class Cell implements Comparable<Cell>, Value
return value.getText (); return value.getText ();
} }
// @Override
// public boolean isValue ()
// {
// return type == CellType.VALUE;
// }
//
// @Override
// public boolean isError ()
// {
// return value.isError ();
// }
//
// @Override
// public boolean isNotAvailable ()
// {
// if (!isValue ())
// return true;
// return value.isNotAvailable ();
// }
//
// @Override
// public boolean isNotANumber ()
// {
// return value.isNotANumber ();
// }
@Override @Override
public boolean is (ValueType type) public boolean is (ValueType type)
{ {
return valueType == type; return value.is (type);
} }
public boolean is (CellType type) public boolean is (CellType type)
@ -233,23 +205,18 @@ class Cell implements Comparable<Cell>, Value
public Value calculate () public Value calculate ()
{ {
if (!is (CellType.VALUE)) if (!is (CellType.VALUE))
{
// System.out.println (value);
return this; return this;
}
assert is (CellType.VALUE) : "Cell type: " + cellType + " @ " + address;
if (expressionText == null) if (expressionText == null)
{ {
System.out.printf ("%s null expression text %n", address); System.out.printf ("%s null expression text %n", address);
value = Function.getInstance (parent, "@ERROR"); value = Function.getInstance (parent, "@ERROR");
valueType = ValueType.ERROR;
} }
else else
{ {
// should use Number or Cell or Function for simple Values // should use Number or Cell or Function for simple Values
value = new Expression (parent, expressionText); value = new Expression (parent, expressionText);
value.calculate (); value.calculate ();
valueType = value.getValueType ();
} }
return this; return this;
} }