Package src.database

Class Database

Object
Database

public class Database extends Object
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 Details

    • CINEPLEX

      public static HashMap<String,Cineplex> CINEPLEX
      Cineplex Model in database
    • CINEMA

      public static HashMap<String,Cinema> CINEMA
      Cinema Model in database
    • SEAT

      public static HashMap<String,Seat> SEAT
      Seat Model in database
    • MOVIE_SCHEDULE

      public static HashMap<String,MovieSchedule> MOVIE_SCHEDULE
      Movie Schedule Model in database
    • BOOKING_HISTORY

      public static HashMap<String,BookingHistory> BOOKING_HISTORY
      Booking History Model in database
    • PAYMENT

      public static HashMap<String,Payment> PAYMENT
      Payment Model in database
    • MOVIE

      public static HashMap<String,Movie> MOVIE
      Movie Model in database
    • MOVIE_GOER

      public static HashMap<String,MovieGoer> MOVIE_GOER
      Movie Goer in database
    • MOVIE_REVIEW

      public static HashMap<String,MovieReview> MOVIE_REVIEW
      Movie Review in database
    • CINEMA_STAFF

      public static HashMap<String,CinemaStaff> CINEMA_STAFF
      Cinema Staff in database
    • MOVIE_TICKET

      public static HashMap<String,MovieTicket> MOVIE_TICKET
      Movie Ticket in database
    • totalNumOfSeats

      public static int totalNumOfSeats
      Total number of seats for every cinema
    • numOfRows

      public static int numOfRows
      Total number of rows in a cinema
    • numOfCoupleRows

      public static int numOfCoupleRows
      Total number of couple rows in a cinema
    • holidays

      public static ArrayList<DateTime> holidays
      All the holidays
    • PRICES

      public static Prices PRICES
      All the price weights of cinema class, movie goer age, seat type, movie type
    • PERMISSION

      public static Permission PERMISSION
      All the permissions of a movie goer
    • platinumNumOfRow

      public static int platinumNumOfRow
      Pre-defined variables for the number of rows of seats in a platinum cinema
    • platinumNumOfSeatsPerRow

      public static int platinumNumOfSeatsPerRow
      Pre-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

      public static boolean readData(ModelType modelType)
      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

      public static boolean writeData(ModelType modelType)
      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

      public static ArrayList<String> getKeyList(Collection keySet)
      Method to return an ArrayList of HashMap keys for the collection keySet
      Parameters:
      keySet - a HashMap keys collection
      Returns:
      ArrayList of String containing HashMap keys
    • getValueList

      public static <V> ArrayList<V> getValueList(Collection valueSet)
      Method to return an ArrayList of HashMap values for the collection valueSet
      Type Parameters:
      V - generic form for value
      Parameters:
      valueSet - a HashMap values collection
      Returns:
      ArrayList of Value containing HashMap values
    • getValueByKey

      public static <K, V> V getValueByKey(K key, HashMap<K,V> data)
      Method to retrieve the value of a key in the HashMap database
      Type Parameters:
      K - generic form for Key
      V - generic form for value
      Parameters:
      key - the key we wish to search the value for
      data - the database
      Returns:
      V that is the value of the key key
    • getKeyByValue

      public static <K, V> String getKeyByValue(V value, HashMap<K,V> data)
      Method to retrieve the key of a value in the HashMap database
      Type Parameters:
      K - generic form for Key
      V - generic form for value
      Parameters:
      value - the value we wish to search the key for
      data - the database
      Returns:
      String that is the key of the value value