From 320826e45fefae4cb41d2b14d1c565afcd541de8 Mon Sep 17 00:00:00 2001 From: Anders <anders.morille@gmail.com> Date: Mon, 19 Feb 2024 14:28:54 +0100 Subject: [PATCH 1/5] :fire: Removed .idea stuff --- .gitignore | 4 +++- .idea/.gitignore | 8 -------- .idea/encodings.xml | 7 ------- .idea/inspectionProfiles/Project_Default.xml | 14 -------------- .idea/misc.xml | 15 --------------- .idea/vcs.xml | 6 ------ 6 files changed, 3 insertions(+), 51 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index 5ff6309..3083309 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,6 @@ build/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store + +.idea/ diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index aa00ffa..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="Encoding"> - <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" /> - <file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" /> - </component> -</project> \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 5d3987f..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,14 +0,0 @@ -<component name="InspectionProjectProfileManager"> - <profile version="1.0"> - <option name="myName" value="Project Default" /> - <inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true"> - <option name="ignoredPackages"> - <value> - <list size="1"> - <item index="0" class="java.lang.String" itemvalue="mysqlclient" /> - </list> - </value> - </option> - </inspection_tool> - </profile> -</component> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index de4b033..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ExternalStorageConfigurationManager" enabled="true" /> - <component name="MavenProjectsManager"> - <option name="originalFiles"> - <list> - <option value="$PROJECT_DIR$/pom.xml" /> - </list> - </option> - <option name="workspaceImportForciblyTurnedOn" value="true" /> - </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK"> - <output url="file://$PROJECT_DIR$/out" /> - </component> -</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="VcsDirectoryMappings"> - <mapping directory="" vcs="Git" /> - </component> -</project> \ No newline at end of file -- GitLab From fa2179760190669ad09f5e4de836c5a761e3d85e Mon Sep 17 00:00:00 2001 From: Anders <anders.morille@gmail.com> Date: Mon, 19 Feb 2024 14:29:09 +0100 Subject: [PATCH 2/5] :sparkles: Created all model classes for the db --- .../model/Ingredient.java | 133 +++++++++++++ .../model/InventoryItem.java | 122 ++++++++++++ .../model/PlannedRecipe.java | 55 ++++++ .../model/Recipe.java | 177 ++++++++++++++++++ .../model/RecipeIngredient.java | 48 +++++ .../model/ShoppingListItem.java | 105 +++++++++++ 6 files changed, 640 insertions(+) create mode 100644 src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Ingredient.java create mode 100644 src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/InventoryItem.java create mode 100644 src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/PlannedRecipe.java create mode 100644 src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Recipe.java create mode 100644 src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/RecipeIngredient.java create mode 100644 src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/ShoppingListItem.java diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Ingredient.java b/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Ingredient.java new file mode 100644 index 0000000..0a418a2 --- /dev/null +++ b/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Ingredient.java @@ -0,0 +1,133 @@ +package idi.ntnu.no.idatt1005_gr8_prosjektoppgave.model; + +import java.util.Optional; + +/** + * Represents a single ingredient record in the database + */ +public class Ingredient { + /** + * The primary identifier and key for this row in the database + */ + private final int id; + + /** + * The name of this ingredient + */ + private final String name; + + /** + * The type of measuring unit used to measure this ingredient + */ + private final MeasuringUnit unit; + + /** + * The default amount of this ingredient unless otherwise is specified + */ + private final int defaultAmount; + + /** + * The ingredient category this ingredient belongs to, used to categorize ingredients + */ + private final Category category; + + /** + * Where this ingredient should be stored at home + */ + private final StorageType storageType; + + /** + * Construct an ingredient object using a value for each field + * You may pass -1 to defaultAmount in order to set a none value + * @param id The primary key + * @param name The name of the ingredient + * @param unit The unit to use + * @param defaultAmount The default amount. Either a positive integer or -1 for none + * @param category Food category + * @param storageType Where to store this ingredient at home + */ + public Ingredient(int id, String name, MeasuringUnit unit, int defaultAmount, Category category, StorageType storageType) { + this.id = id; + this.name = name; + this.unit = unit; + this.defaultAmount = defaultAmount; + this.category = category; + this.storageType = storageType; + } + + /** + * @return The ingredient id/primary key + */ + public int getId() { + return id; + } + + /** + * @return The name of the ingredient + */ + public String getName() { + return name; + } + + /** + * @return The measuring unit used for this ingredient + */ + public MeasuringUnit getUnit() { + return unit; + } + + /** + * @return The default amount of this ingredient. Is empty if there is no default amount + */ + public Optional<Integer> getDefaultAmount() { + return defaultAmount == -1 ? Optional.empty() : Optional.of(defaultAmount); + } + + /** + * @return The category this ingredient belongs to + */ + public Category getCategory() { + return category; + } + + /** + * @return The storage type where this ingredient should be stored + */ + public StorageType getStorageType() { + return storageType; + } + + /** + * All types of measuring units that can be used by ingredients + */ + public enum MeasuringUnit { + milliliter, + gram, + teaspoon, + spoon, + piece + } + + /** + * Food category of an ingredient + */ + public enum Category { + fruit, + vegetable, + meat, + dairy, + grain, + herb, + spice, + oil + } + + /** + * All places an ingredient can be stored at home + */ + public enum StorageType { + fridge, + freezer, + pantry + } +} diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/InventoryItem.java b/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/InventoryItem.java new file mode 100644 index 0000000..68f7e91 --- /dev/null +++ b/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/InventoryItem.java @@ -0,0 +1,122 @@ +package idi.ntnu.no.idatt1005_gr8_prosjektoppgave.model; + +import java.util.Optional; + +/** + * An item placed in the user's inventory. + */ +public class InventoryItem { + /** + * The id/primary key of the item. + */ + private final int id; + + /** + * The ingredient of the item, if it is not custom. + */ + private final Ingredient ingredient; + + /** + * The custom name of the item, if it is custom. + */ + private final String customName; + + /** + * The amount of the item. + */ + private final int amount; + + /** + * The planned recipe of the item, if it is planned. + */ + private final PlannedRecipe plannedRecipe; + + /** + * Creates a new inventory item using an ingredient reference + * + * @param id The id of the item. + * @param ingredient The ingredient of the item, if it is not custom. + * @param amount The amount of the item. + * @param plannedRecipe The planned recipe of the item, if it is planned. + */ + public InventoryItem(int id, Ingredient ingredient, int amount, + PlannedRecipe plannedRecipe) { + this.id = id; + this.ingredient = ingredient; + this.customName = null; + this.amount = amount; + this.plannedRecipe = plannedRecipe; + } + + /** + * Creates a new inventory item using a custom name + * + * @param id The id of the item. + * @param customName The custom name of the item, if it is custom. + * @param amount The amount of the item. + * @param plannedRecipe The planned recipe of the item, if it is planned. + */ + public InventoryItem(int id, String customName, int amount, + PlannedRecipe plannedRecipe) { + this.id = id; + this.ingredient = null; + this.customName = customName; + this.amount = amount; + this.plannedRecipe = plannedRecipe; + } + + + /** + * @return The id of the item. + */ + public int getId() { + return id; + } + + /** + * @return The ingredient of the item, if it is not custom. + */ + public Optional<Ingredient> getIngredient() { + return Optional.ofNullable(this.ingredient); + } + + /** + * @return The custom name of the item, if it is custom. + */ + public Optional<String> getCustomName() { + return Optional.of(this.customName); + } + + /** + * @return The amount of the item. + */ + public int getAmount() { + return amount; + } + + /** + * @return The planned recipe of the item, if it is planned. + */ + public Optional<PlannedRecipe> getPlannedRecipe() { + return Optional.ofNullable(this.plannedRecipe); + } + + /** + * @return True if the item is custom, false otherwise. + */ + public boolean isCustom() { + return this.customName != null; + } + + /** + * @return The name of the item. + * @throws NullPointerException if neither the customName nor the ingredient is set. + */ + public String getName() throws NullPointerException { + if (isCustom()) { + return this.customName; + } else { + return this.ingredient.getName(); + } + } +} diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/PlannedRecipe.java b/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/PlannedRecipe.java new file mode 100644 index 0000000..4467756 --- /dev/null +++ b/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/PlannedRecipe.java @@ -0,0 +1,55 @@ +package idi.ntnu.no.idatt1005_gr8_prosjektoppgave.model; + +import java.time.ZonedDateTime; + +/** + * A recipe that is planned in the future + * Can be looked on as a "Recipe instance" + */ +public class PlannedRecipe { + /** + * The primary key of this row in the database + */ + private final int id; + /** + * The recipe that is being planned/linked to + */ + private final Recipe recipe; + /** + * For when this recipe is being planned + */ + private final ZonedDateTime plannedDate; + + /** + * Creates a PlannedRecipe by filling in fields from the database + * @param id The primary key + * @param recipe The recipe to make + * @param plannedDate When it is planned + */ + public PlannedRecipe(int id, Recipe recipe, ZonedDateTime plannedDate) { + this.id = id; + this.recipe = recipe; + this.plannedDate = plannedDate; + } + + /** + * @return The primary key + */ + public int getId() { + return id; + } + + /** + * @return The recipe + */ + public Recipe getRecipe() { + return recipe; + } + + /** + * @return When it is planned + */ + public ZonedDateTime getPlannedDate() { + return plannedDate; + } +} diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Recipe.java b/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Recipe.java new file mode 100644 index 0000000..f98a752 --- /dev/null +++ b/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Recipe.java @@ -0,0 +1,177 @@ +package idi.ntnu.no.idatt1005_gr8_prosjektoppgave.model; + +import java.time.Duration; +import java.util.List; + +/** + * A single meal recipe + */ +public class Recipe { + /** + * The id/primary key of this recipe + */ + private final int id; + + /** + * The path to the markdown file containing all steps for this recipe in a list format + */ + private final List<String> steps; + + /** + * The meal category this recipe belongs to + */ + private final Category category; + + /** + * How long it usually takes to make this recipe + */ + private final Duration duration; + + /** + * How difficult it is to make this recipe + */ + private final Difficulty difficulty; + + /** + * The name of this recipe + */ + private final String name; + + /** + * The description of this recipe + */ + private final String description; + + /** + * Whether this recipe has been marked as a favorite by the user + */ + private final boolean isFavorite; + + /** + * A custom note attached to this recipe by the user + */ + private final String note; + + /** + * All ingredients required to make this recipe + */ + private final List<RecipeIngredient> ingredients; + + /** + * Construct a recipe using all fields from the database + * @param id The primary key of this record + * @param steps The steps required to make this recipe + * @param category The category + * @param duration The duration + * @param difficulty The difficulty + * @param name The name + * @param description The description + * @param isFavorite Whether this is marked as favorite + * @param note Custom note from user + * @param ingredients All ingredients in this recipe + */ + public Recipe(int id, List<String> steps, Category category, Duration duration, + Difficulty difficulty, String name, String description, boolean isFavorite, + String note, List<RecipeIngredient> ingredients) { + this.id = id; + this.steps = steps; + this.category = category; + this.duration = duration; + this.difficulty = difficulty; + this.name = name; + this.description = description; + this.isFavorite = isFavorite; + this.note = note; + this.ingredients = ingredients; + } + + /** + * @return The id / primary key + */ + public int getId() { + return id; + } + + /** + * @return All steps required to perform this recipe, in order + */ + public List<String> steps() { + return steps; + } + + /** + * @return The meal category + */ + public Category getCategory() { + return category; + } + + /** + * @return The duration of + */ + public Duration getDuration() { + return duration; + } + + /** + * @return The difficulty of this recipe + */ + public Difficulty getDifficulty() { + return difficulty; + } + + /** + * @return The name of the recipe + */ + public String getName() { + return name; + } + + /** + * @return The description + */ + public String getDescription() { + return description; + } + + /** + * @return Whether this is marked as favorite by the user + */ + public boolean isFavorite() { + return isFavorite; + } + + /** + * @return Custom user note on this recipe + */ + public String getNote() { + return note; + } + + /** + * @return Add required ingredients to make this recipe + */ + public List<RecipeIngredient> getIngredients() { + return ingredients; + } + + /** + * The type of meal + */ + public enum Category { + breakfast, + lunch, + dinner, + supper, + snacks + } + + /** + * The difficulty level on a recipe + */ + public enum Difficulty { + beginner, + intermediate, + expert + } +} diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/RecipeIngredient.java b/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/RecipeIngredient.java new file mode 100644 index 0000000..c02fd2d --- /dev/null +++ b/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/RecipeIngredient.java @@ -0,0 +1,48 @@ +package idi.ntnu.no.idatt1005_gr8_prosjektoppgave.model; + +/** + * An ingredient used in a recipe, with a specific amount and necessity. + */ +public class RecipeIngredient extends Ingredient { + /** + * The amount of the ingredient needed in the recipe. + */ + private final int amount; + + /** + * Whether the ingredient is necessary for the recipe. + */ + private final boolean isNecessary; + + /** + * Constructs a new RecipeIngredient. + * @param id The id of the ingredient. + * @param name The name of the ingredient. + * @param unit The measuring unit of the ingredient. + * @param defaultAmount The default amount of the ingredient. + * @param category The category of the ingredient. + * @param storageType The storage type of the ingredient. + * @param amount The amount of the ingredient needed in the recipe. + * @param isNecessary Whether the ingredient is necessary for the recipe. + */ + public RecipeIngredient(int id, String name, MeasuringUnit unit, int defaultAmount, + Category category, StorageType storageType, int amount, boolean isNecessary) { + super(id, name, unit, defaultAmount, category, storageType); + this.amount = amount; + this.isNecessary = isNecessary; + } + + /** + * Returns the amount of the ingredient needed in the recipe. + */ + public int getAmount() { + return amount; + } + + /** + * @return Whether this ingredient is necessary for the recipe. + */ + public boolean isNecessary() { + return isNecessary; + } +} diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/ShoppingListItem.java b/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/ShoppingListItem.java new file mode 100644 index 0000000..5130237 --- /dev/null +++ b/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/ShoppingListItem.java @@ -0,0 +1,105 @@ +package idi.ntnu.no.idatt1005_gr8_prosjektoppgave.model; + +import java.util.Optional; + +/** + * Represents a shopping list item. + */ +public class ShoppingListItem { + /** + * The id of the shopping list item. + */ + private final int id; + + /** + * The ingredient of the shopping list item. + */ + private final Ingredient ingredient; + + /** + * The custom name of the shopping list item. + */ + + private final String customName; + /** + * The amount of the shopping list item. + */ + + private final int amount; + /** + * The planned recipe of the shopping list item. + */ + + private final PlannedRecipe recipe; + + /** + * Initializes a newly created ShoppingListItem object using an ingredient reference + * @param id The id of the shopping list item. + * @param ingredient The ingredient of the shopping list item. + * @param amount The amount of the shopping list item. + * @param recipe The planned recipe of the shopping list item. + */ + public ShoppingListItem(int id, Ingredient ingredient, int amount, + PlannedRecipe recipe) { + this.id = id; + this.ingredient = ingredient; + this.customName = null; + this.amount = amount; + this.recipe = recipe; + } + + /** + * Initializes a newly created ShoppingListItem object using a custom name + * @param id The id of the shopping list item. + * @param customName The custom name of the shopping list item. + * @param amount The amount of the shopping list item. + * @param recipe The planned recipe of the shopping list item. + */ + public ShoppingListItem(int id, String customName, int amount, + PlannedRecipe recipe) { + this.id = id; + this.ingredient = null; + this.customName = customName; + this.amount = amount; + this.recipe = recipe; + } + + /** + * @return The id of the shopping list item. + */ + public int getId() { + return id; + } + + /** + * @return The ingredient of the shopping list item. Is empty if the shopping list item has a + * custom name instead of an ingredient reference. + */ + public Optional<Ingredient> getIngredient() { + return Optional.ofNullable(ingredient); + } + + /** + * @return The custom name assigned by the user. Is empty if the shopping list item has a + * reference to an ingredient instead of a custom name. + */ + public Optional<String> getCustomName() { + return Optional.ofNullable(customName); + } + + /** + * @return The amount of the shopping list item. + */ + public int getAmount() { + return amount; + } + + /** + * @return Get the planned recipe associated with this shopping list item, meaning the shopping + * list item exists to fulfill the ingredients of a planned recipe. Is empty if the shopping list + * item is not associated with a planned recipe. + */ + public Optional<PlannedRecipe> getRecipe() { + return Optional.ofNullable(recipe); + } +} -- GitLab From a38dd482017d58dea3eeb224b2e58b4ad95db32b Mon Sep 17 00:00:00 2001 From: Anders <anders.morille@gmail.com> Date: Mon, 19 Feb 2024 14:58:10 +0100 Subject: [PATCH 3/5] Added google checks config for code style --- google_checks.xml | 379 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 379 insertions(+) create mode 100644 google_checks.xml diff --git a/google_checks.xml b/google_checks.xml new file mode 100644 index 0000000..9a0fc83 --- /dev/null +++ b/google_checks.xml @@ -0,0 +1,379 @@ +<?xml version="1.0"?> +<!DOCTYPE module PUBLIC + "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" + "https://checkstyle.org/dtds/configuration_1_3.dtd"> + +<!-- + Checkstyle configuration that checks the Google coding conventions from Google Java Style + that can be found at https://google.github.io/styleguide/javaguide.html + + Checkstyle is very configurable. Be sure to read the documentation at + http://checkstyle.org (or in your downloaded distribution). + + To completely disable a check, just comment it out or delete it from the file. + To suppress certain violations please review suppression filters. + + Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov. + --> + +<module name="Checker"> + <module name="SuppressWarningsFilter"/> + + <property name="charset" value="UTF-8"/> + + <property name="severity" value="warning"/> + + <property name="fileExtensions" value="java, properties, xml"/> + <!-- Excludes all 'module-info.java' files --> + <!-- See https://checkstyle.org/filefilters/index.html --> + <module name="BeforeExecutionExclusionFileFilter"> + <property name="fileNamePattern" value="module\-info\.java$"/> + </module> + <!-- https://checkstyle.org/filters/suppressionfilter.html --> + <module name="SuppressionFilter"> + <property name="file" value="${org.checkstyle.google.suppressionfilter.config}" + default="checkstyle-suppressions.xml"/> + <property name="optional" value="true"/> + </module> + + <!-- Checks for whitespace --> + <!-- See http://checkstyle.org/checks/whitespace/index.html --> + <module name="FileTabCharacter"> + <property name="eachLine" value="true"/> + </module> + + <module name="LineLength"> + <property name="fileExtensions" value="java"/> + <property name="max" value="100"/> + <property name="ignorePattern" + value="^package.*|^import.*|a href|href|http://|https://|ftp://"/> + </module> + + <module name="TreeWalker"> + <module name="OuterTypeFilename"/> + <module name="IllegalTokenText"> + <property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/> + <property name="format" + value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/> + <property name="message" + value="Consider using special escape sequence instead of octal value or Unicode escaped value."/> + </module> + <module name="AvoidEscapedUnicodeCharacters"> + <property name="allowEscapesForControlCharacters" value="true"/> + <property name="allowByTailComment" value="true"/> + <property name="allowNonPrintableEscapes" value="true"/> + </module> + <module name="AvoidStarImport"/> + <module name="OneTopLevelClass"/> + <module name="NoLineWrap"> + <property name="tokens" value="PACKAGE_DEF, IMPORT, STATIC_IMPORT"/> + </module> + <module name="EmptyBlock"> + <property name="option" value="TEXT"/> + <property name="tokens" + value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/> + </module> + <module name="NeedBraces"> + <property name="tokens" + value="LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF, LITERAL_WHILE"/> + </module> + <module name="LeftCurly"> + <property name="tokens" + value="ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ENUM_DEF, + INTERFACE_DEF, LAMBDA, LITERAL_CASE, LITERAL_CATCH, LITERAL_DEFAULT, + LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, + LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, METHOD_DEF, + OBJBLOCK, STATIC_INIT, RECORD_DEF, COMPACT_CTOR_DEF"/> + </module> + <module name="RightCurly"> + <property name="id" value="RightCurlySame"/> + <property name="tokens" + value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, + LITERAL_DO"/> + </module> + <module name="RightCurly"> + <property name="id" value="RightCurlyAlone"/> + <property name="option" value="alone"/> + <property name="tokens" + value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT, + INSTANCE_INIT, ANNOTATION_DEF, ENUM_DEF, INTERFACE_DEF, RECORD_DEF, + COMPACT_CTOR_DEF, LITERAL_SWITCH"/> + </module> + <module name="SuppressionXpathSingleFilter"> + <!-- suppresion is required till https://github.com/checkstyle/checkstyle/issues/7541 --> + <property name="id" value="RightCurlyAlone"/> + <property name="query" value="//RCURLY[parent::SLIST[count(./*)=1] + or preceding-sibling::*[last()][self::LCURLY]]"/> + </module> + <module name="WhitespaceAfter"> + <property name="tokens" + value="COMMA, SEMI, TYPECAST, LITERAL_IF, LITERAL_ELSE, LITERAL_RETURN, + LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, LITERAL_FINALLY, DO_WHILE, ELLIPSIS, + LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_CATCH, LAMBDA, + LITERAL_YIELD, LITERAL_CASE"/> + </module> + <module name="WhitespaceAround"> + <property name="allowEmptyConstructors" value="true"/> + <property name="allowEmptyLambdas" value="true"/> + <property name="allowEmptyMethods" value="true"/> + <property name="allowEmptyTypes" value="true"/> + <property name="allowEmptyLoops" value="true"/> + <property name="ignoreEnhancedForColon" value="false"/> + <property name="tokens" + value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, + BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAMBDA, LAND, + LCURLY, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, + LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, + LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, + NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR, + SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/> + <message key="ws.notFollowed" + value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks + may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/> + <message key="ws.notPreceded" + value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/> + </module> + <module name="OneStatementPerLine"/> + <module name="MultipleVariableDeclarations"/> + <module name="ArrayTypeStyle"/> + <module name="MissingSwitchDefault"/> + <module name="FallThrough"/> + <module name="UpperEll"/> + <module name="ModifierOrder"/> + <module name="EmptyLineSeparator"> + <property name="tokens" + value="PACKAGE_DEF, IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, + STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF, RECORD_DEF, + COMPACT_CTOR_DEF"/> + <property name="allowNoEmptyLineBetweenFields" value="true"/> + </module> + <module name="SeparatorWrap"> + <property name="id" value="SeparatorWrapDot"/> + <property name="tokens" value="DOT"/> + <property name="option" value="nl"/> + </module> + <module name="SeparatorWrap"> + <property name="id" value="SeparatorWrapComma"/> + <property name="tokens" value="COMMA"/> + <property name="option" value="EOL"/> + </module> + <module name="SeparatorWrap"> + <!-- ELLIPSIS is EOL until https://github.com/google/styleguide/issues/259 --> + <property name="id" value="SeparatorWrapEllipsis"/> + <property name="tokens" value="ELLIPSIS"/> + <property name="option" value="EOL"/> + </module> + <module name="SeparatorWrap"> + <!-- ARRAY_DECLARATOR is EOL until https://github.com/google/styleguide/issues/258 --> + <property name="id" value="SeparatorWrapArrayDeclarator"/> + <property name="tokens" value="ARRAY_DECLARATOR"/> + <property name="option" value="EOL"/> + </module> + <module name="SeparatorWrap"> + <property name="id" value="SeparatorWrapMethodRef"/> + <property name="tokens" value="METHOD_REF"/> + <property name="option" value="nl"/> + </module> + <module name="TypeName"> + <property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, + ANNOTATION_DEF, RECORD_DEF"/> + <message key="name.invalidPattern" + value="Type name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="MemberName"> + <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/> + <message key="name.invalidPattern" + value="Member name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="ParameterName"> + <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> + <message key="name.invalidPattern" + value="Parameter name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="LambdaParameterName"> + <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> + <message key="name.invalidPattern" + value="Lambda parameter name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="CatchParameterName"> + <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> + <message key="name.invalidPattern" + value="Catch parameter name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="LocalVariableName"> + <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> + <message key="name.invalidPattern" + value="Local variable name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="PatternVariableName"> + <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> + <message key="name.invalidPattern" + value="Pattern variable name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="ClassTypeParameterName"> + <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> + <message key="name.invalidPattern" + value="Class type name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="RecordComponentName"> + <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> + <message key="name.invalidPattern" + value="Record component name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="RecordTypeParameterName"> + <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> + <message key="name.invalidPattern" + value="Record type name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="MethodTypeParameterName"> + <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> + <message key="name.invalidPattern" + value="Method type name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="InterfaceTypeParameterName"> + <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> + <message key="name.invalidPattern" + value="Interface type name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="NoFinalizer"/> + <module name="GenericWhitespace"> + <message key="ws.followed" + value="GenericWhitespace ''{0}'' is followed by whitespace."/> + <message key="ws.preceded" + value="GenericWhitespace ''{0}'' is preceded with whitespace."/> + <message key="ws.illegalFollow" + value="GenericWhitespace ''{0}'' should followed by whitespace."/> + <message key="ws.notPreceded" + value="GenericWhitespace ''{0}'' is not preceded with whitespace."/> + </module> + <module name="Indentation"> + <property name="basicOffset" value="2"/> + <property name="braceAdjustment" value="2"/> + <property name="caseIndent" value="2"/> + <property name="throwsIndent" value="4"/> + <property name="lineWrappingIndentation" value="4"/> + <property name="arrayInitIndent" value="2"/> + </module> + <module name="AbbreviationAsWordInName"> + <property name="ignoreFinal" value="false"/> + <property name="allowedAbbreviationLength" value="0"/> + <property name="tokens" + value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF, + PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, PATTERN_VARIABLE_DEF, RECORD_DEF, + RECORD_COMPONENT_DEF"/> + </module> + <module name="NoWhitespaceBeforeCaseDefaultColon"/> + <module name="OverloadMethodsDeclarationOrder"/> + <module name="VariableDeclarationUsageDistance"/> + <module name="CustomImportOrder"> + <property name="sortImportsInGroupAlphabetically" value="true"/> + <property name="separateLineBetweenGroups" value="true"/> + <property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/> + <property name="tokens" value="IMPORT, STATIC_IMPORT, PACKAGE_DEF"/> + </module> + <module name="MethodParamPad"> + <property name="tokens" + value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF, + SUPER_CTOR_CALL, ENUM_CONSTANT_DEF, RECORD_DEF"/> + </module> + <module name="NoWhitespaceBefore"> + <property name="tokens" + value="COMMA, SEMI, POST_INC, POST_DEC, DOT, + LABELED_STAT, METHOD_REF"/> + <property name="allowLineBreaks" value="true"/> + </module> + <module name="ParenPad"> + <property name="tokens" + value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, DOT, ENUM_CONSTANT_DEF, + EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW, + LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL, + METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA, + RECORD_DEF"/> + </module> + <module name="OperatorWrap"> + <property name="option" value="NL"/> + <property name="tokens" + value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, + LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF, + TYPE_EXTENSION_AND "/> + </module> + <module name="AnnotationLocation"> + <property name="id" value="AnnotationLocationMostCases"/> + <property name="tokens" + value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, + RECORD_DEF, COMPACT_CTOR_DEF"/> + </module> + <module name="AnnotationLocation"> + <property name="id" value="AnnotationLocationVariables"/> + <property name="tokens" value="VARIABLE_DEF"/> + <property name="allowSamelineMultipleAnnotations" value="true"/> + </module> + <module name="NonEmptyAtclauseDescription"/> + <module name="InvalidJavadocPosition"/> + <module name="JavadocTagContinuationIndentation"/> + <module name="SummaryJavadoc"> + <property name="forbiddenSummaryFragments" + value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/> + </module> + <module name="JavadocParagraph"/> + <module name="RequireEmptyLineBeforeBlockTagGroup"/> + <module name="AtclauseOrder"> + <property name="tagOrder" value="@param, @return, @throws, @deprecated"/> + <property name="target" + value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/> + </module> + <module name="JavadocMethod"> + <property name="accessModifiers" value="public"/> + <property name="allowMissingParamTags" value="true"/> + <property name="allowMissingReturnTag" value="true"/> + <property name="allowedAnnotations" value="Override, Test"/> + <property name="tokens" + value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, COMPACT_CTOR_DEF"/> + </module> + <module name="MissingJavadocMethod"> + <property name="scope" value="public"/> + <property name="minLineCount" value="2"/> + <property name="allowedAnnotations" value="Override, Test"/> + <property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, + COMPACT_CTOR_DEF"/> + </module> + <module name="MissingJavadocType"> + <property name="scope" value="protected"/> + <property name="tokens" + value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, + RECORD_DEF, ANNOTATION_DEF"/> + <property name="excludeScope" value="nothing"/> + </module> + <module name="MethodName"> + <property name="format" value="^[a-z][a-z0-9]\w*$"/> + <message key="name.invalidPattern" + value="Method name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="SingleLineJavadoc"/> + <module name="EmptyCatchBlock"> + <property name="exceptionVariableName" value="expected"/> + </module> + <module name="CommentsIndentation"> + <property name="tokens" value="SINGLE_LINE_COMMENT, BLOCK_COMMENT_BEGIN"/> + </module> + <!-- https://checkstyle.org/filters/suppressionxpathfilter.html --> + <module name="SuppressionXpathFilter"> + <property name="file" value="${org.checkstyle.google.suppressionxpathfilter.config}" + default="checkstyle-xpath-suppressions.xml"/> + <property name="optional" value="true"/> + </module> + <module name="SuppressWarningsHolder"/> + <module name="SuppressionCommentFilter"> + <property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/> + <property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/> + <property name="checkFormat" value="$1"/> + </module> + <module name="SuppressWithNearbyCommentFilter"> + <property name="commentFormat" value="CHECKSTYLE.SUPPRESS\: ([\w\|]+)"/> + <!-- $1 refers to the first match group in the regex defined in commentFormat --> + <property name="checkFormat" value="$1"/> + <!-- The check is suppressed in the next line of code after the comment --> + <property name="influenceFormat" value="1"/> + </module> + </module> +</module> -- GitLab From da1d1ab926a23cf9c65444016a4bf93e719f0566 Mon Sep 17 00:00:00 2001 From: Anders <anders.morille@gmail.com> Date: Mon, 19 Feb 2024 14:58:31 +0100 Subject: [PATCH 4/5] :rotating_light: Fixed checkstyle errors in project --- pom.xml | 2 +- .../AteApplication.java} | 14 ++++++++------ .../HomeController.java} | 7 +++++-- src/main/java/module-info.java | 4 ++-- .../home-view.fxml} | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) rename src/main/java/idi/ntnu/no/{idatt1005_gr8_prosjektoppgave/HelloApplication.java => idatt1005projektoppgave/AteApplication.java} (58%) rename src/main/java/idi/ntnu/no/{idatt1005_gr8_prosjektoppgave/HelloController.java => idatt1005projektoppgave/HomeController.java} (63%) rename src/main/resources/idi/ntnu/no/{idatt1005_gr8_prosjektoppgave/hello-view.fxml => idatt1005projektoppgave/home-view.fxml} (85%) diff --git a/pom.xml b/pom.xml index 508d8e2..ebc2c00 100644 --- a/pom.xml +++ b/pom.xml @@ -81,7 +81,7 @@ <id>default-cli</id> <configuration> <mainClass> - idi.ntnu.no.idatt1005_gr8_prosjektoppgave/idi.ntnu.no.idatt1005_gr8_prosjektoppgave.HelloApplication + idi.ntnu.no.idatt1005_gr8_prosjektoppgave/idi.ntnu.no.idatt1005projektoppgave.AteApplication </mainClass> <launcher>app</launcher> <jlinkZipName>app</jlinkZipName> diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/HelloApplication.java b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/AteApplication.java similarity index 58% rename from src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/HelloApplication.java rename to src/main/java/idi/ntnu/no/idatt1005projektoppgave/AteApplication.java index 47a75ff..452d1d0 100644 --- a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/HelloApplication.java +++ b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/AteApplication.java @@ -1,18 +1,20 @@ -package idi.ntnu.no.idatt1005_gr8_prosjektoppgave; +package idi.ntnu.no.idatt1005projektoppgave; +import java.io.IOException; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.stage.Stage; -import java.io.IOException; - -public class HelloApplication extends Application { +/** + * The main entry point for the application. + */ +public class AteApplication extends Application { @Override public void start(Stage stage) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml")); + FXMLLoader fxmlLoader = new FXMLLoader(AteApplication.class.getResource("home-view.fxml")); Scene scene = new Scene(fxmlLoader.load(), 320, 240); - stage.setTitle("Hello!"); + stage.setTitle("Home"); stage.setScene(scene); stage.show(); } diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/HelloController.java b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/HomeController.java similarity index 63% rename from src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/HelloController.java rename to src/main/java/idi/ntnu/no/idatt1005projektoppgave/HomeController.java index 9387753..9b34bb8 100644 --- a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/HelloController.java +++ b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/HomeController.java @@ -1,9 +1,12 @@ -package idi.ntnu.no.idatt1005_gr8_prosjektoppgave; +package idi.ntnu.no.idatt1005projektoppgave; import javafx.fxml.FXML; import javafx.scene.control.Label; -public class HelloController { +/** + * Controls the state of the home page. + */ +public class HomeController { @FXML private Label welcomeText; diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 1b79929..13d85b1 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -6,6 +6,6 @@ module idi.ntnu.no.idatt1005_gr8_prosjektoppgave { requires org.kordamp.ikonli.javafx; requires org.kordamp.bootstrapfx.core; - opens idi.ntnu.no.idatt1005_gr8_prosjektoppgave to javafx.fxml; - exports idi.ntnu.no.idatt1005_gr8_prosjektoppgave; + opens idi.ntnu.no.idatt1005projektoppgave to javafx.fxml; + exports idi.ntnu.no.idatt1005projektoppgave; } diff --git a/src/main/resources/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/hello-view.fxml b/src/main/resources/idi/ntnu/no/idatt1005projektoppgave/home-view.fxml similarity index 85% rename from src/main/resources/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/hello-view.fxml rename to src/main/resources/idi/ntnu/no/idatt1005projektoppgave/home-view.fxml index 54f8ab9..eb5ead8 100644 --- a/src/main/resources/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/hello-view.fxml +++ b/src/main/resources/idi/ntnu/no/idatt1005projektoppgave/home-view.fxml @@ -6,7 +6,7 @@ <?import javafx.scene.control.Button?> <VBox alignment="CENTER" spacing="20.0" xmlns:fx="http://javafx.com/fxml" - fx:controller="idi.ntnu.no.idatt1005_gr8_prosjektoppgave.HelloController"> + fx:controller="idi.ntnu.no.idatt1005projektoppgave.HomeController"> <padding> <Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/> </padding> -- GitLab From 5a483db0c064a1b28e1598f47aced5cd932eced1 Mon Sep 17 00:00:00 2001 From: Anders <anders.morille@gmail.com> Date: Mon, 19 Feb 2024 14:58:42 +0100 Subject: [PATCH 5/5] :rotating_light: Fixed checkstyle lint errors --- .../model/Ingredient.java | 85 ++++++++++--------- .../model/InventoryItem.java | 25 ++++-- .../model/PlannedRecipe.java | 23 ++--- .../model/Recipe.java | 67 ++++++++------- .../model/RecipeIngredient.java | 22 ++--- .../model/ShoppingListItem.java | 38 +++++---- 6 files changed, 141 insertions(+), 119 deletions(-) rename src/main/java/idi/ntnu/no/{idatt1005_gr8_prosjektoppgave => idatt1005projektoppgave}/model/Ingredient.java (57%) rename src/main/java/idi/ntnu/no/{idatt1005_gr8_prosjektoppgave => idatt1005projektoppgave}/model/InventoryItem.java (81%) rename src/main/java/idi/ntnu/no/{idatt1005_gr8_prosjektoppgave => idatt1005projektoppgave}/model/PlannedRecipe.java (64%) rename src/main/java/idi/ntnu/no/{idatt1005_gr8_prosjektoppgave => idatt1005projektoppgave}/model/Recipe.java (62%) rename src/main/java/idi/ntnu/no/{idatt1005_gr8_prosjektoppgave => idatt1005projektoppgave}/model/RecipeIngredient.java (59%) rename src/main/java/idi/ntnu/no/{idatt1005_gr8_prosjektoppgave => idatt1005projektoppgave}/model/ShoppingListItem.java (64%) diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Ingredient.java b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/Ingredient.java similarity index 57% rename from src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Ingredient.java rename to src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/Ingredient.java index 0a418a2..69cae6e 100644 --- a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Ingredient.java +++ b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/Ingredient.java @@ -1,52 +1,54 @@ -package idi.ntnu.no.idatt1005_gr8_prosjektoppgave.model; +package idi.ntnu.no.idatt1005projektoppgave.model; import java.util.Optional; /** - * Represents a single ingredient record in the database + * Represents a single ingredient record in the database. */ public class Ingredient { /** - * The primary identifier and key for this row in the database + * The primary identifier and key for this row in the database. */ private final int id; /** - * The name of this ingredient + * The name of this ingredient. */ private final String name; /** - * The type of measuring unit used to measure this ingredient + * The type of measuring unit used to measure this ingredient. */ private final MeasuringUnit unit; /** - * The default amount of this ingredient unless otherwise is specified + * The default amount of this ingredient unless otherwise is specified. */ private final int defaultAmount; /** - * The ingredient category this ingredient belongs to, used to categorize ingredients + * The ingredient category this ingredient belongs to, used to categorize ingredients. */ private final Category category; /** - * Where this ingredient should be stored at home + * Where this ingredient should be stored at home. */ private final StorageType storageType; /** - * Construct an ingredient object using a value for each field - * You may pass -1 to defaultAmount in order to set a none value - * @param id The primary key - * @param name The name of the ingredient - * @param unit The unit to use - * @param defaultAmount The default amount. Either a positive integer or -1 for none - * @param category Food category - * @param storageType Where to store this ingredient at home + * Construct an ingredient object using a value for each field. + * You may pass -1 to defaultAmount in order to set a none value. + * + * @param id The primary key. + * @param name The name of the ingredient. + * @param unit The unit to use. + * @param defaultAmount The default amount. Either a positive integer or -1 for none. + * @param category Food category. + * @param storageType Where to store this ingredient at home. */ - public Ingredient(int id, String name, MeasuringUnit unit, int defaultAmount, Category category, StorageType storageType) { + public Ingredient(int id, String name, MeasuringUnit unit, int defaultAmount, Category category, + StorageType storageType) { this.id = id; this.name = name; this.unit = unit; @@ -56,78 +58,77 @@ public class Ingredient { } /** - * @return The ingredient id/primary key + * Gets the id. + * + * @return The ingredient id/primary key. */ public int getId() { return id; } /** - * @return The name of the ingredient + * Gets the name. + * + * @return The name of the ingredient. */ public String getName() { return name; } /** - * @return The measuring unit used for this ingredient + * Gets the measuring unit. + * + * @return The measuring unit used for this ingredient. */ public MeasuringUnit getUnit() { return unit; } /** - * @return The default amount of this ingredient. Is empty if there is no default amount + * Gets the default amount. + * + * @return The default amount of this ingredient. Is empty if there is no default amount. */ public Optional<Integer> getDefaultAmount() { return defaultAmount == -1 ? Optional.empty() : Optional.of(defaultAmount); } /** - * @return The category this ingredient belongs to + * Get the category. + * + * @return The category this ingredient belongs to. */ public Category getCategory() { return category; } /** - * @return The storage type where this ingredient should be stored + * Get the storage type. + * + * @return The storage type where this ingredient should be stored. */ public StorageType getStorageType() { return storageType; } /** - * All types of measuring units that can be used by ingredients + * All types of measuring units that can be used by ingredients. */ public enum MeasuringUnit { - milliliter, - gram, - teaspoon, - spoon, - piece + milliliter, gram, teaspoon, spoon, piece } /** - * Food category of an ingredient + * Food category of an ingredient. */ public enum Category { - fruit, - vegetable, - meat, - dairy, - grain, - herb, - spice, - oil + fruit, vegetable, meat, dairy, grain, herb, spice, oil } /** - * All places an ingredient can be stored at home + * All places an ingredient can be stored at home. */ public enum StorageType { - fridge, - freezer, - pantry + fridge, freezer, pantry } } diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/InventoryItem.java b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/InventoryItem.java similarity index 81% rename from src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/InventoryItem.java rename to src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/InventoryItem.java index 68f7e91..55eae2a 100644 --- a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/InventoryItem.java +++ b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/InventoryItem.java @@ -1,4 +1,4 @@ -package idi.ntnu.no.idatt1005_gr8_prosjektoppgave.model; +package idi.ntnu.no.idatt1005projektoppgave.model; import java.util.Optional; @@ -32,7 +32,7 @@ public class InventoryItem { private final PlannedRecipe plannedRecipe; /** - * Creates a new inventory item using an ingredient reference + * Creates a new inventory item using an ingredient reference. * * @param id The id of the item. * @param ingredient The ingredient of the item, if it is not custom. @@ -49,7 +49,7 @@ public class InventoryItem { } /** - * Creates a new inventory item using a custom name + * Creates a new inventory item using a custom name. * * @param id The id of the item. * @param customName The custom name of the item, if it is custom. @@ -67,6 +67,8 @@ public class InventoryItem { /** + * Get the id. + * * @return The id of the item. */ public int getId() { @@ -74,6 +76,8 @@ public class InventoryItem { } /** + * Get the ingredients. + * * @return The ingredient of the item, if it is not custom. */ public Optional<Ingredient> getIngredient() { @@ -81,6 +85,8 @@ public class InventoryItem { } /** + * Get the custom name. + * * @return The custom name of the item, if it is custom. */ public Optional<String> getCustomName() { @@ -88,6 +94,8 @@ public class InventoryItem { } /** + * Get the amount. + * * @return The amount of the item. */ public int getAmount() { @@ -95,6 +103,8 @@ public class InventoryItem { } /** + * Get the planned recipe. + * * @return The planned recipe of the item, if it is planned. */ public Optional<PlannedRecipe> getPlannedRecipe() { @@ -102,6 +112,8 @@ public class InventoryItem { } /** + * Get whether it is custom (custom name). + * * @return True if the item is custom, false otherwise. */ public boolean isCustom() { @@ -109,14 +121,17 @@ public class InventoryItem { } /** + * Get the name of the item, either custom or by ingredient reference. + * * @return The name of the item. * @throws NullPointerException if neither the customName nor the ingredient is set. */ - public String getName() throws NullPointerException { + public String getName() throws IllegalStateException { if (isCustom()) { return this.customName; - } else { + } else if (this.ingredient != null) { return this.ingredient.getName(); } + throw new IllegalStateException("Both customName and ingredient were null"); } } diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/PlannedRecipe.java b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/PlannedRecipe.java similarity index 64% rename from src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/PlannedRecipe.java rename to src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/PlannedRecipe.java index 4467756..6251671 100644 --- a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/PlannedRecipe.java +++ b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/PlannedRecipe.java @@ -1,29 +1,30 @@ -package idi.ntnu.no.idatt1005_gr8_prosjektoppgave.model; +package idi.ntnu.no.idatt1005projektoppgave.model; import java.time.ZonedDateTime; /** - * A recipe that is planned in the future + * A recipe that is planned in the future. * Can be looked on as a "Recipe instance" */ public class PlannedRecipe { /** - * The primary key of this row in the database + * The primary key of this row in the database. */ private final int id; /** - * The recipe that is being planned/linked to + * The recipe that is being planned/linked to. */ private final Recipe recipe; /** - * For when this recipe is being planned + * For when this recipe is being planned. */ private final ZonedDateTime plannedDate; /** - * Creates a PlannedRecipe by filling in fields from the database - * @param id The primary key - * @param recipe The recipe to make + * Creates a PlannedRecipe by filling in fields from the database. + * + * @param id The primary key + * @param recipe The recipe to make * @param plannedDate When it is planned */ public PlannedRecipe(int id, Recipe recipe, ZonedDateTime plannedDate) { @@ -33,21 +34,21 @@ public class PlannedRecipe { } /** - * @return The primary key + * The primary key. */ public int getId() { return id; } /** - * @return The recipe + * The recipe. */ public Recipe getRecipe() { return recipe; } /** - * @return When it is planned + * When it is planned. */ public ZonedDateTime getPlannedDate() { return plannedDate; diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Recipe.java b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/Recipe.java similarity index 62% rename from src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Recipe.java rename to src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/Recipe.java index f98a752..6fdafee 100644 --- a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/Recipe.java +++ b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/Recipe.java @@ -1,73 +1,74 @@ -package idi.ntnu.no.idatt1005_gr8_prosjektoppgave.model; +package idi.ntnu.no.idatt1005projektoppgave.model; import java.time.Duration; import java.util.List; /** - * A single meal recipe + * A single meal recipe. */ public class Recipe { /** - * The id/primary key of this recipe + * The id/primary key of this recipe. */ private final int id; /** - * The path to the markdown file containing all steps for this recipe in a list format + * The path to the markdown file containing all steps for this recipe in a list format. */ private final List<String> steps; /** - * The meal category this recipe belongs to + * The meal category this recipe belongs to. */ private final Category category; /** - * How long it usually takes to make this recipe + * How long it usually takes to make this recipe. */ private final Duration duration; /** - * How difficult it is to make this recipe + * How difficult it is to make this recipe. */ private final Difficulty difficulty; /** - * The name of this recipe + * The name of this recipe. */ private final String name; /** - * The description of this recipe + * The description of this recipe. */ private final String description; /** - * Whether this recipe has been marked as a favorite by the user + * Whether this recipe has been marked as a favorite by the user. */ private final boolean isFavorite; /** - * A custom note attached to this recipe by the user + * A custom note attached to this recipe by the user. */ private final String note; /** - * All ingredients required to make this recipe + * All ingredients required to make this recipe. */ private final List<RecipeIngredient> ingredients; /** - * Construct a recipe using all fields from the database - * @param id The primary key of this record - * @param steps The steps required to make this recipe - * @param category The category - * @param duration The duration - * @param difficulty The difficulty - * @param name The name + * Construct a recipe using all fields from the database. + * + * @param id The primary key of this record + * @param steps The steps required to make this recipe + * @param category The category + * @param duration The duration + * @param difficulty The difficulty + * @param name The name * @param description The description - * @param isFavorite Whether this is marked as favorite - * @param note Custom note from user + * @param isFavorite Whether this is marked as favorite + * @param note Custom note from user * @param ingredients All ingredients in this recipe */ public Recipe(int id, List<String> steps, Category category, Duration duration, @@ -86,77 +87,77 @@ public class Recipe { } /** - * @return The id / primary key + * Gets the id / primary key. */ public int getId() { return id; } /** - * @return All steps required to perform this recipe, in order + * All steps required to perform this recipe, in order. */ public List<String> steps() { return steps; } /** - * @return The meal category + * The meal category. */ public Category getCategory() { return category; } /** - * @return The duration of + * The duration of. */ public Duration getDuration() { return duration; } /** - * @return The difficulty of this recipe + * The difficulty of this recipe. */ public Difficulty getDifficulty() { return difficulty; } /** - * @return The name of the recipe + * The name of the recipe. */ public String getName() { return name; } /** - * @return The description + * The description. */ public String getDescription() { return description; } /** - * @return Whether this is marked as favorite by the user + * Whether this is marked as favorite by the user. */ public boolean isFavorite() { return isFavorite; } /** - * @return Custom user note on this recipe + * Custom user note on this recipe. */ public String getNote() { return note; } /** - * @return Add required ingredients to make this recipe + * Add required ingredients to make this recipe. */ public List<RecipeIngredient> getIngredients() { return ingredients; } /** - * The type of meal + * The type of meal. */ public enum Category { breakfast, @@ -167,7 +168,7 @@ public class Recipe { } /** - * The difficulty level on a recipe + * The difficulty level on a recipe. */ public enum Difficulty { beginner, diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/RecipeIngredient.java b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/RecipeIngredient.java similarity index 59% rename from src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/RecipeIngredient.java rename to src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/RecipeIngredient.java index c02fd2d..c39cc71 100644 --- a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/RecipeIngredient.java +++ b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/RecipeIngredient.java @@ -1,4 +1,4 @@ -package idi.ntnu.no.idatt1005_gr8_prosjektoppgave.model; +package idi.ntnu.no.idatt1005projektoppgave.model; /** * An ingredient used in a recipe, with a specific amount and necessity. @@ -16,17 +16,19 @@ public class RecipeIngredient extends Ingredient { /** * Constructs a new RecipeIngredient. - * @param id The id of the ingredient. - * @param name The name of the ingredient. - * @param unit The measuring unit of the ingredient. + * + * @param id The id of the ingredient. + * @param name The name of the ingredient. + * @param unit The measuring unit of the ingredient. * @param defaultAmount The default amount of the ingredient. - * @param category The category of the ingredient. - * @param storageType The storage type of the ingredient. - * @param amount The amount of the ingredient needed in the recipe. - * @param isNecessary Whether the ingredient is necessary for the recipe. + * @param category The category of the ingredient. + * @param storageType The storage type of the ingredient. + * @param amount The amount of the ingredient needed in the recipe. + * @param isNecessary Whether the ingredient is necessary for the recipe. */ public RecipeIngredient(int id, String name, MeasuringUnit unit, int defaultAmount, - Category category, StorageType storageType, int amount, boolean isNecessary) { + Category category, StorageType storageType, int amount, + boolean isNecessary) { super(id, name, unit, defaultAmount, category, storageType); this.amount = amount; this.isNecessary = isNecessary; @@ -40,7 +42,7 @@ public class RecipeIngredient extends Ingredient { } /** - * @return Whether this ingredient is necessary for the recipe. + * Whether this ingredient is necessary for the recipe. */ public boolean isNecessary() { return isNecessary; diff --git a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/ShoppingListItem.java b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/ShoppingListItem.java similarity index 64% rename from src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/ShoppingListItem.java rename to src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/ShoppingListItem.java index 5130237..7c65600 100644 --- a/src/main/java/idi/ntnu/no/idatt1005_gr8_prosjektoppgave/model/ShoppingListItem.java +++ b/src/main/java/idi/ntnu/no/idatt1005projektoppgave/model/ShoppingListItem.java @@ -1,4 +1,4 @@ -package idi.ntnu.no.idatt1005_gr8_prosjektoppgave.model; +package idi.ntnu.no.idatt1005projektoppgave.model; import java.util.Optional; @@ -12,32 +12,33 @@ public class ShoppingListItem { private final int id; /** - * The ingredient of the shopping list item. + * The ingredient of the shopping list item. */ private final Ingredient ingredient; /** - * The custom name of the shopping list item. + * The custom name of the shopping list item. */ private final String customName; /** - * The amount of the shopping list item. + * The amount of the shopping list item. */ private final int amount; /** - * The planned recipe of the shopping list item. + * The planned recipe of the shopping list item. */ private final PlannedRecipe recipe; /** - * Initializes a newly created ShoppingListItem object using an ingredient reference - * @param id The id of the shopping list item. + * Initializes a newly created ShoppingListItem object using an ingredient reference. + * + * @param id The id of the shopping list item. * @param ingredient The ingredient of the shopping list item. - * @param amount The amount of the shopping list item. - * @param recipe The planned recipe of the shopping list item. + * @param amount The amount of the shopping list item. + * @param recipe The planned recipe of the shopping list item. */ public ShoppingListItem(int id, Ingredient ingredient, int amount, PlannedRecipe recipe) { @@ -49,11 +50,12 @@ public class ShoppingListItem { } /** - * Initializes a newly created ShoppingListItem object using a custom name - * @param id The id of the shopping list item. + * Initializes a newly created ShoppingListItem object using a custom name. + * + * @param id The id of the shopping list item. * @param customName The custom name of the shopping list item. - * @param amount The amount of the shopping list item. - * @param recipe The planned recipe of the shopping list item. + * @param amount The amount of the shopping list item. + * @param recipe The planned recipe of the shopping list item. */ public ShoppingListItem(int id, String customName, int amount, PlannedRecipe recipe) { @@ -65,14 +67,14 @@ public class ShoppingListItem { } /** - * @return The id of the shopping list item. + * The id of the shopping list item. */ public int getId() { return id; } /** - * @return The ingredient of the shopping list item. Is empty if the shopping list item has a + * The ingredient of the shopping list item. Is empty if the shopping list item has a * custom name instead of an ingredient reference. */ public Optional<Ingredient> getIngredient() { @@ -80,7 +82,7 @@ public class ShoppingListItem { } /** - * @return The custom name assigned by the user. Is empty if the shopping list item has a + * The custom name assigned by the user. Is empty if the shopping list item has a * reference to an ingredient instead of a custom name. */ public Optional<String> getCustomName() { @@ -88,14 +90,14 @@ public class ShoppingListItem { } /** - * @return The amount of the shopping list item. + * The amount of the shopping list item. */ public int getAmount() { return amount; } /** - * @return Get the planned recipe associated with this shopping list item, meaning the shopping + * Get the planned recipe associated with this shopping list item, meaning the shopping * list item exists to fulfill the ingredients of a planned recipe. Is empty if the shopping list * item is not associated with a planned recipe. */ -- GitLab