added @NOT

This commit is contained in:
Denis Molony 2017-03-26 08:58:10 +11:00
parent bf246bc171
commit 212e877ebe
9 changed files with 74 additions and 58 deletions

View File

@ -8,7 +8,7 @@ public abstract class AbstractValue implements Value//, Iterable<Value>
{
protected static final String FMT2 = "| %-9.9s : %-70.70s|%n";
protected static final String FMT4 = "| %-9.9s : %-50.50s %-8.8s %-10.10s|%n";
protected static final String FMT5 = "| %-9.9s : %-3.3s : %-45.45s%-8.8s %-10.10s|%n";
protected static final String FMT5 = "| %-9.9s : %-39.39s %-10.10s %-8.8s %-10.10s|%n";
protected static final String LINE = "+--------------------------------------------"
+ "---------------------------------------+";
@ -75,25 +75,7 @@ public abstract class AbstractValue implements Value//, Iterable<Value>
@Override
public String getText ()
{
switch (valueResult)
{
case NA:
return "NA";
case ERROR:
return "ERROR";
case VALID:
switch (valueType)
{
case BOOLEAN:
return bool ? "TRUE" : "FALSE";
case NUMBER:
return value + "";
default:
return "impossible";
}
default:
return "impossible";
}
return valueResult == ValueResult.VALID ? getValueText (this) : valueResult + "";
}
@Override
@ -112,8 +94,8 @@ public abstract class AbstractValue implements Value//, Iterable<Value>
protected String getValueText (Value value)
{
return "" + (value.getValueType () == ValueType.NUMBER ? value.getDouble ()
: value.getBoolean ());
return value.getValueType () == ValueType.NUMBER ? value.getDouble () + ""
: value.getBoolean () ? "TRUE" : "FALSE";
}
@Override

View File

@ -11,6 +11,8 @@ class And extends ConditionListFunction
@Override
public void calculate ()
{
valueResult = ValueResult.VALID;
for (Value condition : conditions)
{
condition.calculate ();
@ -27,6 +29,7 @@ class And extends ConditionListFunction
return;
}
}
bool = true;
}
}

View File

