Package MySTARS

Class Database

java.lang.Object
MySTARS.Database

public final class Database
extends java.lang.Object
The Class that interacts with the files and handles reading and writing of information.
Since:
2020-11-1
Version:
1.0
Author:
Bhargav
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected static java.util.HashMap<java.lang.String,​Course> COURSES
    A Hashmap<String, Course> that stores all Courses and its contained information.
    protected static AccessLevel CURRENT_ACCESS_LEVEL
    The current AccessLevel of the currently logged in User.
    protected static User CURRENT_USER
    A User object that keeps track of the currently logged in User.
    private static java.lang.String filePath
    The path to the directory where the data files are stored.
    protected static java.util.HashMap<java.lang.String,​java.lang.Object> SETTINGS
    A Hashmap<String, Object> that stores all Miscellaneous settings so that the application can return to its previous state after shutdown.
    protected static java.util.HashMap<java.lang.String,​User> USERS
    A Hashmap<String, User> that stores all Users and their contained information.
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
    protected Database()
    The initialiser for the Database class.
  • Method Summary

    Modifier and Type Method Description
    protected static boolean deserialise​(FileType fileType)
    Reads files into its respective Hashmap.
    private void resetUsers()
    Resets Admin users if they have been deleted.
    private void restoreSettings()
    Reads and restores key settings from file.
    protected static boolean serialise​(FileType fileType)
    Writes Hashmaps into the respective files.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • filePath

      private static java.lang.String filePath
      The path to the directory where the data files are stored.
    • COURSES

      protected static java.util.HashMap<java.lang.String,​Course> COURSES
      A Hashmap<String, Course> that stores all Courses and its contained information.
    • USERS

      protected static java.util.HashMap<java.lang.String,​User> USERS
      A Hashmap<String, User> that stores all Users and their contained information.
    • SETTINGS

      protected static java.util.HashMap<java.lang.String,​java.lang.Object> SETTINGS
      A Hashmap<String, Object> that stores all Miscellaneous settings so that the application can return to its previous state after shutdown.
    • CURRENT_USER

      protected static User CURRENT_USER
      A User object that keeps track of the currently logged in User.
    • CURRENT_ACCESS_LEVEL

      protected static AccessLevel CURRENT_ACCESS_LEVEL
      The current AccessLevel of the currently logged in User.
  • Constructor Details

    • Database

      protected Database()
      The initialiser for the Database class. Reads Files on startup, resets key Admin Users if they have been deleted and retores all Application Settings from last close.
  • Method Details

    • deserialise

      protected static boolean deserialise​(FileType fileType)
      Reads files into its respective Hashmap.
      Parameters:
      fileType - The type of file being read of type FileType.
      Returns:
      true if successfully read file.
    • serialise

      protected static boolean serialise​(FileType fileType)
      Writes Hashmaps into the respective files.
      Parameters:
      fileType - The type of the file being written.
      Returns:
      true if successfully wrote file.
    • resetUsers

      private void resetUsers()
      Resets Admin users if they have been deleted.
    • restoreSettings

      private void restoreSettings()
      Reads and restores key settings from file.