Module Client : correction bug commit update StockScreenModel; Les méthds de la clss UpdateBuilder sont désormais chainables

This commit is contained in:
Notmoo 2017-08-19 20:54:35 +02:00
parent 90985fbc46
commit 2cbe949b03
2 changed files with 9 additions and 6 deletions

View File

@ -35,15 +35,15 @@ class StockScreenModel {
} }
void commitProductDeletion(Product product) { void commitProductDeletion(Product product) {
stockService.commitUpdate(stockService.getNewUpdateBuilder().removeProduct(product));
} }
void commitProductModification(Product oldProduct, Product newProduct) { void commitProductModification(Product oldProduct, Product newProduct) {
stockService.commitUpdate(stockService.getNewUpdateBuilder().modifyProduct(oldProduct, newProduct));
} }
void commitProductAddition(Product product) { void commitProductAddition(Product product) {
stockService.commitUpdate(stockService.getNewUpdateBuilder().addProduct(product));
} }
void addListener(IStockScreenModelListener l){ void addListener(IStockScreenModelListener l){

View File

@ -16,20 +16,23 @@ public class UpdateBuilder {
toModify = new HashMap<>(); toModify = new HashMap<>();
} }
public void addProduct(Product product) { public UpdateBuilder addProduct(Product product) {
if(!toAdd.contains(product)){ if(!toAdd.contains(product)){
toAdd.add(product); toAdd.add(product);
} }
return this;
} }
public void removeProduct(Product product) { public UpdateBuilder removeProduct(Product product) {
if(toRemove.contains(product)){ if(toRemove.contains(product)){
toRemove.remove(product); toRemove.remove(product);
} }
return this;
} }
public void modifyProduct(Product oldVersion, Product newVersion) { public UpdateBuilder modifyProduct(Product oldVersion, Product newVersion) {
toModify.put(oldVersion, newVersion); toModify.put(oldVersion, newVersion);
return this;
} }
public List<ProductUpdate> build() { public List<ProductUpdate> build() {