Skip to content

Commit

Permalink
added @Not
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolony committed Mar 25, 2017
1 parent bf246bc commit 212e877
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 58 deletions.
26 changes: 4 additions & 22 deletions src/com/bytezone/diskbrowser/visicalc/AbstractValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "+--------------------------------------------"
+ "---------------------------------------+";

Expand Down Expand Up @@ -75,25 +75,7 @@ public int size ()
@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
Expand All @@ -112,8 +94,8 @@ protected void attach (StringBuilder text, String title, String textValue, 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
Expand Down
3 changes: 3 additions & 0 deletions src/com/bytezone/diskbrowser/visicalc/And.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public And (Cell cell, String text)
@Override
public void calculate ()
{
valueResult = ValueResult.VALID;

for (Value condition : conditions)
{
condition.calculate ();
Expand All @@ -27,6 +29,7 @@ public void calculate ()
return;
}
}

bool = true;
}
}
6 changes: 0 additions & 6 deletions src/com/bytezone/diskbrowser/visicalc/BooleanFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ public class BooleanFunction extends Function
valueType = ValueType.BOOLEAN;
}

@Override
public boolean getBoolean ()
{
return bool;
}

@Override
public String getType ()
{
Expand Down
32 changes: 19 additions & 13 deletions src/com/bytezone/diskbrowser/visicalc/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -46,28 +46,31 @@ void setFormat (String formatText)

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
{
Expand Down Expand Up @@ -330,6 +333,7 @@ public String toString ()
{
String contents = "";
String contents2 = "";
String valueTypeText = "";
String valueText = "";
String line2 = "";
String rest = "";
Expand All @@ -347,19 +351,21 @@ public String toString ()
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);
}
}
4 changes: 2 additions & 2 deletions src/com/bytezone/diskbrowser/visicalc/Expression.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ public String toString ()
{
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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/com/bytezone/diskbrowser/visicalc/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions src/com/bytezone/diskbrowser/visicalc/Not.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 3 additions & 0 deletions src/com/bytezone/diskbrowser/visicalc/Or.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public Or (Cell cell, String text)
@Override
public void calculate ()
{
valueResult = ValueResult.VALID;

for (Value condition : conditions)
{
condition.calculate ();
Expand All @@ -27,6 +29,7 @@ public void calculate ()
return;
}
}

bool = false;
}
}
29 changes: 16 additions & 13 deletions src/com/bytezone/diskbrowser/visicalc/Sheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,22 +402,22 @@ else if (width == 2)
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));
}
Expand Down Expand Up @@ -583,27 +583,30 @@ Function getFunction (Cell cell, String text)
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:
Expand Down

0 comments on commit 212e877

Please sign in to comment.