renamed is()

This commit is contained in:
Denis Molony 2016-08-01 15:18:51 +10:00
parent 40db75e96a
commit cf833ab7d7
14 changed files with 32 additions and 66 deletions

View File

@ -117,8 +117,8 @@ class Cell implements Comparable<Cell>, Value
return justify (repeat, colWidth, format);
case VALUE:
if (value.is (ValueType.ERROR) || value.is (ValueType.NA)
|| value.is (ValueType.NAN))
if (value.isValueType (ValueType.ERROR) || value.isValueType (ValueType.NA)
|| value.isValueType (ValueType.NAN))
return justify (value.getText (), colWidth, format);
Double thisValue = value.getValue ();
@ -173,7 +173,6 @@ class Cell implements Comparable<Cell>, Value
@Override
public double getValue ()
{
assert cellType == CellType.VALUE;
return value.getValue ();
}
@ -186,17 +185,16 @@ class Cell implements Comparable<Cell>, Value
@Override
public String getText ()
{
assert is (CellType.VALUE) : "Cell type: " + cellType;
return value.getText ();
}
@Override
public boolean is (ValueType type)
public boolean isValueType (ValueType type)
{
return value.is (type);
return value.isValueType (type);
}
public boolean is (CellType type)
public boolean isCellType (CellType type)
{
return cellType == type;
}
@ -204,7 +202,7 @@ class Cell implements Comparable<Cell>, Value
@Override
public Value calculate ()
{
if (!is (CellType.VALUE))
if (!isCellType (CellType.VALUE))
return this;
if (expressionText == null)

View File

@ -56,7 +56,7 @@ class Condition
valueExpression.calculate ();
}
if (conditionExpression.is (ValueType.ERROR) || valueExpression.is (ValueType.ERROR))
if (conditionExpression.isValueType (ValueType.ERROR) || valueExpression.isValueType (ValueType.ERROR))
return false;
double conditionResult = conditionExpression.getValue ();

View File

@ -16,10 +16,10 @@ class Count extends RangeFunction
for (Address address : range)
{
Cell cell = parent.getCell (address);
if (cell == null || cell.is (ValueType.NA))
if (cell == null || cell.isValueType (ValueType.NA))
continue;
if (cell.is (ValueType.ERROR))
if (cell.isValueType (ValueType.ERROR))
{
valueType = ValueType.ERROR;
break;

View File

@ -127,13 +127,13 @@ class Expression implements Value
{
Value thisValue = values.get (0);
thisValue.calculate ();
if (thisValue.is (ValueType.ERROR))
if (thisValue.isValueType (ValueType.ERROR))
{
valueType = thisValue.getValueType ();
return this;
}
value = thisValue.is (ValueType.NA) ? 0 : thisValue.getValue ();
value = thisValue.isValueType (ValueType.NA) ? 0 : thisValue.getValue ();
String sign = signs.get (0);
if (sign.equals ("(-)"))
@ -143,13 +143,13 @@ class Expression implements Value
{
thisValue = values.get (i);
thisValue.calculate ();
if (thisValue.is (ValueType.ERROR))
if (thisValue.isValueType (ValueType.ERROR))
{
valueType = thisValue.getValueType ();
return this;
}
double nextValue = thisValue.is (ValueType.NA) ? 0 : thisValue.getValue ();
double nextValue = thisValue.isValueType (ValueType.NA) ? 0 : thisValue.getValue ();
sign = signs.get (i);
if (sign.equals ("(-)"))
@ -211,7 +211,7 @@ class Expression implements Value
// return valueType == ValueType.ERROR;
// }
@Override
public boolean is (ValueType type)
public boolean isValueType (ValueType type)
{
return valueType == type;
}

View File

@ -114,32 +114,8 @@ abstract class Function implements Value
return valueType;
}
// @Override
// public boolean isValue ()
// {
// return valueType == ValueType.VALUE;
// }
//
// @Override
// public boolean isError ()
// {
// return valueType == ValueType.ERROR;
// }
//
// @Override
// public boolean isNotAvailable ()
// {
// return valueType == ValueType.NA;
// }
//
// @Override
// public boolean isNotANumber ()
// {
// return valueType == ValueType.NAN;
// }
@Override
public boolean is (ValueType type)
public boolean isValueType (ValueType type)
{
return valueType == type;
}
@ -165,7 +141,6 @@ abstract class Function implements Value
default:
return "";
}
// return isNotAvailable () ? "NA" : isError () ? "Error" : isNotANumber () ? "NaN" : "";
}
@Override

View File

@ -36,7 +36,7 @@ class If extends Function
expTrue.calculate ();
if (expTrue.is (ValueType.ERROR) || expTrue.is (ValueType.NA))
if (expTrue.isValueType (ValueType.ERROR) || expTrue.isValueType (ValueType.NA))
valueType = expTrue.getValueType ();
else
value = expTrue.getValue ();
@ -49,7 +49,7 @@ class If extends Function
expFalse.calculate ();
if (expFalse.is (ValueType.ERROR) || expFalse.is (ValueType.NA))
if (expFalse.isValueType (ValueType.ERROR) || expFalse.isValueType (ValueType.NA))
valueType = expFalse.getValueType ();
else
value = expFalse.getValue ();

View File

@ -22,15 +22,15 @@ class Lookup extends RangeFunction
source = new Expression (parent, sourceText);
source.calculate ();
if (source.is (ValueType.ERROR) || source.is (ValueType.NA))
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
return this;
}
double sourceValue = source.getValue ();
Address target = null;
for (Address address : range)
{
Cell cell = parent.getCell (address);

View File

@ -16,10 +16,10 @@ class Max extends RangeFunction
for (Address address : range)
{
Cell cell = parent.getCell (address);
if (cell == null || cell.is (ValueType.NA))
if (cell == null || cell.isValueType (ValueType.NA))
continue;
if (cell.is (ValueType.ERROR))
if (cell.isValueType (ValueType.ERROR))
{
valueType = ValueType.ERROR;
break;

View File

@ -16,10 +16,10 @@ class Min extends RangeFunction
for (Address address : range)
{
Cell cell = parent.getCell (address);
if (cell == null || cell.is (ValueType.NA))
if (cell == null || cell.isValueType (ValueType.NA))
continue;
if (cell.is (ValueType.ERROR))
if (cell.isValueType (ValueType.ERROR))
{
valueType = ValueType.ERROR;
break;

View File

@ -27,10 +27,10 @@ public class Npv extends RangeFunction
for (Address address : range)
{
Cell cell = parent.getCell (address);
if (cell == null || cell.is (ValueType.NA))
if (cell == null || cell.isValueType (ValueType.NA))
continue;
if (cell.is (ValueType.ERROR))
if (cell.isValueType (ValueType.ERROR))
{
valueType = ValueType.ERROR;
break;

View File

@ -42,7 +42,7 @@ class Number implements Value
// return valueType == ValueType.NAN;
// }
@Override
public boolean is (ValueType type)
public boolean isValueType (ValueType type)
{
return valueType == type;
}

View File

@ -164,7 +164,7 @@ public class Sheet
{
Map<Integer, Cell> cells = order == 'R' ? rowOrderCells : columnOrderCells;
for (Cell cell : cells.values ())
if (cell.is (ValueType.VALUE))
if (cell.isValueType (ValueType.VALUE))
cell.calculate ();
}

View File

@ -16,10 +16,10 @@ class Sum extends RangeFunction
for (Address address : range)
{
Cell cell = parent.getCell (address);
if (cell == null || cell.is (ValueType.NA))
if (cell == null || cell.isValueType (ValueType.NA))
continue;
if (cell.is (ValueType.ERROR))
if (cell.isValueType (ValueType.ERROR))
{
valueType = ValueType.ERROR;
break;

View File

@ -7,20 +7,13 @@ interface Value
VALUE, ERROR, NA, NAN
}
public ValueType getValueType ();
public double getValue ();
public String getText ();
// public boolean isValue ();
//
// public boolean isError ();
//
// public boolean isNotAvailable ();
//
// public boolean isNotANumber ();
public boolean is (ValueType valueType);
public boolean isValueType (ValueType valueType);
public ValueType getValueType ();
public Value calculate ();
}