Blame view

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