summaryrefslogtreecommitdiff
path: root/graphs/java/pizzaStreams/src/main
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
commitc9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch)
tree3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/java/pizzaStreams/src/main
add: graphs et rushs
Diffstat (limited to 'graphs/java/pizzaStreams/src/main')
-rw-r--r--graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Dough.java16
-rw-r--r--graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Pizza.java47
-rw-r--r--graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/PizzaStreams.java60
-rw-r--r--graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Topping.java82
4 files changed, 205 insertions, 0 deletions
diff --git a/graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Dough.java b/graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Dough.java
new file mode 100644
index 0000000..a0ea259
--- /dev/null
+++ b/graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Dough.java
@@ -0,0 +1,16 @@
+package fr.epita.assistants.pizzastreams;
+
+public enum Dough {
+ NATURE(2),
+ CAJUN(3);
+
+ private final Integer price;
+
+ Dough(final Integer price) {
+ this.price = price;
+ }
+
+ public Integer getPrice() {
+ return this.price;
+ }
+}
diff --git a/graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Pizza.java b/graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Pizza.java
new file mode 100644
index 0000000..d47b8da
--- /dev/null
+++ b/graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Pizza.java
@@ -0,0 +1,47 @@
+package fr.epita.assistants.pizzastreams;
+
+import fr.epita.assistants.pizzastreams.Topping.Cheese;
+import fr.epita.assistants.pizzastreams.Topping.Protein;
+import fr.epita.assistants.pizzastreams.Topping.Sauce;
+import fr.epita.assistants.pizzastreams.Topping.Vegetable;
+
+import java.util.List;
+
+public class Pizza {
+ private final String name;
+ private final Dough dough;
+ private final Topping topping;
+ private final Integer price;
+
+ public Pizza(final String name, final Dough dough, final Sauce sauce, final Cheese cheese,
+ final List<Vegetable> vegetableList, final Protein protein) {
+ this.name = name;
+ this.topping = new Topping(sauce, cheese, vegetableList, protein);
+ this.dough = dough;
+
+ final int doughPrice = dough.getPrice();
+ final int saucePrice = topping.getSaucePrice();
+ final int cheesePrice = topping.getCheesePrice();
+ final int vegetablesPrice = topping.getVegetablesPrice();
+ final int proteinPrice = topping.getProteinPrice();
+
+ this.price = doughPrice + saucePrice + cheesePrice + vegetablesPrice
+ + proteinPrice;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Dough getDough() {
+ return dough;
+ }
+
+ public Topping getTopping() {
+ return topping;
+ }
+
+ public Integer getPrice() {
+ return price;
+ }
+}
diff --git a/graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/PizzaStreams.java b/graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/PizzaStreams.java
new file mode 100644
index 0000000..26259a3
--- /dev/null
+++ b/graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/PizzaStreams.java
@@ -0,0 +1,60 @@
+package fr.epita.assistants.pizzastreams;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Stream;
+
+import fr.epita.assistants.pizzastreams.Topping.*;
+
+public class PizzaStreams {
+ /**
+ * @return The sum of the prices of all the pizzas in the stream
+ */
+ public static Integer getTotalPrice(Stream<Pizza> pizzaStream) {
+ return pizzaStream.mapToInt(Pizza::getPrice).sum();
+ }
+
+ /**
+ * @return The average price of the pizzas in the stream, or the
+ * double NaN if the stream is empty
+ */
+ public static Double getAveragePrice(Stream<Pizza> pizzaStream) {
+ return pizzaStream.mapToDouble(Pizza::getPrice).average().orElse(Double.NaN);
+ }
+
+ /**
+ * @return Names of the pizzas, sorted by price in ascending order
+ */
+ public static List<String> sortByPrice(Stream<Pizza> pizzaStream) {
+ return pizzaStream.sorted(Comparator.comparing(Pizza::getPrice)).map(Pizza::getName).toList();
+ }
+
+ /**
+ * @return The Pizza object that has the lowest price, or null by default
+ */
+ public static Pizza getCheapest(Stream<Pizza> pizzaStream) {
+ return pizzaStream.min(Comparator.comparing(Pizza::getPrice)).orElse(null);
+ }
+
+ /**
+ * @return Names of the pizzas with meat (Protein)
+ */
+ public static List<String> getCarnivorous(Stream<Pizza> pizzaStream) {
+ return pizzaStream.filter(i -> i.getTopping().getProtein().isPresent()).map(Pizza::getName).toList();
+ }
+
+ /**
+ * @return Names of the pizzas with at least one Vegetable and no Proteins
+ */
+ public static List<String> getVeggies(Stream<Pizza> pizzaStream) {
+ return pizzaStream.filter(i -> i.getTopping().getProtein().isEmpty() && !i.getTopping().getVegetableList().isEmpty()).map(Pizza::getName).toList();
+ }
+
+ /**
+ * @return true if all the pizzas with a nature dough are based with tomato
+ * and mozzarella (italian pizza criteria), false otherwise
+ */
+ public static boolean areAllNatureItalians(Stream<Pizza> pizzaStream) {
+ return pizzaStream.filter(i -> i.getDough() == Dough.NATURE).allMatch(i -> i.getTopping().getCheese() == Cheese.MOZZARELLA && i.getTopping().getSauce() == Sauce.TOMATO);
+ }
+}
diff --git a/graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Topping.java b/graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Topping.java
new file mode 100644
index 0000000..aaacb58
--- /dev/null
+++ b/graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Topping.java
@@ -0,0 +1,82 @@
+package fr.epita.assistants.pizzastreams;
+
+import java.util.List;
+import java.util.Optional;
+
+public class Topping {
+ public enum Sauce {
+ TOMATO,
+ BUFFALO,
+ PESTO,
+ }
+
+ public enum Cheese {
+ MOZZARELLA,
+ CHEDDAR,
+ CREAM,
+ }
+
+ public enum Vegetable {
+ OLIVE,
+ MUSHROOM,
+ ONION,
+ }
+
+ public enum Protein {
+ CHICKEN,
+ BACON,
+ MERGUEZ,
+ }
+
+ private final Sauce sauce;
+ private final Cheese cheese;
+ private final List<Vegetable> vegetableList;
+ private final Protein protein;
+
+ public Topping(final Sauce sauce, final Cheese cheese, final List<Vegetable> vegetableList,
+ final Protein protein) {
+ this.sauce = sauce;
+ this.cheese = cheese;
+ this.vegetableList = vegetableList;
+ this.protein = protein;
+ }
+
+ public Sauce getSauce() {
+ return sauce;
+ }
+
+ public Cheese getCheese() {
+ return cheese;
+ }
+
+ public List<Vegetable> getVegetableList() {
+ return vegetableList;
+ }
+
+ public Optional<Protein> getProtein() {
+ return Optional.ofNullable(protein);
+ }
+
+ public Integer getSaucePrice() {
+ return (sauce == Sauce.TOMATO) ? 1 : ((sauce == Sauce.BUFFALO) ? 2 : 3);
+ }
+
+ public Integer getCheesePrice() {
+ return (cheese == Cheese.MOZZARELLA) ? 2 : ((cheese == Cheese.CHEDDAR) ? 3 : 4);
+ }
+
+ public Integer getProteinPrice() {
+ return protein == null ? 0
+ : protein == Protein.CHICKEN ? 5 : 8;
+ }
+
+ public Integer getVegetablesPrice() {
+ return (vegetableList
+ .isEmpty()
+ ? 0
+ : vegetableList.stream()
+ .mapToInt((v) -> (v == Vegetable.OLIVE
+ || v == Vegetable.ONION) ? 1 : 2)
+ .sum());
+ }
+}