diff --git a/app/src/main/java/xl/model/BombCell.java b/app/src/main/java/xl/model/BombCell.java index c8dc2b8..cacf355 100644 --- a/app/src/main/java/xl/model/BombCell.java +++ b/app/src/main/java/xl/model/BombCell.java @@ -15,7 +15,7 @@ public class BombCell implements Cell { throw XLException.ERROR_RECURSIVE; } - public String displayValue() { + public String displayValue(Environment e) { throw XLException.ERROR_RECURSIVE; } diff --git a/app/src/main/java/xl/model/Cell.java b/app/src/main/java/xl/model/Cell.java index 0971c7f..f75ff1f 100644 --- a/app/src/main/java/xl/model/Cell.java +++ b/app/src/main/java/xl/model/Cell.java @@ -7,6 +7,6 @@ import xl.expr.Environment; */ public interface Cell { public double cellValue(Environment e); - public String displayValue(); + public String displayValue(Environment e); public String formula(); } diff --git a/app/src/main/java/xl/model/CommentCell.java b/app/src/main/java/xl/model/CommentCell.java index 45a98e7..c9b03ec 100644 --- a/app/src/main/java/xl/model/CommentCell.java +++ b/app/src/main/java/xl/model/CommentCell.java @@ -15,7 +15,7 @@ public class CommentCell implements Cell { return 0; } - public String displayValue() { + public String displayValue(Environment e) { return "# " + commentText; } diff --git a/app/src/main/java/xl/model/ExpressionCell.java b/app/src/main/java/xl/model/ExpressionCell.java index 630dc39..4575352 100644 --- a/app/src/main/java/xl/model/ExpressionCell.java +++ b/app/src/main/java/xl/model/ExpressionCell.java @@ -17,8 +17,8 @@ public class ExpressionCell implements Cell { return expr.value(env); } - public String displayValue() { - return Double.toString(cellValue(ENVIRON)); + public String displayValue(Environment e) { + return Double.toString(cellValue(e)); } public String formula() { diff --git a/app/src/main/java/xl/model/XLModel.java b/app/src/main/java/xl/model/XLModel.java index 62c3483..50a5e7b 100644 --- a/app/src/main/java/xl/model/XLModel.java +++ b/app/src/main/java/xl/model/XLModel.java @@ -99,7 +99,7 @@ public class XLModel extends Observable implements Environment { public void save(String path) { try (XLPrintStream xlPrintStream = new XLPrintStream(path)) { - xlPrintStream.save(map.entrySet()); + xlPrintStream.save(this, map.entrySet()); } catch (IOException e) { status = "Error saving file"; } @@ -107,7 +107,7 @@ public class XLModel extends Observable implements Environment { public String getAddressValue(String address) { if (map.containsKey(address)) { - return map.get(address).displayValue(); + return map.get(address).displayValue(this); } return ""; } diff --git a/app/src/main/java/xl/model/XLPrintStream.java b/app/src/main/java/xl/model/XLPrintStream.java index 3bbe6ca..869f4d2 100644 --- a/app/src/main/java/xl/model/XLPrintStream.java +++ b/app/src/main/java/xl/model/XLPrintStream.java @@ -3,6 +3,9 @@ package xl.model; import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.Map.Entry; + +import xl.expr.Environment; + import java.util.Set; /** @@ -14,16 +17,11 @@ public class XLPrintStream extends PrintStream { super(fileName); } - public void save(Set> set) { + public void save(Environment e, Set> set) { for (Entry entry : set) { print(entry.getKey()); print('='); - Cell cell = entry.getValue(); - if (cell instanceof CommentCell) { - println("#" + cell.displayValue()); - } else { - println(cell.displayValue()); - } + println(entry.getValue().displayValue(e)); } flush(); close();