Blame view

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