Package crms.lib
Class CarDatabase
The
CarDatabase class manages the collection of recorded Car
objects in the local database and performs various operations related to
them.
It implements the singleton pattern to ensure only one instance of the class exists.
It provides methods to add, remove, and retrieve Car objects,
generate reports, and handle data persistence to a local file.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoidFetches the recordedCarobjects from the filecars.txt.static CarDatabaseReturns the singleton instance ofCarDatabase.getItemById(String id) Retrieves aCarobject using the given ID.voidSaves the list ofCarobjects to the filecars.txt.
-
Method Details
-
getInstance
Returns the singleton instance ofCarDatabase. If the instance does not exist, it is created and the cars are fetched from disk.- Returns:
- the singleton instance of
CarDatabase.
-
getItemById
Retrieves aCarobject using the given ID.- Specified by:
getItemByIdin classDatabase<Car>- Parameters:
id- the ID of the car to be retrieved.- Returns:
- the
Carobject with the specified ID, ornullif not found.
-
fetchFromDisk
public void fetchFromDisk()Fetches the recordedCarobjects from the filecars.txt.- Specified by:
fetchFromDiskin classDatabase<Car>
-
saveToDisk
public void saveToDisk()Saves the list ofCarobjects to the filecars.txt.- Specified by:
saveToDiskin classDatabase<Car>
-