Class RequestList

All Implemented Interfaces:
Saveable

public class RequestList extends ModelList<Request>
Manages a list of Request objects and their potential subclasses (e.g., Enquiry, BTOApplication), handling data persistence and retrieval. This class extends the generic ModelList to specialize in managing request data, likely loaded from and saved to a CSV file specified by FILE_PATH. It overrides the load method to handle the polymorphic nature of Request objects during deserialization. Provides methods to access the list instance and retrieve requests by their ID. Uses a static factory method getInstance() for convenient access.
  • Constructor Details

    • RequestList

      public RequestList(String filePath)
      Constructs a RequestList instance associated with a specific file path. Calls the superclass constructor to initialize the list, providing the file path and the base Request.class type. Note that the overridden load(java.lang.String, boolean) method handles determining specific subclasses during loading. Typically accessed via the static getInstance() method using the default path.
      Parameters:
      filePath - The path to the CSV file used for data persistence.
  • Method Details

    • getInstance

      public static RequestList getInstance()
      Provides a static factory method to get an instance of RequestList. This method creates a new instance using the default FILE_PATH. Note: This implementation creates a new instance on each call, potentially reloading data. Consider implementing a true Singleton pattern if a single shared instance is desired.
      Returns:
      A new instance of RequestList initialized with the default file path.
    • getFilePath

      public String getFilePath()
      Gets the file path associated with this RequestList instance, indicating where the request data is persisted.
      Specified by:
      getFilePath in class ModelList<Request>
      Returns:
      The file path string (e.g., "data_csv/RequestList.csv").
    • getByID

      public Request getByID(String requestID)
      Retrieves a Request (or one of its subclasses) from the list based on its unique request ID. Iterates through the list maintained by the superclass (ModelList.getAll()) and returns the first request matching the provided ID.
      Specified by:
      getByID in class ModelList<Request>
      Parameters:
      requestID - The unique ID of the request to find.
      Returns:
      The Request object (or subclass instance) if found, otherwise null.
    • load

      public void load(String FILE_PATH, boolean hasHeader)
      Overrides the load method to handle polymorphism within the Request hierarchy. Reads data from the specified CSV file, determines the specific subclass of Request for each line using Converter.getRequestClass(String), deserializes the line into an object of that specific subclass using Converter.stringtoObj(String, Class), and adds the resulting object to the internal list using the superclass's add method. Note: Calling super.add(val) might trigger the superclass's save mechanism repeatedly during load, which could be inefficient. Consider loading all objects first, then adding them to the internal list directly if performance is critical.
      Specified by:
      load in interface Saveable
      Overrides:
      load in class ModelList<Request>
      Parameters:
      FILE_PATH - The path to the file from which to load data.
      hasHeader - If true, the first line of the file is skipped as a header.