mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-06-29 05:29:37 +00:00
changed Value interface
This commit is contained in:
parent
d037cc1d97
commit
a569a8aee7
|
@ -8,9 +8,10 @@ public class Abs extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
Expression exp = new Expression (parent, functionText);
|
Expression exp = new Expression (parent, functionText);
|
||||||
value = Math.abs (exp.getValue ());
|
value = Math.abs (exp.getValue ());
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,8 +9,9 @@ class And extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
value = 0;
|
value = 0;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -32,6 +32,7 @@ class Cell implements Comparable<Cell>, Value
|
||||||
type = CellType.VALUE; // default to VALUE, formatting may change it
|
type = CellType.VALUE; // default to VALUE, formatting may change it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isValue ()
|
public boolean isValue ()
|
||||||
{
|
{
|
||||||
return type == CellType.VALUE;
|
return type == CellType.VALUE;
|
||||||
|
@ -124,7 +125,7 @@ class Cell implements Comparable<Cell>, Value
|
||||||
return justify (repeat, colWidth);
|
return justify (repeat, colWidth);
|
||||||
|
|
||||||
case VALUE:
|
case VALUE:
|
||||||
if (value.isError () || value.isNaN ())
|
if (value.isError () || value.isNotAvailable ())
|
||||||
return justify (value.getText (), colWidth);
|
return justify (value.getText (), colWidth);
|
||||||
|
|
||||||
Double thisValue = value.getValue ();
|
Double thisValue = value.getValue ();
|
||||||
|
@ -203,14 +204,14 @@ class Cell implements Comparable<Cell>, Value
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNaN ()
|
public boolean isNotAvailable ()
|
||||||
{
|
{
|
||||||
assert type == CellType.VALUE;
|
assert type == CellType.VALUE;
|
||||||
return value.isNaN ();
|
return value.isNotAvailable ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
assert type == CellType.VALUE;
|
assert type == CellType.VALUE;
|
||||||
if (expressionText == null)
|
if (expressionText == null)
|
||||||
|
@ -221,11 +222,12 @@ class Cell implements Comparable<Cell>, Value
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// should use Number or Cell 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 ();
|
valueType = value.getValueType ();
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,13 +11,18 @@ class Count extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
value = 0;
|
value = 0;
|
||||||
|
valueType = ValueType.VALUE;
|
||||||
|
|
||||||
for (Address address : range)
|
for (Address address : range)
|
||||||
{
|
{
|
||||||
Cell cell = parent.getCell (address);
|
Cell cell = parent.getCell (address);
|
||||||
if (cell == null || cell.isError () || cell.isNaN ())
|
if (cell == null || cell.isNotAvailable ())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (cell.isError ())
|
||||||
{
|
{
|
||||||
valueType = ValueType.ERROR;
|
valueType = ValueType.ERROR;
|
||||||
break;
|
break;
|
||||||
|
@ -26,5 +31,6 @@ class Count extends Function
|
||||||
if (cell.getValue () != 0.0)
|
if (cell.getValue () != 0.0)
|
||||||
value++;
|
value++;
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,9 +14,9 @@ class Error extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNaN ()
|
public boolean isNotAvailable ()
|
||||||
{
|
{
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,7 +26,8 @@ class Error extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -90,6 +90,8 @@ class Expression implements Value
|
||||||
{
|
{
|
||||||
String addressText = getAddressText (line.substring (ptr));
|
String addressText = getAddressText (line.substring (ptr));
|
||||||
ptr += addressText.length ();
|
ptr += addressText.length ();
|
||||||
|
Cell cell = parent.getCell (addressText);
|
||||||
|
if (cell != null)
|
||||||
values.add (parent.getCell (addressText));
|
values.add (parent.getCell (addressText));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -117,18 +119,19 @@ class Expression implements Value
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
|
// System.out.println (this);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Value thisValue = values.get (0);
|
Value thisValue = values.get (0);
|
||||||
thisValue.calculate ();
|
thisValue.calculate ();
|
||||||
if (thisValue.isError ())
|
if (thisValue.isError ())
|
||||||
{
|
{
|
||||||
valueType = ValueType.ERROR;
|
valueType = thisValue.getValueType ();
|
||||||
return;
|
return this;
|
||||||
}
|
}
|
||||||
value = thisValue.getValue ();
|
value = thisValue.isNotAvailable () ? 0 : thisValue.getValue ();
|
||||||
|
|
||||||
String sign = signs.get (0);
|
String sign = signs.get (0);
|
||||||
if (sign.equals ("(-)"))
|
if (sign.equals ("(-)"))
|
||||||
|
@ -140,10 +143,11 @@ class Expression implements Value
|
||||||
thisValue.calculate ();
|
thisValue.calculate ();
|
||||||
if (thisValue.isError ())
|
if (thisValue.isError ())
|
||||||
{
|
{
|
||||||
valueType = ValueType.ERROR;
|
valueType = thisValue.getValueType ();
|
||||||
return;
|
return this;
|
||||||
}
|
}
|
||||||
double nextValue = thisValue.getValue ();
|
|
||||||
|
double nextValue = thisValue.isNotAvailable () ? 0 : thisValue.getValue ();
|
||||||
|
|
||||||
sign = signs.get (i);
|
sign = signs.get (i);
|
||||||
if (sign.equals ("(-)"))
|
if (sign.equals ("(-)"))
|
||||||
|
@ -167,6 +171,7 @@ class Expression implements Value
|
||||||
{
|
{
|
||||||
valueType = ValueType.ERROR;
|
valueType = ValueType.ERROR;
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -176,15 +181,15 @@ class Expression implements Value
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNaN ()
|
public boolean isValue ()
|
||||||
{
|
{
|
||||||
return Double.isNaN (value);
|
return valueType == ValueType.VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getText ()
|
public boolean isNotAvailable ()
|
||||||
{
|
{
|
||||||
return isNaN () ? "NaN" : isError () ? "Error" : "";
|
return valueType == ValueType.NA;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -200,6 +205,12 @@ class Expression implements Value
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getText ()
|
||||||
|
{
|
||||||
|
return isNotAvailable () ? "NA" : isError () ? "Error" : "";
|
||||||
|
}
|
||||||
|
|
||||||
private String checkBrackets (String input)
|
private String checkBrackets (String input)
|
||||||
{
|
{
|
||||||
String line = input.trim ();
|
String line = input.trim ();
|
||||||
|
@ -220,7 +231,7 @@ class Expression implements Value
|
||||||
System.out.printf ("**** Unbalanced brackets: left:%d, right:%d ****%n",
|
System.out.printf ("**** Unbalanced brackets: left:%d, right:%d ****%n",
|
||||||
leftBracket, rightBracket);
|
leftBracket, rightBracket);
|
||||||
System.out.println (input);
|
System.out.println (input);
|
||||||
return "@ERROR()";
|
return "@ERROR";
|
||||||
}
|
}
|
||||||
// System.out.printf ("Old expression:[%s]%n", line);
|
// System.out.printf ("Old expression:[%s]%n", line);
|
||||||
while (rightBracket < leftBracket)
|
while (rightBracket < leftBracket)
|
||||||
|
@ -286,11 +297,18 @@ class Expression implements Value
|
||||||
int ptr = 0;
|
int ptr = 0;
|
||||||
for (Value value : values)
|
for (Value value : values)
|
||||||
{
|
{
|
||||||
|
assert value != null;
|
||||||
text.append (signs.get (ptr));
|
text.append (signs.get (ptr));
|
||||||
text.append (value.getValue ());
|
// value.calculate ();
|
||||||
|
// if (value.isValue ())
|
||||||
|
// text.append (value.getValue ());
|
||||||
if (ptr < operators.size ())
|
if (ptr < operators.size ())
|
||||||
|
{
|
||||||
|
// System.out.println (operators.get (ptr));
|
||||||
text.append (operators.get (ptr++));
|
text.append (operators.get (ptr++));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// System.out.println ("finished building");
|
||||||
|
|
||||||
return text.toString ();
|
return text.toString ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ abstract class Function implements Value
|
||||||
private static final Pattern addressList = Pattern.compile ("\\(([^,]+(,[^,]+)*)\\)");
|
private static final Pattern addressList = Pattern.compile ("\\(([^,]+(,[^,]+)*)\\)");
|
||||||
|
|
||||||
protected final Sheet parent;
|
protected final Sheet parent;
|
||||||
|
protected String functionName;
|
||||||
protected String functionText;
|
protected String functionText;
|
||||||
|
|
||||||
protected ValueType valueType;
|
protected ValueType valueType;
|
||||||
|
@ -97,10 +98,16 @@ abstract class Function implements Value
|
||||||
// get function's parameter string
|
// get function's parameter string
|
||||||
int pos = text.indexOf ('(');
|
int pos = text.indexOf ('(');
|
||||||
if (pos >= 0)
|
if (pos >= 0)
|
||||||
|
{
|
||||||
|
functionName = text.substring (0, pos);
|
||||||
functionText = text.substring (pos + 1, text.length () - 1);
|
functionText = text.substring (pos + 1, text.length () - 1);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
functionName = "";
|
||||||
functionText = "";
|
functionText = "";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ValueType getValueType ()
|
public ValueType getValueType ()
|
||||||
|
@ -108,6 +115,12 @@ abstract class Function implements Value
|
||||||
return valueType;
|
return valueType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValue ()
|
||||||
|
{
|
||||||
|
return valueType == ValueType.VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isError ()
|
public boolean isError ()
|
||||||
{
|
{
|
||||||
|
@ -115,9 +128,9 @@ abstract class Function implements Value
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNaN ()
|
public boolean isNotAvailable ()
|
||||||
{
|
{
|
||||||
return Double.isNaN (value);
|
return valueType == ValueType.NA;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -130,7 +143,7 @@ abstract class Function implements Value
|
||||||
@Override
|
@Override
|
||||||
public String getText ()
|
public String getText ()
|
||||||
{
|
{
|
||||||
return isNaN () ? "NaN" : isError () ? "Error" : "";
|
return isNotAvailable () ? "" : isError () ? "Error" : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Range getRange (String text)
|
protected Range getRange (String text)
|
||||||
|
@ -176,6 +189,6 @@ abstract class Function implements Value
|
||||||
@Override
|
@Override
|
||||||
public String toString ()
|
public String toString ()
|
||||||
{
|
{
|
||||||
return String.format ("Function: %s", functionText);
|
return String.format ("Function: %s %s", functionName, functionText);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -23,7 +23,7 @@ class If extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
valueType = ValueType.VALUE;
|
valueType = ValueType.VALUE;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class If extends Function
|
||||||
expTrue = new Expression (parent, textTrue);
|
expTrue = new Expression (parent, textTrue);
|
||||||
expTrue.calculate ();
|
expTrue.calculate ();
|
||||||
}
|
}
|
||||||
if (expTrue.isError () || expTrue.isNaN ())
|
if (expTrue.isError () || expTrue.isNotAvailable ())
|
||||||
valueType = expTrue.getValueType ();
|
valueType = expTrue.getValueType ();
|
||||||
else
|
else
|
||||||
value = expTrue.getValue ();
|
value = expTrue.getValue ();
|
||||||
|
@ -46,11 +46,12 @@ class If extends Function
|
||||||
expFalse = new Expression (parent, textFalse);
|
expFalse = new Expression (parent, textFalse);
|
||||||
expFalse.calculate ();
|
expFalse.calculate ();
|
||||||
}
|
}
|
||||||
if (expFalse.isError () || expFalse.isNaN ())
|
if (expFalse.isError () || expFalse.isNotAvailable ())
|
||||||
valueType = expFalse.getValueType ();
|
valueType = expFalse.getValueType ();
|
||||||
else
|
else
|
||||||
value = expFalse.getValue ();
|
value = expFalse.getValue ();
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -9,9 +9,10 @@ public class Int extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
Expression exp = new Expression (parent, functionText);
|
Expression exp = new Expression (parent, functionText);
|
||||||
value = (int) exp.getValue ();
|
value = (int) exp.getValue ();
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,11 +11,12 @@ class IsError extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
expression.calculate ();
|
expression.calculate ();
|
||||||
// value = expression.getValue ();
|
// value = expression.getValue ();
|
||||||
valueType = expression.getValueType ();
|
valueType = expression.getValueType ();
|
||||||
value = isError () ? 1 : 0;
|
value = isError () ? 1 : 0;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,9 +11,10 @@ public class IsNa extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
value = expression.getValue ();
|
value = expression.getValue ();
|
||||||
valueType = expression.getValueType ();
|
valueType = expression.getValueType ();
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,13 +20,13 @@ class Lookup extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
source.calculate ();
|
source.calculate ();
|
||||||
if (source.isError () || source.isNaN ())
|
if (source.isError () || source.isNotAvailable ())
|
||||||
{
|
{
|
||||||
valueType = source.getValueType ();
|
valueType = source.getValueType ();
|
||||||
return;
|
return this;
|
||||||
}
|
}
|
||||||
double sourceValue = source.getValue ();
|
double sourceValue = source.getValue ();
|
||||||
|
|
||||||
|
@ -44,5 +44,7 @@ class Lookup extends Function
|
||||||
value = parent.getCell (target.nextColumn ()).getValue ();
|
value = parent.getCell (target.nextColumn ()).getValue ();
|
||||||
else
|
else
|
||||||
value = parent.getCell (target.nextRow ()).getValue ();
|
value = parent.getCell (target.nextRow ()).getValue ();
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,7 +11,7 @@ class Max extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
value = Double.MIN_VALUE;
|
value = Double.MIN_VALUE;
|
||||||
int totalChecked = 0;
|
int totalChecked = 0;
|
||||||
|
@ -19,13 +19,13 @@ 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)
|
if (cell == null || cell.isNotAvailable ())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (cell.isError () || cell.isNaN ())
|
if (cell.isError ())
|
||||||
{
|
{
|
||||||
valueType = ValueType.ERROR;
|
valueType = ValueType.ERROR;
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
double temp = cell.getValue ();
|
double temp = cell.getValue ();
|
||||||
|
@ -35,8 +35,10 @@ class Max extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalChecked == 0)
|
if (totalChecked == 0)
|
||||||
valueType = ValueType.ERROR;
|
valueType = ValueType.NA;
|
||||||
else
|
else
|
||||||
valueType = ValueType.VALUE;
|
valueType = ValueType.VALUE;
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,7 +11,7 @@ class Min extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
value = Double.MAX_VALUE;
|
value = Double.MAX_VALUE;
|
||||||
int totalChecked = 0;
|
int totalChecked = 0;
|
||||||
|
@ -19,13 +19,13 @@ 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)
|
if (cell == null || cell.isNotAvailable ())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (cell.isError () || cell.isNaN ())
|
if (cell.isError ())
|
||||||
{
|
{
|
||||||
valueType = ValueType.ERROR;
|
valueType = ValueType.ERROR;
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
double temp = cell.getValue ();
|
double temp = cell.getValue ();
|
||||||
|
@ -35,8 +35,10 @@ class Min extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalChecked == 0)
|
if (totalChecked == 0)
|
||||||
valueType = ValueType.ERROR;
|
valueType = ValueType.NA;
|
||||||
else
|
else
|
||||||
valueType = ValueType.VALUE;
|
valueType = ValueType.VALUE;
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@ public class Na extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNaN ()
|
public boolean isNotAvailable ()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,8 @@ public class Na extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ public class Npv extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
value = 0;
|
value = 0;
|
||||||
valueType = ValueType.VALUE;
|
valueType = ValueType.VALUE;
|
||||||
|
@ -29,16 +29,18 @@ 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)
|
if (cell == null || cell.isNotAvailable ())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (cell.isError () || cell.isNaN ())
|
if (cell.isError ())
|
||||||
{
|
{
|
||||||
valueType = ValueType.VALUE;
|
valueType = ValueType.ERROR;
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
double temp = cell.getValue ();
|
double temp = cell.getValue ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,6 +10,7 @@ class Number implements Value
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
value = Double.parseDouble (text);
|
value = Double.parseDouble (text);
|
||||||
|
valueType = ValueType.VALUE;
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
|
@ -17,6 +18,12 @@ class Number implements Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValue ()
|
||||||
|
{
|
||||||
|
return valueType == ValueType.VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isError ()
|
public boolean isError ()
|
||||||
{
|
{
|
||||||
|
@ -24,9 +31,9 @@ class Number implements Value
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNaN ()
|
public boolean isNotAvailable ()
|
||||||
{
|
{
|
||||||
return Double.isNaN (value);
|
return valueType == ValueType.NA;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,17 +51,18 @@ class Number implements Value
|
||||||
@Override
|
@Override
|
||||||
public String getText ()
|
public String getText ()
|
||||||
{
|
{
|
||||||
return null;
|
return valueType == ValueType.ERROR ? "Error" : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ValueType getValueType ()
|
public ValueType getValueType ()
|
||||||
{
|
{
|
||||||
return null;
|
return valueType;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,8 +9,9 @@ class Or extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
value = 0;
|
value = 0;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,8 +8,9 @@ class Pi extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
value = 3.1415926536;
|
value = 3.1415926536;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Sum extends Function
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public Value calculate ()
|
||||||
{
|
{
|
||||||
value = 0;
|
value = 0;
|
||||||
valueType = ValueType.VALUE;
|
valueType = ValueType.VALUE;
|
||||||
|
@ -19,15 +19,18 @@ 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)
|
if (cell == null || cell.isNotAvailable ())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (cell.isError () || cell.isNaN ())
|
if (cell.isError ())
|
||||||
{
|
{
|
||||||
valueType = ValueType.ERROR;
|
valueType = ValueType.ERROR;
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
value += cell.getValue ();
|
value += cell.getValue ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,9 +13,11 @@ interface Value
|
||||||
|
|
||||||
public String getText ();
|
public String getText ();
|
||||||
|
|
||||||
|
public boolean isValue ();
|
||||||
|
|
||||||
public boolean isError ();
|
public boolean isError ();
|
||||||
|
|
||||||
public boolean isNaN ();
|
public boolean isNotAvailable ();
|
||||||
|
|
||||||
public void calculate ();
|
public Value calculate ();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user