From 2bbe1432962e17c7e8fa890e60ba9b907022a6e9 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Sat, 4 Mar 2017 10:41:08 +1100 Subject: [PATCH] privacy --- .../bytezone/diskbrowser/visicalc/Abs.java | 12 ++--- .../diskbrowser/visicalc/AbstractValue.java | 2 +- .../diskbrowser/visicalc/Address.java | 38 +++++++++++-- .../bytezone/diskbrowser/visicalc/And.java | 3 +- .../diskbrowser/visicalc/Average.java | 3 +- .../bytezone/diskbrowser/visicalc/Cell.java | 53 +++++++++---------- .../bytezone/diskbrowser/visicalc/Choose.java | 12 +++-- .../diskbrowser/visicalc/Condition.java | 24 ++++----- .../bytezone/diskbrowser/visicalc/Count.java | 4 +- .../diskbrowser/visicalc/Expression.java | 22 ++++---- .../bytezone/diskbrowser/visicalc/Format.java | 5 ++ src/com/bytezone/diskbrowser/visicalc/If.java | 21 +++----- .../diskbrowser/visicalc/IsError.java | 6 ++- .../bytezone/diskbrowser/visicalc/IsNa.java | 8 +-- .../bytezone/diskbrowser/visicalc/Lookup.java | 16 +++--- .../bytezone/diskbrowser/visicalc/Max.java | 3 +- .../bytezone/diskbrowser/visicalc/Min.java | 3 +- .../bytezone/diskbrowser/visicalc/Npv.java | 3 +- src/com/bytezone/diskbrowser/visicalc/Or.java | 3 +- src/com/bytezone/diskbrowser/visicalc/Pi.java | 2 + .../bytezone/diskbrowser/visicalc/Range.java | 18 +++---- .../bytezone/diskbrowser/visicalc/Sheet.java | 30 +++++------ .../bytezone/diskbrowser/visicalc/Sum.java | 4 +- 23 files changed, 165 insertions(+), 130 deletions(-) diff --git a/src/com/bytezone/diskbrowser/visicalc/Abs.java b/src/com/bytezone/diskbrowser/visicalc/Abs.java index 16d398c..b7c9e0e 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Abs.java +++ b/src/com/bytezone/diskbrowser/visicalc/Abs.java @@ -2,22 +2,20 @@ package com.bytezone.diskbrowser.visicalc; public class Abs extends Function { - Expression source; + private final Expression source; Abs (Sheet parent, String text) { super (parent, text); + + source = new Expression (parent, functionText); + values.add (source); } @Override public void calculate () { - if (source == null) - { - source = new Expression (parent, functionText); - values.add (source); - source.calculate (); - } + source.calculate (); value = Math.abs (source.getValue ()); valueType = source.getValueType (); diff --git a/src/com/bytezone/diskbrowser/visicalc/AbstractValue.java b/src/com/bytezone/diskbrowser/visicalc/AbstractValue.java index f5e0ae7..846e48f 100644 --- a/src/com/bytezone/diskbrowser/visicalc/AbstractValue.java +++ b/src/com/bytezone/diskbrowser/visicalc/AbstractValue.java @@ -89,7 +89,7 @@ public abstract class AbstractValue implements Value else if (this instanceof Condition) { text.append ( - String.format ("| Condition : %-69s |%n", ((Condition) this).fullText)); + String.format ("| Condition : %-69s |%n", ((Condition) this).getFullText ())); for (Value v : (Condition) this) text.append (((AbstractValue) v).getValueText (depth + 1)); } diff --git a/src/com/bytezone/diskbrowser/visicalc/Address.java b/src/com/bytezone/diskbrowser/visicalc/Address.java index 04fbd71..adcbbb2 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Address.java +++ b/src/com/bytezone/diskbrowser/visicalc/Address.java @@ -7,10 +7,10 @@ class Address implements Comparable
private static final int MAX_ROWS = 255; private static final int MAX_COLUMNS = 64; - int row, column; - int rowKey; - int columnKey; - String text; + private int row, column; + private int rowKey; + private int columnKey; + private String text; public Address (String column, String row) { @@ -65,6 +65,26 @@ class Address implements Comparable
} } + boolean rowMatches (Address other) + { + return row == other.row; + } + + boolean columnMatches (Address other) + { + return column == other.column; + } + + int getRow () + { + return row; + } + + int getColumn () + { + return column; + } + Address nextRow () { Address next = new Address (column, row + 1); @@ -90,6 +110,16 @@ class Address implements Comparable
return text; } + int getRowKey () + { + return rowKey; + } + + int getColumnKey () + { + return columnKey; + } + public String getDetails () { return String.format ("Row:%3d Col:%3d rKey:%5d cKey:%5d", row, column, rowKey, diff --git a/src/com/bytezone/diskbrowser/visicalc/And.java b/src/com/bytezone/diskbrowser/visicalc/And.java index ee0f738..0f9dc48 100644 --- a/src/com/bytezone/diskbrowser/visicalc/And.java +++ b/src/com/bytezone/diskbrowser/visicalc/And.java @@ -5,11 +5,12 @@ import java.util.List; class And extends Function { - List conditions = new ArrayList (); + private final List conditions = new ArrayList (); public And (Sheet parent, String text) { super (parent, text); + String list[] = text.split (","); for (String s : list) conditions.add (new Condition (parent, s)); diff --git a/src/com/bytezone/diskbrowser/visicalc/Average.java b/src/com/bytezone/diskbrowser/visicalc/Average.java index dde7ca5..dcdc544 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Average.java +++ b/src/com/bytezone/diskbrowser/visicalc/Average.java @@ -7,6 +7,7 @@ public class Average extends Function public Average (Sheet parent, String text) { super (parent, text); + range = new Range (parent, text); } @@ -19,7 +20,7 @@ public class Average extends Function for (Address address : range) { Cell cell = parent.getCell (address); - if (cell == null || cell.isValueType (ValueType.NA)) + if (cell.isValueType (ValueType.NA)) continue; if (!cell.isValueType (ValueType.VALUE)) diff --git a/src/com/bytezone/diskbrowser/visicalc/Cell.java b/src/com/bytezone/diskbrowser/visicalc/Cell.java index 465f7c5..c4ee57c 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Cell.java +++ b/src/com/bytezone/diskbrowser/visicalc/Cell.java @@ -24,7 +24,7 @@ class Cell extends AbstractValue implements Comparable public Cell (Sheet parent, Address address) { - super ("Cell " + address.text); + super ("Cell " + address.getText ()); this.parent = parent; this.address = address; @@ -88,13 +88,13 @@ class Cell extends AbstractValue implements Comparable if (false) { System.out.println ("****** Hardcoded values ******"); - if (address.rowKey == 67) + if (address.getRowKey () == 67) expressionText = "1000"; - else if (address.rowKey == 131) + else if (address.getRowKey () == 131) expressionText = "10.5"; - else if (address.rowKey == 195) + else if (address.getRowKey () == 195) expressionText = "12"; - else if (address.rowKey == 259) + else if (address.getRowKey () == 259) expressionText = "8"; } @@ -102,15 +102,15 @@ class Cell extends AbstractValue implements Comparable if (false) { System.out.println ("****** Hardcoded values ******"); - if (address.rowKey == 66) + if (address.getRowKey () == 66) expressionText = "10"; - else if (address.rowKey == 130) + else if (address.getRowKey () == 130) expressionText = "30"; - else if (address.rowKey == 194) + else if (address.getRowKey () == 194) expressionText = "65"; - else if (address.rowKey == 258) + else if (address.getRowKey () == 258) expressionText = "1000"; - else if (address.rowKey == 386) + else if (address.getRowKey () == 386) expressionText = "15"; } @@ -118,13 +118,13 @@ class Cell extends AbstractValue implements Comparable if (false) { System.out.println ("****** Hardcoded values ******"); - if (address.rowKey == 67) + if (address.getRowKey () == 67) expressionText = "9375"; - else if (address.rowKey == 131) + else if (address.getRowKey () == 131) expressionText = "4500"; - else if (address.rowKey == 195) + else if (address.getRowKey () == 195) expressionText = "24"; - else if (address.rowKey == 259) + else if (address.getRowKey () == 259) expressionText = "11.9"; } } @@ -173,10 +173,10 @@ class Cell extends AbstractValue implements Comparable @Override public ValueType getValueType () { - // if (value == null) - // calculate (); if (cellType == CellType.EMPTY) return ValueType.NA; + if (cellType == CellType.LABEL || cellType == CellType.REPEATING_CHARACTER) + return ValueType.VALUE; return value.getValueType (); } @@ -184,8 +184,6 @@ class Cell extends AbstractValue implements Comparable @Override public String getText () { - // if (value == null) - // calculate (); if (cellType == CellType.EMPTY) return ""; @@ -195,16 +193,15 @@ class Cell extends AbstractValue implements Comparable @Override public boolean isValueType (ValueType type) { - // if (value == null || value.getValueType () != ValueType.VALUE) - // calculate (); - if (cellType == CellType.LABEL || cellType == CellType.REPEATING_CHARACTER) - return type == ValueType.VALUE; - - if (cellType == CellType.EMPTY) - return type == ValueType.NA; - - assert value != null : "bollocks " + address; - return value.isValueType (type); + // if (cellType == CellType.LABEL || cellType == CellType.REPEATING_CHARACTER) + // return type == ValueType.VALUE; + // + // if (cellType == CellType.EMPTY) + // return type == ValueType.NA; + // + // assert value != null : "bollocks " + address; + // return value.isValueType (type); + return type == getValueType (); } public boolean isCellType (CellType type) diff --git a/src/com/bytezone/diskbrowser/visicalc/Choose.java b/src/com/bytezone/diskbrowser/visicalc/Choose.java index f5eaa00..ec7a8e2 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Choose.java +++ b/src/com/bytezone/diskbrowser/visicalc/Choose.java @@ -2,10 +2,10 @@ package com.bytezone.diskbrowser.visicalc; public class Choose extends Function { - protected final Range range; - String sourceText; - String rangeText; - Number source; + private final Range range; + private final String sourceText; + private final String rangeText; + private final Number source; Choose (Sheet parent, String text) { @@ -13,8 +13,10 @@ public class Choose extends Function int pos = text.indexOf (','); sourceText = text.substring (8, pos); + source = new Number (sourceText); rangeText = text.substring (pos + 1, text.length () - 1); range = new Range (parent, rangeText); - source = new Number (sourceText); + + values.add (source); } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/Condition.java b/src/com/bytezone/diskbrowser/visicalc/Condition.java index 780f487..dbad00d 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Condition.java +++ b/src/com/bytezone/diskbrowser/visicalc/Condition.java @@ -12,7 +12,7 @@ class Condition extends AbstractValue implements Iterable private String comparator; private String conditionText; private String valueText; - protected String fullText; + private final String fullText; private Expression conditionExpression; private Expression valueExpression; @@ -30,6 +30,10 @@ class Condition extends AbstractValue implements Iterable { conditionText = text.substring (0, pos); valueText = text.substring (pos + comp.length ()); + conditionExpression = new Expression (parent, conditionText); + valueExpression = new Expression (parent, valueText); + values.add (conditionExpression); + values.add (valueExpression); comparator = comp; break; } @@ -53,17 +57,8 @@ class Condition extends AbstractValue implements Iterable { value = 0; - if (conditionExpression == null) - { - conditionExpression = new Expression (parent, conditionText); - valueExpression = new Expression (parent, valueText); - - conditionExpression.calculate (); - valueExpression.calculate (); - - values.add (conditionExpression); - values.add (valueExpression); - } + conditionExpression.calculate (); + valueExpression.calculate (); if (conditionExpression.isValueType (ValueType.ERROR) || valueExpression.isValueType (ValueType.ERROR)) @@ -88,6 +83,11 @@ class Condition extends AbstractValue implements Iterable System.out.printf ("Unexpected comparator result [%s]%n", comparator); } + String getFullText () + { + return fullText; + } + @Override public String toString () { diff --git a/src/com/bytezone/diskbrowser/visicalc/Count.java b/src/com/bytezone/diskbrowser/visicalc/Count.java index 5211bfd..3507a29 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Count.java +++ b/src/com/bytezone/diskbrowser/visicalc/Count.java @@ -7,6 +7,7 @@ class Count extends Function public Count (Sheet parent, String text) { super (parent, text); + range = new Range (parent, text); } @@ -19,7 +20,8 @@ class Count extends Function for (Address address : range) { Cell cell = parent.getCell (address); - if (cell == null || cell.isValueType (ValueType.NA)) + + if (cell.isValueType (ValueType.NA)) continue; if (!cell.isValueType (ValueType.VALUE)) diff --git a/src/com/bytezone/diskbrowser/visicalc/Expression.java b/src/com/bytezone/diskbrowser/visicalc/Expression.java index 8d04b13..656d854 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Expression.java +++ b/src/com/bytezone/diskbrowser/visicalc/Expression.java @@ -32,7 +32,7 @@ class Expression extends AbstractValue implements Iterable private final List operators = new ArrayList (); private final List signs = new ArrayList (); - private String text; + private final String text; public Expression (Sheet parent, String text) { @@ -93,9 +93,8 @@ class Expression extends AbstractValue implements Iterable Cell cell = parent.getCell (addressText); if (cell == null) { - // should this (or parent) create a new empty cell? - // cell = parent.addCell (addressText); - values.add (new Number ("0")); + assert false : "Impossible"; + // values.add (new Number ("0")); } else values.add (parent.getCell (addressText)); @@ -155,17 +154,16 @@ class Expression extends AbstractValue implements Iterable try { Value thisValue = values.get (0); - if (thisValue != null) // || thisValue.getValueType () != ValueType.VALUE) - thisValue.calculate (); + thisValue.calculate (); value = 0; - if (!thisValue.isValueType (ValueType.VALUE)) + if (thisValue.isValueType (ValueType.ERROR)) { valueType = thisValue.getValueType (); return; } - value = thisValue.getValue (); + value = thisValue.getValue (); // NA returns zero String sign = signs.get (0); if (sign.equals ("(-)")) @@ -174,17 +172,15 @@ class Expression extends AbstractValue implements Iterable for (int i = 1; i < values.size (); i++) { thisValue = values.get (i); - if (thisValue != null) // || thisValue.getValueType () != ValueType.VALUE) - thisValue.calculate (); + thisValue.calculate (); - if (!thisValue.isValueType (ValueType.VALUE)) - // if (thisValue.isValueType (ValueType.ERROR)) + if (thisValue.isValueType (ValueType.ERROR)) { valueType = thisValue.getValueType (); return; } - double nextValue = thisValue.getValue (); + double nextValue = thisValue.getValue (); // NA returns zero sign = signs.get (i); if (sign.equals ("(-)")) diff --git a/src/com/bytezone/diskbrowser/visicalc/Format.java b/src/com/bytezone/diskbrowser/visicalc/Format.java index 10d2769..b40502e 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Format.java +++ b/src/com/bytezone/diskbrowser/visicalc/Format.java @@ -6,6 +6,11 @@ public class Format { private static final DecimalFormat nf = new DecimalFormat ("#####0.00"); + private Format () + { + + } + static String format (Value value, char formatChar, int colWidth) { double actualValue = value.getValue (); diff --git a/src/com/bytezone/diskbrowser/visicalc/If.java b/src/com/bytezone/diskbrowser/visicalc/If.java index e4c7965..5083790 100644 --- a/src/com/bytezone/diskbrowser/visicalc/If.java +++ b/src/com/bytezone/diskbrowser/visicalc/If.java @@ -6,8 +6,8 @@ class If extends Function private final String textTrue; private final String textFalse; - private Expression expTrue; - private Expression expFalse; + private final Expression expTrue; + private final Expression expFalse; public If (Sheet parent, String text) { @@ -21,6 +21,11 @@ class If extends Function textTrue = functionText.substring (pos1 + 1, pos2); textFalse = functionText.substring (pos2 + 1); + + expTrue = new Expression (parent, textTrue); + values.add (expTrue); + expFalse = new Expression (parent, textFalse); + values.add (expFalse); } @Override @@ -31,12 +36,6 @@ class If extends Function if (condition.getValue () == 1) { - if (expTrue == null) - { - expTrue = new Expression (parent, textTrue); - values.add (expTrue); - } - expTrue.calculate (); if (!expTrue.isValueType (ValueType.VALUE)) @@ -46,12 +45,6 @@ class If extends Function } else { - if (expFalse == null) - { - expFalse = new Expression (parent, textFalse); - values.add (expFalse); - } - expFalse.calculate (); if (!expFalse.isValueType (ValueType.VALUE)) diff --git a/src/com/bytezone/diskbrowser/visicalc/IsError.java b/src/com/bytezone/diskbrowser/visicalc/IsError.java index f4520ed..93645b6 100644 --- a/src/com/bytezone/diskbrowser/visicalc/IsError.java +++ b/src/com/bytezone/diskbrowser/visicalc/IsError.java @@ -7,13 +7,15 @@ class IsError extends Function public IsError (Sheet parent, String text) { super (parent, text); + + cell = parent.getCell (functionText); } @Override public void calculate () { - if (cell == null) - cell = parent.getCell (functionText); + // if (cell == null) + // cell = parent.getCell (functionText); value = cell == null ? 1 : cell.isValueType (ValueType.ERROR) ? 1 : 0; valueType = ValueType.VALUE; diff --git a/src/com/bytezone/diskbrowser/visicalc/IsNa.java b/src/com/bytezone/diskbrowser/visicalc/IsNa.java index 0e87cc9..ad292ee 100644 --- a/src/com/bytezone/diskbrowser/visicalc/IsNa.java +++ b/src/com/bytezone/diskbrowser/visicalc/IsNa.java @@ -2,18 +2,20 @@ package com.bytezone.diskbrowser.visicalc; public class IsNa extends Function { - Expression expression; + Value expression; IsNa (Sheet parent, String text) { super (parent, text); + + expression = new Expression (parent, functionText).reduce (); } @Override public void calculate () { - if (expression == null) - expression = new Expression (parent, functionText); + // if (expression == null) + // expression = new Expression (parent, functionText); expression.calculate (); value = expression.getValue (); diff --git a/src/com/bytezone/diskbrowser/visicalc/Lookup.java b/src/com/bytezone/diskbrowser/visicalc/Lookup.java index 29bfe80..5fdca09 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Lookup.java +++ b/src/com/bytezone/diskbrowser/visicalc/Lookup.java @@ -2,10 +2,10 @@ package com.bytezone.diskbrowser.visicalc; class Lookup extends Function { - protected final Range range; - String sourceText; - String rangeText; - Expression source; + private final String sourceText; + private final String rangeText; + private final Expression source; + private final Range range; public Lookup (Sheet parent, String text) { @@ -14,9 +14,10 @@ class Lookup extends Function int pos = text.indexOf (','); sourceText = text.substring (8, pos); source = new Expression (parent, sourceText); - values.add (source); rangeText = text.substring (pos + 1, text.length () - 1); range = new Range (parent, rangeText); + + values.add (source); } @Override @@ -47,7 +48,6 @@ class Lookup extends Function target = address; } - // System.out.printf ("*****-----**** %s%n", target); if (target == null) valueType = ValueType.NA; else @@ -57,9 +57,7 @@ class Lookup extends Function if (parent.cellExists (adjacentAddress)) { - Cell adjacentCell = parent.getCell (adjacentAddress); - if (adjacentCell != null) - value = adjacentCell.getValue (); + value = parent.getCell (adjacentAddress).getValue (); valueType = ValueType.VALUE; } else diff --git a/src/com/bytezone/diskbrowser/visicalc/Max.java b/src/com/bytezone/diskbrowser/visicalc/Max.java index e698492..2cc6dd6 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Max.java +++ b/src/com/bytezone/diskbrowser/visicalc/Max.java @@ -7,6 +7,7 @@ class Max extends Function public Max (Sheet parent, String text) { super (parent, text); + range = new Range (parent, text); } @@ -19,7 +20,7 @@ class Max extends Function for (Address address : range) { Cell cell = parent.getCell (address); - if (cell == null || cell.isValueType (ValueType.NA)) + if (cell.isValueType (ValueType.NA)) continue; if (!cell.isValueType (ValueType.VALUE)) diff --git a/src/com/bytezone/diskbrowser/visicalc/Min.java b/src/com/bytezone/diskbrowser/visicalc/Min.java index b7ef5d2..8b61eb2 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Min.java +++ b/src/com/bytezone/diskbrowser/visicalc/Min.java @@ -7,6 +7,7 @@ class Min extends Function public Min (Sheet parent, String text) { super (parent, text); + range = new Range (parent, text); } @@ -19,7 +20,7 @@ class Min extends Function for (Address address : range) { Cell cell = parent.getCell (address); - if (cell == null || cell.isValueType (ValueType.NA)) + if (cell.isValueType (ValueType.NA)) continue; if (!cell.isValueType (ValueType.VALUE)) diff --git a/src/com/bytezone/diskbrowser/visicalc/Npv.java b/src/com/bytezone/diskbrowser/visicalc/Npv.java index 9ae69ea..b293633 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Npv.java +++ b/src/com/bytezone/diskbrowser/visicalc/Npv.java @@ -11,6 +11,7 @@ public class Npv extends Function Npv (Sheet parent, String text) { super (parent, text); + range = new Range (parent, text); // int pos = text.indexOf (','); @@ -29,7 +30,7 @@ public class Npv extends Function for (Address address : range) { Cell cell = parent.getCell (address); - if (cell == null || cell.isValueType (ValueType.NA)) + if (cell.isValueType (ValueType.NA)) continue; if (!cell.isValueType (ValueType.VALUE)) diff --git a/src/com/bytezone/diskbrowser/visicalc/Or.java b/src/com/bytezone/diskbrowser/visicalc/Or.java index a3029fd..cd0ed51 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Or.java +++ b/src/com/bytezone/diskbrowser/visicalc/Or.java @@ -5,11 +5,12 @@ import java.util.List; class Or extends Function { - List conditions = new ArrayList (); + private final List conditions = new ArrayList (); public Or (Sheet parent, String text) { super (parent, text); + String list[] = text.split (","); for (String s : list) conditions.add (new Condition (parent, s)); diff --git a/src/com/bytezone/diskbrowser/visicalc/Pi.java b/src/com/bytezone/diskbrowser/visicalc/Pi.java index 66391e0..651b481 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Pi.java +++ b/src/com/bytezone/diskbrowser/visicalc/Pi.java @@ -5,6 +5,8 @@ class Pi extends Function Pi (Sheet parent, String text) { super (parent, text); + value = Math.PI; + valueType = ValueType.VALUE; } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/visicalc/Range.java b/src/com/bytezone/diskbrowser/visicalc/Range.java index 70f95b2..4ad223d 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Range.java +++ b/src/com/bytezone/diskbrowser/visicalc/Range.java @@ -13,9 +13,9 @@ class Range implements Iterable
Pattern.compile ("([A-B]?[A-Z])([0-9]{1,3})\\.\\.\\.([A-B]?[A-Z])([0-9]{1,3})"); private static final Pattern addressList = Pattern.compile ("\\(([^,]+(,[^,]+)*)\\)"); - Address from, to; - List
range = new ArrayList
(); - Sheet parent; + private Address from, to; + private final List
range = new ArrayList
(); + private final Sheet parent; public Range (Sheet parent, String rangeText) { @@ -57,13 +57,13 @@ class Range implements Iterable
range.add (from); Address tempFrom = from; - if (from.row == to.row) + if (from.rowMatches (to)) while (from.compareTo (to) < 0) { from = from.nextColumn (); range.add (from); } - else if (from.column == to.column) + else if (from.columnMatches (to)) while (from.compareTo (to) < 0) { from = from.nextRow (); @@ -79,14 +79,14 @@ class Range implements Iterable
{ Address first = range.get (0); Address last = range.get (range.size () - 1); - return first.row == last.row; + return first.rowMatches (last); } boolean isVertical () { Address first = range.get (0); Address last = range.get (range.size () - 1); - return first.column == last.column; + return first.columnMatches (last); } @Override @@ -148,11 +148,11 @@ class Range implements Iterable
{ StringBuilder text = new StringBuilder (); for (Address address : range) - text.append (address.text + ","); + text.append (address.getText () + ","); if (text.length () > 0) text.deleteCharAt (text.length () - 1); return text.toString (); } - return String.format (" %s -> %s", from.text, to.text); + return String.format (" %s -> %s", from.getText (), to.getText ()); } } \ 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 41f985f..040369f 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Sheet.java +++ b/src/com/bytezone/diskbrowser/visicalc/Sheet.java @@ -199,7 +199,7 @@ public class Sheet if (m.find ()) { Address address = new Address (m.group (1), m.group (2)); - currentCell = rowOrderCells.get (address.rowKey); + currentCell = rowOrderCells.get (address.getRowKey ()); int pos = line.indexOf (':'); // end of cell address line = line.substring (pos + 1); // remove address from line @@ -224,7 +224,7 @@ public class Sheet if (line.charAt (2) == 'C' && line.charAt (3) == 'C') { int width = Integer.parseInt (line.substring (4)); - columnWidths.put (currentCell.getAddress ().column, width); + columnWidths.put (currentCell.getAddress ().getColumn (), width); } else System.out.printf ("Unknown Global:[%s]%n", line); @@ -262,11 +262,11 @@ public class Sheet private void addCell (Cell cell) { // System.out.printf ("Adding: %s%n", cell); - rowOrderCells.put (cell.getAddress ().rowKey, cell); - columnOrderCells.put (cell.getAddress ().columnKey, cell); + rowOrderCells.put (cell.getAddress ().getRowKey (), cell); + columnOrderCells.put (cell.getAddress ().getColumnKey (), cell); - highestRow = Math.max (highestRow, cell.getAddress ().row); - highestColumn = Math.max (highestColumn, cell.getAddress ().column); + highestRow = Math.max (highestRow, cell.getAddress ().getRow ()); + highestColumn = Math.max (highestColumn, cell.getAddress ().getColumn ()); } Cell getCell (String addressText) @@ -276,7 +276,7 @@ public class Sheet Cell getCell (Address address) { - Cell cell = rowOrderCells.get (address.rowKey); + Cell cell = rowOrderCells.get (address.getRowKey ()); if (cell == null) { // System.out.printf ("cell not found, creating: %s%n", address); @@ -288,7 +288,7 @@ public class Sheet boolean cellExists (Address address) { - return rowOrderCells.get (address.rowKey) != null; + return rowOrderCells.get (address.getRowKey ()) != null; } public int size () @@ -397,7 +397,7 @@ public class Sheet Address cellAddress = cell.getAddress (); // insert newlines for empty rows - while (lastRow < cellAddress.row) + while (lastRow < cellAddress.getRow ()) { ++lastRow; lastColumn = 0; @@ -408,7 +408,7 @@ public class Sheet } // pad out empty columns - while (lastColumn < cellAddress.column) + while (lastColumn < cellAddress.getColumn ()) { int width = columnWidth; if (columnWidths.containsKey (lastColumn)) @@ -420,8 +420,8 @@ public class Sheet ++lastColumn; int colWidth = columnWidth; - if (columnWidths.containsKey (cellAddress.column)) - colWidth = columnWidths.get (cellAddress.column); + if (columnWidths.containsKey (cellAddress.getColumn ())) + colWidth = columnWidths.get (cellAddress.getColumn ()); text.append (cell.getText (colWidth, globalFormat)); } @@ -432,13 +432,13 @@ public class Sheet int last = -1; for (Cell cell : columnOrderCells.values ()) { - if (last < cell.getAddress ().column) + if (last < cell.getAddress ().getColumn ()) { - String columnName = Address.getCellName (1, cell.getAddress ().column); + String columnName = Address.getCellName (1, cell.getAddress ().getColumn ()); columnName = columnName.substring (0, columnName.length () - 1); text.append ("\n *** Column " + columnName + " ***\n\n"); - last = cell.getAddress ().column; + last = cell.getAddress ().getColumn (); } text.append (cell.getDebugText ()); text.append ("\n"); diff --git a/src/com/bytezone/diskbrowser/visicalc/Sum.java b/src/com/bytezone/diskbrowser/visicalc/Sum.java index 5b4d4eb..cd5a750 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Sum.java +++ b/src/com/bytezone/diskbrowser/visicalc/Sum.java @@ -7,6 +7,7 @@ class Sum extends Function public Sum (Sheet parent, String text) { super (parent, text); + range = new Range (parent, text); } @@ -19,7 +20,8 @@ class Sum extends Function for (Address address : range) { Cell cell = parent.getCell (address); - if (cell == null || cell.isValueType (ValueType.NA)) + + if (cell.isValueType (ValueType.NA)) continue; if (!cell.isValueType (ValueType.VALUE))