Blame view

src/kernel/operation/BinaryOperation.java 1.46 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 {
4186cd92   Remi   fix tests
11
12
  	
  	private static final long serialVersionUID = 1L;
080a0e68   Remi   change return
13
14
  	private Cell leftCell;
  	private Cell rightCell;
4186cd92   Remi   fix tests
15
16
17
18
19
20
21
22
23
24
  	
  	public BinaryOperation(Cell leftCell, Cell rightCell) {
  		this.leftCell = leftCell;
  		this.rightCell = rightCell;
  	}
  	
  	abstract public double eval();
  	
  	abstract public String getOperator();
  	
080a0e68   Remi   change return
25
26
27
28
29
30
31
32
33
  	public Cell getLeftCell() {
  		return this.leftCell;
  	}
  	
  	public Cell getRightCell() {
  		return this.rightCell;
  	}
  	
  	@Override
4186cd92   Remi   fix tests
34
35
36
37
  	public String getDevelopedFormula() {
  		return "(" + this.leftCell.getDevelopedFormula() + this.getOperator() + this.rightCell.getDevelopedFormula() + ")";
  	}
  	
080a0e68   Remi   change return
38
  	@Override
4186cd92   Remi   fix tests
39
40
41
42
  	public String toString() {
  		return "(" + this.leftCell.getId() + this.getOperator() + this.rightCell.getId() + ")";
  	}
  	
080a0e68   Remi   change return
43
  	@Override
4186cd92   Remi   fix tests
44
  	public boolean createCycle(Cell cell) {
3ac71733   Remi   update binary ope...
45
46
  		if (this.createCycleWith(this.leftCell, cell) || this.createCycleWith(this.rightCell, cell))
  			return true;
4186cd92   Remi   fix tests
47
  		
3ac71733   Remi   update binary ope...
48
  		return this.rightCell.equals(cell) || this.leftCell.equals(cell);
4186cd92   Remi   fix tests
49
50
  	}
  	
080a0e68   Remi   change return
51
  	@Override
4186cd92   Remi   fix tests
52
53
54
55
56
57
58
  	public List<Cell> getUtilisedCells() {
  		List<Cell> cells = new ArrayList<>();
  		cells.add(this.leftCell);
  		cells.add(this.rightCell);
  		
  		return cells;
  	}
3ac71733   Remi   update binary ope...
59
60
61
62
  	
  	private boolean createCycleWith(Cell cell, Cell current) {
  		return cell.containFormula() && cell.getFormula().createCycle(current);
  	}
2e8fbd04   Remi   global refactor
63
  }