Compare commits

..

No commits in common. "d130907159cb8288d8d80d3525dc6571ab26a5ec" and "465700e1961550bb3ea3002965d74bde652b346e" have entirely different histories.

6 changed files with 26 additions and 26 deletions

View file

@ -15,11 +15,8 @@ public class BombCell implements Cell {
throw XLException.ERROR_RECURSIVE;
}
public String displayValue(Environment e) {
public String displayValue() {
throw XLException.ERROR_RECURSIVE;
}
public String formula() {
throw XLException.ERROR_RECURSIVE;
}
}

View file

@ -7,6 +7,5 @@ import xl.expr.Environment;
*/
public interface Cell {
public double cellValue(Environment e);
public String displayValue(Environment e);
public String formula();
public String displayValue();
}

View file

@ -15,11 +15,7 @@ public class CommentCell implements Cell {
return 0;
}
public String displayValue(Environment e) {
return "# " + commentText;
}
public String formula() {
public String displayValue() {
return commentText;
}
}

View file

@ -17,13 +17,10 @@ public class ExpressionCell implements Cell {
return expr.value(env);
}
public String displayValue(Environment e) {
return Double.toString(cellValue(e));
}
public String formula() {
public String displayValue() {
return expr.toString();
}
}

View file

@ -58,7 +58,7 @@ public class XLModel extends Observable implements Environment {
status = "Error creating cell";
return;
}
// Tell observers that the model has changed
setChanged();
notifyObservers();
@ -99,7 +99,7 @@ public class XLModel extends Observable implements Environment {
public void save(String path) {
try (XLPrintStream xlPrintStream = new XLPrintStream(path)) {
xlPrintStream.save(this, map.entrySet());
xlPrintStream.save(map.entrySet());
} catch (IOException e) {
status = "Error saving file";
}
@ -107,16 +107,25 @@ public class XLModel extends Observable implements Environment {
public String getAddressValue(String address) {
if (map.containsKey(address)) {
return map.get(address).displayValue(this);
Cell cell = map.get(address);
if (cell instanceof CommentCell) {
return cell.displayValue();
}
return Double.toString(cell.cellValue(this));
}
return "";
}
public String getAddressContent(String address) {
if (map.containsKey(address)) {
return map.get(address).formula();
Cell cell = map.get(address);
if (cell instanceof CommentCell) {
return "#" + map.get(address).displayValue();
}
return map.get(address).displayValue();
} else {
return "";
}
return "";
}
public boolean containsKey(String address) {

View file

@ -3,9 +3,6 @@ package xl.model;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Map.Entry;
import xl.expr.Environment;
import java.util.Set;
/**
@ -17,11 +14,16 @@ public class XLPrintStream extends PrintStream {
super(fileName);
}
public void save(Environment e, Set<Entry<String, Cell>> set) {
public void save(Set<Entry<String, Cell>> set) {
for (Entry<String, Cell> entry : set) {
print(entry.getKey());
print('=');
println(entry.getValue().displayValue(e));
Cell cell = entry.getValue();
if (cell instanceof CommentCell) {
println("#" + cell.displayValue());
} else {
println(cell.displayValue());
}
}
flush();
close();