Blame view

src/kernel/Grid.java 2.72 KB
2e8fbd04   Remi   global refactor
1
  package kernel;
18e7a394   Remi   add package
2
  
2e8fbd04   Remi   global refactor
3
  import kernel.exception.CellNotFoundException;
5731029f   Remi   merge
4
  import kernel.exception.CreateCycleException;
4186cd92   Remi   fix tests
5
  import kernel.exception.InvalidIntervalException;
8112a2dd   Remi   merge
6
  
eb07e5e3   [mandjemb]   avec serialisation
7
  import java.io.Serializable;
94ba86ff   Remi   Auto stash before...
8
  import java.util.ArrayList;
8112a2dd   Remi   merge
9
  import java.util.HashMap;
94ba86ff   Remi   Auto stash before...
10
  import java.util.List;
8112a2dd   Remi   merge
11
12
  import java.util.Map;
  
eb07e5e3   [mandjemb]   avec serialisation
13
  public class Grid implements Serializable {
4186cd92   Remi   fix tests
14
15
16
17
18
19
20
21
  	
  	private static final long serialVersionUID = 1L;
  	
  	private Map<String, Cell> cells = new HashMap<>();
  	public static LanguageEnum language = LanguageEnum.FR;
  	private List<Integer> listLine = new ArrayList<>();
  	private List<Integer> listColumn = new ArrayList<>();
  	
a7f554a1   Remi   delete return val...
22
  	public void createCell(String column, int line, double value) throws InvalidIntervalException {
4186cd92   Remi   fix tests
23
24
25
26
  		String id = this.getCellId(column, line);
  		Cell cell = new Cell(column, line, value);
  		
  		this.cells.put(id, cell);
a7f554a1   Remi   delete return val...
27
  		this.saveDifferentLineColumn(column, line);
4186cd92   Remi   fix tests
28
29
  	}
  	
a7f554a1   Remi   delete return val...
30
  	public void createCell(String column, int line, Formula formula) throws CreateCycleException, InvalidIntervalException {
4186cd92   Remi   fix tests
31
32
33
34
  		String id = this.getCellId(column, line);
  		Cell cell = new Cell(column, line, formula);
  		
  		this.cells.put(id, cell);
a7f554a1   Remi   delete return val...
35
  		this.saveDifferentLineColumn(column, line);
4186cd92   Remi   fix tests
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  	}
  	
  	public void setValue(String column, int line, double value) throws CellNotFoundException {
  		this.getCell(column, line).setValue(value);
  	}
  	
  	public void setFormula(String column, int line, Formula formula) throws CellNotFoundException,
  			CreateCycleException {
  		this.getCell(column, line).setFormula(formula);
  	}
  	
  	public Cell getCell(String column, int line) throws CellNotFoundException {
  		Cell cell = this.cells.get(this.getCellId(column, line));
  		
  		if (cell != null)
  			return cell;
  		else
  			throw new CellNotFoundException();
  	}
  	
  	public List<Cell> getCells() {
  		return new ArrayList<>(this.cells.values());
  	}
  	
  	public List<String> getCellsId() {
  		return new ArrayList<>(this.cells.keySet());
  	}
  	
  	public double getValue(String column, int line) throws CellNotFoundException {
  		return this.getCell(column, line).getValue();
  	}
  	
  	public String getFormulaAsString(String column, int line) throws CellNotFoundException {
  		return this.getCell(column, line).toString();
  	}
  	
  	public String getDevelopedFormula(String column, int line) throws CellNotFoundException {
  		return this.getCell(column, line).getDevelopedFormula();
  	}
  	
  	private String getCellId(String column, int line) {
  		return column + line;
  	}
  	
a7f554a1   Remi   delete return val...
80
81
82
83
84
85
86
  	private void saveDifferentLineColumn(String column, int line) {
  		if (!this.listLine.contains(line))
  			this.listLine.add(line);
  		if (!this.listColumn.contains((int) column.charAt(0)))
  			this.listColumn.add((int) column.charAt(0) - (int) 'A' + 1);
  	}
  	
4186cd92   Remi   fix tests
87
88
89
90
91
92
93
  	public List<Integer> getTotalColumn() {
  		return listColumn;
  	}
  	
  	public List<Integer> getTotalLine() {
  		return listLine;
  	}
18e7a394   Remi   add package
94
  }