Refactor Cell and subclasses
This commit is contained in:
parent
465700e196
commit
6475fa67a0
5 changed files with 16 additions and 14 deletions
|
@ -19,4 +19,7 @@ public class BombCell implements Cell {
|
||||||
throw XLException.ERROR_RECURSIVE;
|
throw XLException.ERROR_RECURSIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String formula() {
|
||||||
|
throw XLException.ERROR_RECURSIVE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,4 +8,5 @@ import xl.expr.Environment;
|
||||||
public interface Cell {
|
public interface Cell {
|
||||||
public double cellValue(Environment e);
|
public double cellValue(Environment e);
|
||||||
public String displayValue();
|
public String displayValue();
|
||||||
|
public String formula();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,10 @@ public class CommentCell implements Cell {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String displayValue() {
|
public String displayValue() {
|
||||||
|
return "# " + commentText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String formula() {
|
||||||
return commentText;
|
return commentText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,12 @@ public class ExpressionCell implements Cell {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String displayValue() {
|
public String displayValue() {
|
||||||
|
return Double.toString(cellValue(ENVIRON));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String formula() {
|
||||||
return expr.toString();
|
return expr.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -107,26 +107,17 @@ 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)) {
|
||||||
Cell cell = map.get(address);
|
return map.get(address).displayValue();
|
||||||
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)) {
|
||||||
Cell cell = map.get(address);
|
return map.get(address).formula();
|
||||||
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);
|
||||||
|
|
Loading…
Reference in a new issue