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

public abstract class Register<T extends Model> extends Object
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 Details

  • Constructor Details

    • Register

      protected Register()
      Constructor for Register class. Initializes the register as a new LinkedHashMap.
    • Register

      protected Register(Register<T> registerMap)
      Deep-copy constructor for Register class.
      Parameters:
      registerMap - the register to be copied
  • Method Details

    • getErrorMessage

      protected abstract String getErrorMessage()
      Abstract method to get the error message.
      Returns:
      the error message
    • getRegister

      public Map<String,T> getRegister()
      Get the register map.
      Returns:
      the register map
    • getModel

      protected T getModel(String key) throws IllegalArgumentException
      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

      protected boolean containsModel(String key)
      Check if a model exists in the register.
      Parameters:
      key - the key of the model to be checked
    • addModel

      protected void addModel(T model)
      Add an item to the register.
      Parameters:
      model - item to be added
    • removeModel

      protected void removeModel(T model) throws IllegalArgumentException
      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

      protected List<T> searchModels(String search)
      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