Commit 8112a2ddc830f4eefb5133b01e6171d24c32d22d
1 parent
f209d477
merge
Showing
3 changed files
with
133 additions
and
8 deletions
Show diff stats
src/noyau/Case.java
1 | 1 | package noyau; |
2 | 2 | |
3 | -import java.util.*; | |
3 | +import java.util.ArrayList; | |
4 | +import java.util.List; | |
4 | 5 | |
5 | 6 | public class Case { |
6 | - | |
7 | - String colonne; | |
8 | - int ligne; | |
9 | - double valeur; | |
10 | - ArrayList<Case> utiliseDans = new ArrayList<Case>(); | |
11 | - boolean isFormule; | |
12 | 7 | |
8 | + private String column; | |
9 | + private Integer line; | |
10 | + private Double value; | |
11 | + private Formule formula; | |
12 | + private List<Case> usedIn = new ArrayList<>(); | |
13 | + | |
14 | + public Case(String column, Integer line, Double value) { | |
15 | + this.column = column; | |
16 | + this.line = line; | |
17 | + this.value = value; | |
18 | + } | |
19 | + | |
20 | + public Case(String column, Integer line, Formule formula) { | |
21 | + this.column = column; | |
22 | + this.line = line; | |
23 | + this.formula = formula; | |
24 | + } | |
25 | + | |
26 | + public Double getValue() { | |
27 | + return this.value; | |
28 | + } | |
29 | + | |
30 | + public void setValue(Double value) { | |
31 | + this.value = value; | |
32 | + this.spread(); | |
33 | + } | |
34 | + | |
35 | + public void updateValue() { | |
36 | + | |
37 | + } | |
38 | + | |
39 | + public String getId() { | |
40 | + return this.column + this.line.toString(); | |
41 | + } | |
42 | + | |
43 | + public Boolean containFormula() { | |
44 | + return this.formula != null; | |
45 | + } | |
46 | + | |
47 | + | |
48 | + | |
49 | + public Formule getFormula() { | |
50 | + return this.formula; | |
51 | + } | |
52 | + | |
53 | + public void setFormula(Formule formula) { | |
54 | + this.formula = formula; | |
55 | + this.spread(); | |
56 | + } | |
57 | + | |
58 | + private void spread() { | |
59 | + for (Case cell : this.usedIn) | |
60 | + cell.updateValue(); | |
61 | + } | |
13 | 62 | } | ... | ... |
src/noyau/Grille.java
1 | 1 | package noyau; |
2 | 2 | |
3 | +import noyau.exception.CellNotFoundException; | |
4 | + | |
5 | +import java.util.HashMap; | |
6 | +import java.util.Map; | |
7 | + | |
3 | 8 | public class Grille { |
4 | - | |
9 | + | |
10 | + private Map<String, Case> cases = new HashMap<>(); | |
11 | + | |
12 | + public String createCase(String column, Integer line, Double value) { | |
13 | + String id = this.getId(column, line); | |
14 | + Case cell = new Case(column, line, value); | |
15 | + | |
16 | + this.cases.put(id, cell); | |
17 | + | |
18 | + return id; | |
19 | + } | |
20 | + | |
21 | + public String createCase(String column, Integer line, Formule formula) { | |
22 | + String id = this.getId(column, line); | |
23 | + Case cell = new Case(column, line, formula); | |
24 | + | |
25 | + this.cases.put(id, cell); | |
26 | + | |
27 | + return id; | |
28 | + } | |
29 | + | |
30 | + public void setValue(String column, Integer line, Double value) throws CellNotFoundException { | |
31 | + Case cell = this.getCase(column, line); | |
32 | + | |
33 | + try { | |
34 | + cell.setValue(value); | |
35 | + } catch (NullPointerException exception) { | |
36 | + throw new CellNotFoundException(); | |
37 | + } | |
38 | + } | |
39 | + | |
40 | + public void setFormula(String column, Integer line, Formule formula) throws CellNotFoundException { | |
41 | + Case cell = this.getCase(column, line); | |
42 | + | |
43 | + try { | |
44 | + cell.setFormula(formula); | |
45 | + } catch (NullPointerException exception) { | |
46 | + throw new CellNotFoundException(); | |
47 | + } | |
48 | + } | |
49 | + | |
50 | + public Case getCase(String column, Integer line) { | |
51 | + return this.cases.get(this.getId(column, line)); | |
52 | + } | |
53 | + | |
54 | + public Double getValeur(String column, Integer line) throws CellNotFoundException { | |
55 | + Case cell = this.getCase(column, line); | |
56 | + | |
57 | + try { | |
58 | + return cell.getValue(); | |
59 | + } catch (NullPointerException exception) { | |
60 | + throw new CellNotFoundException(); | |
61 | + } | |
62 | + } | |
63 | + | |
64 | + public String getFormuleAsString(String column, Integer line) throws CellNotFoundException { | |
65 | + Case cell = this.getCase(column, line); | |
66 | + | |
67 | + try { | |
68 | + return cell.getValue(); | |
69 | + } catch (NullPointerException exception) { | |
70 | + throw new CellNotFoundException(); | |
71 | + } | |
72 | + } | |
73 | + | |
74 | + private String getId(String column, Integer line) { | |
75 | + return column + line.toString(); | |
76 | + } | |
5 | 77 | } | ... | ... |