Blame view

src/kernel/BinaryOperation.java 1.39 KB
2e8fbd04   Remi   global refactor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  package kernel;
  
  abstract public class BinaryOperation extends Formula {
  
      protected Cell leftCell;
      protected Cell rightCell;
      protected String operator;
  
      public BinaryOperation(Cell leftCell, Cell rightCell) {
          this.leftCell = leftCell;
          this.rightCell = rightCell;
      }
  
      public String getDevelopedFormula() {
          return this.leftCell.getDevelopedFormula() + " " + this.operator + " " + this.rightCell.getDevelopedFormula();
      }
  
      public String toString() {
          return this.leftCell.toString() + " " + this.operator + " " + this.rightCell.toString();
      }
  
      abstract public Double eval();
  
      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()));
                  }
              }
  
          }
      }
  }