Cell.java
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package kernel;
import java.util.ArrayList;
import java.util.List;
public class Cell {
private String column;
private Integer line;
private Double value;
private Formula formula;
private List<Cell> usedIn = new ArrayList<>();
public Cell(String column, Integer line, Double value) {
this.column = column;
this.line = line;
this.value = value;
}
public Cell(String column, Integer line, Formula formula) {
this.column = column;
this.line = line;
this.setFormula(formula);
}
public Double getValue() {
return this.value;
}
public Formula getFormula() {
return this.formula;
}
public String getDevelopedFormula() {
return this.containFormula() ? this.formula.getDevelopedFormula() : this.getId();
}
public String getId() {
return this.column + this.line.toString();
}
public List<Cell> getUsedIn() {
return this.usedIn;
}
public String toString() {
return this.containFormula() ? this.formula.toString() : this.getId();
}
public void updateValue() {
this.value = this.formula.eval();
}
public Boolean containFormula() {
return this.formula != null;
}
public void setFormula(Formula formula) {
this.formula = formula;
this.updateValue();
this.spread();
}
public void setValue(Double value) {
this.value = value;
this.spread();
}
private void spread() {
for (Cell cell : this.usedIn)
cell.updateValue();
}
}