From 5dbdbadf5e4c7d4cbc600265c82cbc29f8409fa6 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Fri, 24 Mar 2017 13:00:11 +1100 Subject: [PATCH] debug text --- .../diskbrowser/visicalc/AbstractValue.java | 75 ++++--------------- .../bytezone/diskbrowser/visicalc/Cell.java | 68 +++-------------- .../diskbrowser/visicalc/Condition.java | 19 +++-- .../visicalc/ConditionListFunction.java | 12 ++- .../diskbrowser/visicalc/Expression.java | 17 ++--- .../diskbrowser/visicalc/Function.java | 13 ++-- src/com/bytezone/diskbrowser/visicalc/If.java | 21 +++--- .../bytezone/diskbrowser/visicalc/Number.java | 9 +-- .../bytezone/diskbrowser/visicalc/Sheet.java | 16 ++-- 9 files changed, 74 insertions(+), 176 deletions(-) diff --git a/src/com/bytezone/diskbrowser/visicalc/AbstractValue.java b/src/com/bytezone/diskbrowser/visicalc/AbstractValue.java index 879e415..3bde047 100644 --- a/src/com/bytezone/diskbrowser/visicalc/AbstractValue.java +++ b/src/com/bytezone/diskbrowser/visicalc/AbstractValue.java @@ -6,8 +6,16 @@ import java.util.List; public abstract class AbstractValue implements Value, Iterable { + 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 String fullText; + protected double value; protected boolean bool; protected ValueType valueType = ValueType.NUMBER; // could be BOOLEAN @@ -44,12 +52,6 @@ public abstract class AbstractValue implements Value, Iterable return valueResult == ValueResult.VALID; } - // @Override - // public boolean isValueType (ValueType type) - // { - // return valueType == type; - // } - @Override public double getDouble () { @@ -92,64 +94,15 @@ public abstract class AbstractValue implements Value, Iterable // System.out.println ("calculate not overridden: " + cell); } + protected String getValueText (Value value) + { + return "" + (value.getValueType () == ValueType.NUMBER ? value.getDouble () + : value.getBoolean ()); + } + @Override public Iterator 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 (); - // } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/Cell.java b/src/com/bytezone/diskbrowser/visicalc/Cell.java index e878a87..1999517 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Cell.java +++ b/src/com/bytezone/diskbrowser/visicalc/Cell.java @@ -287,9 +287,9 @@ class Cell implements Value, Comparable switch (cellType) { case LABEL: - return label; + return "LBL : " + label; case REPEATING_CHARACTER: - return repeatingText; + return "RPT : " + repeatingText; case EMPTY: return "Empty Cell"; case VALUE: @@ -302,7 +302,7 @@ class Cell implements Value, Comparable @Override public String getType () { - return "Cell"; + return "Cell " + getAddressText (); } @Override @@ -320,77 +320,31 @@ class Cell implements Value, Comparable 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 public String toString () { String contents = ""; + String valueText = ""; switch (cellType) { case LABEL: - contents = "Labl: " + label; + contents = label; break; case REPEATING_CHARACTER: - contents = "Rept: " + repeatingText; + contents = repeatingText; break; case EMPTY: - contents = "Empty"; + contents = ""; break; case VALUE: - switch (value.getValueType ()) - { - case NUMBER: - contents = "Num : " + fullText; - break; - case BOOLEAN: - contents = "Bool: " + fullText; - break; - } - // contents = "Exp : " + expressionText; + contents = fullText; + valueText = ": " + value.getValueType (); 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 diff --git a/src/com/bytezone/diskbrowser/visicalc/Condition.java b/src/com/bytezone/diskbrowser/visicalc/Condition.java index 1eee3a4..b018c72 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Condition.java +++ b/src/com/bytezone/diskbrowser/visicalc/Condition.java @@ -161,20 +161,19 @@ class Condition extends AbstractValue implements Iterable @Override public String toString () { - String line = "+-------------------------------------------------------------+"; StringBuilder text = new StringBuilder (); - text.append (line + "\n"); - text.append (String.format ("| %-10.10s: CND : %-34.34s%-8.8s|%n", - cell.getAddressText (), getFullText (), valueType)); - text.append (String.format ("| %-10.10s: %-40.40s%-8.8s|%n", "Condition", - conditionText, conditionExpression.getValueType ())); + text.append (LINE + "\n"); + text.append (String.format (FMT4, "Predicate", getFullText (), valueType, + getValueText (this))); + text.append (String.format (FMT4, "Left", conditionText, + conditionExpression.getValueType (), getValueText (conditionExpression))); if (comparator != null) { - text.append (String.format ("| %-10.10s: %-60.60s|%n", "Comparatr", comparator)); - text.append (String.format ("| %-10.10s: %-40.40s%-8.8s|%n", "Value", valueText, - valueExpression.getValueType ())); + text.append (String.format (FMT2, "Comparatr", comparator)); + text.append (String.format (FMT4, "Right", valueText, + valueExpression.getValueType (), getValueText (valueExpression))); } - text.append (line); + // text.append (LINE); return text.toString (); } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/ConditionListFunction.java b/src/com/bytezone/diskbrowser/visicalc/ConditionListFunction.java index dc415aa..d7a3d5b 100644 --- a/src/com/bytezone/diskbrowser/visicalc/ConditionListFunction.java +++ b/src/com/bytezone/diskbrowser/visicalc/ConditionListFunction.java @@ -21,15 +21,13 @@ public class ConditionListFunction extends Function @Override public String toString () { - String line = "+-------------------------------------------------------------+"; StringBuilder text = new StringBuilder (); - text.append (line + "\n"); - text.append (String.format ("| %-10.10s: CFN : %-34.34s%-8.8s|%n", - cell.getAddressText (), getFullText (), valueType)); + text.append (String.format ("%s%n", LINE)); + text.append ( + String.format (FMT4, "CFN", getFullText (), valueType, getValueText (this))); for (Value value : conditions) - text.append (String.format ("| %-10.10s: %-40.40s%-8.8s|%n", "Value", - value.getFullText (), value.getValueType ())); - text.append (line); + text.append (String.format (FMT4, value.getType (), value.getFullText (), + value.getValueType (), getValueText (value))); return text.toString (); } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/Expression.java b/src/com/bytezone/diskbrowser/visicalc/Expression.java index 070d9a9..9fdd77f 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Expression.java +++ b/src/com/bytezone/diskbrowser/visicalc/Expression.java @@ -355,25 +355,22 @@ class Expression extends AbstractValue //implements Iterable @Override public String toString () { - String line = "+-------------------------------------------------------------+"; StringBuilder text = new StringBuilder (); - text.append (line + "\n"); - text.append (String.format ("| %-10.10s: EXP : %-34.34s%-8.8s|%n", - cell.getAddressText (), getFullText (), valueType)); + text.append (String.format ("%s%n", LINE)); + text.append ( + String.format (FMT4, "Exprss", getFullText (), valueType, getValueText (this))); int index = 0; for (Value value : values) { String sign = signs.get (index); if (!"(+)".equals (sign)) - text.append (String.format ("| %-10.10s: %-40.40s|%n", "sign", sign)); - text.append (String.format ("| %-10.10s: %-40.40s%-8.8s|%n", "Value", - value.getFullText (), value.getValueType ())); + text.append (String.format (FMT2, "sign", sign)); + text.append (String.format (FMT4, value.getType (), value.getFullText (), + value.getValueType (), getValueText (value))); if (index < operators.size ()) - text.append ( - String.format ("| %-10.10s: %-48.48s|%n", "operator", operators.get (index))); + text.append (String.format (FMT2, "operator", operators.get (index))); ++index; } - text.append (line); return text.toString (); } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/Function.java b/src/com/bytezone/diskbrowser/visicalc/Function.java index 79148d5..61a6ce6 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Function.java +++ b/src/com/bytezone/diskbrowser/visicalc/Function.java @@ -32,12 +32,15 @@ abstract class Function extends AbstractValue @Override public String toString () { - String line = "+-------------------------------------------------------------+"; StringBuilder text = new StringBuilder (); - text.append (line + "\n"); - text.append (String.format ("| %-10.10s: FN : %-34.34s%-8.8s|%n", - cell.getAddressText (), getFullText (), valueType)); - text.append (line); + text.append (String.format ("%s%n", LINE)); + text.append ( + String.format (FMT4, "Function", getFullText (), valueType, getValueText (this))); + for (Value value : values) + { + text.append (String.format (FMT4, value.getType (), value.getFullText (), + value.getValueType (), getValueText (value))); + } return text.toString (); } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/If.java b/src/com/bytezone/diskbrowser/visicalc/If.java index f52d85c..ac5ca66 100644 --- a/src/com/bytezone/diskbrowser/visicalc/If.java +++ b/src/com/bytezone/diskbrowser/visicalc/If.java @@ -78,18 +78,17 @@ class If extends Function @Override public String toString () { - String line = "+-------------------------------------------------------------+"; StringBuilder text = new StringBuilder (); - text.append (line + "\n"); - text.append (String.format ("| %-10.10s: %-40.40s%-8.8s|%n", cell.getAddressText (), - fullText, valueType)); - text.append (String.format ("| condition : %-40.40s%-8.8s|%n", conditionText, - condition.getValueType ())); - text.append (String.format ("| true : %-40.40s%-8.8s|%n", textTrue, - expTrue.getValueType ())); - text.append (String.format ("| false : %-40.40s%-8.8s|%n", textFalse, - expFalse.getValueType ())); - text.append (line); + text.append (String.format ("%s%n", LINE)); + text.append (String.format (FMT4, "IF", 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))); + else + text.append (String.format (FMT4, "false", textFalse, expFalse.getValueType (), + getValueText (expFalse))); return text.toString (); } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/Number.java b/src/com/bytezone/diskbrowser/visicalc/Number.java index 25da709..827ae70 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Number.java +++ b/src/com/bytezone/diskbrowser/visicalc/Number.java @@ -34,13 +34,10 @@ class Number extends AbstractValue @Override public String toString () { - // return String.format ("Number: %f", value); - String line = "+-------------------------------------------------------------+"; StringBuilder text = new StringBuilder (); - text.append (line + "\n"); - text.append (String.format ("| %-10.10s: NUM : %-34.34s%-8.8s|%n", - cell.getAddressText (), getFullText (), valueType)); - text.append (line); + text.append (String.format ("%s%n", LINE)); + text.append (String.format (FMT5, cell.getAddressText (), "NUM", getFullText (), + valueType, getValueText (this))); return text.toString (); } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/Sheet.java b/src/com/bytezone/diskbrowser/visicalc/Sheet.java index cf5d59a..f6cd210 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Sheet.java +++ b/src/com/bytezone/diskbrowser/visicalc/Sheet.java @@ -473,16 +473,14 @@ public class Sheet + " ***\n\n"); 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");