Class DataManager
java.lang.Object
io.github.michael_bailey.client.managers.DataManager
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class DataManager
extends java.lang.Object
implements java.io.Closeable
Data Manager
this class privides a way to store objects using key value pairs
so that they can be stored securely in a file for later use.
- Since:
- 1.0
-
Constructor Summary
Constructors Constructor Description DataManager()establishes inital state on creation -
Method Summary
Modifier and Type Method Description booleanaddObject(java.lang.String key, java.lang.Object object)this adds an object to the unlockedstatic booleancheckFileNameValid(java.lang.String filename)checkFileNameValid this is a helper function that checks a string to see if it is a valid file name.static booleancheckPasswordValid(java.lang.String password)checkFileNameValid this is a helper function that checks a string to see if it is a valid password.voidclose()used to close the file when it is lost to gc or the program is closing downbooleancreateNew(java.lang.String name, java.lang.String password)creates a new data file and saves a blank hash mapjava.lang.ObjectgetObject(java.lang.String key)this gets the data from a unlocked data storebooleanisUnlocked()booleanlock()called when data is to be saved and the object be reset to its original statejava.lang.BooleanremoveObject(java.lang.String key)removes the objecto stored at the key provided technically sets it to nullbooleansave()forces the data to be saved to the filebooleanunlock(java.lang.String name, java.lang.String password)loads data stored in a file into the data manager.
-
Constructor Details
-
DataManager
public DataManager()establishes inital state on creation- Since:
- 1.0
-
-
Method Details
-
unlock
public boolean unlock(java.lang.String name, java.lang.String password)loads data stored in a file into the data manager.- Parameters:
name- the name of the file that contains the data.password- the password used when encrypting the data.- Returns:
- true when loaded.
- Since:
- 1.0
-
lock
public boolean lock()called when data is to be saved and the object be reset to its original state- Returns:
- true if it completed
- Since:
- 1.0
-
createNew
public boolean createNew(java.lang.String name, java.lang.String password)creates a new data file and saves a blank hash map- Parameters:
name- the name of the file that will be created.password- the pasword used when encrypting the data.- Returns:
- true when created and ready to use.
- Since:
- 1.0
-
save
public boolean save()forces the data to be saved to the file- Returns:
- true if it was successful
-
getObject
public java.lang.Object getObject(java.lang.String key)this gets the data from a unlocked data store- Parameters:
key- the key of where the object is stored- Returns:
- returns the new object that is decoded
-
addObject
public boolean addObject(java.lang.String key, java.lang.Object object)this adds an object to the unlocked- Parameters:
key- the key where the object is to be storedobject- the object thta is to be stored- Returns:
- boolean if the function finished correctly
-
removeObject
public java.lang.Boolean removeObject(java.lang.String key)removes the objecto stored at the key provided technically sets it to null- Parameters:
key- the key of the object to be removed- Returns:
- boolean if the function succeded
-
close
public void close()used to close the file when it is lost to gc or the program is closing down- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
isUnlocked
public boolean isUnlocked() -
checkFileNameValid
public static boolean checkFileNameValid(java.lang.String filename)checkFileNameValid this is a helper function that checks a string to see if it is a valid file name. invalid file names include any string with a special character, are less than 4 characters, and contain spaces.- Parameters:
filename- the filename without the extension (that is added in other calls)- Returns:
- boolean whether the string is a valid file name.
-
checkPasswordValid
public static boolean checkPasswordValid(java.lang.String password)checkFileNameValid this is a helper function that checks a string to see if it is a valid password. valid passwords must include a special character, be more than 8 characters, contain at least one capital letter. can be infinite in length (theoretically) credit to https://stackoverflow.com/questions/3802192/regexp-java-for-password-validation for a regex to match any password- Parameters:
password- the files password- Returns:
- boolean whether the string is a valid password.
-