Compare commits
No commits in common. "d130907159cb8288d8d80d3525dc6571ab26a5ec" and "465700e1961550bb3ea3002965d74bde652b346e" have entirely different histories.
d130907159
...
465700e196
6 changed files with 26 additions and 26 deletions
|
@ -15,11 +15,8 @@ public class BombCell implements Cell {
|
||||||
throw XLException.ERROR_RECURSIVE;
|
throw XLException.ERROR_RECURSIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String displayValue(Environment e) {
|
public String displayValue() {
|
||||||
throw XLException.ERROR_RECURSIVE;
|
throw XLException.ERROR_RECURSIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String formula() {
|
|
||||||
throw XLException.ERROR_RECURSIVE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,5 @@ import xl.expr.Environment;
|
||||||
*/
|
*/
|
||||||
public interface Cell {
|
public interface Cell {
|
||||||
public double cellValue(Environment e);
|
public double cellValue(Environment e);
|
||||||
public String displayValue(Environment e);
|
public String displayValue();
|
||||||
public String formula();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,7 @@ public class CommentCell implements Cell {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String displayValue(Environment e) {
|
public String displayValue() {
|
||||||
return "# " + commentText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String formula() {
|
|
||||||
return commentText;
|
return commentText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,10 @@ public class ExpressionCell implements Cell {
|
||||||
return expr.value(env);
|
return expr.value(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String displayValue(Environment e) {
|
public String displayValue() {
|
||||||
return Double.toString(cellValue(e));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String formula() {
|
|
||||||
return expr.toString();
|
return expr.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class XLModel extends Observable implements Environment {
|
||||||
|
|
||||||
public void save(String path) {
|
public void save(String path) {
|
||||||
try (XLPrintStream xlPrintStream = new XLPrintStream(path)) {
|
try (XLPrintStream xlPrintStream = new XLPrintStream(path)) {
|
||||||
xlPrintStream.save(this, map.entrySet());
|
xlPrintStream.save(map.entrySet());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
status = "Error saving file";
|
status = "Error saving file";
|
||||||
}
|
}
|
||||||
|
@ -107,17 +107,26 @@ public class XLModel extends Observable implements Environment {
|
||||||
|
|
||||||
public String getAddressValue(String address) {
|
public String getAddressValue(String address) {
|
||||||
if (map.containsKey(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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAddressContent(String address) {
|
public String getAddressContent(String address) {
|
||||||
if (map.containsKey(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) {
|
public boolean containsKey(String address) {
|
||||||
return map.containsKey(address);
|
return map.containsKey(address);
|
||||||
|
|
|
@ -3,9 +3,6 @@ package xl.model;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import xl.expr.Environment;
|
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,11 +14,16 @@ public class XLPrintStream extends PrintStream {
|
||||||
super(fileName);
|
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) {
|
for (Entry<String, Cell> entry : set) {
|
||||||
print(entry.getKey());
|
print(entry.getKey());
|
||||||
print('=');
|
print('=');
|
||||||
println(entry.getValue().displayValue(e));
|
Cell cell = entry.getValue();
|
||||||
|
if (cell instanceof CommentCell) {
|
||||||
|
println("#" + cell.displayValue());
|
||||||
|
} else {
|
||||||
|
println(cell.displayValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
flush();
|
flush();
|
||||||
close();
|
close();
|
||||||
|
|
Loading…
Reference in a new issue