java.lang.Object
stud.ntnu.idatt1005.pantrypal.registers.Register<Grocery>
stud.ntnu.idatt1005.pantrypal.registers.GroceryRegister

public class GroceryRegister extends Register<Grocery>
Represents a register of groceries. The register is a map of grocery names and grocery objects.
  • Constructor Details

    • GroceryRegister

      public GroceryRegister()
      Constructor for the GroceryRegister class.
    • GroceryRegister

      public GroceryRegister(GroceryRegister register)
      Deep-copy constructor for the GroceryRegister class.
      Parameters:
      register - the register to be used
  • Method Details

    • getErrorMessage

      protected String getErrorMessage()
      Description copied from class: Register
      Abstract method to get the error message.
      Specified by:
      getErrorMessage in class Register<Grocery>
      Returns:
      the error message
    • getGrocery

      public Grocery getGrocery(String name) throws IllegalArgumentException
      Get a grocery from the register.
      Parameters:
      name - the name of the grocery to be retrieved
      Returns:
      the grocery with the specified name
      Throws:
      IllegalArgumentException
    • containsGrocery

      public boolean containsGrocery(String name)
      Check if the register contains a grocery.
      Parameters:
      name - the name of the grocery to be checked
    • addGrocery

      public void addGrocery(Grocery grocery)
      Add a grocery to the register.
      Parameters:
      grocery - the grocery to be added
      Throws:
      IllegalArgumentException - if the grocery already exists in the register
    • removeGrocery

      public void removeGrocery(Grocery grocery)
      Remove a grocery from the register.
      Parameters:
      grocery - the grocery to be removed