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 7efaac42e731f31e6c71a8f8a2ebac78323567ea 1 parent 4a1a872
@alexbiehl alexbiehl authored
View
57 src/main/java/org/fhw/asta/kasse/client/controller/BasketController.java
@@ -88,38 +88,22 @@ public void init(BasketWidget basketWidget) {
basketWidget.getMatrNrBox().addValueChangeHandler(this.matrNrUpdater);
}
- private static class SameArticleIdPredicate implements
- Predicate<BasketItem> {
-
- private final int articleId;
-
- public SameArticleIdPredicate(int articleId) {
- this.articleId = articleId;
- }
-
- @Override
- public boolean apply(@Nullable BasketItem input) {
- return input.getArticleId() == articleId;
- }
-
- }
-
public void addBasketPosition(BasketItem basketItem) {
Optional<BasketItem> maybeBasketItem = Iterables.tryFind(
basketDataProvider.getList(), new SameArticleIdPredicate(
basketItem.getArticleId()));
-
if (maybeBasketItem.isPresent()) {
-
+
BasketItem bi = maybeBasketItem.get();
-
+
this.basketDataProvider.getList().remove(bi);
- basketItem = basketItem.addAmount(bi.getAmount()).updateDiscount(bi.getDiscount());
+ basketItem = basketItem.addAmount(bi.getAmount()).updateDiscount(
+ bi.getDiscount());
}
-
+
this.basketDataProvider.getList().add(basketItem);
this.flush();
}
@@ -225,15 +209,12 @@ public void update(int index, BasketItem object, String value) {
public void update(int index, BasketItem object, String value) {
BasketItem toUpdate;
- if (value.matches("[0-9]+")) {
- toUpdate = new BasketItem(object.getItemName(),
- object.getItemPrice(), object.getArticleId(),
- object.getAmount(), Integer.valueOf(value));
- } else {
- toUpdate = new BasketItem(object.getItemName(),
- object.getItemPrice(), object.getArticleId(),
- object.getAmount(), 0);
- }
+ int discountVal = value.matches("[0-9]+") ? Integer.valueOf(value)
+ : 0;
+
+ toUpdate = new BasketItem(object.getItemName(),
+ object.getItemPrice(), object.getArticleId(),
+ object.getAmount(), discountVal);
BasketController.this.basketDataProvider.getList().remove(object);
BasketController.this.basketDataProvider.getList().add(toUpdate);
@@ -305,4 +286,20 @@ public void onSuccess(Integer result) {
}
+ private static class SameArticleIdPredicate implements
+ Predicate<BasketItem> {
+
+ private final int articleId;
+
+ public SameArticleIdPredicate(int articleId) {
+ this.articleId = articleId;
+ }
+
+ @Override
+ public boolean apply(@Nullable BasketItem input) {
+ return input.getArticleId() == articleId;
+ }
+
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.