Class ListHandling

java.lang.Object
edu.ntnu.stud.utils.ListHandling

public class ListHandling extends Object
Utility class for handling lists.
  • Constructor Details

    • ListHandling

      public ListHandling()
  • Method Details

    • addSubtractFromList

      public static List<Ingredient> addSubtractFromList(List<Ingredient> mainList, List<Ingredient> subList, int operation)
      Add or subtract ingredients from a list. The integer at the end of the method name indicates the operation to perform. 1 for addition, -1 for subtraction.
      Parameters:
      mainList - The main list to add or subtract ingredients from.
      subList - The list of ingredients to add or subtract.
      operation - The operation to perform. 1 for addition, -1 for subtraction.
      Returns:
      The updated main list.
    • addIngredientToList

      public static void addIngredientToList(List<Ingredient> inputList, String ingName, String quantity) throws IllegalArgumentException
      Add an ingredient to a list.
      Parameters:
      inputList - The list to add the ingredient to.
      ingName - The name of the ingredient to add.
      quantity - The quantity of the ingredient to add.
      Throws:
      IllegalArgumentException - If the quantity is not an integer.
    • getIngredientsFromRecipe

      public static List<Ingredient> getIngredientsFromRecipe(String recName)
      Get the ingredients from a recipe.
      Parameters:
      recName - The name of the recipe to get the ingredients from.
      Returns:
      A list of ingredients from the recipe.