Commit a7f554a188ae67c12b6cd5a3de41c8a284d0a4ea

Authored by Remi
1 parent 4186cd92

delete return value from createCell method

  1 +essai.ser
1 /.idea 2 /.idea
2 *.iml 3 *.iml
3 /out 4 /out
essai.ser
No preview for this file type
src/app/Application.java
@@ -17,67 +17,67 @@ import java.util.ArrayList; @@ -17,67 +17,67 @@ import java.util.ArrayList;
17 import java.util.List; 17 import java.util.List;
18 18
19 public class Application { 19 public class Application {
20 -  
21 - public static void main(String[] args) throws IOException {  
22 - File fichier = new File("essai.ser");  
23 -  
24 - // ouverture d'un flux sur un fichier  
25 - ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichier));  
26 -  
27 - Grid grid = new Grid();  
28 -  
29 - // Création  
30 - System.out.println("Création de quelques cases...");  
31 -  
32 - try {  
33 - grid.createCell("A", 1, 60.);  
34 - grid.createCell("B", 1, 0.);  
35 - grid.createCell("A", 2, 5.);  
36 - grid.createCell("A", 6, new Addition(grid.getCell("A", 1),grid.getCell("A", 2)));  
37 -  
38 - List<Cell> sumList = new ArrayList<>();  
39 - sumList.add(grid.getCell("A", 1));  
40 - sumList.add(grid.getCell("A", 2));  
41 -  
42 - grid.createCell("A", 3, new Sum(sumList));  
43 -  
44 - List<Cell> averageList = new ArrayList<>();  
45 - averageList.add(grid.getCell("A", 3));  
46 - averageList.add(grid.getCell("B", 1));  
47 -  
48 - grid.createCell("B", 2, new Average(averageList));  
49 - } catch (CellNotFoundException | CreateCycleException | InvalidIntervalException exception) {  
50 - System.out.println(exception.getMessage());  
51 - }  
52 -  
53 - // Affichage  
54 - List<Cell> cells = grid.getCells();  
55 -  
56 - System.out.println("Affichage des valeurs :");  
57 - for (Cell cell : cells)  
58 - System.out.println(cell.getId() + ": " + cell.getValue());  
59 -  
60 - System.out.println("Affichage des formules :");  
61 - for (Cell cell : cells)  
62 - System.out.println(cell.getId() + ": " + cell.toString());  
63 -  
64 - System.out.println("Affichage des formules développées :");  
65 - for (Cell cell : cells)  
66 - System.out.println(cell.getId() + ": " + cell.getDevelopedFormula());  
67 -  
68 - // Propagation  
69 - try {  
70 - grid.setValue("A", 1, 20.);  
71 - } catch (CellNotFoundException exception) {  
72 - System.out.println("exception");  
73 - }  
74 -  
75 - System.out.println("Affichage des valeurs après modification :");  
76 - for (Cell cell : cells)  
77 - System.out.println(cell.getId() + ": " + cell.getValue());  
78 -  
79 - // sérialization de l'objet  
80 - oos.writeObject(grid);  
81 - oos.close();  
82 - } 20 +
  21 + public static void main(String[] args) throws IOException {
  22 + File fichier = new File("essai.ser");
  23 +
  24 + // ouverture d'un flux sur un fichier
  25 + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichier));
  26 +
  27 + Grid grid = new Grid();
  28 +
  29 + // Création
  30 + System.out.println("Création de quelques cases...");
  31 +
  32 + try {
  33 + grid.createCell("A", 1, 60.);
  34 + grid.createCell("B", 1, 0.);
  35 + grid.createCell("A", 2, 5.);
  36 + grid.createCell("A", 6, new Addition(grid.getCell("A", 1), grid.getCell("A", 2)));
  37 +
  38 + List<Cell> sumList = new ArrayList<>();
  39 + sumList.add(grid.getCell("A", 1));
  40 + sumList.add(grid.getCell("A", 2));
  41 +
  42 + grid.createCell("A", 3, new Sum(sumList));
  43 +
  44 + List<Cell> averageList = new ArrayList<>();
  45 + averageList.add(grid.getCell("A", 3));
  46 + averageList.add(grid.getCell("B", 1));
  47 +
  48 + grid.createCell("B", 2, new Average(averageList));
  49 + } catch (CellNotFoundException | CreateCycleException | InvalidIntervalException exception) {
  50 + System.out.println(exception.getMessage());
  51 + }
  52 +
  53 + // Affichage
  54 + List<Cell> cells = grid.getCells();
  55 +
  56 + System.out.println("Affichage des valeurs :");
  57 + for (Cell cell : cells)
  58 + System.out.println(cell.getId() + ": " + cell.getValue());
  59 +
  60 + System.out.println("Affichage des formules :");
  61 + for (Cell cell : cells)
  62 + System.out.println(cell.getId() + ": " + cell.toString());
  63 +
  64 + System.out.println("Affichage des formules développées :");
  65 + for (Cell cell : cells)
  66 + System.out.println(cell.getId() + ": " + cell.getDevelopedFormula());
  67 +
  68 + // Propagation
  69 + try {
  70 + grid.setValue("A", 1, 20.);
  71 + } catch (CellNotFoundException exception) {
  72 + System.out.println("exception");
  73 + }
  74 +
  75 + System.out.println("Affichage des valeurs après modification :");
  76 + for (Cell cell : cells)
  77 + System.out.println(cell.getId() + ": " + cell.getValue());
  78 +
  79 + // sérialization de l'objet
  80 + oos.writeObject(grid);
  81 + oos.close();
  82 + }
