debug text

This commit is contained in:
Denis Molony
2017-03-24 13:00:11 +11:00
parent 71ce82ce69
commit 5dbdbadf5e
9 changed files with 74 additions and 176 deletions

View File

@@ -6,8 +6,16 @@ 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 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 =
"+----------------------------------------------------------"
+ "------------------------+";
protected final Cell cell; protected final Cell cell;
protected final String fullText; protected final String fullText;
protected double value; protected double value;
protected boolean bool; protected boolean bool;
protected ValueType valueType = ValueType.NUMBER; // could be BOOLEAN protected ValueType valueType = ValueType.NUMBER; // could be BOOLEAN
@@ -44,12 +52,6 @@ public abstract class AbstractValue implements Value, Iterable<Value>
return valueResult == ValueResult.VALID; return valueResult == ValueResult.VALID;
} }
// @Override
// public boolean isValueType (ValueType type)
// {
// return valueType == type;
// }
@Override @Override
public double getDouble () public double getDouble ()
{ {
@@ -92,64 +94,15 @@ public abstract class AbstractValue implements Value, Iterable<Value>
// System.out.println ("calculate not overridden: " + cell); // System.out.println ("calculate not overridden: " + cell);
} }
protected String getValueText (Value value)
{
return "" + (value.getValueType () == ValueType.NUMBER ? value.getDouble ()
: value.getBoolean ());
}
@Override @Override
public Iterator<Value> iterator () public Iterator<Value> iterator ()
{ {
return values.iterator (); return values.iterator ();
} }
// for debugging
// String getValueText (int depth)
// {
// StringBuilder text = new StringBuilder ();
//
// String typeText = " " + getTypeText ();
// if (getValueType () == ValueType.NUMBER)
// {
// String valueText = String.format ("%f", getDouble ());
// text.append (String.format ("| %-10s : %-69s |%n", typeText, valueText));
// }
// else if (getValueType () == ValueType.BOOLEAN)
// {
// String valueText = String.format ("%s", getBoolean ());
// text.append (String.format ("| %-10s : %-69s |%n", typeText, valueText));
// }
// else
// text.append (String.format ("| %-10s : %-69s |%n", typeText, getValueType ()));
//
// if (this instanceof Expression)
// {
// text.append (
// String.format ("| Expression : %-69s |%n", ((Expression) this).fullText ()));
// for (Value v : (Expression) this)
// {
// if (v instanceof Cell)
// {
// Cell c = (Cell) v;
// ValueType vt = c.getValueType ();
// String tx = vt == ValueType.NUMBER ? c.getDouble () + "" : c.getBoolean () + "";
// text.append (
// String.format ("| Cell %-3s : %-69s |%n", c.getAddressText (), tx));
// }
// else
// text.append (((AbstractValue) v).getValueText (depth + 1));
// }
// }
// else if (this instanceof Function)
// {
// text.append (
// String.format ("| Function : %-69s |%n", ((Function) this).fullText));
// for (Value v : (Function) this)
// text.append (((AbstractValue) v).getValueText (depth + 1));
// }
// else if (this instanceof Condition)
// {
// text.append (
// String.format ("| Condition : %-69s |%n", ((Condition) this).getFullText ()));
// for (Value v : (Condition) this)
// text.append (((AbstractValue) v).getValueText (depth + 1));
// }
//
// return text.toString ();
// }
} }

View File

