package kernel; import kernel.exception.CellNotFoundException; import kernel.exception.CreateCycleException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Grid { private Map cells = new HashMap<>(); public static LanguageEnum language = LanguageEnum.FR; public String createCell(String column, Integer line, Double value) { String id = this.getCellId(column, line); Cell cell = new Cell(column, line, value); this.cells.put(id, cell); return id; } public String createCell(String column, Integer line, Formula formula) throws CreateCycleException { String id = this.getCellId(column, line); Cell cell = new Cell(column, line, formula); this.cells.put(id, cell); return id; } public void setValue(String column, Integer line, Double value) throws CellNotFoundException { this.getCell(column, line).setValue(value); } public void setFormula(String column, Integer line, Formula formula) throws CellNotFoundException, CreateCycleException { this.getCell(column, line).setFormula(formula); } public Cell getCell(String column, Integer line) throws CellNotFoundException { Cell cell = this.cells.get(this.getCellId(column, line)); if (cell != null) return cell; else throw new CellNotFoundException(); } public List getCells() { return new ArrayList<>(this.cells.values()); } public Double getValue(String column, Integer line) throws CellNotFoundException { return this.getCell(column, line).getValue(); } public String getFormulaAsString(String column, Integer line) throws CellNotFoundException { return this.getCell(column, line).toString(); } public String getDevelopedFormula(String column, Integer line) throws CellNotFoundException { return this.getCell(column, line).getDevelopedFormula(); } private String getCellId(String column, Integer line) { return column + line.toString(); } }