| 1 | package model; | |
| 2 | ||
| 3 | import exception.GenericError; | |
| 4 | import model.maglietta.MagliettaBean; | |
| 5 | import model.maglietta.MagliettaDAO; | |
| 6 | import model.maglietta.MagliettaOrdine; | |
| 7 | ||
| 8 | import java.io.Serializable; | |
| 9 | import java.sql.SQLException; | |
| 10 | import java.util.ArrayList; | |
| 11 | import java.util.List; | |
| 12 | ||
| 13 | public class CarrelloModel implements Serializable { | |
| 14 | private static final long serialVersionUID = 1L; | |
| 15 | private transient ArrayList<MagliettaOrdine> carrello; | |
| 16 | private final transient MagliettaDAO magliettaDAO; | |
| 17 | ||
| 18 | public CarrelloModel() { | |
| 19 | this(new MagliettaDAO()); | |
| 20 | } | |
| 21 | ||
| 22 | public CarrelloModel(MagliettaDAO dao) { | |
| 23 | this.carrello = new ArrayList<>(); | |
| 24 | this.magliettaDAO = dao; | |
| 25 | } | |
| 26 | ||
| 27 | public List<MagliettaOrdine> getCarrello() { | |
| 28 |
1
1. getCarrello : replaced return value with Collections.emptyList for model/CarrelloModel::getCarrello → KILLED |
return carrello; |
| 29 | } | |
| 30 | ||
| 31 | public void setCarrello(List<MagliettaOrdine> carrello) { | |
| 32 | this.carrello = (ArrayList<MagliettaOrdine>) carrello; | |
| 33 | } | |
| 34 | ||
| 35 | public synchronized void aggiungi(int id, String taglia) { | |
| 36 | for (MagliettaOrdine m : carrello) { | |
| 37 |
1
1. aggiungi : negated conditional → KILLED |
if (m.getMagliettaBean().getID() == id && |
| 38 |
1
1. aggiungi : negated conditional → KILLED |
m.getTaglia().equals(taglia)) { |
| 39 |
1
1. aggiungi : removed call to model/maglietta/MagliettaOrdine::incrementaQuantita → KILLED |
m.incrementaQuantita(); |
| 40 | return; | |
| 41 | } | |
| 42 | } | |
| 43 | ||
| 44 | try { | |
| 45 | MagliettaBean magliettaBean = magliettaDAO.doRetrieveByKey(id); | |
| 46 | carrello.add(new MagliettaOrdine(magliettaBean, taglia)); | |
| 47 | } catch (SQLException e) { | |
| 48 | throw new GenericError(); | |
| 49 | } | |
| 50 | } | |
| 51 | ||
| 52 | public synchronized void setQuantita(int id, int quantita, String taglia) { | |
| 53 | for (MagliettaOrdine m : carrello) { | |
| 54 |
2
1. setQuantita : negated conditional → KILLED 2. setQuantita : negated conditional → KILLED |
if (m.getMagliettaBean().getID() == id && m.getTaglia().equals(taglia)) { |
| 55 |
3
1. setQuantita : negated conditional → KILLED 2. setQuantita : negated conditional → KILLED 3. setQuantita : changed conditional boundary → KILLED |
if (m.getQuantita() <= 0 || quantita == 0) |
| 56 | carrello.remove(m); | |
| 57 | else | |
| 58 |
1
1. setQuantita : removed call to model/maglietta/MagliettaOrdine::setQuantita → KILLED |
m.setQuantita(quantita); |
| 59 | return; | |
| 60 | } | |
| 61 | } | |
| 62 | } | |
| 63 | ||
| 64 | public synchronized void rimuovi(int id, String taglia) { | |
| 65 |
2
1. lambda$rimuovi$0 : replaced boolean return with true for model/CarrelloModel::lambda$rimuovi$0 → KILLED 2. lambda$rimuovi$0 : negated conditional → KILLED |
carrello.removeIf(m -> m.getMagliettaBean().getID() == id && |
| 66 |
1
1. lambda$rimuovi$0 : negated conditional → KILLED |
m.getTaglia().equals(taglia)); |
| 67 | } | |
| 68 | ||
| 69 | } | |
Mutations | ||
| 28 |
1.1 |
|
| 37 |
1.1 |
|
| 38 |
1.1 |
|
| 39 |
1.1 |
|
| 54 |
1.1 2.2 |
|
| 55 |
1.1 2.2 3.3 |
|
| 58 |
1.1 |
|
| 65 |
1.1 2.2 |
|
| 66 |
1.1 |