Class OfficerList

All Implemented Interfaces:
Saveable

public class OfficerList extends ModelList<Officer>
Manages a list of Officer objects, handling data persistence and retrieval. This class extends the generic ModelList to specialize in managing officer data, likely loaded from and saved to a CSV file specified by FILE_PATH. It provides methods to access the list instance and retrieve officers by their ID. Uses a static factory method getInstance() for convenient access.
  • Constructor Details

    • OfficerList

      public OfficerList(String filePath)
      Constructs an OfficerList instance associated with a specific file path. Calls the superclass constructor to initialize the list, providing the file path and the Officer.class type for CSV data mapping. 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 OfficerList getInstance()
      Provides a static factory method to get an instance of OfficerList. 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 OfficerList initialized with the default file path.
    • getFilePath

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

      public Officer getByID(String ID)
      Retrieves an Officer from the list based on their unique user ID. Iterates through the list maintained by the superclass (ModelList.getAll()) and returns the first officer matching the provided ID.
      Specified by:
      getByID in class ModelList<Officer>
      Parameters:
      ID - The user ID of the officer to find.
      Returns:
      The Officer object if found, otherwise null.