Blame view

src/kernel/Cell.java 1.58 KB
2e8fbd04   Remi   global refactor
1
  package kernel;
d8507aee   [mandjemb]   Fichiers
2
  
8112a2dd   Remi   merge
3
4
  import java.util.ArrayList;
  import java.util.List;
d8507aee   [mandjemb]   Fichiers
5
  
2e8fbd04   Remi   global refactor
6
  public class Cell {
d8507aee   [mandjemb]   Fichiers
7
  
8112a2dd   Remi   merge
8
9
10
      private String column;
      private Integer line;
      private Double value;
2e8fbd04   Remi   global refactor
11
12
      private Formula formula;
      private List<Cell> usedIn = new ArrayList<>();
8112a2dd   Remi   merge
13
  
2e8fbd04   Remi   global refactor
14
      public Cell(String column, Integer line, Double value) {
8112a2dd   Remi   merge
15
16
17
18
19
          this.column = column;
          this.line = line;
          this.value = value;
      }
  
2e8fbd04   Remi   global refactor
20
      public Cell(String column, Integer line, Formula formula) {
8112a2dd   Remi   merge
21
22
          this.column = column;
          this.line = line;
94ba86ff   Remi   Auto stash before...
23
          this.setFormula(formula);
8112a2dd   Remi   merge
24
25
      }
  
2e8fbd04   Remi   global refactor
26
      public Double getValue() {
8112a2dd   Remi   merge
27
28
          return this.value;
      }
8112a2dd   Remi   merge
29
  
2e8fbd04   Remi   global refactor
30
31
      public Formula getFormula() {
          return this.formula;
8112a2dd   Remi   merge
32
33
      }
  
2e8fbd04   Remi   global refactor
34
      public String getDevelopedFormula() {
94ba86ff   Remi   Auto stash before...
35
          return this.containFormula() ? this.formula.getDevelopedFormula() : this.getId();
8112a2dd   Remi   merge
36
37
38
39
40
41
      }
  
      public String getId() {
          return this.column + this.line.toString();
      }
  
2e8fbd04   Remi   global refactor
42
43
      public List<Cell> getUsedIn() {
          return this.usedIn;
8112a2dd   Remi   merge
44
45
      }
  
2e8fbd04   Remi   global refactor
46
      public String toString() {
94ba86ff   Remi   Auto stash before...
47
          return this.containFormula() ? this.formula.toString() : this.getId();
2e8fbd04   Remi   global refactor
48
      }
8112a2dd   Remi   merge
49
  
2e8fbd04   Remi   global refactor
50
51
52
53
54
55
      public void updateValue() {
          this.value = this.formula.eval();
      }
  
      public Boolean containFormula() {
          return this.formula != null;
8112a2dd   Remi   merge
56
57
      }
  
2e8fbd04   Remi   global refactor
58
      public void setFormula(Formula formula) {
8112a2dd   Remi   merge
59
          this.formula = formula;
94ba86ff   Remi   Auto stash before...
60
          this.updateValue();
8112a2dd   Remi   merge
61
62
63
          this.spread();
      }
  
2e8fbd04   Remi   global refactor
64
65
66
67
68
      public void setValue(Double value) {
          this.value = value;
          this.spread();
      }
  
8112a2dd   Remi   merge
69
      private void spread() {
2e8fbd04   Remi   global refactor
70
          for (Cell cell : this.usedIn)
8112a2dd   Remi   merge
71
72
              cell.updateValue();
      }
d8507aee   [mandjemb]   Fichiers
73
  }