Blame view

src/kernel/operation/BinaryOperation.java 1.65 KB
5731029f   Remi   merge
1
  package kernel.operation;
2e8fbd04   Remi   global refactor
2
  
5731029f   Remi   merge
3
4
5
  import kernel.Cell;
  import kernel.Formula;
  
1ff9c9a9   [mandjemb]   Recommandation pr...
6
  import java.io.Serializable;
5731029f   Remi   merge
7
8
9
  import java.util.ArrayList;
  import java.util.List;
  
e0bdcd83   Remi   refacto
10
  abstract public class BinaryOperation implements Formula, Serializable {
2e8fbd04   Remi   global refactor
11
  
e0bdcd83   Remi   refacto
12
13
      private static final long serialVersionUID = 1L;
      protected Cell leftCell;
2e8fbd04   Remi   global refactor
14
      protected Cell rightCell;
2e8fbd04   Remi   global refactor
15
16
17
18
19
20
  
      public BinaryOperation(Cell leftCell, Cell rightCell) {
          this.leftCell = leftCell;
          this.rightCell = rightCell;
      }
  
1ff9c9a9   [mandjemb]   Recommandation pr...
21
      abstract public double eval();
e0bdcd83   Remi   refacto
22
  
1ff9c9a9   [mandjemb]   Recommandation pr...
23
      abstract public String getOperator();
e0bdcd83   Remi   refacto
24
  
2e8fbd04   Remi   global refactor
25
      public String getDevelopedFormula() {
e0bdcd83   Remi   refacto
26
          return "(" + this.leftCell.getDevelopedFormula() + this.getOperator() + this.rightCell.getDevelopedFormula() + ")";
2e8fbd04   Remi   global refactor
27
28
29
      }
  
      public String toString() {
1ff9c9a9   [mandjemb]   Recommandation pr...
30
          return this.leftCell.getId() + this.getOperator() + this.rightCell.getId();
2e8fbd04   Remi   global refactor
31
32
      }
  
1ff9c9a9   [mandjemb]   Recommandation pr...
33
      public boolean createCycle(Cell cell) {
2e8fbd04   Remi   global refactor
34
35
          if (this.leftCell.containFormula() && !this.rightCell.containFormula())
              return this.leftCell.getFormula().createCycle(cell);
e0bdcd83   Remi   refacto
36
  
1ff9c9a9   [mandjemb]   Recommandation pr...
37
38
          if (!this.leftCell.containFormula() && this.rightCell.containFormula())
              return this.rightCell.getFormula().createCycle(cell);
e0bdcd83   Remi   refacto
39
  
1ff9c9a9   [mandjemb]   Recommandation pr...
40
41
          if (this.leftCell.containFormula() && this.rightCell.containFormula())
              return this.leftCell.getFormula().createCycle(cell) && this.rightCell.getFormula().createCycle(cell);
1ff9c9a9   [mandjemb]   Recommandation pr...
42
  
e0bdcd83   Remi   refacto
43
          return (cell.getId().equals(this.rightCell.getId()) || cell.getId().equals(this.leftCell.getId()));
2e8fbd04   Remi   global refactor
44
      }
5731029f   Remi   merge
45
  
5731029f   Remi   merge
46
47
48
49
50
51
52
      public List<Cell> getUtilisedCells() {
          List<Cell> cells = new ArrayList<>();
          cells.add(this.leftCell);
          cells.add(this.rightCell);
  
          return cells;
      }
2e8fbd04   Remi   global refactor
53
  }