Blame view

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