[CLIENT] #16 : Correction de bugs dans l'algo permetant de déterminer si la créa/modif de produit est valide

This commit is contained in:
Notmoo-PC\Notmoo 2018-01-24 21:50:56 +01:00
parent 55b7f7f4de
commit 0a5db85a9a
1 changed files with 27 additions and 3 deletions

View File

@ -1,9 +1,7 @@
package com.pqt.client.gui.modules.stock_screen.product_manager_screen;
import com.pqt.client.gui.ressources.strings.GUIStringTool;
import com.pqt.client.module.stock.StockService;
import com.pqt.core.entities.product.Category;
import com.pqt.core.entities.product.LightweightProduct;
import com.pqt.core.entities.product.Product;
import java.util.*;
@ -40,12 +38,38 @@ class ProductManagerScreenModel {
}
boolean isProductCreationPossible() {
return (initialData!=null && !currentData.equals(initialData))
return (initialData==null || !areProductsEqual(initialData, currentData))
&& !currentData.getName().isEmpty()
&& currentData.getCategory()!=null
&& currentData.getPrice()>=0;
}
private boolean areProductsEqual(Product p1, Product p2){
/*
Ces listes sont des différentiels entre les deux listes de composants des deux produits.
Elles sont toutes les deux vides ssi les produits ont les mêmes composants.
Si la liste diff de p1 contient un produit après le diff, c'est que ce produit n'était pas un composant de
p2, et vice-versa.
*/
List<Product> p1Diff = new ArrayList<>(p1.getComponents()),
p2Diff = new ArrayList<>(p2.getComponents());
p1Diff.removeAll(p2.getComponents());
p2Diff.removeAll(p1.getComponents());
return p1.getName().equals(p2.getName())
&& p1.getPrice() == p2.getPrice()
&& p1.getCategory() == p2.getCategory()
&& p1.getAmountSold() == p2.getAmountSold()
&& p1.getAmountRemaining() == p2.getAmountRemaining()
&& p1.isSellable() == p2.isSellable()
&& p1Diff.size()==0
&& p2Diff.size()==0;
}
void addComponent(Product product) {
currentData.getComponents().add(product);
}