Function.java
1.43 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
package kernel.function;
import kernel.Cell;
import kernel.Formula;
import kernel.Grid;
import kernel.LanguageEnum;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
abstract public class Function implements Formula, Serializable {
private static final long serialVersionUID = 1L;
private Map<LanguageEnum, String> names = new HashMap<>();
private List<Cell> listCells;
public Function(List<Cell> listCells) {
this.listCells = listCells;
}
abstract public double eval();
public Map<LanguageEnum, String> getNames() {
return this.names;
}
@Override
public String getDevelopedFormula() {
return names.get(Grid.language) + "("
+ this.listCells.stream()
.map(Cell::getDevelopedFormula)
.collect(Collectors.joining(",")) + ")";
}
@Override
public String toString() {
return names.get(Grid.language) + "("
+ this.listCells.stream()
.map(Cell::getId)
.collect(Collectors.joining(",")) + ")";
}
@Override
public boolean createCycle(Cell cell) {
return this.listCells.contains(cell) || this.generateIndirectCycle(cell);
}
@Override
public List<Cell> getUtilisedCells() {
return this.listCells;
}
private boolean generateIndirectCycle(Cell cell) {
for (Cell currentCell : this.listCells)
if (currentCell.containFormula() && currentCell.getFormula().createCycle(cell))
return true;
return false;
}
}