Cell now properly differentiates between formula and displayValue
This commit is contained in:
parent
6475fa67a0
commit
d130907159
6 changed files with 12 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ public class CommentCell implements Cell {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public String displayValue() {
|
||||
public String displayValue(Environment e) {
|
||||
return "# " + commentText;
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 "";
|
||||
}
|
||||
|
|
|
@ -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<Entry<String, Cell>> set) {
|
||||
public void save(Environment e, Set<Entry<String, Cell>> set) {
|
||||
for (Entry<String, Cell> 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();
|
||||
|
|
Loading…
Reference in a new issue