debugging text

This commit is contained in:
Denis Molony 2017-03-24 15:09:24 +11:00
parent 5dbdbadf5e
commit 987c91690c
6 changed files with 54 additions and 22 deletions

View File

@ -4,9 +4,9 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public abstract class AbstractValue implements Value, Iterable<Value>
public abstract class AbstractValue implements Value//, Iterable<Value>
{
protected static final String FMT4 = "| %-9.9s : %-50.50s%-8.8s %-10.10s|%n";
protected static final String FMT4 = "| %-9.9s : %-49.49s %-8.8s %-10.10s|%n";
protected static final String FMT2 = "| %-9.9s : %-69.69s|%n";
protected static final String FMT5 = "| %-9.9s : %-3.3s : %-44.44s%-8.8s %-10.10s|%n";
protected static final String LINE =
@ -64,6 +64,12 @@ public abstract class AbstractValue implements Value, Iterable<Value>
return bool;
}
@Override
public int size ()
{
return values.size ();
}
@Override
public String getText ()
{

View File

@ -1,5 +1,7 @@
package com.bytezone.diskbrowser.visicalc;
import java.util.Iterator;
class Cell implements Value, Comparable<Cell>
{
private static final String line = "+----------------------------------------"
@ -20,7 +22,7 @@ class Cell implements Value, Comparable<Cell>
enum CellType
{
LABEL, REPEATING_CHARACTER, VALUE, EMPTY
LABEL, FILLER, VALUE, EMPTY
}
public Cell (Sheet parent, Address address)
@ -105,7 +107,7 @@ class Cell implements Value, Comparable<Cell>
repeatingText = formatText.substring (2);
for (int i = 0; i < 20; i++)
repeat += repeatingText;
cellType = CellType.REPEATING_CHARACTER;
cellType = CellType.FILLER;
return;
}
@ -198,7 +200,7 @@ class Cell implements Value, Comparable<Cell>
fmtChar = 'L';
return Format.justify (label, colWidth, fmtChar);
case REPEATING_CHARACTER:
case FILLER:
return Format.justify (repeat, colWidth, ' ');
case EMPTY:
@ -281,6 +283,18 @@ class Cell implements Value, Comparable<Cell>
return cellType == CellType.VALUE ? value.getBoolean () : false;
}
@Override
public int size ()
{
return cellType == CellType.VALUE ? value.size () : 0;
}
@Override
public Iterator<Value> iterator ()
{
return cellType == CellType.VALUE ? value.iterator () : null;
}
@Override
public String getFullText ()
{
@ -288,7 +302,7 @@ class Cell implements Value, Comparable<Cell>
{
case LABEL:
return "LBL : " + label;
case REPEATING_CHARACTER:
case FILLER:
return "RPT : " + repeatingText;
case EMPTY:
return "Empty Cell";
@ -324,14 +338,16 @@ class Cell implements Value, Comparable<Cell>
public String toString ()
{
String contents = "";
String contents2 = "";
String valueText = "";
String line2 = "";
switch (cellType)
{
case LABEL:
contents = label;
break;
case REPEATING_CHARACTER:
case FILLER:
contents = repeatingText;
break;
case EMPTY:
@ -343,8 +359,14 @@ class Cell implements Value, Comparable<Cell>
break;
}
return String.format ("%s%n| %-9.9s : %-49.49s %-18.18s |%n", AbstractValue.LINE,
address.getText (), contents, cellType + valueText);
if (contents.length () > 49)
{
contents2 = contents.substring (49);
contents = contents.substring (0, 49);
line2 = String.format ("| %-69.69s|%n", contents2);
}
return String.format ("%s%n| %-9.9s : %-49.49s %-18.18s |%n%s", AbstractValue.LINE,
address.getText (), contents, cellType + valueText, line2);
}
@Override

View File

@ -125,11 +125,6 @@ class Expression extends AbstractValue //implements Iterable<Value>
return values.size () == 1 && signs.get (0).equals ("(+)") ? values.get (0) : this;
}
int size ()
{
return values.size ();
}
Value get (int index)
{
if (index < 0 || index >= values.size ())

View File

@ -80,15 +80,22 @@ class If extends Function
{
StringBuilder text = new StringBuilder ();
text.append (String.format ("%s%n", LINE));
text.append (String.format (FMT4, "IF", fullText, valueType, getValueText (this)));
text.append (
String.format (FMT4, getType (), fullText, valueType, getValueText (this)));
text.append (String.format (FMT4, "condition", conditionText,
condition.getValueType (), getValueText (condition)));
if (condition.getBoolean ())
text.append (String.format (FMT4, "true", textTrue, expTrue.getValueType (),
getValueText (expTrue)));
attach (text, "true", expTrue, textTrue);
else
text.append (String.format (FMT4, "false", textFalse, expFalse.getValueType (),
getValueText (expFalse)));
attach (text, "false", expFalse, textFalse);
return text.toString ();
}
private void attach (StringBuilder text, String title, Value exp, String s)
{
text.append (String.format (FMT4, title, s, exp.getValueType (), getValueText (exp)));
if (exp.size () > 1)
for (Value value : exp)
text.append (value);
}
}

View File

@ -36,8 +36,8 @@ class Number extends AbstractValue
{
StringBuilder text = new StringBuilder ();
text.append (String.format ("%s%n", LINE));
text.append (String.format (FMT5, cell.getAddressText (), "NUM", getFullText (),
valueType, getValueText (this)));
text.append (
String.format (FMT4, "Constant", getFullText (), valueType, getValueText (this)));
return text.toString ();
}
}

View File

@ -1,6 +1,6 @@
package com.bytezone.diskbrowser.visicalc;
interface Value
interface Value extends Iterable<Value>
{
enum ValueType
{
@ -29,4 +29,6 @@ interface Value
public String getFullText (); // original text
public String getType (); // FUNCTION, CONDITION, EXPRESSION
public int size ();
}