2e8fbd04
Remi
global refactor
|
1
|
package kernel;
|
18e7a394
Remi
add package
|
2
|
|
2e8fbd04
Remi
global refactor
|
3
|
import kernel.exception.CellNotFoundException;
|
5731029f
Remi
merge
|
4
|
import kernel.exception.CreateCycleException;
|
4186cd92
Remi
fix tests
|
5
|
import kernel.exception.InvalidIntervalException;
|
8112a2dd
Remi
merge
|
6
|
|
eb07e5e3
[mandjemb]
avec serialisation
|
7
|
import java.io.Serializable;
|
94ba86ff
Remi
Auto stash before...
|
8
|
import java.util.ArrayList;
|
8112a2dd
Remi
merge
|
9
|
import java.util.HashMap;
|
94ba86ff
Remi
Auto stash before...
|
10
|
import java.util.List;
|
8112a2dd
Remi
merge
|
11
12
|
import java.util.Map;
|
eb07e5e3
[mandjemb]
avec serialisation
|
13
|
public class Grid implements Serializable {
|
4186cd92
Remi
fix tests
|
14
15
|
private static final long serialVersionUID = 1L;
|
23982881
[mandjemb]
update ihm
|
16
17
|
private static final int MAX_LIGNES = 20;
private static final String MAX_COLONNES = "Z";
|
4186cd92
Remi
fix tests
|
18
19
|
private Map<String, Cell> cells = new HashMap<>();
public static LanguageEnum language = LanguageEnum.FR;
|
23982881
[mandjemb]
update ihm
|
20
|
|
4186cd92
Remi
fix tests
|
21
|
|
a7f554a1
Remi
delete return val...
|
22
|
public void createCell(String column, int line, double value) throws InvalidIntervalException {
|
23982881
[mandjemb]
update ihm
|
23
24
25
26
|
column = column.toUpperCase();
if (!validateInterval(column, line))
throw new InvalidIntervalException();
|
4186cd92
Remi
fix tests
|
27
28
|
String id = this.getCellId(column, line);
Cell cell = new Cell(column, line, value);
|
4186cd92
Remi
fix tests
|
29
|
this.cells.put(id, cell);
|
23982881
[mandjemb]
update ihm
|
30
|
|
4186cd92
Remi
fix tests
|
31
32
|
}
|
a7f554a1
Remi
delete return val...
|
33
|
public void createCell(String column, int line, Formula formula) throws CreateCycleException, InvalidIntervalException {
|
23982881
[mandjemb]
update ihm
|
34
35
36
37
|
column = column.toUpperCase();
if (!validateInterval(column, line))
throw new InvalidIntervalException();
|
4186cd92
Remi
fix tests
|
38
39
|
String id = this.getCellId(column, line);
Cell cell = new Cell(column, line, formula);
|
4186cd92
Remi
fix tests
|
40
|
this.cells.put(id, cell);
|
23982881
[mandjemb]
update ihm
|
41
|
|
4186cd92
Remi
fix tests
|
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
78
79
80
81
82
83
84
85
|
}
public void setValue(String column, int line, double value) throws CellNotFoundException {
this.getCell(column, line).setValue(value);
}
public void setFormula(String column, int line, Formula formula) throws CellNotFoundException,
CreateCycleException {
this.getCell(column, line).setFormula(formula);
}
public Cell getCell(String column, int line) throws CellNotFoundException {
Cell cell = this.cells.get(this.getCellId(column, line));
if (cell != null)
return cell;
else
throw new CellNotFoundException();
}
public List<Cell> getCells() {
return new ArrayList<>(this.cells.values());
}
public List<String> getCellsId() {
return new ArrayList<>(this.cells.keySet());
}
public double getValue(String column, int line) throws CellNotFoundException {
return this.getCell(column, line).getValue();
}
public String getFormulaAsString(String column, int line) throws CellNotFoundException {
return this.getCell(column, line).toString();
}
public String getDevelopedFormula(String column, int line) throws CellNotFoundException {
return this.getCell(column, line).getDevelopedFormula();
}
private String getCellId(String column, int line) {
return column + line;
}
|
23982881
[mandjemb]
update ihm
|
86
87
88
89
90
91
92
93
|
public int getTotalColumn() {
return MAX_COLONNES.charAt(0) - (int) 'A' + 1;
//return convertStringToInt(MAX_COLONNES);
}
public int getTotalLine() {
return MAX_LIGNES;
|
a7f554a1
Remi
delete return val...
|
94
95
|
}
|
23982881
[mandjemb]
update ihm
|
96
97
|
private boolean validateInterval(String column, int line) {
return line >= 1 && line <= MAX_LIGNES && convertStringToInt(column)>=convertStringToInt("A") && convertStringToInt(column)<=convertStringToInt(MAX_COLONNES);
|
4186cd92
Remi
fix tests
|
98
99
|
}
|
23982881
[mandjemb]
update ihm
|
100
101
102
103
104
105
106
107
|
private int convertStringToInt(String str){
int ascii=0;
for(int i = 0; i < str.length(); i++){ // while counting characters if less than the length add one
char character = str.charAt(i); // start on the first character
ascii = ascii+(int) character;
}
return ascii;
|
4186cd92
Remi
fix tests
|
108
|
}
|
23982881
[mandjemb]
update ihm
|
109
|
|
18e7a394
Remi
add package
|
110
|
}
|