Skip to content

Commit

Permalink
- Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbiehl committed Mar 27, 2013
1 parent 7efaac4 commit 12a45a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public void addBasketPosition(BasketItem basketItem) {

this.basketDataProvider.getList().remove(bi);

basketItem = basketItem.addAmount(bi.getAmount()).updateDiscount(
basketItem = basketItem.updateAmount(
bi.getAmount() + basketItem.getAmount()).updateDiscount(
bi.getDiscount());
}

Expand Down Expand Up @@ -176,16 +177,11 @@ private class AmountUpdater implements FieldUpdater<BasketItem, String> {
@Override
public void update(int index, BasketItem object, String value) {
BasketItem toUpdate;
if (value.matches("[1-9][0-9]*")) {
toUpdate = new BasketItem(object.getItemName(),
object.getItemPrice(), object.getArticleId(),
Integer.valueOf(value), object.getDiscount());

} else {
toUpdate = new BasketItem(object.getItemName(),
object.getItemPrice(), object.getArticleId(), 1,
object.getDiscount());
}

int amountVal = value.matches("[1-9][0-9]*") ? Integer
.valueOf(value) : 1;

toUpdate = object.updateAmount(amountVal);

BasketController.this.basketDataProvider.getList().remove(object);
BasketController.this.basketDataProvider.getList().add(toUpdate);
Expand All @@ -212,9 +208,7 @@ public void update(int index, BasketItem object, String value) {
int discountVal = value.matches("[0-9]+") ? Integer.valueOf(value)
: 0;

toUpdate = new BasketItem(object.getItemName(),
object.getItemPrice(), object.getArticleId(),
object.getAmount(), discountVal);
toUpdate = object.updateDiscount(discountVal);

BasketController.this.basketDataProvider.getList().remove(object);
BasketController.this.basketDataProvider.getList().add(toUpdate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public EuroAmount totalWithDiscount() {
return total().withDiscount(discount);
}

public BasketItem addAmount(int amount) {
return new BasketItem(itemName, itemPrice, articleId, amount + this.amount, discount);
public BasketItem updateAmount(int amount) {
return new BasketItem(itemName, itemPrice, articleId, amount, discount);
}

public BasketItem updateDiscount(int discount) {
Expand Down

0 comments on commit 12a45a6

Please sign in to comment.