Blame view

src/kernel/function/Function.java 1.41 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
  
94ba86ff   Remi   Auto stash before...
8
9
10
11
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import java.util.stream.Collectors;
2e8fbd04   Remi   global refactor
12
  import java.util.ArrayList;
6ccf7ee5   [mandjemb]   cycle
13
  import java.util.Iterator;
2e8fbd04   Remi   global refactor
14
15
16
  
  abstract public class Function extends Formula {
  
94ba86ff   Remi   Auto stash before...
17
18
      protected Map<LanguageEnum, String> names = new HashMap<>();
      protected 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
24
25
  
      abstract public Double eval();
  
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(",")) + ")";
      }
  
2e8fbd04   Remi   global refactor
40
      public Boolean createCycle(Cell cell) {
6ccf7ee5   [mandjemb]   cycle
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
   
      	boolean cycle=false;
          if (!this.listCells.contains(cell)){
          	Iterator<Cell> it=listCells.iterator();
          	while (it.hasNext() &&!cycle){
          		if (it.next().containFormula()){
          			cycle=it.next().getFormula().createCycle(cell);
          		}
          	}
          	return cycle;
          	
          }
          else
          	return true;
      	
      	
2e8fbd04   Remi   global refactor
57
58
      }
  }