Created
May 14, 2016 17:12
-
-
Save HDBandit/566227fb24948ba548d4d638c1ed296c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Pizza { | |
private Ingredient[] ingredients; | |
private Function<Pizza, Pizza> complement; | |
private int basePrice; | |
public static Pizza newPizza(int price, Ingredient... ingredients) { | |
return new Pizza(price, ingredients); | |
} | |
private Pizza(int basePrice, Ingredient... ingredients) { | |
this.ingredients = ingredients; | |
this.basePrice = basePrice; | |
} | |
public void setComplements(Function<Pizza, Pizza>... complements) { | |
complement = Stream.of(complements).reduce(Function.identity(), Function::andThen); | |
} | |
public int getTotalPrice() { | |
Pizza p = complement.apply(this); | |
return p.getBasePrice(); | |
} | |
public int getBasePrice() { | |
return basePrice; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment