From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/java/pizzaStreams/.gitignore | 38 ++++++ graphs/java/pizzaStreams/pom.xml | 138 +++++++++++++++++++++ .../fr/epita/assistants/pizzastreams/Dough.java | 16 +++ .../fr/epita/assistants/pizzastreams/Pizza.java | 47 +++++++ .../assistants/pizzastreams/PizzaStreams.java | 60 +++++++++ .../fr/epita/assistants/pizzastreams/Topping.java | 82 ++++++++++++ 6 files changed, 381 insertions(+) create mode 100644 graphs/java/pizzaStreams/.gitignore create mode 100644 graphs/java/pizzaStreams/pom.xml create mode 100644 graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Dough.java create mode 100644 graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Pizza.java create mode 100644 graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/PizzaStreams.java create mode 100644 graphs/java/pizzaStreams/src/main/java/fr/epita/assistants/pizzastreams/Topping.java (limited to 'graphs/java/pizzaStreams') diff --git a/graphs/java/pizzaStreams/.gitignore b/graphs/java/pizzaStreams/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/graphs/java/pizzaStreams/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/graphs/java/pizzaStreams/pom.xml b/graphs/java/pizzaStreams/pom.xml new file mode 100644 index 0000000..ffa630f --- /dev/null +++ b/graphs/java/pizzaStreams/pom.xml @@ -0,0 +1,138 @@ + + + 4.0.0 + fr.epita.assistants + pizzaStreams + 1.0 + + + 21 + 5.9.1 + 3.13.0 + 3.5.0 + 3.1.1 + 3.1.0 + + UTF-8 + + ${project.build.directory}/surefire-reports + + + + + org.junit.jupiter + junit-jupiter + ${versions.junit} + + + org.apache.maven.surefire + surefire-junit-platform + ${versions.maven-surefire-plugin} + + + org.apache.maven + maven-compat + 3.9.8 + + + org.apache.maven + maven-plugin-api + 3.9.8 + + + org.apache.maven + maven-project + 2.2.1 + + + org.apache.maven + maven-core + 3.8.1 + + + org.apache.maven + maven-monitor + 2.2.1 + + + org.codehaus.plexus + plexus-utils + 3.0.24 + + + org.apache.maven.shared + maven-filtering + 3.3.2 + + + org.codehaus.plexus + plexus-interpolation + 1.13 + + + org.apache.maven + maven-profile + 2.2.1 + + + org.apache.maven + maven-artifact-manager + 2.2.1 + + + org.apache.maven + maven-plugin-registry + 2.2.1 + + + org.apache.maven + maven-repository-metadata + 2.2.1 + + + classworlds + classworlds + 1.1 + + + org.junit.platform + junit-platform-commons + 1.9.3 + + + org.javassist + javassist + 3.29.2-GA + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${versions.maven-compiler-plugin} + + ${versions.java} + ${versions.java} + + + + org.apache.maven.plugins + maven-install-plugin + ${versions.maven-install-plugin} + + + + org.apache.maven.plugins + maven-surefire-plugin + ${versions.maven-surefire-plugin} + + ${surefire.reportsDirectory} + + + + + 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 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 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 pizzaStream) { + return pizzaStream.mapToDouble(Pizza::getPrice).average().orElse(Double.NaN); + } + + /** + * @return Names of the pizzas, sorted by price in ascending order + */ + public static List sortByPrice(Stream 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 pizzaStream) { + return pizzaStream.min(Comparator.comparing(Pizza::getPrice)).orElse(null); + } + + /** + * @return Names of the pizzas with meat (Protein) + */ + public static List getCarnivorous(Stream 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 getVeggies(Stream 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 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 vegetableList; + private final Protein protein; + + public Topping(final Sauce sauce, final Cheese cheese, final List 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 getVegetableList() { + return vegetableList; + } + + public Optional 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()); + } +} -- cgit v1.2.3