Commit 1ff9c9a91d6485bc8fc9985873ae4839e2b9e655

Authored by [mandjemb]
1 parent 218ff5c4

Recommandation prof(Integer en int, Boolean en boolean and Double en double

essai.ser
No preview for this file type
src/app/Application.java
... ... @@ -19,7 +19,10 @@ import java.util.List;
19 19  
20 20 public class Application implements Serializable{
21 21  
22   - //private static final long serialVersionUID = 1L;
  22 +
  23 + //private static final long serialVersionUID = -5923230541404119541L;
  24 +
  25 + private static final long serialVersionUID = 1L;
23 26  
24 27 public static void main(String[] args) throws IOException {
25 28  
... ... @@ -35,7 +38,7 @@ public class Application implements Serializable{
35 38  
36 39  
37 40 try {
38   - grid.createCell("AA", 1, 10.);
  41 + grid.createCell("A", 1, 10.);
39 42 grid.createCell("B", 1, 0.);
40 43 grid.createCell("A", 2, 5.);
41 44 List<Cell> sumList = new ArrayList<>();
... ...
src/kernel/Cell.java
... ... @@ -8,17 +8,26 @@ import java.util.ArrayList;
8 8 import java.util.List;
9 9  
10 10 public class Cell implements Serializable {
  11 +
  12 + private static final long serialVersionUID = 1L;
  13 +
11 14 final int MAX_LIGNES = 20;
12 15  
13 16 private String column;
14   - private Integer line;
15   - private Double value;
  17 + private int line;
  18 + private double value;
16 19 private Formula formula;
17 20 private List<Cell> usedIn = new ArrayList<>();
  21 +
  22 + public boolean IntervallCondition(String column, int line){
  23 +
  24 + return line >= 1 && line <= MAX_LIGNES && column.compareTo("A") >= 0 && column.compareTo("Z") <= 0;
18 25  
19   - public Cell(String column, Integer line, Double value) throws InvalidIntervalLineColumnEception {
  26 + }
  27 +
  28 + public Cell(String column,int line, double value) throws InvalidIntervalLineColumnEception {
20 29 column = column.toUpperCase();
21   - if ((line >= 1 && line <= MAX_LIGNES) || (column.compareTo("A") >= 0 && column.compareTo("Z") <= 0)) {
  30 + if (IntervallCondition(column,line)) {
22 31 this.column = column;
23 32 this.line = line;
24 33 this.setValue(value);
... ... @@ -26,10 +35,10 @@ public class Cell implements Serializable {
26 35 throw new InvalidIntervalLineColumnEception();
27 36 }
28 37  
29   - public Cell(String column, Integer line, Formula formula)
  38 + public Cell(String column, int line, Formula formula)
30 39 throws CreateCycleException, InvalidIntervalLineColumnEception {
31 40 column = column.toUpperCase();
32   - if ((line >= 1 && line <= MAX_LIGNES) || (column.compareTo("A") >= 0 && column.compareTo("Z") <= 0)) {
  41 + if (IntervallCondition(column,line)) {
33 42 this.column = column;
34 43 this.line = line;
35 44 this.setFormula(formula);
... ... @@ -38,7 +47,7 @@ public class Cell implements Serializable {
38 47  
39 48 }
40 49  
41   - public Double getValue() {
  50 + public double getValue() {
42 51 return this.value;
43 52 }
44 53  
... ... @@ -51,7 +60,7 @@ public class Cell implements Serializable {
51 60 }
52 61  
53 62 public String getId() {
54   - return this.column + this.line.toString();
  63 + return this.column + this.line;
55 64 }
56 65  
57 66 public List<Cell> getUsedIn() {
... ...
src/kernel/Formula.java
... ... @@ -8,9 +8,9 @@ public interface Formula {
8 8  
9 9 String toString();
10 10  
11   - Double eval();
  11 + double eval();
12 12  
13   - Boolean createCycle(Cell cell);
  13 + boolean createCycle(Cell cell);
14 14  
15 15 List<Cell> getUtilisedCells();
16 16 }
... ...
src/kernel/Grid.java
... ... @@ -12,10 +12,12 @@ import java.util.Map;
12 12  
13 13 public class Grid implements Serializable {
14 14  
15   - private Map<String, Cell> cells = new HashMap<>();
  15 + private static final long serialVersionUID = 1L;
  16 +
  17 + private Map<String, Cell> cells = new HashMap<>();
16 18 public static LanguageEnum language = LanguageEnum.FR;
17 19  
18   - public String createCell(String column, Integer line, Double value) throws InvalidIntervalLineColumnEception {
  20 + public String createCell(String column, int line, double value) throws InvalidIntervalLineColumnEception {
19 21 String id = this.getCellId(column, line);
20 22 Cell cell = new Cell(column, line, value);
21 23  
... ... @@ -24,7 +26,7 @@ public class Grid implements Serializable {
24 26 return id;
25 27 }
26 28  
27   - public String createCell(String column, Integer line, Formula formula) throws CreateCycleException, InvalidIntervalLineColumnEception {
  29 + public String createCell(String column, int line, Formula formula) throws CreateCycleException, InvalidIntervalLineColumnEception {
28 30 String id = this.getCellId(column, line);
29 31 Cell cell = new Cell(column, line, formula);
30 32  
... ... @@ -33,16 +35,16 @@ public class Grid implements Serializable {
33 35 return id;
34 36 }
35 37  
36   - public void setValue(String column, Integer line, Double value) throws CellNotFoundException {
  38 + public void setValue(String column, int line, double value) throws CellNotFoundException {
37 39 this.getCell(column, line).setValue(value);
38 40 }
39 41  
40   - public void setFormula(String column, Integer line, Formula formula) throws CellNotFoundException,
  42 + public void setFormula(String column, int line, Formula formula) throws CellNotFoundException,
41 43 CreateCycleException {
42 44 this.getCell(column, line).setFormula(formula);
43 45 }
44 46  
45   - public Cell getCell(String column, Integer line) throws CellNotFoundException {
  47 + public Cell getCell(String column, int line) throws CellNotFoundException {
46 48 Cell cell = this.cells.get(this.getCellId(column, line));
47 49  
48 50 if (cell != null)
... ... @@ -55,19 +57,19 @@ public class Grid implements Serializable {
55 57 return new ArrayList<>(this.cells.values());
56 58 }
57 59  
58   - public Double getValue(String column, Integer line) throws CellNotFoundException {
  60 + public Double getValue(String column, int line) throws CellNotFoundException {
59 61 return this.getCell(column, line).getValue();
60 62 }
61 63  
62   - public String getFormulaAsString(String column, Integer line) throws CellNotFoundException {
  64 + public String getFormulaAsString(String column, int line) throws CellNotFoundException {
63 65 return this.getCell(column, line).toString();
64 66 }
65 67  
66   - public String getDevelopedFormula(String column, Integer line) throws CellNotFoundException {
  68 + public String getDevelopedFormula(String column, int line) throws CellNotFoundException {
67 69 return this.getCell(column, line).getDevelopedFormula();
68 70 }
69 71  
70   - private String getCellId(String column, Integer line) {
71   - return column + line.toString();
  72 + private String getCellId(String column, int line) {
  73 + return column + line;
72 74 }
73 75 }
... ...
src/kernel/exception/CellNotFoundException.java
1 1 package kernel.exception;
2 2  
3 3 public class CellNotFoundException extends Exception {
  4 +
  5 +
  6 + private static final long serialVersionUID = 1L;
4 7 }
... ...
src/kernel/exception/CreateCycleException.java
1 1 package kernel.exception;
2 2  
3 3 public class CreateCycleException extends Exception {
  4 +
  5 + private static final long serialVersionUID = 1L;
4 6 }
... ...
src/kernel/exception/InvalidIntervalLineColumnEception.java
... ... @@ -2,4 +2,7 @@ package kernel.exception;
2 2  
3 3 public class InvalidIntervalLineColumnEception extends Exception {
4 4  
  5 +
  6 + private static final long serialVersionUID = 1L;
  7 +
5 8 }
... ...
src/kernel/function/Average.java
... ... @@ -8,13 +8,15 @@ import java.util.OptionalDouble;
8 8  
9 9 public class Average extends Function {
10 10  
11   - public Average(List<Cell> listCells) {
  11 + private static final long serialVersionUID = 1L;
  12 +
  13 + public Average(List<Cell> listCells) {
12 14 super(listCells);
13 15 this.names.put(LanguageEnum.FR, "MOYENNE");
14 16 this.names.put(LanguageEnum.EN, "AVERAGE");
15 17 }
16 18  
17   - public Double eval() {
  19 + public double eval() {
18 20  
19 21 OptionalDouble average = this.listCells.stream()
20 22 .mapToDouble(Cell::getValue)
... ...
src/kernel/function/Function.java
... ... @@ -7,21 +7,22 @@ import kernel.LanguageEnum;
7 7  
8 8 import java.io.Serializable;
9 9 import java.util.HashMap;
10   -import java.util.Iterator;
11 10 import java.util.List;
12 11 import java.util.Map;
13 12 import java.util.stream.Collectors;
14 13  
15 14 abstract public class Function implements Formula,Serializable {
16 15  
17   - public Map<LanguageEnum, String> names = new HashMap<>();
  16 +
  17 + private static final long serialVersionUID = 1L;
  18 + public Map<LanguageEnum, String> names = new HashMap<>();
18 19 public List<Cell> listCells;
19 20  
20 21 public Function(List<Cell> listCells) {
21 22 this.listCells = listCells;
22 23 }
23 24  
24   - abstract public Double eval();
  25 + abstract public double eval();
25 26  
26 27 public String getDevelopedFormula() {
27 28 return names.get(Grid.language) + "("
... ... @@ -37,6 +38,16 @@ abstract public class Function implements Formula,Serializable {
37 38 .collect(Collectors.joining(",")) + ")";
38 39 }
39 40  
  41 + public boolean createCycle(Cell cell) {
  42 +
  43 + if (!this.listCells.contains(cell))
  44 + for(Cell currentCell:this.listCells)
  45 + return currentCell.containFormula() && currentCell.getFormula().createCycle(cell);
  46 +
  47 + return true;
  48 + }
  49 +
  50 + /*
40 51 public Boolean createCycle(Cell cell) {
41 52 boolean cycle = false;
42 53 if (!this.listCells.contains(cell)) {
... ... @@ -51,7 +62,8 @@ abstract public class Function implements Formula,Serializable {
51 62 } else
52 63 return true;
53 64 }
54   -
  65 +
  66 + */
55 67 public List<Cell> getUtilisedCells() {
56 68 return this.listCells;
57 69 }
... ...
src/kernel/function/Sum.java
... ... @@ -7,13 +7,16 @@ import java.util.List;
7 7  
8 8 public class Sum extends Function {
9 9  
10   - public Sum(List<Cell> listCells) {
  10 +
  11 + private static final long serialVersionUID = 1L;
  12 +
  13 + public Sum(List<Cell> listCells) {
11 14 super(listCells);
12 15 this.names.put(LanguageEnum.FR, "SOMME");
13 16 this.names.put(LanguageEnum.EN, "SUM");
14 17 }
15 18  
16   - public Double eval() {
  19 + public double eval() {
17 20 return this.listCells.stream()
18 21 .mapToDouble(Cell::getValue)
19 22 .sum();
... ...
src/kernel/operation/Addition.java
... ... @@ -4,12 +4,19 @@ import kernel.Cell;
4 4  
5 5 public class Addition extends BinaryOperation {
6 6  
7   - public Addition(Cell leftCell, Cell rightCell) {
  7 +
  8 + private static final long serialVersionUID = 1L;
  9 +
  10 + public Addition(Cell leftCell, Cell rightCell) {
8 11 super(leftCell, rightCell);
9   - this.operator = "+";
  12 +
10 13 }
11   -
12   - public Double eval() {
  14 +
  15 + public String getOperator(){
  16 + return "+";
  17 + }
  18 +
  19 + public double eval() {
13 20  
14 21 return this.leftCell.getValue() + this.rightCell.getValue();
15 22 }
... ...
src/kernel/operation/BinaryOperation.java
... ... @@ -3,47 +3,50 @@ package kernel.operation;
3 3 import kernel.Cell;
4 4 import kernel.Formula;
5 5  
  6 +import java.io.Serializable;
6 7 import java.util.ArrayList;
7 8 import java.util.List;
8 9  
9   -abstract public class BinaryOperation implements Formula {
  10 +abstract public class BinaryOperation implements Formula,Serializable {
10 11  
11   - protected Cell leftCell;
  12 + private static final long serialVersionUID = 1L;
  13 + protected Cell leftCell;
12 14 protected Cell rightCell;
13   - protected String operator;
  15 +
14 16  
15 17 public BinaryOperation(Cell leftCell, Cell rightCell) {
16 18 this.leftCell = leftCell;
17 19 this.rightCell = rightCell;
18 20 }
19 21  
20   - abstract public Double eval();
21   -
  22 + abstract public double eval();
  23 + abstract public String getOperator();
22 24 public String getDevelopedFormula() {
23   - return "(" + this.leftCell.getDevelopedFormula() + this.operator + this.rightCell.getDevelopedFormula()+")";
  25 + return "(" + this.leftCell.getDevelopedFormula() + this.getOperator() + this.rightCell.getDevelopedFormula()+")";
24 26 }
25 27  
26 28 public String toString() {
27   - return this.leftCell.getId() + this.operator + this.rightCell.getId();
  29 + return this.leftCell.getId() + this.getOperator() + this.rightCell.getId();
28 30 }
29 31  
30   - public Boolean createCycle(Cell cell) {
  32 +
  33 + public boolean createCycle(Cell cell) {
31 34 if (this.leftCell.containFormula() && !this.rightCell.containFormula())
32 35 return this.leftCell.getFormula().createCycle(cell);
33   - else {
34   - if (!this.leftCell.containFormula() && this.rightCell.containFormula())
35   - return this.rightCell.getFormula().createCycle(cell);
36   - else {
37   - if (this.leftCell.containFormula() && this.rightCell.containFormula())
38   - return this.leftCell.getFormula().createCycle(cell) && this.rightCell.getFormula().createCycle(cell);
39   - else {
40   - return (cell.getId().equals(this.rightCell.getId()) || cell.getId().equals(this.leftCell.getId()));
41   - }
42   - }
43   -
44   - }
  36 +
  37 + if (!this.leftCell.containFormula() && this.rightCell.containFormula())
  38 + return this.rightCell.getFormula().createCycle(cell);
  39 +
  40 + if (this.leftCell.containFormula() && this.rightCell.containFormula())
  41 + return this.leftCell.getFormula().createCycle(cell) && this.rightCell.getFormula().createCycle(cell);
  42 +
  43 + return (cell.getId().equals(this.rightCell.getId()) || cell.getId().equals(this.leftCell.getId()));
  44 +
45 45 }
46 46  
  47 +
  48 +
  49 +
47 50 public List<Cell> getUtilisedCells() {
48 51 List<Cell> cells = new ArrayList<>();
49 52 cells.add(this.leftCell);
... ...
src/kernel/operation/Division.java
... ... @@ -4,12 +4,22 @@ import kernel.Cell;
4 4  
5 5 public class Division extends BinaryOperation {
6 6  
7   - public Division(Cell leftCell, Cell rightCell) {
  7 +
  8 + private static final long serialVersionUID = 1L;
  9 +
  10 + public Division(Cell leftCell, Cell rightCell) {
8 11 super(leftCell, rightCell);
9   - this.operator = "/";
  12 +
10 13 }
11 14  
12   - public Double eval() {
  15 +
  16 +
  17 + public String getOperator(){
  18 + return "/";
  19 + }
  20 +
  21 +
  22 + public double eval() {
13 23 return this.leftCell.getValue() / this.rightCell.getValue();
14 24 }
15 25 }
... ...
src/kernel/operation/Multiplication.java
... ... @@ -4,12 +4,19 @@ import kernel.Cell;
4 4  
5 5 public class Multiplication extends BinaryOperation {
6 6  
7   - public Multiplication(Cell leftCell, Cell rightCell) {
  7 + private static final long serialVersionUID = 1L;
  8 +
  9 + public Multiplication(Cell leftCell, Cell rightCell) {
8 10 super(leftCell, rightCell);
9   - this.operator = "*";
10   - }
11 11  
12   - public Double eval() {
  12 + }
  13 +
  14 + public String getOperator(){
  15 + return "*";
  16 + }
  17 +
  18 +
  19 + public double eval() {
13 20 return this.leftCell.getValue() * this.rightCell.getValue();
14 21 }
15 22 }
... ...
src/kernel/operation/Subtraction.java
... ... @@ -4,12 +4,20 @@ import kernel.Cell;
4 4  
5 5 public class Subtraction extends BinaryOperation {
6 6  
7   - public Subtraction(Cell leftCell, Cell rightCell) {
  7 + private static final long serialVersionUID = 1L;
  8 +
  9 + public Subtraction(Cell leftCell, Cell rightCell) {
8 10 super(leftCell, rightCell);
9   - this.operator = "-";
  11 +
10 12 }
11 13  
12   - public Double eval() {
  14 +
  15 + public String getOperator(){
  16 + return "-";
  17 + }
  18 +
  19 +
  20 + public double eval() {
13 21 return this.leftCell.getValue() - this.rightCell.getValue();
14 22 }
15 23 }
... ...
src/kernel/test/CellTest.java
... ... @@ -7,6 +7,7 @@ import java.util.List;
7 7  
8 8 import kernel.Cell;
9 9 import kernel.exception.CreateCycleException;
  10 +import kernel.exception.InvalidIntervalLineColumnEception;
10 11 import kernel.function.Average;
11 12 import kernel.function.Sum;
12 13 import kernel.operation.Addition;
... ... @@ -15,7 +16,7 @@ import kernel.operation.Addition;
15 16 public class CellTest {
16 17  
17 18 @org.junit.Test
18   - public void CreateCellValueTest() {
  19 + public void CreateCellValueTest() throws InvalidIntervalLineColumnEception {
19 20 Cell A1= new Cell("A",1,25.);
20 21 assertEquals(A1.getValue(),25.,0);
21 22 assertEquals(A1.containFormula(),false);
... ... @@ -25,7 +26,7 @@ public class CellTest {
25 26  
26 27  
27 28 @org.junit.Test
28   - public void CreateCellBinaryOperationTest() throws CreateCycleException {
  29 + public void CreateCellBinaryOperationTest() throws CreateCycleException, InvalidIntervalLineColumnEception {
29 30 Cell A1= new Cell("A",1,25.);
30 31 Cell A2= new Cell("A",2,35.);
31 32  
... ... @@ -46,7 +47,7 @@ public class CellTest {
46 47  
47 48  
48 49 @org.junit.Test
49   - public void CreateCellFunctionTest() throws CreateCycleException {
  50 + public void CreateCellFunctionTest() throws CreateCycleException, InvalidIntervalLineColumnEception {
50 51 Cell A1= new Cell("A",1,25.);
51 52 Cell A2= new Cell("A",2,35.);
52 53 Cell A3= new Cell("A",3,new Addition(A1,A2));
... ... @@ -75,7 +76,7 @@ public class CellTest {
75 76  
76 77  
77 78 @org.junit.Test
78   - public void ModifyCellValueTest() throws CreateCycleException {
  79 + public void ModifyCellValueTest() throws CreateCycleException, InvalidIntervalLineColumnEception {
79 80 Cell A1= new Cell("A",1,25.);
80 81 Cell A2= new Cell("A",2,35.);
81 82 Cell A3= new Cell("A",3,new Addition(A1,A2));
... ... @@ -89,7 +90,7 @@ public class CellTest {
89 90 }
90 91  
91 92 @org.junit.Test
92   - public void ModifyCellFormulaTest() throws CreateCycleException {
  93 + public void ModifyCellFormulaTest() throws CreateCycleException, InvalidIntervalLineColumnEception {
93 94 Cell A1= new Cell("A",1,25.);
94 95 Cell A2= new Cell("A",2,35.);
95 96 Cell A3= new Cell("A",3,new Addition(A1,A2));
... ... @@ -136,7 +137,7 @@ public class CellTest {
136 137 }
137 138  
138 139 @org.junit.Test(expected=CreateCycleException.class)
139   - public void DirectCycleBynaryOperation() throws CreateCycleException {
  140 + public void DirectCycleBynaryOperation() throws CreateCycleException, InvalidIntervalLineColumnEception {
140 141 Cell A1= new Cell("A",1,25.);
141 142 Cell A2= new Cell("A",2,35.);
142 143 try{
... ... @@ -149,7 +150,7 @@ public class CellTest {
149 150  
150 151  
151 152 @org.junit.Test(expected=CreateCycleException.class)
152   - public void DirectCycleFunction() throws CreateCycleException {
  153 + public void DirectCycleFunction() throws CreateCycleException, InvalidIntervalLineColumnEception {
153 154 Cell A2= new Cell("A",2,25.);
154 155 Cell B2= new Cell("B",2,35.);
155 156 Cell A3= new Cell("A",3,0.5);
... ... @@ -167,7 +168,7 @@ public class CellTest {
167 168 }
168 169  
169 170 @org.junit.Test(expected=CreateCycleException.class)
170   - public void IndirectCycle() throws CreateCycleException {
  171 + public void IndirectCycle() throws CreateCycleException, InvalidIntervalLineColumnEception {
171 172 Cell A1= new Cell("A",1,25.);
172 173 Cell A2= new Cell("A",2,5.);
173 174 Cell B4= new Cell("B",4,new Addition(A1,A2));
... ...