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;
|
||||
}
|
||||
|
||||
public String formula() {
|
||||
throw XLException.ERROR_RECURSIVE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,4 +8,5 @@ import xl.expr.Environment;
|
|||
public interface Cell {
|
||||
public double cellValue(Environment e);
|
||||
public String displayValue();
|
||||
public String formula();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@ public class CommentCell implements Cell {
|
|||
}
|
||||
|
||||
public String displayValue() {
|
||||
return "# " + commentText;
|
||||
}
|
||||
|
||||
public String formula() {
|
||||
return commentText;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,12 @@ public class ExpressionCell implements Cell {
|
|||
}
|
||||
|
||||
public String displayValue() {
|
||||
return Double.toString(cellValue(ENVIRON));
|
||||
}
|
||||
|
||||
public String formula() {
|
||||
return expr.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
@ -107,25 +107,16 @@ public class XLModel extends Observable implements Environment {
|
|||
|
||||
public String getAddressValue(String address) {
|
||||
if (map.containsKey(address)) {
|
||||
Cell cell = map.get(address);
|
||||
if (cell instanceof CommentCell) {
|
||||
return cell.displayValue();
|
||||
}
|
||||
return Double.toString(cell.cellValue(this));
|
||||
return map.get(address).displayValue();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getAddressContent(String address) {
|
||||
if (map.containsKey(address)) {
|
||||
Cell cell = map.get(address);
|
||||
if (cell instanceof CommentCell) {
|
||||
return "#" + map.get(address).displayValue();
|
||||
}
|
||||
return map.get(address).displayValue();
|
||||
} else {
|
||||
return "";
|
||||
return map.get(address).formula();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean containsKey(String address) {
|
||||
|
|
Loading…
Reference in a new issue