@@ -287,9 +287,9 @@ class Cell implements Value, Comparable<Cell>
switch (cellType) switch (cellType)
{ {
case LABEL: case LABEL:
return label; return "LBL : " + label;
case REPEATING_CHARACTER: case REPEATING_CHARACTER:
return repeatingText; return "RPT : " + repeatingText;
case EMPTY: case EMPTY:
return "Empty Cell"; return "Empty Cell";
case VALUE: case VALUE:
@@ -302,7 +302,7 @@ class Cell implements Value, Comparable<Cell>
@Override @Override
public String getType () public String getType ()
{ {
return "Cell"; return "Cell " + getAddressText ();
} }
@Override @Override
@@ -320,77 +320,31 @@ class Cell implements Value, Comparable<Cell>
return value; return value;
} }
// public String getDebugText ()
// {
// StringBuilder text = new StringBuilder ();
// text.append (line);
// text.append ("\n");
// text.append (String.format ("| %-11s %s Format: %s |%n",
// address.getText (), address.getDetails (), cellFormat));
// text.append (line);
// text.append ("\n");
//
// switch (cellType)
// {
// case LABEL:
// text.append (String.format ("| LABEL : %-69s |%n", label));
// break;
//
// case REPEATING_CHARACTER:
// text.append (String.format ("| REPEAT : %-69s |%n", repeatingText));
// break;
//
// case EMPTY:
// text.append (String.format ("| EMPTY : %-69s |%n", ""));
// break;
//
// case VALUE:
// text.append (String.format ("| VALUE : %-69s |%n", expressionText));
// if (value == null)
// text.append (String.format ("| Value : %-69s |%n", "null"));
// else
// text.append (((AbstractValue) value).getValueText (0));
// break;
//
// default:
// text.append ("Unknown CellType: " + cellType + "\n");
// }
//
// text.append (line);
// return text.toString ();
// }
@Override @Override
public String toString () public String toString ()
{ {
String contents = ""; String contents = "";
String valueText = "";
switch (cellType) switch (cellType)
{ {
case LABEL: case LABEL:
contents = "Labl: " + label; contents = label;
break; break;
case REPEATING_CHARACTER: case REPEATING_CHARACTER:
contents = "Rept: " + repeatingText; contents = repeatingText;
break; break;
case EMPTY: case EMPTY:
contents = "Empty"; contents = "";
break; break;
case VALUE: case VALUE:
switch (value.getValueType ()) contents = fullText;
{ valueText = ": " + value.getValueType ();
case NUMBER:
contents = "Num : " + fullText;
break;
case BOOLEAN:
contents = "Bool: " + fullText;
break;
}
// contents = "Exp : " + expressionText;
break; break;
} }
return String.format ("Cell:%5s %s", address.getText (), contents); return String.format ("%s%n| %-9.9s : %-49.49s %-18.18s |%n", AbstractValue.LINE,
address.getText (), contents, cellType + valueText);
} }
@Override @Override

View File

@@ -161,20 +161,19 @@ class Condition extends AbstractValue implements Iterable<Value>
@Override @Override
public String toString () public String toString ()
{ {
String line = "+-------------------------------------------------------------+";
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
text.append (line + "\n"); text.append (LINE + "\n");
text.append (String.format ("| %-10.10s: CND : %-34.34s%-8.8s|%n", text.append (String.format (FMT4, "Predicate", getFullText (), valueType,
cell.getAddressText (), getFullText (), valueType)); getValueText (this)));
text.append (String.format ("| %-10.10s: %-40.40s%-8.8s|%n", "Condition", text.append (String.format (FMT4, "Left", conditionText,
conditionText, conditionExpression.getValueType ())); conditionExpression.getValueType (), getValueText (conditionExpression)));
if (comparator != null) if (comparator != null)
{ {
text.append (String.format ("| %-10.10s: %-60.60s|%n", "Comparatr", comparator)); text.append (String.format (FMT2, "Comparatr", comparator));
text.append (String.format ("| %-10.10s: %-40.40s%-8.8s|%n", "Value", valueText, text.append (String.format (FMT4, "Right", valueText,
valueExpression.getValueType ())); valueExpression.getValueType (), getValueText (valueExpression)));
} }
text.append (line); // text.append (LINE);
return text.toString (); return text.toString ();
} }
} }

View File

@@ -21,15 +21,13 @@ public class ConditionListFunction extends Function
@Override @Override
public String toString () public String toString ()
{ {
String line = "+-------------------------------------------------------------+";
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
text.append (line + "\n"); text.append (String.format ("%s%n", LINE));
text.append (String.format ("| %-10.10s: CFN : %-34.34s%-8.8s|%n", text.append (
cell.getAddressText (), getFullText (), valueType)); String.format (FMT4, "CFN", getFullText (), valueType, getValueText (this)));
for (Value value : conditions) for (Value value : conditions)
text.append (String.format ("| %-10.10s: %-40.40s%-8.8s|%n", "Value", text.append (String.format (FMT4, value.getType (), value.getFullText (),
value.getFullText (), value.getValueType ())); value.getValueType (), getValueText (value)));
text.append (line);
return text.toString (); return text.toString ();
} }
} }

View File

