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
6
7
8
9
  import kernel.Cell;
  import kernel.Formula;
  
  import java.util.ArrayList;
  import java.util.List;
  
  abstract public class BinaryOperation implements Formula {
2e8fbd04   Remi   global refactor
10
11
12
13
14
15
16
17
18
19
  
      protected Cell leftCell;
      protected Cell rightCell;
      protected String operator;
  
      public BinaryOperation(Cell leftCell, Cell rightCell) {
          this.leftCell = leftCell;
          this.rightCell = rightCell;
      }
  
5731029f   Remi   merge
20
21
      abstract public Double eval();
  
2e8fbd04   Remi   global refactor
22
      public String getDevelopedFormula() {
5731029f   Remi   merge
23
          return this.leftCell.getDevelopedFormula() + this.operator + this.rightCell.getDevelopedFormula();
2e8fbd04   Remi   global refactor
24
25
26
      }
  
      public String toString() {
5731029f   Remi   merge
27
          return this.leftCell.getId() + this.operator + this.rightCell.getId();
2e8fbd04   Remi   global refactor
28
29
      }
  
2e8fbd04   Remi   global refactor
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
      public Boolean createCycle(Cell cell) {
          if (this.leftCell.containFormula() && !this.rightCell.containFormula())
              return this.leftCell.getFormula().createCycle(cell);
          else {
              if (!this.leftCell.containFormula() && this.rightCell.containFormula())
                  return this.rightCell.getFormula().createCycle(cell);
              else {
                  if (this.leftCell.containFormula() && this.rightCell.containFormula())
                      return this.leftCell.getFormula().createCycle(cell) && this.rightCell.getFormula().createCycle(cell);
                  else {
                      return (cell.getId().equals(this.rightCell.getId()) || cell.getId().equals(this.leftCell.getId()));
                  }
              }
  
          }
      }
5731029f   Remi   merge
46
47
48
49
50
51
52
53
  
      public List<Cell> getUtilisedCells() {
          List<Cell> cells = new ArrayList<>();
          cells.add(this.leftCell);
          cells.add(this.rightCell);
  
          return cells;
      }
2e8fbd04   Remi   global refactor
54
  }