Class RecipeRegister

java.lang.Object
no.ntnu.idatt1002.demo.data.recipes.RecipeRegister

public class RecipeRegister extends Object
The RecipeRegister class holds a collection of Recipes in a list and provides methods to access the recipes, add recipes to the register as well as to pick a number of recipe's best fitting a list of food types provided as a IngredientsAtHand object. The register is instantiated using the default constructor.
Author:
hannesofie
  • Constructor Details

    • RecipeRegister

      public RecipeRegister()
  • Method Details

    • getRecipes

      public ArrayList<Recipe> getRecipes()
      The method returns the list of recipes in the Register.
      Returns:
      A list of recipes that belong to this register.
    • addRecipe

      public void addRecipe(Recipe recipe)
      The method takes in a Recipe object. If the recipe is already in the register, the old recipe will be replaced. If the recipe is null, an IllegalArgumentException is thrown. Otherwise, the new recipe is added to the register's collection of recipes.
      Parameters:
      recipe - A new recipe to add to the register.
    • getRecipe

      public Recipe getRecipe(String name)
      The method takes in a string with the name of a recipe and returns that recipe object if it is in the recipe register. If it is not found, null is returned instead.
      Parameters:
      name - The name of a recipe as a String.
      Returns:
      The recipe matching the provided name if it is present in the recipe register.
    • pickBestFits

      public ArrayList<Recipe> pickBestFits(int number, IngredientsAtHand atHand)
      The method takes in a number and an IngredientsAtHand object and returns an ArrayList containing that number of recipes that, based on the ingredients at hand, require the fewest extra ingredients apart from the ones at hand. If the number of recipes in the register is fewer than the provided number, the list will contain as many as the register can provide. The resulting list is sorted by the number of ingredients required apart from those ingredients at hand. If zero recipes are requested, and empty ArrayList is returned.
      Parameters:
      number - Number of recipes to pick from the recipe register.
      atHand - A IngredientsAtHand object providing a collection of the food types at hand to the user.
      Returns:
      A list of recipes of sorted by available ingredients and limited to the provided number or the number of recipes in the register.