diff --git a/src/com/bytezone/diskbrowser/visicalc/Abs.java b/src/com/bytezone/diskbrowser/visicalc/Abs.java index 1a719e4..4c8139d 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Abs.java +++ b/src/com/bytezone/diskbrowser/visicalc/Abs.java @@ -8,6 +8,8 @@ public class Abs extends Function { super (cell, text); + assert text.startsWith ("@ABS(") : text; + source = new Expression (parent, cell, functionText); values.add (source); } diff --git a/src/com/bytezone/diskbrowser/visicalc/Acos.java b/src/com/bytezone/diskbrowser/visicalc/Acos.java index 9a81a4e..a80309c 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Acos.java +++ b/src/com/bytezone/diskbrowser/visicalc/Acos.java @@ -8,6 +8,8 @@ public class Acos extends Function { super (cell, text); + assert text.startsWith ("@ACOS(") : text; + v = new Expression (parent, cell, functionText).reduce (); valueType = ValueType.VALUE; } diff --git a/src/com/bytezone/diskbrowser/visicalc/And.java b/src/com/bytezone/diskbrowser/visicalc/And.java index bb4334c..b718a7d 100644 --- a/src/com/bytezone/diskbrowser/visicalc/And.java +++ b/src/com/bytezone/diskbrowser/visicalc/And.java @@ -11,6 +11,8 @@ class And extends Function { super (cell, text); + assert text.startsWith ("@AND(") : text; + String remainder = functionText; while (true) { diff --git a/src/com/bytezone/diskbrowser/visicalc/Asin.java b/src/com/bytezone/diskbrowser/visicalc/Asin.java index a91f883..89ea385 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Asin.java +++ b/src/com/bytezone/diskbrowser/visicalc/Asin.java @@ -8,6 +8,8 @@ public class Asin extends Function { super (cell, text); + assert text.startsWith ("@ASIN(") : text; + v = new Expression (parent, cell, functionText).reduce (); valueType = ValueType.VALUE; } diff --git a/src/com/bytezone/diskbrowser/visicalc/Atan.java b/src/com/bytezone/diskbrowser/visicalc/Atan.java index 224ac31..1e36cd7 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Atan.java +++ b/src/com/bytezone/diskbrowser/visicalc/Atan.java @@ -8,6 +8,8 @@ public class Atan extends Function { super (cell, text); + assert text.startsWith ("@ATAN(") : text; + v = new Expression (parent, cell, functionText).reduce (); valueType = ValueType.VALUE; } diff --git a/src/com/bytezone/diskbrowser/visicalc/Average.java b/src/com/bytezone/diskbrowser/visicalc/Average.java index 745a501..15a4d88 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Average.java +++ b/src/com/bytezone/diskbrowser/visicalc/Average.java @@ -11,6 +11,8 @@ public class Average extends Function { super (cell, text); + assert text.startsWith ("@AVERAGE(") : text; + list = new ValueList (parent, cell, functionText); isRange = functionText.indexOf ("...") > 0; } diff --git a/src/com/bytezone/diskbrowser/visicalc/Choose.java b/src/com/bytezone/diskbrowser/visicalc/Choose.java index 70f147b..3339ee2 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Choose.java +++ b/src/com/bytezone/diskbrowser/visicalc/Choose.java @@ -11,6 +11,8 @@ public class Choose extends Function { super (cell, text); + assert text.startsWith ("@CHOOSE(") : text; + // int pos = functionText.indexOf (','); // sourceText = functionText.substring (0, pos); sourceText = Expression.getParameter (functionText); diff --git a/src/com/bytezone/diskbrowser/visicalc/Cos.java b/src/com/bytezone/diskbrowser/visicalc/Cos.java index 4accc0e..95a7d08 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Cos.java +++ b/src/com/bytezone/diskbrowser/visicalc/Cos.java @@ -8,6 +8,8 @@ public class Cos extends Function { super (cell, text); + assert text.startsWith ("@COS(") : text; + v = new Expression (parent, cell, functionText).reduce (); valueType = ValueType.VALUE; } diff --git a/src/com/bytezone/diskbrowser/visicalc/Count.java b/src/com/bytezone/diskbrowser/visicalc/Count.java index 0a81078..68ce695 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Count.java +++ b/src/com/bytezone/diskbrowser/visicalc/Count.java @@ -11,6 +11,8 @@ class Count extends Function { super (cell, text); + assert text.startsWith ("@COUNT(") : text; + list = new ValueList (parent, cell, functionText); isRange = functionText.indexOf ("...") > 0; } diff --git a/src/com/bytezone/diskbrowser/visicalc/Error.java b/src/com/bytezone/diskbrowser/visicalc/Error.java index 6b9ce61..ed69e6f 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Error.java +++ b/src/com/bytezone/diskbrowser/visicalc/Error.java @@ -5,6 +5,9 @@ class Error extends Function public Error (Cell cell, String text) { super (cell, text); + + assert text.startsWith ("@ERROR") : text; + valueType = ValueType.ERROR; } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/Exp.java b/src/com/bytezone/diskbrowser/visicalc/Exp.java index 97e0d9d..fb69594 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Exp.java +++ b/src/com/bytezone/diskbrowser/visicalc/Exp.java @@ -8,6 +8,8 @@ public class Exp extends Function { super (cell, text); + assert text.startsWith ("@EXP(") : text; + v = new Expression (parent, cell, functionText).reduce (); valueType = ValueType.VALUE; } diff --git a/src/com/bytezone/diskbrowser/visicalc/False.java b/src/com/bytezone/diskbrowser/visicalc/False.java index f4ecea0..30a106a 100644 --- a/src/com/bytezone/diskbrowser/visicalc/False.java +++ b/src/com/bytezone/diskbrowser/visicalc/False.java @@ -6,6 +6,8 @@ public class False extends Function { super (cell, text); + assert text.equals ("@FALSE") : text; + value = 0; valueType = ValueType.VALUE; } diff --git a/src/com/bytezone/diskbrowser/visicalc/If.java b/src/com/bytezone/diskbrowser/visicalc/If.java index 9b235b9..6a9ba88 100644 --- a/src/com/bytezone/diskbrowser/visicalc/If.java +++ b/src/com/bytezone/diskbrowser/visicalc/If.java @@ -14,6 +14,8 @@ class If extends Function { super (cell, text); + assert text.startsWith ("@IF(") : text; + conditionText = Expression.getParameter (functionText); textTrue = Expression.getParameter (functionText.substring (conditionText.length () + 1)); diff --git a/src/com/bytezone/diskbrowser/visicalc/Int.java b/src/com/bytezone/diskbrowser/visicalc/Int.java index 460c4da..c94f786 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Int.java +++ b/src/com/bytezone/diskbrowser/visicalc/Int.java @@ -8,6 +8,8 @@ public class Int extends Function { super (cell, text); + assert text.startsWith ("@INT(") : text; + source = new Expression (parent, cell, functionText); values.add (source); } diff --git a/src/com/bytezone/diskbrowser/visicalc/IsError.java b/src/com/bytezone/diskbrowser/visicalc/IsError.java index b577562..7ee87e1 100644 --- a/src/com/bytezone/diskbrowser/visicalc/IsError.java +++ b/src/com/bytezone/diskbrowser/visicalc/IsError.java @@ -8,6 +8,8 @@ class IsError extends Function { super (cell, text); + assert text.startsWith ("@ISERROR(") : text; + expression = new Expression (parent, cell, functionText).reduce (); } diff --git a/src/com/bytezone/diskbrowser/visicalc/IsNa.java b/src/com/bytezone/diskbrowser/visicalc/IsNa.java index ddf5f99..1b3c09f 100644 --- a/src/com/bytezone/diskbrowser/visicalc/IsNa.java +++ b/src/com/bytezone/diskbrowser/visicalc/IsNa.java @@ -8,6 +8,8 @@ public class IsNa extends Function { super (cell, text); + assert text.startsWith ("@ISNA(") : text; + expression = new Expression (parent, cell, functionText).reduce (); } diff --git a/src/com/bytezone/diskbrowser/visicalc/Ln.java b/src/com/bytezone/diskbrowser/visicalc/Ln.java index e3e3a50..ce15d6e 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Ln.java +++ b/src/com/bytezone/diskbrowser/visicalc/Ln.java @@ -8,6 +8,8 @@ public class Ln extends Function { super (cell, text); + assert text.startsWith ("@LN(") : text; + v = new Expression (parent, cell, functionText).reduce (); valueType = ValueType.VALUE; } diff --git a/src/com/bytezone/diskbrowser/visicalc/Log10.java b/src/com/bytezone/diskbrowser/visicalc/Log10.java index 3051e87..6134d01 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Log10.java +++ b/src/com/bytezone/diskbrowser/visicalc/Log10.java @@ -8,6 +8,8 @@ public class Log10 extends Function { super (cell, text); + assert text.startsWith ("@LOG10(") : text; + v = new Expression (parent, cell, functionText).reduce (); valueType = ValueType.VALUE; } diff --git a/src/com/bytezone/diskbrowser/visicalc/Lookup.java b/src/com/bytezone/diskbrowser/visicalc/Lookup.java index 4f0464e..789cbe3 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Lookup.java +++ b/src/com/bytezone/diskbrowser/visicalc/Lookup.java @@ -11,17 +11,14 @@ class Lookup extends Function { super (cell, text); - // int pos = text.indexOf (','); + assert text.startsWith ("@LOOKUP(") : text; + sourceText = Expression.getParameter (functionText); - - // sourceText = text.substring (8, pos); source = new Expression (parent, cell, sourceText); + values.add (source); - // rangeText = text.substring (pos + 1, text.length () - 1); rangeText = functionText.substring (sourceText.length () + 1); range = new Range (parent, cell, rangeText); - - values.add (source); } @Override diff --git a/src/com/bytezone/diskbrowser/visicalc/Max.java b/src/com/bytezone/diskbrowser/visicalc/Max.java index b9caf1b..c5893f9 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Max.java +++ b/src/com/bytezone/diskbrowser/visicalc/Max.java @@ -8,6 +8,8 @@ class Max extends Function { super (cell, text); + assert text.startsWith ("@MAX(") : text; + list = new ValueList (parent, cell, functionText); } diff --git a/src/com/bytezone/diskbrowser/visicalc/Min.java b/src/com/bytezone/diskbrowser/visicalc/Min.java index 75be45f..f124f29 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Min.java +++ b/src/com/bytezone/diskbrowser/visicalc/Min.java @@ -8,6 +8,8 @@ class Min extends Function { super (cell, text); + assert text.startsWith ("@MIN(") : text; + list = new ValueList (parent, cell, functionText); } diff --git a/src/com/bytezone/diskbrowser/visicalc/Na.java b/src/com/bytezone/diskbrowser/visicalc/Na.java index f21643c..0fff1a5 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Na.java +++ b/src/com/bytezone/diskbrowser/visicalc/Na.java @@ -5,6 +5,9 @@ public class Na extends Function public Na (Cell cell, String text) { super (cell, text); + + assert text.equals ("@NA") : text; + valueType = ValueType.NA; } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/Npv.java b/src/com/bytezone/diskbrowser/visicalc/Npv.java index 0edab39..99e6348 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Npv.java +++ b/src/com/bytezone/diskbrowser/visicalc/Npv.java @@ -14,14 +14,14 @@ public class Npv extends Function { super (cell, text); - int pos = text.indexOf (','); - valueText = text.substring (5, pos); - rangeText = text.substring (pos + 1, text.length () - 1); + assert text.startsWith ("@NPV(") : text; + valueText = Expression.getParameter (functionText); rateExp = new Expression (parent, cell, valueText); - range = new Range (parent, cell, rangeText); - values.add (rateExp); + + rangeText = functionText.substring (valueText.length () + 1); + range = new Range (parent, cell, rangeText); } @Override diff --git a/src/com/bytezone/diskbrowser/visicalc/Or.java b/src/com/bytezone/diskbrowser/visicalc/Or.java index ff5757b..6ffb616 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Or.java +++ b/src/com/bytezone/diskbrowser/visicalc/Or.java @@ -11,14 +11,13 @@ class Or extends Function { super (cell, text); + assert text.startsWith ("@OR(") : text; + String remainder = functionText; while (true) { String parameter = Expression.getParameter (remainder); - // System.out.printf ("cond: [%s]%n", parameter); conditions.add (new Condition (parent, cell, parameter)); - // System.out.printf (" [%s]%n", remainder); - // System.out.printf (" [%s]%n", parameter); if (remainder.length () == parameter.length ()) break; remainder = remainder.substring (parameter.length () + 1); diff --git a/src/com/bytezone/diskbrowser/visicalc/Pi.java b/src/com/bytezone/diskbrowser/visicalc/Pi.java index ecb8e24..d7dcb3d 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Pi.java +++ b/src/com/bytezone/diskbrowser/visicalc/Pi.java @@ -7,6 +7,9 @@ class Pi extends Function super (cell, text); value = Math.PI; + + assert text.equals ("@PI") : text; + valueType = ValueType.VALUE; } } \ 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 00e1e4f..8254852 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Sheet.java +++ b/src/com/bytezone/diskbrowser/visicalc/Sheet.java @@ -500,129 +500,118 @@ public class Sheet return new Error (cell, "@ERROR"); } + String functionName = ""; + int functionId = -1; for (int i = 0; i < Function.functionList.length; i++) if (text.startsWith (Function.functionList[i])) { + functionId = i; functionTotals[i]++; + functionName = Function.functionList[i]; break; } - if (text.charAt (1) == 'A') + if (functionName.isEmpty ()) { - if (text.startsWith ("@ABS(")) + System.out.printf ("Unknown function: [%s]%n", text); + return new Error (cell, "@ERROR"); + } + + switch (functionId) + { + case 0: return new Abs (cell, text); - if (text.startsWith ("@ACOS(")) + case 1: return new Acos (cell, text); - if (text.startsWith ("@AND(")) + case 2: return new And (cell, text); - if (text.startsWith ("@ASIN(")) + case 3: return new Asin (cell, text); - if (text.startsWith ("@ATAN(")) + case 4: return new Atan (cell, text); - if (text.startsWith ("@AVERAGE(")) + case 5: return new Average (cell, text); - } - else if (text.charAt (1) == 'C') - { - if (text.startsWith ("@COUNT(")) + + case 6: return new Count (cell, text); - if (text.startsWith ("@CHOOSE(")) + case 7: return new Choose (cell, text); - if (text.startsWith ("@COS(")) + case 8: return new Cos (cell, text); - } - else if (text.charAt (1) == 'E') - { - if (text.startsWith ("@ERROR")) + + case 9: return new Error (cell, text); - if (text.startsWith ("@EXP(")) + case 10: return new Exp (cell, text); - } - else if (text.charAt (1) == 'F') - { - if (text.startsWith ("@FALSE")) + + case 11: return new False (cell, text); - } - else if (text.charAt (1) == 'I') - { - if (text.startsWith ("@IF(")) + + case 12: return new If (cell, text); - if (text.startsWith ("@INT(")) + case 13: return new Int (cell, text); - if (text.startsWith ("@ISERROR(")) + case 14: return new IsError (cell, text); - if (text.startsWith ("@ISNA(")) + case 15: return new IsNa (cell, text); - } - else if (text.charAt (1) == 'L') - { - if (text.startsWith ("@LOG10(")) + + case 16: return new Log10 (cell, text); - if (text.startsWith ("@LOOKUP(")) + case 17: return new Lookup (cell, text); - if (text.startsWith ("@LN(")) + case 18: return new Ln (cell, text); - } - else if (text.charAt (1) == 'M') - { - if (text.startsWith ("@MIN(")) + + case 19: return new Min (cell, text); - if (text.startsWith ("@MAX(")) + case 20: return new Max (cell, text); - } - else if (text.charAt (1) == 'N') - { - if (text.equals ("@NA")) + + case 21: return new Na (cell, text); - if (text.startsWith ("@NPV(")) + case 22: return new Npv (cell, text); - } - else if (text.charAt (1) == 'O') - { - if (text.startsWith ("@OR(")) + + case 23: return new Or (cell, text); - } - else if (text.charAt (1) == 'P') - { - if (text.startsWith ("@PI")) + + case 24: return new Pi (cell, text); - } - else if (text.charAt (1) == 'S') - { - if (text.startsWith ("@SIN(")) + + case 25: return new Sin (cell, text); - if (text.startsWith ("@SUM(")) + case 26: return new Sum (cell, text); - if (text.startsWith ("@SQRT(")) + case 27: return new Sqrt (cell, text); - } - else if (text.charAt (1) == 'T') - { - if (text.startsWith ("@TAN(")) + + case 28: return new Tan (cell, text); - if (text.startsWith ("@TRUE")) + case 29: return new True (cell, text); - } - System.out.printf ("Unknown function: [%s]%n", text); - return new Error (cell, "@ERROR"); + default: + System.out.printf ("Unknown function: [%s]%n", text); + return new Error (cell, "@ERROR"); + } } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/Sin.java b/src/com/bytezone/diskbrowser/visicalc/Sin.java index b760bb7..b01de26 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Sin.java +++ b/src/com/bytezone/diskbrowser/visicalc/Sin.java @@ -8,6 +8,8 @@ public class Sin extends Function { super (cell, text); + assert text.startsWith ("@SIN(") : text; + v = new Expression (parent, cell, functionText).reduce (); valueType = ValueType.VALUE; } diff --git a/src/com/bytezone/diskbrowser/visicalc/Sqrt.java b/src/com/bytezone/diskbrowser/visicalc/Sqrt.java index dad018e..6819ed1 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Sqrt.java +++ b/src/com/bytezone/diskbrowser/visicalc/Sqrt.java @@ -7,7 +7,10 @@ public class Sqrt extends Function Sqrt (Cell cell, String text) { super (cell, text); - source = new Expression (parent, cell, text.substring (5, text.length () - 1)); + + assert text.startsWith ("@SQRT(") : text; + + source = new Expression (parent, cell, functionText); values.add (source); } diff --git a/src/com/bytezone/diskbrowser/visicalc/Sum.java b/src/com/bytezone/diskbrowser/visicalc/Sum.java index 4ebcbab..53cd1af 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Sum.java +++ b/src/com/bytezone/diskbrowser/visicalc/Sum.java @@ -8,6 +8,8 @@ class Sum extends Function { super (cell, text); + assert text.startsWith ("@SUM(") : text; + list = new ValueList (parent, cell, functionText); } diff --git a/src/com/bytezone/diskbrowser/visicalc/Tan.java b/src/com/bytezone/diskbrowser/visicalc/Tan.java index 7b78f24..4ef515d 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Tan.java +++ b/src/com/bytezone/diskbrowser/visicalc/Tan.java @@ -8,6 +8,8 @@ public class Tan extends Function { super (cell, text); + assert text.startsWith ("@TAN(") : text; + v = new Expression (parent, cell, functionText).reduce (); valueType = ValueType.VALUE; } diff --git a/src/com/bytezone/diskbrowser/visicalc/True.java b/src/com/bytezone/diskbrowser/visicalc/True.java index 1f1548b..5622c1f 100644 --- a/src/com/bytezone/diskbrowser/visicalc/True.java +++ b/src/com/bytezone/diskbrowser/visicalc/True.java @@ -6,6 +6,8 @@ public class True extends Function { super (cell, text); + assert text.equals ("@TRUE") : text; + value = 1; valueType = ValueType.VALUE; }