From a7f554a188ae67c12b6cd5a3de41c8a284d0a4ea Mon Sep 17 00:00:00 2001 From: Remi Date: Wed, 12 Jun 2019 11:25:49 +0200 Subject: [PATCH] delete return value from createCell method --- .gitignore | 1 + essai.ser | Bin 826 -> 0 bytes src/app/Application.java | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------- src/ihm/TablooProto.java | 25 +++++++++---------------- src/kernel/Grid.java | 24 +++++++++++------------- 5 files changed, 84 insertions(+), 92 deletions(-) diff --git a/.gitignore b/.gitignore index 3373e25..4b49ee8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +essai.ser /.idea *.iml /out diff --git a/essai.ser b/essai.ser index 9fa6fc3..a851fdf 100644 Binary files a/essai.ser and b/essai.ser differ diff --git a/src/app/Application.java b/src/app/Application.java index b0d1902..4b3d13d 100644 --- a/src/app/Application.java +++ b/src/app/Application.java @@ -17,67 +17,67 @@ import java.util.ArrayList; import java.util.List; public class Application { - - public static void main(String[] args) throws IOException { - File fichier = new File("essai.ser"); - - // ouverture d'un flux sur un fichier - ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichier)); - - Grid grid = new Grid(); - - // Création - System.out.println("Création de quelques cases..."); - - try { - grid.createCell("A", 1, 60.); - grid.createCell("B", 1, 0.); - grid.createCell("A", 2, 5.); - grid.createCell("A", 6, new Addition(grid.getCell("A", 1),grid.getCell("A", 2))); - - List sumList = new ArrayList<>(); - sumList.add(grid.getCell("A", 1)); - sumList.add(grid.getCell("A", 2)); - - grid.createCell("A", 3, new Sum(sumList)); - - List averageList = new ArrayList<>(); - averageList.add(grid.getCell("A", 3)); - averageList.add(grid.getCell("B", 1)); - - grid.createCell("B", 2, new Average(averageList)); - } catch (CellNotFoundException | CreateCycleException | InvalidIntervalException exception) { - System.out.println(exception.getMessage()); - } - - // Affichage - List 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()); - - // 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()); - - // sérialization de l'objet - oos.writeObject(grid); - oos.close(); - } + + public static void main(String[] args) throws IOException { + File fichier = new File("essai.ser"); + + // ouverture d'un flux sur un fichier + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichier)); + + Grid grid = new Grid(); + + // Création + System.out.println("Création de quelques cases..."); + + try { + grid.createCell("A", 1, 60.); + grid.createCell("B", 1, 0.); + grid.createCell("A", 2, 5.); + grid.createCell("A", 6, new Addition(grid.getCell("A", 1), grid.getCell("A", 2))); + + List sumList = new ArrayList<>(); + sumList.add(grid.getCell("A", 1)); + sumList.add(grid.getCell("A", 2)); + + grid.createCell("A", 3, new Sum(sumList)); + + List averageList = new ArrayList<>(); + averageList.add(grid.getCell("A", 3)); + averageList.add(grid.getCell("B", 1)); + + grid.createCell("B", 2, new Average(averageList)); + } catch (CellNotFoundException | CreateCycleException | InvalidIntervalException exception) { + System.out.println(exception.getMessage()); + } + + // Affichage + List 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()); + + // 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()); + + // sérialization de l'objet + oos.writeObject(grid); + oos.close(); + } } diff --git a/src/ihm/TablooProto.java b/src/ihm/TablooProto.java index 164b40c..39a93b8 100644 --- a/src/ihm/TablooProto.java +++ b/src/ihm/TablooProto.java @@ -4,29 +4,22 @@ package ihm; * TablooProto.java requires no other files. * */ -import java.awt.Color; -import java.awt.Component; -import javax.swing.JFrame; -import javax.swing.JScrollPane; -import javax.swing.JTable; + +import kernel.Grid; +import kernel.exception.CellNotFoundException; +import kernel.exception.InvalidIntervalException; + +import javax.swing.*; import javax.swing.table.AbstractTableModel; -import java.awt.Dimension; -import java.awt.GridLayout; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableColumn; +import java.awt.*; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.util.Collections; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableColumn; - -import kernel.Grid; -import kernel.exception.CellNotFoundException; -import kernel.exception.InvalidIntervalException; - public class TablooProto extends JPanel { private static final long serialVersionUID = 1L; diff --git a/src/kernel/Grid.java b/src/kernel/Grid.java index 0b6d068..2a7249f 100644 --- a/src/kernel/Grid.java +++ b/src/kernel/Grid.java @@ -19,29 +19,20 @@ public class Grid implements Serializable { private List listLine = new ArrayList<>(); private List listColumn = new ArrayList<>(); - public void saveDifferentLineColumn(String column, int line) { - if (!this.listLine.contains(line)) - listLine.add(line); - if (!this.listColumn.contains((int) column.charAt(0))) - listColumn.add((int) column.charAt(0) - (int) 'A' + 1); - } - - public String createCell(String column, int line, double value) throws InvalidIntervalException { + public void createCell(String column, int line, double value) throws InvalidIntervalException { String id = this.getCellId(column, line); Cell cell = new Cell(column, line, value); this.cells.put(id, cell); - saveDifferentLineColumn(column, line); - return id; + this.saveDifferentLineColumn(column, line); } - public String createCell(String column, int line, Formula formula) throws CreateCycleException, InvalidIntervalException { + public void createCell(String column, int line, Formula formula) throws CreateCycleException, InvalidIntervalException { String id = this.getCellId(column, line); Cell cell = new Cell(column, line, formula); this.cells.put(id, cell); - saveDifferentLineColumn(column, line); - return id; + this.saveDifferentLineColumn(column, line); } public void setValue(String column, int line, double value) throws CellNotFoundException { @@ -86,6 +77,13 @@ public class Grid implements Serializable { return column + line; } + private void saveDifferentLineColumn(String column, int line) { + if (!this.listLine.contains(line)) + this.listLine.add(line); + if (!this.listColumn.contains((int) column.charAt(0))) + this.listColumn.add((int) column.charAt(0) - (int) 'A' + 1); + } + public List getTotalColumn() { return listColumn; } -- libgit2 0.21.2