Commit 218ff5c4eb0278d3058b9a24a49b97dde644474c

Authored by [mandjemb]
1 parent eb07e5e3

SERIALIZATION 2.0

essai.ser
No preview for this file type
src/app/Application.java
... ... @@ -19,7 +19,9 @@ import java.util.List;
19 19  
20 20 public class Application implements Serializable{
21 21  
22   - public static void main(String[] args) throws IOException {
  22 + //private static final long serialVersionUID = 1L;
  23 +
  24 + public static void main(String[] args) throws IOException {
23 25  
24 26 File fichier = new File("essai.ser") ;
25 27  
... ... @@ -33,7 +35,7 @@ public class Application implements Serializable{
33 35  
34 36  
35 37 try {
36   - grid.createCell("A", 1, 10.);
  38 + grid.createCell("AA", 1, 10.);
37 39 grid.createCell("B", 1, 0.);
38 40 grid.createCell("A", 2, 5.);
39 41 List<Cell> sumList = new ArrayList<>();
... ...
src/kernel/Cell.java
... ... @@ -7,93 +7,91 @@ import java.io.Serializable;
7 7 import java.util.ArrayList;
8 8 import java.util.List;
9 9  
10   -public class Cell implements Serializable{
11   - final int MAX_LIGNES=20;
12   -
13   - private String column;
14   - private Integer line;
15   - private Double value;
16   - private Formula formula;
17   - private List<Cell> usedIn = new ArrayList<>();
18   -
19   - public Cell(String column, Integer line, Double value) throws InvalidIntervalLineColumnEception {
20   - column=column.toUpperCase();
21   - if ((line>= 1 && line<=MAX_LIGNES) || (column.compareTo("A")>=0 && column.compareTo("Z")<=0)){
22   - this.column = column;
23   - this.line = line;
24   - this.setValue(value);
25   - }
26   - else
27   - throw new InvalidIntervalLineColumnEception();
28   - }
29   -
30   - public Cell(String column, Integer line, Formula formula) throws CreateCycleException,InvalidIntervalLineColumnEception {
31   - column=column.toUpperCase();
32   - if ((line>= 1 && line<=MAX_LIGNES) || (column.compareTo("A")>=0 && column.compareTo("Z")<=0)){
33   - this.column = column;
34   - this.line = line;
35   - this.setFormula(formula);
36   - }
37   - else
38   - throw new InvalidIntervalLineColumnEception();
39   -
40   - }
41   -
42   - public Double getValue() {
43   - return this.value;
44   - }
45   -
46   - public Formula getFormula() {
47   - return this.formula;
48   - }
49   -
50   - public String getDevelopedFormula() {
51   - return this.containFormula() ? this.formula.getDevelopedFormula() : this.getId();
52   - }
53   -
54   - public String getId() {
55   - return this.column + this.line.toString();
56   - }
57   -
58   - public List<Cell> getUsedIn() {
59   - return this.usedIn;
60   - }
61   -
62   - public String toString() {
63   - return this.containFormula() ? this.formula.toString() : this.getId();
64   - }
65   -
66   - public void updateValue() {
67   - if (this.containFormula())
68   - this.value = this.formula.eval();
69   - }
70   -
71   - public Boolean containFormula() {
72   - return this.formula != null;
73   - }
74   -
75   - public void setFormula(Formula formula) throws CreateCycleException {
76   - if (formula.createCycle(this))
77   - throw new CreateCycleException();
78   - else {
79   - this.formula = formula;
80   - for (Cell cell : this.formula.getUtilisedCells())
81   - cell.usedIn.add(this);
82   - this.updateValue();
83   - this.spreadValue();
84   - }
85   - }
86   -
87   - public void setValue(Double value) {
88   - this.value = value;
89   - this.formula = null;
90   - this.spreadValue();
91   - }
92   -
93   - private void spreadValue() {
94   - for (Cell cell : this.usedIn) {
95   - cell.updateValue();
96   - cell.spreadValue();
97   - }
98   - }
  10 +public class Cell implements Serializable {
  11 + final int MAX_LIGNES = 20;
  12 +
  13 + private String column;
  14 + private Integer line;
  15 + private Double value;
  16 + private Formula formula;
  17 + private List<Cell> usedIn = new ArrayList<>();
  18 +
  19 + public Cell(String column, Integer line, Double value) throws InvalidIntervalLineColumnEception {
  20 + column = column.toUpperCase();
  21 + if ((line >= 1 && line <= MAX_LIGNES) || (column.compareTo("A") >= 0 && column.compareTo("Z") <= 0)) {
  22 + this.column = column;
  23 + this.line = line;
  24 + this.setValue(value);
  25 + } else
  26 + throw new InvalidIntervalLineColumnEception();
  27 + }
  28 +
  29 + public Cell(String column, Integer line, Formula formula)
  30 + throws CreateCycleException, InvalidIntervalLineColumnEception {
  31 + column = column.toUpperCase();
  32 + if ((line >= 1 && line <= MAX_LIGNES) || (column.compareTo("A") >= 0 && column.compareTo("Z") <= 0)) {
  33 + this.column = column;
  34 + this.line = line;
  35 + this.setFormula(formula);
  36 + } else
  37 + throw new InvalidIntervalLineColumnEception();
  38 +
  39 + }
  40 +
  41 + public Double getValue() {
  42 + return this.value;
  43 + }
  44 +
  45 + public Formula getFormula() {
  46 + return this.formula;
  47 + }
  48 +
  49 + public String getDevelopedFormula() {
  50 + return this.containFormula() ? this.formula.getDevelopedFormula() : this.getId();
  51 + }
  52 +
  53 + public String getId() {
  54 + return this.column + this.line.toString();
  55 + }
  56 +
  57 + public List<Cell> getUsedIn() {
  58 + return this.usedIn;
  59 + }
  60 +
  61 + public String toString() {
  62 + return this.containFormula() ? this.formula.toString() : this.getId();
  63 + }
  64 +
  65 + public void updateValue() {
  66 + if (this.containFormula())
  67 + this.value = this.formula.eval();
  68 + }
  69 +
  70 + public Boolean containFormula() {
  71 + return this.formula != null;
  72 + }
  73 +
  74 + public void setFormula(Formula formula) throws CreateCycleException {
  75 + if (formula.createCycle(this))
  76 + throw new CreateCycleException();
  77 +
  78 + this.formula = formula;
  79 + for (Cell cell : this.formula.getUtilisedCells())
  80 + cell.usedIn.add(this);
  81 + this.updateValue();
  82 + this.spreadValue();
  83 + }
  84 +
  85 + public void setValue(Double value) {
  86 + this.value = value;
  87 + this.formula = null;
  88 + this.spreadValue();
  89 + }
  90 +
  91 + private void spreadValue() {
  92 + for (Cell cell : this.usedIn) {
  93 + cell.updateValue();
  94 + cell.spreadValue();
  95 + }
  96 + }
99 97 }
... ...
src/kernel/function/Function.java
... ... @@ -53,6 +53,6 @@ abstract public class Function implements Formula,Serializable {
53 53 }
54 54  
55 55 public List<Cell> getUtilisedCells() {
56   - return this.listCells;
57   - }
  56 + return this.listCells;
  57 + }
58 58 }
... ...