Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
public class ShoppingBasketBuilder {
private Map<Product, Integer> products = new HashMap<Product, Integer>();
public static ShoppingBasketBuilder aShoppingBasket() {
return new ShoppingBasketBuilder();
public ShoppingBasketBuilder with(Product product) {
this.products.put(product, 1);
return this;
public ShoppingBasketBuilder with(ProductBuilder productBuilder) {
return with(;
public ShoppingBasketBuilder with(Integer quantity, Product product) {
this.products.put(product, quantity);
return this;
public ShoppingBasketBuilder with(Integer quantity, ProductBuilder productBuider) {
return with(quantity,;
public ShoppingBasket build() {
ShoppingBasket shoppingBasket = new ShoppingBasket();
for (Map.Entry<Product, Integer> entry : products.entrySet()) {
shoppingBasket.add(entry.getKey(), entry.getValue());
return shoppingBasket;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.