From 420c77853bb86d523237f581cd31a07dab91f2e7 Mon Sep 17 00:00:00 2001 From: Lukas Karsch <lk224@hdm-stuttgart.de> Date: Wed, 7 Jun 2023 17:40:40 +0200 Subject: [PATCH] fixed hashcode bug for ingredients --- src/main/java/mi/hdm/GuiController.java | 4 +-- src/main/java/mi/hdm/TastyPages.java | 2 +- .../controllers/RecipeCreatorController.java | 4 +++ .../java/mi/hdm/recipes/NutritionTable.java | 5 +++ src/main/resources/fxml/recipe-creator.fxml | 31 +++++++++++++++++++ .../mi/hdm/recipes/NutritionTableTest.java | 3 +- 6 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 src/main/java/mi/hdm/controllers/RecipeCreatorController.java create mode 100644 src/main/resources/fxml/recipe-creator.fxml diff --git a/src/main/java/mi/hdm/GuiController.java b/src/main/java/mi/hdm/GuiController.java index 71ad1f0..b4ebf46 100644 --- a/src/main/java/mi/hdm/GuiController.java +++ b/src/main/java/mi/hdm/GuiController.java @@ -21,12 +21,12 @@ public class GuiController extends Application { log.info("Starting TastyPages"); try { model = FileManager.deserializeFromFilesystem(); + model.createRecipe(); } catch (Exception e) { - log.fatal("Internal exception, check filepaths and URIs"); + log.fatal("Internal exception, check file paths and URIs"); e.printStackTrace(); System.exit(1); } - model.createRecipe(); launch(args); log.info("Shutting down application"); log.info("Saving all data"); diff --git a/src/main/java/mi/hdm/TastyPages.java b/src/main/java/mi/hdm/TastyPages.java index 77f7092..fc5ee4d 100644 --- a/src/main/java/mi/hdm/TastyPages.java +++ b/src/main/java/mi/hdm/TastyPages.java @@ -78,7 +78,7 @@ public class TastyPages { public void createRecipe() { //TODO: write correct default recipe for demo (create it in app and save it from there -> no need to search ingredient keys) String name = "Something"; - Map<RecipeComponent, Integer> ingredients = Map.of(ingredientManager.getIngredient("i-1005353693").get(), 5); + Map<RecipeComponent, Integer> ingredients = Map.of(ingredientManager.getIngredient("i1912137995").get(), 5); String description = "10-Minuten-Rezept"; List<String> preparation = List.of("Put it in a pan and heat it."); List<Category> categories = List.of(); diff --git a/src/main/java/mi/hdm/controllers/RecipeCreatorController.java b/src/main/java/mi/hdm/controllers/RecipeCreatorController.java new file mode 100644 index 0000000..72a3989 --- /dev/null +++ b/src/main/java/mi/hdm/controllers/RecipeCreatorController.java @@ -0,0 +1,4 @@ +package mi.hdm.controllers; + +public class RecipeCreatorController { +} diff --git a/src/main/java/mi/hdm/recipes/NutritionTable.java b/src/main/java/mi/hdm/recipes/NutritionTable.java index 0ef2320..9809fd0 100644 --- a/src/main/java/mi/hdm/recipes/NutritionTable.java +++ b/src/main/java/mi/hdm/recipes/NutritionTable.java @@ -96,4 +96,9 @@ public class NutritionTable { public static NutritionTable empty() { return new NutritionTable(); } + + @Override + public int hashCode() { + return toString().hashCode(); + } } diff --git a/src/main/resources/fxml/recipe-creator.fxml b/src/main/resources/fxml/recipe-creator.fxml new file mode 100644 index 0000000..ad7005f --- /dev/null +++ b/src/main/resources/fxml/recipe-creator.fxml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.geometry.Insets?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.control.SplitPane?> +<?import javafx.scene.control.TextField?> +<?import javafx.scene.layout.*?> +<AnchorPane prefHeight="800" prefWidth="1200.0" xmlns="http://javafx.com/javafx/17.0.2-ea" + xmlns:fx="http://javafx.com/fxml/1" fx:controller="mi.hdm.controllers.RecipeCreatorController"> + <children> + <SplitPane dividerPositions="0.5" prefHeight="160.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" + AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0"> + <items> + <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> + <children> + <VBox prefHeight="200.0" prefWidth="100.0"> + <children> + <Label text="Recipe name"/> + <TextField/> + </children> + </VBox> + </children> + </AnchorPane> + <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"/> + </items> + </SplitPane> + </children> + <padding> + <Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/> + </padding> +</AnchorPane> diff --git a/src/test/java/mi/hdm/recipes/NutritionTableTest.java b/src/test/java/mi/hdm/recipes/NutritionTableTest.java index 23f20dd..5347d69 100644 --- a/src/test/java/mi/hdm/recipes/NutritionTableTest.java +++ b/src/test/java/mi/hdm/recipes/NutritionTableTest.java @@ -47,7 +47,6 @@ public class NutritionTableTest { NutritionTable underTestEqualToOne = new NutritionTable(100.0, 17.2, 9.4, 4.3, 2.4, 0.4); Assertions.assertNotEquals(underTestOne, underTestTwo); - Assertions.assertEquals(underTestEqualToOne, underTestEqualToOne); + Assertions.assertEquals(underTestEqualToOne, underTestOne); } - } \ No newline at end of file -- GitLab