From 8112a2ddc830f4eefb5133b01e6171d24c32d22d Mon Sep 17 00:00:00 2001 From: Remi Date: Thu, 6 Jun 2019 16:45:05 +0200 Subject: [PATCH] merge --- src/noyau/Case.java | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- src/noyau/Grille.java | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/noyau/exception/CellNotFoundException.java | 4 ++++ 3 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 src/noyau/exception/CellNotFoundException.java diff --git a/src/noyau/Case.java b/src/noyau/Case.java index 468a205..88e4817 100644 --- a/src/noyau/Case.java +++ b/src/noyau/Case.java @@ -1,13 +1,62 @@ package noyau; -import java.util.*; +import java.util.ArrayList; +import java.util.List; public class Case { - - String colonne; - int ligne; - double valeur; - ArrayList utiliseDans = new ArrayList(); - boolean isFormule; + private String column; + private Integer line; + private Double value; + private Formule formula; + private List usedIn = new ArrayList<>(); + + public Case(String column, Integer line, Double value) { + this.column = column; + this.line = line; + this.value = value; + } + + public Case(String column, Integer line, Formule formula) { + this.column = column; + this.line = line; + this.formula = formula; + } + + public Double getValue() { + return this.value; + } + + public void setValue(Double value) { + this.value = value; + this.spread(); + } + + public void updateValue() { + + } + + public String getId() { + return this.column + this.line.toString(); + } + + public Boolean containFormula() { + return this.formula != null; + } + + + + public Formule getFormula() { + return this.formula; + } + + public void setFormula(Formule formula) { + this.formula = formula; + this.spread(); + } + + private void spread() { + for (Case cell : this.usedIn) + cell.updateValue(); + } } diff --git a/src/noyau/Grille.java b/src/noyau/Grille.java index bfb81ed..6380ac9 100644 --- a/src/noyau/Grille.java +++ b/src/noyau/Grille.java @@ -1,5 +1,77 @@ package noyau; +import noyau.exception.CellNotFoundException; + +import java.util.HashMap; +import java.util.Map; + public class Grille { - + + private Map cases = new HashMap<>(); + + public String createCase(String column, Integer line, Double value) { + String id = this.getId(column, line); + Case cell = new Case(column, line, value); + + this.cases.put(id, cell); + + return id; + } + + public String createCase(String column, Integer line, Formule formula) { + String id = this.getId(column, line); + Case cell = new Case(column, line, formula); + + this.cases.put(id, cell); + + return id; + } + + public void setValue(String column, Integer line, Double value) throws CellNotFoundException { + Case cell = this.getCase(column, line); + + try { + cell.setValue(value); + } catch (NullPointerException exception) { + throw new CellNotFoundException(); + } + } + + public void setFormula(String column, Integer line, Formule formula) throws CellNotFoundException { + Case cell = this.getCase(column, line); + + try { + cell.setFormula(formula); + } catch (NullPointerException exception) { + throw new CellNotFoundException(); + } + } + + public Case getCase(String column, Integer line) { + return this.cases.get(this.getId(column, line)); + } + + public Double getValeur(String column, Integer line) throws CellNotFoundException { + Case cell = this.getCase(column, line); + + try { + return cell.getValue(); + } catch (NullPointerException exception) { + throw new CellNotFoundException(); + } + } + + public String getFormuleAsString(String column, Integer line) throws CellNotFoundException { + Case cell = this.getCase(column, line); + + try { + return cell.getValue(); + } catch (NullPointerException exception) { + throw new CellNotFoundException(); + } + } + + private String getId(String column, Integer line) { + return column + line.toString(); + } } diff --git a/src/noyau/exception/CellNotFoundException.java b/src/noyau/exception/CellNotFoundException.java new file mode 100644 index 0000000..810c250 --- /dev/null +++ b/src/noyau/exception/CellNotFoundException.java @@ -0,0 +1,4 @@ +package noyau.exception; + +public class CellNotFoundException extends Exception { +} -- libgit2 0.21.2