Blame view

src/kernel/function/Function.java 1.4 KB
2e8fbd04   Remi   global refactor
1
2
3
4
  package kernel.function;
  
  import kernel.Cell;
  import kernel.Formula;
94ba86ff   Remi   Auto stash before...
5
6
  import kernel.Grid;
  import kernel.LanguageEnum;
2e8fbd04   Remi   global refactor
7
  
eb07e5e3   [mandjemb]   avec serialisation
8
  import java.io.Serializable;
94ba86ff   Remi   Auto stash before...
9
  import java.util.HashMap;
94ba86ff   Remi   Auto stash before...
10
11
12
  import java.util.List;
  import java.util.Map;
  import java.util.stream.Collectors;
2e8fbd04   Remi   global refactor
13
  
e0bdcd83   Remi   refacto
14
  abstract public class Function implements Formula, Serializable {
2e8fbd04   Remi   global refactor
15
  
e0bdcd83   Remi   refacto
16
17
      private static final long serialVersionUID = 1L;
      public Map<LanguageEnum, String> names = new HashMap<>();
5731029f   Remi   merge
18
      public List<Cell> listCells;
2e8fbd04   Remi   global refactor
19
  
94ba86ff   Remi   Auto stash before...
20
21
22
      public Function(List<Cell> listCells) {
          this.listCells = listCells;
      }
2e8fbd04   Remi   global refactor
23
  
1ff9c9a9   [mandjemb]   Recommandation pr...
24
      abstract public double eval();
2e8fbd04   Remi   global refactor
25
  
94ba86ff   Remi   Auto stash before...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
      public String getDevelopedFormula() {
          return names.get(Grid.language) + "("
                  + this.listCells.stream()
                  .map(Cell::getDevelopedFormula)
                  .collect(Collectors.joining(",")) + ")";
      }
  
      public String toString() {
          return names.get(Grid.language) + "("
                  + this.listCells.stream()
                  .map(Cell::getId)
                  .collect(Collectors.joining(",")) + ")";
      }
  
1ff9c9a9   [mandjemb]   Recommandation pr...
40
      public boolean createCycle(Cell cell) {
e0bdcd83   Remi   refacto
41
42
43
44
          if (!this.listCells.contains(cell))
              for (Cell currentCell : this.listCells)
                  if (currentCell.containFormula() && currentCell.getFormula().createCycle(cell))
                      return true;
1ff9c9a9   [mandjemb]   Recommandation pr...
45
  
e0bdcd83   Remi   refacto
46
          return true;
1ff9c9a9   [mandjemb]   Recommandation pr...
47
48
      }
  
5731029f   Remi   merge
49
      public List<Cell> getUtilisedCells() {
e0bdcd83   Remi   refacto
50
51
          return this.listCells;
      }
2e8fbd04   Remi   global refactor
52
  }