Class Register<T extends Model>
java.lang.Object
stud.ntnu.idatt1005.pantrypal.registers.Register<T>
- Type Parameters:
T
- the type of model that the register will contain
- Direct Known Subclasses:
GroceryRegister
,RecipeRegister
,ShelfRegister
This is an abstract class representing a register. It contains a LinkedHashMap where the key is a
string and the value is a model. The class provides methods to get the register map, get a model
from the register, add a model to the register, and remove a model from the register.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Add an item to the register.protected boolean
containsModel
(String key) Check if a model exists in the register.protected abstract String
Abstract method to get the error message.protected T
Get a model from the register.Get the register map.protected void
removeModel
(T model) Remove an item from the register.searchModels
(String search) Searches for items in the register by name, and searches for all names that contains the search-string.
-
Field Details
-
registerMap
LinkedHashMap<String,T extends Model> registerMap
-
-
Constructor Details
-
Register
protected Register()Constructor for Register class. Initializes the register as a new LinkedHashMap. -
Register
Deep-copy constructor for Register class.- Parameters:
registerMap
- the register to be copied
-
-
Method Details
-
getErrorMessage
Abstract method to get the error message.- Returns:
- the error message
-
getRegister
Get the register map.- Returns:
- the register map
-
getModel
Get a model from the register.- Parameters:
key
- the key of the model to be retrieved- Returns:
- the model with the specified name
- Throws:
IllegalArgumentException
- if the item does not exist in the register
-
containsModel
Check if a model exists in the register.- Parameters:
key
- the key of the model to be checked
-
addModel
Add an item to the register.- Parameters:
model
- item to be added
-
removeModel
Remove an item from the register.- Parameters:
model
- the key of the item to be removed- Throws:
IllegalArgumentException
- if the item does not exist in the register
-
searchModels
Searches for items in the register by name, and searches for all names that contains the search-string.- Parameters:
search
- the name of the item to be searched for- Returns:
- a list of items with the specified name
-