Grille.java
2.08 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
75
76
77
package noyau;
import noyau.exception.CellNotFoundException;
import java.util.HashMap;
import java.util.Map;
public class Grille {
private Map<String, Case> cases = new HashMap<>();
public String createCase(String column, Integer line, Double value) {
String id = this.getId(column, line);
Case cell = new Case(column, line, value);
this.cases.put(id, cell);
return id;
}
public String createCase(String column, Integer line, Formule formula) {
String id = this.getId(column, line);
Case cell = new Case(column, line, formula);
this.cases.put(id, cell);
return id;
}
public void setValue(String column, Integer line, Double value) throws CellNotFoundException {
Case cell = this.getCase(column, line);
try {
cell.setValue(value);
} catch (NullPointerException exception) {
throw new CellNotFoundException();
}
}
public void setFormula(String column, Integer line, Formule formula) throws CellNotFoundException {
Case cell = this.getCase(column, line);
try {
cell.setFormula(formula);
} catch (NullPointerException exception) {
throw new CellNotFoundException();
}
}
public Case getCase(String column, Integer line) {
return this.cases.get(this.getId(column, line));
}
public Double getValeur(String column, Integer line) throws CellNotFoundException {
Case cell = this.getCase(column, line);
try {
return cell.getValue();
} catch (NullPointerException exception) {
throw new CellNotFoundException();
}
}
public String getFormuleAsString(String column, Integer line) throws CellNotFoundException {
Case cell = this.getCase(column, line);
try {
return cell.getValue();
} catch (NullPointerException exception) {
throw new CellNotFoundException();
}
}
private String getId(String column, Integer line) {
return column + line.toString();
}
}