Blame view

src/kernel/Grid.java 2.3 KB
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;
eb07e5e3   [mandjemb]   avec serialisation
5
  import kernel.exception.InvalidIntervalLineColumnEception;
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 {
8112a2dd   Remi   merge
14
  
e0bdcd83   Remi   refacto
15
16
17
      private static final long serialVersionUID = 1L;
  
      private Map<String, Cell> cells = new HashMap<>();
94ba86ff   Remi   Auto stash before...
18
      public static LanguageEnum language = LanguageEnum.FR;
8112a2dd   Remi   merge
19
  
1ff9c9a9   [mandjemb]   Recommandation pr...
20
      public String createCell(String column, int line, double value) throws InvalidIntervalLineColumnEception {
94ba86ff   Remi   Auto stash before...
21
          String id = this.getCellId(column, line);
2e8fbd04   Remi   global refactor
22
          Cell cell = new Cell(column, line, value);
8112a2dd   Remi   merge
23
  
2e8fbd04   Remi   global refactor
24
          this.cells.put(id, cell);
8112a2dd   Remi   merge
25
26
27
28
  
          return id;
      }
  
1ff9c9a9   [mandjemb]   Recommandation pr...
29
      public String createCell(String column, int line, Formula formula) throws CreateCycleException, InvalidIntervalLineColumnEception {
94ba86ff   Remi   Auto stash before...
30
          String id = this.getCellId(column, line);
2e8fbd04   Remi   global refactor
31
          Cell cell = new Cell(column, line, formula);
8112a2dd   Remi   merge
32
  
2e8fbd04   Remi   global refactor
33
          this.cells.put(id, cell);
8112a2dd   Remi   merge
34
35
36
37
  
          return id;
      }
  
1ff9c9a9   [mandjemb]   Recommandation pr...
38
      public void setValue(String column, int line, double value) throws CellNotFoundException {
94ba86ff   Remi   Auto stash before...
39
          this.getCell(column, line).setValue(value);
8112a2dd   Remi   merge
40
41
      }
  
1ff9c9a9   [mandjemb]   Recommandation pr...
42
      public void setFormula(String column, int line, Formula formula) throws CellNotFoundException,
5731029f   Remi   merge
43
              CreateCycleException {
94ba86ff   Remi   Auto stash before...
44
45
46
          this.getCell(column, line).setFormula(formula);
      }
  
1ff9c9a9   [mandjemb]   Recommandation pr...
47
      public Cell getCell(String column, int line) throws CellNotFoundException {
94ba86ff   Remi   Auto stash before...
48
          Cell cell = this.cells.get(this.getCellId(column, line));
8112a2dd   Remi   merge
49
  
94ba86ff   Remi   Auto stash before...
50
51
52
          if (cell != null)
              return cell;
          else
8112a2dd   Remi   merge
53
              throw new CellNotFoundException();
8112a2dd   Remi   merge
54
55
      }
  
94ba86ff   Remi   Auto stash before...
56
57
      public List<Cell> getCells() {
          return new ArrayList<>(this.cells.values());
8112a2dd   Remi   merge
58
59
      }
  
e0bdcd83   Remi   refacto
60
      public double getValue(String column, int line) throws CellNotFoundException {
94ba86ff   Remi   Auto stash before...
61
          return this.getCell(column, line).getValue();
8112a2dd   Remi   merge
62
63
      }
  
1ff9c9a9   [mandjemb]   Recommandation pr...
64
      public String getFormulaAsString(String column, int line) throws CellNotFoundException {
94ba86ff   Remi   Auto stash before...
65
66
          return this.getCell(column, line).toString();
      }
8112a2dd   Remi   merge
67
  
1ff9c9a9   [mandjemb]   Recommandation pr...
68
      public String getDevelopedFormula(String column, int line) throws CellNotFoundException {
94ba86ff   Remi   Auto stash before...
69
          return this.getCell(column, line).getDevelopedFormula();
8112a2dd   Remi   merge
70
71
      }
  
1ff9c9a9   [mandjemb]   Recommandation pr...
72
73
      private String getCellId(String column, int line) {
          return column + line;
8112a2dd   Remi   merge
74
      }
18e7a394   Remi   add package
75
  }