Package src.database
Class Database
Object
Database
The database of the application.
A buffer in the form of HashMap is used for handling intermediary data
transfers.
DAT files are used for storing persistent data.
This class is equipped with functions to facilitate the read and write
between program, buffer and the DAT database.
- Version:
- 1.0
- Author:
- Lee Juin
-
Field Summary
Modifier and TypeFieldDescriptionstatic HashMap<String,
BookingHistory> Booking History Model in databaseCinema Model in databasestatic HashMap<String,
CinemaStaff> Cinema Staff in databaseCineplex Model in databaseAll the holidaysMovie Model in databaseMovie Goer in databasestatic HashMap<String,
MovieReview> Movie Review in databasestatic HashMap<String,
MovieSchedule> Movie Schedule Model in databasestatic HashMap<String,
MovieTicket> Movie Ticket in databasestatic int
Total number of couple rows in a cinemastatic int
Total number of rows in a cinemaPayment Model in databasestatic Permission
All the permissions of a movie goerstatic int
Pre-defined variables for the number of rows of seats in a platinum cinemastatic int
Pre-defined variables for the number of seats per row in a platinum cinemastatic Prices
All the price weights of cinema class, movie goer age, seat type, movie typeSeat Model in databasestatic int
Total number of seats for every cinema -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> String getKeyByValue
(V value, HashMap<K, V> data) Method to retrieve the key of a value in the HashMap databasegetKeyList
(Collection keySet) Method to return an ArrayList of HashMap keys for the collectionkeySet
static <K,
V> V getValueByKey
(K key, HashMap<K, V> data) Method to retrieve the value of a key in the HashMap databasestatic <V> ArrayList<V>
getValueList
(Collection valueSet) Method to return an ArrayList of HashMap values for the collectionvalueSet
static boolean
Method to read serialized data from database filestatic boolean
Method to reload the database.static void
Method to reset the databasestatic boolean
Method to write serialized data into database filestatic boolean
Method to save all changes to database.
-
Field Details
-
CINEPLEX
Cineplex Model in database -
CINEMA
Cinema Model in database -
SEAT
Seat Model in database -
MOVIE_SCHEDULE
Movie Schedule Model in database -
BOOKING_HISTORY
Booking History Model in database -
PAYMENT
Payment Model in database -
MOVIE
Movie Model in database -
MOVIE_GOER
Movie Goer in database -
MOVIE_REVIEW
Movie Review in database -
CINEMA_STAFF
Cinema Staff in database -
MOVIE_TICKET
Movie Ticket in database -
totalNumOfSeats
public static int totalNumOfSeatsTotal number of seats for every cinema -
numOfRows
public static int numOfRowsTotal number of rows in a cinema -
numOfCoupleRows
public static int numOfCoupleRowsTotal number of couple rows in a cinema -
holidays
All the holidays -
PRICES
All the price weights of cinema class, movie goer age, seat type, movie type -
PERMISSION
All the permissions of a movie goer -
platinumNumOfRow
public static int platinumNumOfRowPre-defined variables for the number of rows of seats in a platinum cinema -
platinumNumOfSeatsPerRow
public static int platinumNumOfSeatsPerRowPre-defined variables for the number of seats per row in a platinum cinema
-
-
Constructor Details
-
Database
public Database()Constructor for database. Call this when startup to load all data from DAT into HashMap buffer
-
-
Method Details
-
readData
Method to read serialized data from database file- Parameters:
modelType
- is the model to be read- Returns:
true
if read is successful;false
otherwise
-
writeData
Method to write serialized data into database file- Parameters:
modelType
- is the model to be written- Returns:
true
if write is successful;false
otherwise
-
remountDatabase
public static boolean remountDatabase()Method to reload the database. Useful when a change was recently made and user requires immediate reflected changes.- Returns:
true
when reload is successful;false
otherwise
-
writeToDatabase
public static boolean writeToDatabase()Method to save all changes to database. Useful on first load to save dummy data.- Returns:
- {code true} if write is successful;
false
otherwise
-
resetDatabase
public static void resetDatabase()Method to reset the database -
getKeyList
Method to return an ArrayList of HashMap keys for the collectionkeySet
- Parameters:
keySet
- a HashMap keys collection- Returns:
- ArrayList of
String
containing HashMap keys
-
getValueList
Method to return an ArrayList of HashMap values for the collectionvalueSet
- Type Parameters:
V
- generic form for value- Parameters:
valueSet
- a HashMap values collection- Returns:
- ArrayList of
Value
containing HashMap values
-
getValueByKey
Method to retrieve the value of a key in the HashMap database- Type Parameters:
K
- generic form for KeyV
- generic form for value- Parameters:
key
- the key we wish to search the value fordata
- the database- Returns:
V
that is the value of the keykey
-
getKeyByValue
Method to retrieve the key of a value in the HashMap database- Type Parameters:
K
- generic form for KeyV
- generic form for value- Parameters:
value
- the value we wish to search the key fordata
- the database- Returns:
String
that is the key of the valuevalue
-