@@ -355,25 +355,22 @@ class Expression extends AbstractValue //implements Iterable<Value>
@Override @Override
public String toString () public String toString ()
{ {
String line = "+-------------------------------------------------------------+";
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
text.append (line + "\n"); text.append (String.format ("%s%n", LINE));
text.append (String.format ("| %-10.10s: EXP : %-34.34s%-8.8s|%n", text.append (
cell.getAddressText (), getFullText (), valueType)); String.format (FMT4, "Exprss", getFullText (), valueType, getValueText (this)));
int index = 0; int index = 0;
for (Value value : values) for (Value value : values)
{ {
String sign = signs.get (index); String sign = signs.get (index);
if (!"(+)".equals (sign)) if (!"(+)".equals (sign))
text.append (String.format ("| %-10.10s: %-40.40s|%n", "sign", sign)); text.append (String.format (FMT2, "sign", sign));
text.append (String.format ("| %-10.10s: %-40.40s%-8.8s|%n", "Value", text.append (String.format (FMT4, value.getType (), value.getFullText (),
value.getFullText (), value.getValueType ())); value.getValueType (), getValueText (value)));
if (index < operators.size ()) if (index < operators.size ())
text.append ( text.append (String.format (FMT2, "operator", operators.get (index)));
String.format ("| %-10.10s: %-48.48s|%n", "operator", operators.get (index)));
++index; ++index;
} }
text.append (line);
return text.toString (); return text.toString ();
} }
} }

View File

@@ -32,12 +32,15 @@ abstract class Function extends AbstractValue
@Override @Override
public String toString () public String toString ()
{ {
String line = "+-------------------------------------------------------------+";
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
text.append (line + "\n"); text.append (String.format ("%s%n", LINE));
text.append (String.format ("| %-10.10s: FN : %-34.34s%-8.8s|%n", text.append (
cell.getAddressText (), getFullText (), valueType)); String.format (FMT4, "Function", getFullText (), valueType, getValueText (this)));
text.append (line); for (Value value : values)
{
text.append (String.format (FMT4, value.getType (), value.getFullText (),
value.getValueType (), getValueText (value)));
}
return text.toString (); return text.toString ();
} }
} }

View File

@@ -78,18 +78,17 @@ class If extends Function
@Override @Override
public String toString () public String toString ()
{ {
String line = "+-------------------------------------------------------------+";
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
text.append (line + "\n"); text.append (String.format ("%s%n", LINE));
text.append (String.format ("| %-10.10s: %-40.40s%-8.8s|%n", cell.getAddressText (), text.append (String.format (FMT4, "IF", fullText, valueType, getValueText (this)));
fullText, valueType)); text.append (String.format (FMT4, "condition", conditionText,
text.append (String.format ("| condition : %-40.40s%-8.8s|%n", conditionText, condition.getValueType (), getValueText (condition)));
condition.getValueType ())); if (condition.getBoolean ())
text.append (String.format ("| true : %-40.40s%-8.8s|%n", textTrue, text.append (String.format (FMT4, "true", textTrue, expTrue.getValueType (),
expTrue.getValueType ())); getValueText (expTrue)));
text.append (String.format ("| false : %-40.40s%-8.8s|%n", textFalse, else
expFalse.getValueType ())); text.append (String.format (FMT4, "false", textFalse, expFalse.getValueType (),
text.append (line); getValueText (expFalse)));
return text.toString (); return text.toString ();
} }
} }

View File

@@ -34,13 +34,10 @@ class Number extends AbstractValue
@Override @Override
public String toString () public String toString ()
{ {
// return String.format ("Number: %f", value);
String line = "+-------------------------------------------------------------+";
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
text.append (line + "\n"); text.append (String.format ("%s%n", LINE));
text.append (String.format ("| %-10.10s: NUM : %-34.34s%-8.8s|%n", text.append (String.format (FMT5, cell.getAddressText (), "NUM", getFullText (),
cell.getAddressText (), getFullText (), valueType)); valueType, getValueText (this)));
text.append (line);
return text.toString (); return text.toString ();
} }
} }

View File

@@ -473,16 +473,14 @@ public class Sheet
+ " ***\n\n"); + " ***\n\n");
last = cell.getAddress ().getColumn (); last = cell.getAddress ().getColumn ();
} }
// text.append (cell.getDebugText ());
// text.append (cell);
// text.append ("\n");
if (cell.isCellType (CellType.VALUE))
{
text.append (cell.getValue ());
text.append ("\n");
}
text.append ("\n"); // text.append (AbstractValue.LINE + "\n");
text.append (cell);
if (cell.isCellType (CellType.VALUE))
text.append (cell.getValue ());
text.append (AbstractValue.LINE);
text.append ("\n\n");
} }
text.append ("\n"); text.append ("\n");