Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/main/java/io/shodo/BasketInformations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.shodo;

import java.util.HashMap;

/**
* Created by thomas on 02/12/2019.
* This class is a basket
*/
public class BasketInformations {

// The product of the basket
static HashMap<String, Integer> map = new HashMap<String, Integer>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming can be better, what is this a map of?


// The fact that the basket has promo code
private static boolean codeDePromotion = false;

public void addProductToBasket(String product, Integer price, boolean isPromoCode) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

price better be double to accomodate decimals.

if (isPromoCode) {
codeDePromotion = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we convey to callers that adding to basket failed or was not done?

} else {
map.put(product, price);
}
}

public Long getBasketPrice(boolean inCents) {
Integer v = 0;
for (String s : map.keySet()) {
v += map.get(s);
}
if (codeDePromotion) {
v -= 100;
}
return inCents ? v * 100 : Long.valueOf(v);
}

public void resetBasket() {
buyBasket();
codeDePromotion = false;
}

public void buyBasket() {
map.clear();
}

public boolean isBasketContains(String produit) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spell check, produit -> product?

boolean found = false;
for (String s : map.keySet()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not directly do map,get ?

if (s == produit) found = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return true if found, dont need to continue the loop.

}
return found;
}

public void mixWithBasket(BasketInformations b) {
map.putAll(b.map);
}
}