83 } 83 }
src/ihm/TablooProto.java
@@ -4,29 +4,22 @@ package ihm; @@ -4,29 +4,22 @@ package ihm;
4 * TablooProto.java requires no other files. 4 * TablooProto.java requires no other files.
5 * 5 *
6 */ 6 */
7 -import java.awt.Color;  
8 -import java.awt.Component;  
9 -import javax.swing.JFrame;  
10 -import javax.swing.JScrollPane;  
11 -import javax.swing.JTable; 7 +
  8 +import kernel.Grid;
  9 +import kernel.exception.CellNotFoundException;
  10 +import kernel.exception.InvalidIntervalException;
  11 +
  12 +import javax.swing.*;
12 import javax.swing.table.AbstractTableModel; 13 import javax.swing.table.AbstractTableModel;
13 -import java.awt.Dimension;  
14 -import java.awt.GridLayout; 14 +import javax.swing.table.DefaultTableCellRenderer;
  15 +import javax.swing.table.TableColumn;
  16 +import java.awt.*;
15 import java.io.File; 17 import java.io.File;
16 import java.io.FileInputStream; 18 import java.io.FileInputStream;
17 import java.io.IOException; 19 import java.io.IOException;
18 import java.io.ObjectInputStream; 20 import java.io.ObjectInputStream;
19 import java.util.Collections; 21 import java.util.Collections;
20 22
21 -import javax.swing.JLabel;  
22 -import javax.swing.JPanel;  
23 -import javax.swing.table.DefaultTableCellRenderer;  
24 -import javax.swing.table.TableColumn;  
25 -  
26 -import kernel.Grid;  
27 -import kernel.exception.CellNotFoundException;  
28 -import kernel.exception.InvalidIntervalException;  
29 -  
30 public class TablooProto extends JPanel { 23 public class TablooProto extends JPanel {
31 24
32 private static final long serialVersionUID = 1L; 25 private static final long serialVersionUID = 1L;
src/kernel/Grid.java
@@ -19,29 +19,20 @@ public class Grid implements Serializable { @@ -19,29 +19,20 @@ public class Grid implements Serializable {
19 private List<Integer> listLine = new ArrayList<>(); 19 private List<Integer> listLine = new ArrayList<>();
20 private List<Integer> listColumn = new ArrayList<>(); 20 private List<Integer> listColumn = new ArrayList<>();
21 21
22 - public void saveDifferentLineColumn(String column, int line) {  
23 - if (!this.listLine.contains(line))  
24 - listLine.add(line);  
25 - if (!this.listColumn.contains((int) column.charAt(0)))  
26 - listColumn.add((int) column.charAt(0) - (int) 'A' + 1);  
27 - }  
28 -  
29 - public String createCell(String column, int line, double value) throws InvalidIntervalException { 22 + public void createCell(String column, int line, double value) throws InvalidIntervalException {
30 String id = this.getCellId(column, line); 23 String id = this.getCellId(column, line);
31 Cell cell = new Cell(column, line, value); 24 Cell cell = new Cell(column, line, value);
32 25
33 this.cells.put(id, cell); 26 this.cells.put(id, cell);
34 - saveDifferentLineColumn(column, line);  
35 - return id; 27 + this.saveDifferentLineColumn(column, line);
36 } 28 }
37 29
38 - public String createCell(String column, int line, Formula formula) throws CreateCycleException, InvalidIntervalException { 30 + public void createCell(String column, int line, Formula formula) throws CreateCycleException, InvalidIntervalException {
39 String id = this.getCellId(column, line); 31 String id = this.getCellId(column, line);
40 Cell cell = new Cell(column, line, formula); 32 Cell cell = new Cell(column, line, formula);
41 33
42 this.cells.put(id, cell); 34 this.cells.put(id, cell);
43 - saveDifferentLineColumn(column, line);  
44 - return id; 35 + this.saveDifferentLineColumn(column, line);
45 } 36 }
46 37
47 public void setValue(String column, int line, double value) throws CellNotFoundException { 38 public void setValue(String column, int line, double value) throws CellNotFoundException {
@@ -86,6 +77,13 @@ public class Grid implements Serializable { @@ -86,6 +77,13 @@ public class Grid implements Serializable {
86 return column + line; 77 return column + line;
87 } 78 }
88 79
  80 + private void saveDifferentLineColumn(String column, int line) {
  81 + if (!this.listLine.contains(line))
  82 + this.listLine.add(line);
  83 + if (!this.listColumn.contains((int) column.charAt(0)))
  84 + this.listColumn.add((int) column.charAt(0) - (int) 'A' + 1);
  85 + }
  86 +
89 public List<Integer> getTotalColumn() { 87 public List<Integer> getTotalColumn() {
90 return listColumn; 88 return listColumn;
91 } 89 }