Blame view

src/app/Application.java 2.66 KB
18e7a394   Remi   add package
1
2
  package app;
  
94ba86ff   Remi   Auto stash before...
3
  import kernel.Cell;
2e8fbd04   Remi   global refactor
4
  import kernel.Grid;
94ba86ff   Remi   Auto stash before...
5
  import kernel.exception.CellNotFoundException;
5731029f   Remi   merge
6
  import kernel.exception.CreateCycleException;
4186cd92   Remi   fix tests
7
  import kernel.exception.InvalidIntervalException;
94ba86ff   Remi   Auto stash before...
8
9
  import kernel.function.Average;
  import kernel.function.Sum;
ebf0bdb2   mandjemb   interface ok: man...
10
  import kernel.operation.Addition;
94ba86ff   Remi   Auto stash before...
11
  
eb07e5e3   [mandjemb]   avec serialisation
12
13
14
15
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.ObjectOutputStream;
94ba86ff   Remi   Auto stash before...
16
17
  import java.util.ArrayList;
  import java.util.List;
18e7a394   Remi   add package
18
  
e0bdcd83   Remi   refacto
19
  public class Application {
18e7a394   Remi   add package
20
  
e0bdcd83   Remi   refacto
21
22
      public static void main(String[] args) throws IOException {
          File fichier = new File("essai.ser");
eb07e5e3   [mandjemb]   avec serialisation
23
  
e0bdcd83   Remi   refacto
24
25
          // ouverture d'un flux sur un fichier
          ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichier));
1ff9c9a9   [mandjemb]   Recommandation pr...
26
  
e0bdcd83   Remi   refacto
27
          Grid grid = new Grid();
18e7a394   Remi   add package
28
  
94ba86ff   Remi   Auto stash before...
29
30
          // Création
          System.out.println("Création de quelques cases...");
eb07e5e3   [mandjemb]   avec serialisation
31
  
94ba86ff   Remi   Auto stash before...
32
          try {
ebf0bdb2   mandjemb   interface ok: man...
33
              grid.createCell("A", 1, 60.);
eb07e5e3   [mandjemb]   avec serialisation
34
35
              grid.createCell("B", 1, 0.);
              grid.createCell("A", 2, 5.);
ebf0bdb2   mandjemb   interface ok: man...
36
37
              grid.createCell("A", 6, new Addition(grid.getCell("A", 1),grid.getCell("A", 2)));
              
94ba86ff   Remi   Auto stash before...
38
39
40
41
42
43
44
45
46
47
48
              List<Cell> sumList = new ArrayList<>();
              sumList.add(grid.getCell("A", 1));
              sumList.add(grid.getCell("A", 2));
  
              grid.createCell("A", 3, new Sum(sumList));
  
              List<Cell> averageList = new ArrayList<>();
              averageList.add(grid.getCell("A", 3));
              averageList.add(grid.getCell("B", 1));
  
              grid.createCell("B", 2, new Average(averageList));
4186cd92   Remi   fix tests
49
          } catch (CellNotFoundException | CreateCycleException | InvalidIntervalException exception) {
94ba86ff   Remi   Auto stash before...
50
              System.out.println(exception.getMessage());
94ba86ff   Remi   Auto stash before...
51
          }
94ba86ff   Remi   Auto stash before...
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  
          // Affichage
          List<Cell> cells = grid.getCells();
  
          System.out.println("Affichage des valeurs :");
          for (Cell cell : cells)
              System.out.println(cell.getId() + ": " + cell.getValue());
  
          System.out.println("Affichage des formules :");
          for (Cell cell : cells)
              System.out.println(cell.getId() + ": " + cell.toString());
  
          System.out.println("Affichage des formules développées :");
          for (Cell cell : cells)
              System.out.println(cell.getId() + ": " + cell.getDevelopedFormula());
5731029f   Remi   merge
67
68
69
70
71
72
73
74
75
76
77
  
          // Propagation
          try {
              grid.setValue("A", 1, 20.);
          } catch (CellNotFoundException exception) {
              System.out.println("exception");
          }
  
          System.out.println("Affichage des valeurs après modification :");
          for (Cell cell : cells)
              System.out.println(cell.getId() + ": " + cell.getValue());
eb07e5e3   [mandjemb]   avec serialisation
78
79
  
          // sérialization de l'objet
eb07e5e3   [mandjemb]   avec serialisation
80
81
          oos.writeObject(grid);
          oos.close();
18e7a394   Remi   add package
82
      }
18e7a394   Remi   add package
83
  }