From 218ff5c4eb0278d3058b9a24a49b97dde644474c Mon Sep 17 00:00:00 2001 From: [mandjemb] Date: Tue, 11 Jun 2019 12:30:01 +0200 Subject: [PATCH] SERIALIZATION 2.0 --- essai.ser | Bin 1120 -> 0 bytes src/app/Application.java | 6 ++++-- src/kernel/Cell.java | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------- src/kernel/function/Function.java | 4 ++-- 4 files changed, 93 insertions(+), 93 deletions(-) diff --git a/essai.ser b/essai.ser index 6fce183..b4d3973 100644 Binary files a/essai.ser and b/essai.ser differ diff --git a/src/app/Application.java b/src/app/Application.java index 0c968df..15a203f 100644 --- a/src/app/Application.java +++ b/src/app/Application.java @@ -19,7 +19,9 @@ import java.util.List; public class Application implements Serializable{ - public static void main(String[] args) throws IOException { + //private static final long serialVersionUID = 1L; + + public static void main(String[] args) throws IOException { File fichier = new File("essai.ser") ; @@ -33,7 +35,7 @@ public class Application implements Serializable{ try { - grid.createCell("A", 1, 10.); + grid.createCell("AA", 1, 10.); grid.createCell("B", 1, 0.); grid.createCell("A", 2, 5.); List sumList = new ArrayList<>(); diff --git a/src/kernel/Cell.java b/src/kernel/Cell.java index 105c403..4a4e3d0 100644 --- a/src/kernel/Cell.java +++ b/src/kernel/Cell.java @@ -7,93 +7,91 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; -public class Cell implements Serializable{ - final int MAX_LIGNES=20; - - private String column; - private Integer line; - private Double value; - private Formula formula; - private List usedIn = new ArrayList<>(); - - public Cell(String column, Integer line, Double value) throws InvalidIntervalLineColumnEception { - column=column.toUpperCase(); - if ((line>= 1 && line<=MAX_LIGNES) || (column.compareTo("A")>=0 && column.compareTo("Z")<=0)){ - this.column = column; - this.line = line; - this.setValue(value); - } - else - throw new InvalidIntervalLineColumnEception(); - } - - public Cell(String column, Integer line, Formula formula) throws CreateCycleException,InvalidIntervalLineColumnEception { - column=column.toUpperCase(); - if ((line>= 1 && line<=MAX_LIGNES) || (column.compareTo("A")>=0 && column.compareTo("Z")<=0)){ - this.column = column; - this.line = line; - this.setFormula(formula); - } - else - throw new InvalidIntervalLineColumnEception(); - - } - - public Double getValue() { - return this.value; - } - - public Formula getFormula() { - return this.formula; - } - - public String getDevelopedFormula() { - return this.containFormula() ? this.formula.getDevelopedFormula() : this.getId(); - } - - public String getId() { - return this.column + this.line.toString(); - } - - public List getUsedIn() { - return this.usedIn; - } - - public String toString() { - return this.containFormula() ? this.formula.toString() : this.getId(); - } - - public void updateValue() { - if (this.containFormula()) - this.value = this.formula.eval(); - } - - public Boolean containFormula() { - return this.formula != null; - } - - public void setFormula(Formula formula) throws CreateCycleException { - if (formula.createCycle(this)) - throw new CreateCycleException(); - else { - this.formula = formula; - for (Cell cell : this.formula.getUtilisedCells()) - cell.usedIn.add(this); - this.updateValue(); - this.spreadValue(); - } - } - - public void setValue(Double value) { - this.value = value; - this.formula = null; - this.spreadValue(); - } - - private void spreadValue() { - for (Cell cell : this.usedIn) { - cell.updateValue(); - cell.spreadValue(); - } - } +public class Cell implements Serializable { + final int MAX_LIGNES = 20; + + private String column; + private Integer line; + private Double value; + private Formula formula; + private List usedIn = new ArrayList<>(); + + public Cell(String column, Integer line, Double value) throws InvalidIntervalLineColumnEception { + column = column.toUpperCase(); + if ((line >= 1 && line <= MAX_LIGNES) || (column.compareTo("A") >= 0 && column.compareTo("Z") <= 0)) { + this.column = column; + this.line = line; + this.setValue(value); + } else + throw new InvalidIntervalLineColumnEception(); + } + + public Cell(String column, Integer line, Formula formula) + throws CreateCycleException, InvalidIntervalLineColumnEception { + column = column.toUpperCase(); + if ((line >= 1 && line <= MAX_LIGNES) || (column.compareTo("A") >= 0 && column.compareTo("Z") <= 0)) { + this.column = column; + this.line = line; + this.setFormula(formula); + } else + throw new InvalidIntervalLineColumnEception(); + + } + + public Double getValue() { + return this.value; + } + + public Formula getFormula() { + return this.formula; + } + + public String getDevelopedFormula() { + return this.containFormula() ? this.formula.getDevelopedFormula() : this.getId(); + } + + public String getId() { + return this.column + this.line.toString(); + } + + public List getUsedIn() { + return this.usedIn; + } + + public String toString() { + return this.containFormula() ? this.formula.toString() : this.getId(); + } + + public void updateValue() { + if (this.containFormula()) + this.value = this.formula.eval(); + } + + public Boolean containFormula() { + return this.formula != null; + } + + public void setFormula(Formula formula) throws CreateCycleException { + if (formula.createCycle(this)) + throw new CreateCycleException(); + + this.formula = formula; + for (Cell cell : this.formula.getUtilisedCells()) + cell.usedIn.add(this); + this.updateValue(); + this.spreadValue(); + } + + public void setValue(Double value) { + this.value = value; + this.formula = null; + this.spreadValue(); + } + + private void spreadValue() { + for (Cell cell : this.usedIn) { + cell.updateValue(); + cell.spreadValue(); + } + } } diff --git a/src/kernel/function/Function.java b/src/kernel/function/Function.java index 43ce5c2..fc53b11 100644 --- a/src/kernel/function/Function.java +++ b/src/kernel/function/Function.java @@ -53,6 +53,6 @@ abstract public class Function implements Formula,Serializable { } public List getUtilisedCells() { - return this.listCells; - } + return this.listCells; + } } -- libgit2 0.21.2