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>COURSESAHashmap<String, Course>that stores allCourses and its contained information.protected static AccessLevelCURRENT_ACCESS_LEVELThe current AccessLevel of the currently logged in User.protected static UserCURRENT_USERA User object that keeps track of the currently logged in User.private static java.lang.StringfilePathThe path to the directory where the data files are stored.protected static java.util.HashMap<java.lang.String,java.lang.Object>SETTINGSAHashmap<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>USERSAHashmap<String, User>that stores allUsers and their contained information. -
Constructor Summary
Constructors Modifier Constructor Description protectedDatabase()The initialiser for the Database class. -
Method Summary
Modifier and Type Method Description protected static booleandeserialise(FileType fileType)Reads files into its respective Hashmap.private voidresetUsers()Resets Admin users if they have been deleted.private voidrestoreSettings()Reads and restores key settings from file.protected static booleanserialise(FileType fileType)Writes Hashmaps into the respective files.
-
Field Details
-
filePath
private static java.lang.String filePathThe path to the directory where the data files are stored. -
COURSES
AHashmap<String, Course>that stores allCourses and its contained information. -
USERS
AHashmap<String, User>that stores allUsers and their contained information. -
SETTINGS
protected static java.util.HashMap<java.lang.String,java.lang.Object> SETTINGSAHashmap<String, Object>that stores all Miscellaneous settings so that the application can return to its previous state after shutdown. -
CURRENT_USER
A User object that keeps track of the currently logged in User. -
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
Reads files into its respective Hashmap.- Parameters:
fileType- The type of file being read of typeFileType.- Returns:
trueif successfully read file.
-
serialise
Writes Hashmaps into the respective files.- Parameters:
fileType- The type of the file being written.- Returns:
trueif 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.
-