diff --git a/src/main/java/Credential.java b/src/main/java/Credential.java index 506fdb7..913780c 100644 --- a/src/main/java/Credential.java +++ b/src/main/java/Credential.java @@ -1,4 +1,6 @@ -public class Credential { +import java.io.Serializable; + +public class Credential implements Serializable { private String name, password; private int id; diff --git a/src/main/java/CredentialList.java b/src/main/java/CredentialList.java new file mode 100644 index 0000000..f81053f --- /dev/null +++ b/src/main/java/CredentialList.java @@ -0,0 +1,4 @@ +import java.io.Serializable; +import java.util.ArrayList; + +public class CredentialList extends ArrayList implements Serializable{} diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index 923f2f4..d37684d 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -1,15 +1,36 @@ -import java.util.ArrayList; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +/** + * Credential Repository for handling user credentials + * @author Claudia Metzler + */ public class CredentialRepository implements CredentialRepositoryInterface{ private int idCounter = 0; - private ArrayList credentials; + private CredentialList credentials; + /** + * Konstruktor + * + * Initializes instance variable ArrayList + */ public CredentialRepository() { - this.credentials = new ArrayList(); + this.credentials = new CredentialList(); } + + /** + * Create a new Set of User credentials + * @param name + * @param password + * @return size of repositoy - arraylist for checking + */ + public int createNewCredential(String name, String password) { try { @@ -23,6 +44,12 @@ public class CredentialRepository implements CredentialRepositoryInterface{ return this.getListSize(); } + /** + * Function to return a specific Credential via Name input + * @param needle [ aka to-search-for ] + * @return usercredential | NULL + */ + @Override public Credential getCredentialsViaName(String needle) { @@ -38,6 +65,12 @@ public class CredentialRepository implements CredentialRepositoryInterface{ } + /** + * Function to return a specific Credential via ID + * @param id + * @return usercredential | NULL + */ + @Override public Credential getCredentialsViaId(int id) { @@ -51,13 +84,11 @@ public class CredentialRepository implements CredentialRepositoryInterface{ } - /* - The next 3 functions assume you already have successfully - pulled a credential from the repository and now want to edit it. - Thus, these functions require you to pass the desired credential's index + /** + * Function to update userpassword, assuming we already know the userid + * @param index + * @param newPassword */ - - @Override public void updatePassword(int index, String newPassword) { @@ -71,6 +102,12 @@ public class CredentialRepository implements CredentialRepositoryInterface{ } + + /** + * Function to update username analoge to updatePassword + * @param index + * @param newUsername + */ public void updateUsername(int index, String newUsername){ try{ @@ -82,6 +119,11 @@ public class CredentialRepository implements CredentialRepositoryInterface{ } } + /** + * Deletion function for credentials + * Will immediately delete - double check for user permission + * @param index + */ @Override public void delete(int index) { @@ -89,28 +131,68 @@ public class CredentialRepository implements CredentialRepositoryInterface{ } -/* - this function will be required in the future for catching the left-shift in the arrayList - after one entry was deleted. welp, maybe it won't. can't tell and i've no time atm to - finish this + /** + * Function for serialization of all Credentials + * @param fileName + */ + public void serializeObject(String fileName) + { + if(fileName.equals("")) return; - private int mapIndexToListCounter(int needle) { - for(int c = 0; c