Class GroceryRegister
java.lang.Object
stud.ntnu.idatt1005.pantrypal.registers.Register<Grocery>
stud.ntnu.idatt1005.pantrypal.registers.GroceryRegister
Represents a register of groceries. The register is a map of grocery names and grocery objects.
-
Field Summary
Fields inherited from class stud.ntnu.idatt1005.pantrypal.registers.Register
registerMap
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor for the GroceryRegister class.GroceryRegister
(GroceryRegister register) Deep-copy constructor for the GroceryRegister class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addGrocery
(Grocery grocery) Add a grocery to the register.boolean
containsGrocery
(String name) Check if the register contains a grocery.protected String
Abstract method to get the error message.getGrocery
(String name) Get a grocery from the register.void
removeGrocery
(Grocery grocery) Remove a grocery from the register.Methods inherited from class stud.ntnu.idatt1005.pantrypal.registers.Register
addModel, containsModel, getModel, getRegister, removeModel, searchModels
-
Constructor Details
-
GroceryRegister
public GroceryRegister()Constructor for the GroceryRegister class. -
GroceryRegister
Deep-copy constructor for the GroceryRegister class.- Parameters:
register
- the register to be used
-
-
Method Details
-
getErrorMessage
Description copied from class:Register
Abstract method to get the error message.- Specified by:
getErrorMessage
in classRegister<Grocery>
- Returns:
- the error message
-
getGrocery
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
Check if the register contains a grocery.- Parameters:
name
- the name of the grocery to be checked
-
addGrocery
Add a grocery to the register.- Parameters:
grocery
- the grocery to be added- Throws:
IllegalArgumentException
- if the grocery already exists in the register
-
removeGrocery
Remove a grocery from the register.- Parameters:
grocery
- the grocery to be removed
-