From 022446ff2fa96de35ba8bee82fd32a84f1cd0251 Mon Sep 17 00:00:00 2001 From: Liboskat Date: Fri, 21 Jun 2019 18:54:11 +0300 Subject: [PATCH 1/4] init --- src/main/java/model/Pizza.java | 59 ++++++++++++---------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/src/main/java/model/Pizza.java b/src/main/java/model/Pizza.java index 8096217..cf54c65 100644 --- a/src/main/java/model/Pizza.java +++ b/src/main/java/model/Pizza.java @@ -15,62 +15,46 @@ public Pizza() { } - public Pizza( - int size, HashMap ingredients - ) { + public Pizza(int size, HashMap ingredients) { this.size = size; this.ingredients = ingredients; } - public void addIngredient( - Ingredient ingredient, - int count - ) throws PizzaException { - if (ingredient != null && count > 0) { - // Проверка на существование коллекции - if (!ingredientsCollectionNotNull()) - initIngredientsCollection(); - // Если элемент уже существует + public boolean isNotNull(Ingredient ingredient, int count) { + if (ingredient != null && count > 0 && !ingredientsCollectionNotNull()) { + initIngredientsCollection(); + return true; + } + return false; + } + + public void addIngredient(Ingredient ingredient, int count) throws PizzaException { + if(isNotNull(ingredient, count)) { if (ingredients.containsKey(ingredient)) { int alreadyExistIngredientCount = ingredients.get( ingredient); ingredients.put( ingredient, alreadyExistIngredientCount + count); - // Если не существует } else { ingredients.put(ingredient, count); } } else - throw new PizzaException( - "Указан некорректный ингредиент или его количество"); + throw new PizzaException("Указан некорректный ингредиент или его количество"); } - public void removeIngredient( - Ingredient ingredient, - int count - ) throws PizzaException { - if (ingredient != null && count > 0) { - // Проверка на существование коллекции - if (!ingredientsCollectionNotNull()) - initIngredientsCollection(); - // Если элемент уже существует - if (ingredients.containsKey(ingredient)) { + public void removeIngredient(Ingredient ingredient, int count) throws PizzaException { + if (isNotNull(ingredient, count)){ + if (ingredients.containsKey(ingredient)) { int alreadyExistIngredientCount = ingredients.get( - ingredient); - // Если количество уже существующих элементов больше либо - // равно количеству удаляемых + ingredient); if (Math.abs(count) >= alreadyExistIngredientCount) ingredients.remove(ingredient); else ingredients.put( - ingredient, alreadyExistIngredientCount - count); - // Если элемента не сущетсвует - } else - throw new PizzaException( - "Вы пытаетесь удалить ингредиент, который не существует в пицце"); - } else - throw new PizzaException( - "Указан некорректный ингредиент или его количество"); + ingredient, alreadyExistIngredientCount - count); + } else + throw new PizzaException("Вы пытаетесь удалить ингредиент, который не существует в пицце"); + } } private boolean ingredientsCollectionNotNull() { @@ -78,10 +62,9 @@ private boolean ingredientsCollectionNotNull() { } private void initIngredientsCollection() { - ingredients = new HashMap(); + ingredients = new HashMap<>(); } - // -- Getters & Setters -- public int getSize() { return size; From 42780dbd6a54057d7555fe23f5b5f451dfe05bc7 Mon Sep 17 00:00:00 2001 From: Liboskat Date: Mon, 24 Jun 2019 19:45:22 +0300 Subject: [PATCH 2/4] added tests --- .idea/.name | 1 + .idea/compiler.xml | 16 + ..._org_apiguardian_apiguardian_api_1_0_0.xml | 13 + ..._junit_jupiter_junit_jupiter_api_5_3_2.xml | 13 + ..._platform_junit_platform_commons_1_3_2.xml | 13 + ...Maven__org_opentest4j_opentest4j_1_1_1.xml | 13 + .idea/misc.xml | 13 + .idea/modules.xml | 8 + .idea/uiDesigner.xml | 124 +++++ .idea/vcs.xml | 6 + .idea/workspace.xml | 457 ++++++++++++++++++ pizza-order-training.iml | 18 + pom.xml | 19 +- src/main/java/model/Pizza.java | 18 +- src/main/tests/model/PizzaTests.java | 35 ++ target/classes/PizzaOrder.class | Bin 0 -> 4056 bytes target/classes/controller/CliController.class | Bin 0 -> 4784 bytes target/classes/model/DefaultStorage.class | Bin 0 -> 2357 bytes target/classes/model/Ingredient.class | Bin 0 -> 1066 bytes target/classes/model/Pizza.class | Bin 0 -> 3031 bytes target/classes/model/PizzaException.class | Bin 0 -> 541 bytes target/classes/model/Storage.class | Bin 0 -> 544 bytes target/classes/model/StorageException.class | Bin 0 -> 556 bytes target/test-classes/model/PizzaTests.class | Bin 0 -> 1274 bytes 24 files changed, 757 insertions(+), 10 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml create mode 100644 .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_3_2.xml create mode 100644 .idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_3_2.xml create mode 100644 .idea/libraries/Maven__org_opentest4j_opentest4j_1_1_1.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 pizza-order-training.iml create mode 100644 src/main/tests/model/PizzaTests.java create mode 100644 target/classes/PizzaOrder.class create mode 100644 target/classes/controller/CliController.class create mode 100644 target/classes/model/DefaultStorage.class create mode 100644 target/classes/model/Ingredient.class create mode 100644 target/classes/model/Pizza.class create mode 100644 target/classes/model/PizzaException.class create mode 100644 target/classes/model/Storage.class create mode 100644 target/classes/model/StorageException.class create mode 100644 target/test-classes/model/PizzaTests.class diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..ecd3ab2 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +pizza-order-training \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b9c722a --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml new file mode 100644 index 0000000..a82457d --- /dev/null +++ b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_3_2.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_3_2.xml new file mode 100644 index 0000000..75b2f5e --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_3_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_3_2.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_3_2.xml new file mode 100644 index 0000000..26372d3 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_3_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_1.xml b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_1.xml new file mode 100644 index 0000000..70277df --- /dev/null +++ b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d30d09e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b9db595 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..6570014 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,457 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +