Package Common
Class Database
java.lang.Object
Common.Database
- Direct Known Subclasses:
AccountDatabase
,AppointmentOutcomeDatabase
,DoctorSchedule
,InventoryDatabase
,InventoryRequestDatabase
,MedicalRecordDatabase
The
Database
class serves as an abstract base class for managing
collections of DatabaseItems
. It provides methods for extracting
items from a CSV file, storing items to a CSV file, and managing
database records.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
protected String
protected ArrayList
<DatabaseItems> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addItem
(DatabaseItems item) Adds a new item to the database records.protected abstract DatabaseItems
createDatabaseItem
(String[] values) Creates a specificDatabaseItems
object from an array of values.void
Extracts database items from the specified CSV file.Returns a list of all database items.abstract void
Prints all items in this database.protected void
printItems
(String title) Prints all items in the database with a specified title.abstract boolean
removeItem
(String id) Removes an item from the database using its unique identifier.abstract DatabaseItems
searchItem
(String id) Searches for an item in the database using its unique identifier.void
setcsvPath
(String path) Sets the path to the CSV file used for storing and retrieving data.protected void
setHeaderFormat
(String headerFormat) Sets the header format for the CSV file.void
Stores all database items to the specified CSV file.
-
Field Details
-
csvPath
-
headerFormat
-
records
-
-
Constructor Details
-
Database
public Database()
-
-
Method Details
-
setcsvPath
Sets the path to the CSV file used for storing and retrieving data.- Parameters:
path
- the path to the CSV file
-
extractFromCSV
public void extractFromCSV()Extracts database items from the specified CSV file. This method reads from the CSV file, skipping the header, and populates therecords
list with items created using thecreateDatabaseItem(String[])
method. -
storeToCSV
public void storeToCSV()Stores all database items to the specified CSV file. This method writes the header format followed by each item's serialized representation to the CSV file. -
setHeaderFormat
Sets the header format for the CSV file.- Parameters:
headerFormat
- a string representing the header format
-
printItems
Prints all items in the database with a specified title.- Parameters:
title
- the title to be printed before listing items
-
addItem
Adds a new item to the database records.- Parameters:
item
- theDatabaseItems
object to be added
-
getRecords
Returns a list of all database items.- Returns:
- a list of
DatabaseItems
objects in this database
-
createDatabaseItem
Creates a specificDatabaseItems
object from an array of values. This method must be implemented by subclasses to define how database items are created from CSV data.- Parameters:
values
- an array of strings containing data for creating an item- Returns:
- a new instance of
DatabaseItems
-
printItems
public abstract void printItems()Prints all items in this database. This method must be implemented by subclasses to provide specific printing functionality. -
removeItem
Removes an item from the database using its unique identifier.- Parameters:
id
- the unique identifier of the item to be removed- Returns:
- true if the item was successfully removed; false otherwise
-
searchItem
Searches for an item in the database using its unique identifier.- Parameters:
id
- the unique identifier of the item to search for- Returns:
- the found
DatabaseItems
object, or null if not found
-