@ -13,12 +13,6 @@ public class BooleanFunction extends Function
valueType = ValueType.BOOLEAN;
}
@Override
public boolean getBoolean ()
{
return bool;
}
@Override
public String getType ()
{

View File

@ -16,9 +16,9 @@ class Cell implements Value, Comparable<Cell>
private boolean calculated;
private CellType cellType;
private String repeatingText; // REPEATING_CHARACTER
private String label; // LABEL
private Value value; // VALUE
private String repeatingText; // CellType.FILLER
private String label; // CellType.LABEL
private Value value; // CellType.VALUE
enum CellType
{
@ -46,28 +46,31 @@ class Cell implements Value, Comparable<Cell>
if (formatText.startsWith ("/-"))
{
assert cellType == CellType.EMPTY;
repeatingText = formatText.substring (2);
for (int i = 0; i < 20; i++)
repeat += repeatingText;
cellType = CellType.FILLER;
return;
}
System.out.printf ("Unexpected format [%s]%n", formatText);
}
void setValue (String command)
void setValue (String valueText)
{
assert cellType == CellType.EMPTY;
if (!command.isEmpty () && command.charAt (0) == '"')
if (!valueText.isEmpty () && valueText.charAt (0) == '"')
{
label = command.substring (1);
label = valueText.substring (1);
cellType = CellType.LABEL;
}
else
{
fullText = command;
fullText = valueText;
cellType = CellType.VALUE;
try
{
@ -330,6 +333,7 @@ class Cell implements Value, Comparable<Cell>
{
String contents = "";
String contents2 = "";
String valueTypeText = "";
String valueText = "";
String line2 = "";
String rest = "";
@ -347,19 +351,21 @@ class Cell implements Value, Comparable<Cell>
break;
case VALUE:
contents = fullText;
valueText = ": " + value.getValueType ();
valueTypeText = value.getValueType () + "";
rest = value.toString ();
valueText = value.getText ();
break;
}
if (contents.length () > 50)
if (contents.length () > 39)
{
contents2 = contents.substring (50);
contents = contents.substring (0, 50);
contents2 = contents.substring (39);
contents = contents.substring (0, 39);
line2 = String.format ("| %-70.70s|%n", contents2);
}
return String.format ("%s%n| %-9.9s : %-50.50s %-18.18s |%n%s%s", AbstractValue.LINE,
address.getText (), contents, cellType + valueText, line2, rest);
String single = String.format (AbstractValue.FMT5, address.getText (), contents,
cellType, valueTypeText, valueText);
return String.format ("%s%n%s%s%s", AbstractValue.LINE, single, line2, rest);
}
}

View File

@ -331,8 +331,8 @@ class Expression extends AbstractValue
{
StringBuilder text = new StringBuilder ();
text.append (String.format ("%s%n", LINE));
text.append (
String.format (FMT4, "Exprss", getFullText (), valueType, getValueText (this)));
text.append (String.format (FMT4, "Exprssion", getFullText (), valueType,
getValueText (this)));
int index = 0;
for (Value value : values)
{

View File

@ -5,8 +5,8 @@ abstract class Function extends AbstractValue
static final String[] functionList =
{ "@ABS(", "@ACOS(", "@AND(", "@ASIN(", "@ATAN(", "@AVERAGE(", "@COUNT(",
"@CHOOSE(", "@COS(", "@ERROR", "@EXP(", "@FALSE", "@IF(", "@INT(", "@ISERROR(",
"@ISNA(", "@LOG10(", "@LOOKUP(", "@LN(", "@MIN(", "@MAX(", "@NA", "@NPV(", "@OR(",
"@PI", "@SIN(", "@SUM(", "@SQRT(", "@TAN(", "@TRUE" };
"@ISNA(", "@LOG10(", "@LOOKUP(", "@LN(", "@MIN(", "@MAX(", "@NA", "@NOT(",
"@NPV(", "@OR(", "@PI", "@SIN(", "@SUM(", "@SQRT(", "@TAN(", "@TRUE" };
protected final String functionName;
protected final String functionText;

View File

@ -0,0 +1,25 @@
package com.bytezone.diskbrowser.visicalc;
public class Not extends BooleanFunction
{
Not (Cell cell, String text)
{
super (cell, text);
assert text.startsWith ("@NOT(") : text;
}
@Override
public void calculate ()
{
source.calculate ();
if (source.getValueType () != ValueType.BOOLEAN)
{
valueResult = ValueResult.ERROR;
return;
}
bool = !source.getBoolean ();
valueResult = ValueResult.VALID;
}
}

View File

@ -11,6 +11,8 @@ class Or extends ConditionListFunction
@Override
public void calculate ()
{
valueResult = ValueResult.VALID;
for (Value condition : conditions)
{
condition.calculate ();
@ -27,6 +29,7 @@ class Or extends ConditionListFunction
return;
}
}
bool = false;
}
}

View File

@ -402,22 +402,22 @@ public class Sheet
counts.add ("");
text.append (String.format ("+%-83.83s+%n", underline));
text.append (String.format ("| Global format : %-18s %-14s %-14s %-14s |%n",
text.append (String.format ("| Global format : %-18s %-14s %-14s %-14s |%n",
globalFormat, counts.get (0), counts.get (6), counts.get (12)));
text.append (String.format ("| Column width : %-2d %-15s %-14s %-14s %-14s |%n",
text.append (String.format ("| Column width : %-2d %-15s %-14s %-14s %-14s |%n",
columnWidth, "", counts.get (1), counts.get (7), counts.get (13)));
text.append (String.format ("| Recalc order : %-18s %-14s %-14s %-14s |%n",
text.append (String.format ("| Recalc order : %-18s %-14s %-14s %-14s |%n",
recalculationOrder == 'R' ? "Row" : "Column", counts.get (2), counts.get (8),
counts.get (14)));
text.append (String.format ("| Recalculation : %-18s %-14s %-14s %-14s |%n",
text.append (String.format ("| Recalculation : %-18s %-14s %-14s %-14s |%n",
recalculation == 'A' ? "Automatic" : "Manual", counts.get (3), counts.get (9),
counts.get (15)));
text.append (String.format ("| Cells : %-5d %-11s %-14s %-14s %-14s |%n",
text.append (String.format ("| Cells : %-5d %-11s %-14s %-14s %-14s |%n",
size (), "", counts.get (4), counts.get (10), counts.get (16)));
String rangeText = size () > 0 ? Address.getCellName (minRow + 1, minColumn) + ":"
+ Address.getCellName (maxRow + 1, maxColumn) : "";
text.append (String.format ("| Range : %-18s %-14s %-14s %-14s |%n",
text.append (String.format ("| Range : %-18s %-14s %-14s %-14s |%n",
rangeText, counts.get (5), counts.get (11), counts.get (17)));
text.append (String.format ("+%-83.83s+%n", underline));
}
@ -583,27 +583,30 @@ public class Sheet
return new Na (cell, text);
case 22:
return new Npv (cell, text);
return new Not (cell, text);
case 23:
return new Or (cell, text);
return new Npv (cell, text);
case 24:
return new Pi (cell, text);
return new Or (cell, text);
case 25:
return new Sin (cell, text);
return new Pi (cell, text);
case 26:
return new Sum (cell, text);
return new Sin (cell, text);
case 27:
return new Sqrt (cell, text);
return new Sum (cell, text);
case 28:
return new Tan (cell, text);
return new Sqrt (cell, text);
case 29:
return new Tan (cell, text);
case 30:
return new True (cell, text);
default: