summaryrefslogtreecommitdiff
path: root/graphs/java/pizzaStreams
diff options
context:
space:
mode:
Diffstat (limited to 'graphs/java/pizzaStreams')
-rw-r--r--graphs/java/pizzaStreams/.gitignore38
-rw-r--r--graphs/java/pizzaStreams/pom.xml138
-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
6 files changed, 381 insertions, 0 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>fr.epita.assistants</groupId>
+ <artifactId>pizzaStreams</artifactId>
+ <version>1.0</version>
+
+ <properties>
+ <versions.java>21</versions.java>
+ <versions.junit>5.9.1</versions.junit>
+ <versions.maven-compiler-plugin>3.13.0</versions.maven-compiler-plugin>
+ <versions.maven-surefire-plugin>3.5.0</versions.maven-surefire-plugin>
+ <versions.maven-jar-plugin>3.1.1</versions.maven-jar-plugin>
+ <versions.maven-install-plugin>3.1.0</versions.maven-install-plugin>
+
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <surefire.reportsDirectory>${project.build.directory}/surefire-reports</surefire.reportsDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <version>${versions.junit}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-junit-platform</artifactId>
+ <version>${versions.maven-surefire-plugin}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-compat</artifactId>
+ <version>3.9.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>3.9.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-monitor</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>3.0.24</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-filtering</artifactId>
+ <version>3.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-interpolation</artifactId>
+ <version>1.13</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-profile</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact-manager</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-registry</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-repository-metadata</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>classworlds</groupId>
+ <artifactId>classworlds</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-commons</artifactId>
+ <version>1.9.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>3.29.2-GA</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${versions.maven-compiler-plugin}</version>
+ <configuration>
+ <source>${versions.java}</source>
+ <target>${versions.java}</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>${versions.maven-install-plugin}</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${versions.maven-surefire-plugin}</version>
+ <configuration>
+ <reportsDirectory>${surefire.reportsDirectory}</reportsDirectory>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
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());
+ }
+}