Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Minor refactoring

  • Loading branch information...
commit 12a45a6e327e5d21bc241d71389de7ffad3a342d 1 parent 7efaac4
@alexbiehl alexbiehl authored
View
22 src/main/java/org/fhw/asta/kasse/client/controller/BasketController.java
@@ -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());
}
@@ -176,16 +177,11 @@ public void onClick(ClickEvent event) {
@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);
@@ -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);
View
4 src/main/java/org/fhw/asta/kasse/shared/basket/BasketItem.java
@@ -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) {
Please sign in to comment.
Something went wrong with that request. Please try again.