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

View File

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

View File

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

View File

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

View File

@ -5,8 +5,8 @@ abstract class Function extends AbstractValue
static final String[] functionList = static final String[] functionList =
{ "@ABS(", "@ACOS(", "@AND(", "@ASIN(", "@ATAN(", "@AVERAGE(", "@COUNT(", { "@ABS(", "@ACOS(", "@AND(", "@ASIN(", "@ATAN(", "@AVERAGE(", "@COUNT(",
"@CHOOSE(", "@COS(", "@ERROR", "@EXP(", "@FALSE", "@IF(", "@INT(", "@ISERROR(", "@CHOOSE(", "@COS(", "@ERROR", "@EXP(", "@FALSE", "@IF(", "@INT(", "@ISERROR(",
"@ISNA(", "@LOG10(", "@LOOKUP(", "@LN(", "@MIN(", "@MAX(", "@NA", "@NPV(", "@OR(", "@ISNA(", "@LOG10(", "@LOOKUP(", "@LN(", "@MIN(", "@MAX(", "@NA", "@NOT(",
"@PI", "@SIN(", "@SUM(", "@SQRT(", "@TAN(", "@TRUE" }; "@NPV(", "@OR(", "@PI", "@SIN(", "@SUM(", "@SQRT(", "@TAN(", "@TRUE" };
protected final String functionName; protected final String functionName;
protected final String functionText; 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 @Override
public void calculate () public void calculate ()
{ {
valueResult = ValueResult.VALID;
for (Value condition : conditions) for (Value condition : conditions)
{ {
condition.calculate (); condition.calculate ();
@ -27,6 +29,7 @@ class Or extends ConditionListFunction
return; return;
} }
} }
bool = false; bool = false;
} }
} }

View File

@ -583,27 +583,30 @@ public class Sheet
return new Na (cell, text); return new Na (cell, text);
case 22: case 22:
return new Npv (cell, text); return new Not (cell, text);
case 23: case 23:
return new Or (cell, text); return new Npv (cell, text);
case 24: case 24:
return new Pi (cell, text); return new Or (cell, text);
case 25: case 25:
return new Sin (cell, text); return new Pi (cell, text);
case 26: case 26:
return new Sum (cell, text); return new Sin (cell, text);
case 27: case 27:
return new Sqrt (cell, text); return new Sum (cell, text);
case 28: case 28:
return new Tan (cell, text); return new Sqrt (cell, text);
case 29: case 29:
return new Tan (cell, text);
case 30:
return new True (cell, text); return new True (cell, text);
default: default: