Class RequestList
- All Implemented Interfaces:
Saveable
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 Summary
ConstructorsConstructorDescriptionRequestList(String filePath) Constructs a RequestList instance associated with a specific file path. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves aRequest(or one of its subclasses) from the list based on its unique request ID.Gets the file path associated with this RequestList instance, indicating where the request data is persisted.static RequestListProvides a static factory method to get an instance of RequestList.voidOverrides the load method to handle polymorphism within the Request hierarchy.
-
Constructor Details
-
RequestList
Constructs a RequestList instance associated with a specific file path. Calls the superclass constructor to initialize the list, providing the file path and the baseRequest.classtype. Note that the overriddenload(java.lang.String, boolean)method handles determining specific subclasses during loading. Typically accessed via the staticgetInstance()method using the default path.- Parameters:
filePath- The path to the CSV file used for data persistence.
-
-
Method Details
-
getInstance
Provides a static factory method to get an instance of RequestList. This method creates a new instance using the defaultFILE_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
RequestListinitialized with the default file path.
-
getFilePath
Gets the file path associated with this RequestList instance, indicating where the request data is persisted.- Specified by:
getFilePathin classModelList<Request>- Returns:
- The file path string (e.g., "data_csv/RequestList.csv").
-
getByID
Retrieves aRequest(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. -
load
Overrides the load method to handle polymorphism within the Request hierarchy. Reads data from the specified CSV file, determines the specific subclass ofRequestfor each line usingConverter.getRequestClass(String), deserializes the line into an object of that specific subclass usingConverter.stringtoObj(String, Class), and adds the resulting object to the internal list using the superclass's add method. Note: Callingsuper.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.
-