You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
1.9 KiB
92 lines
1.9 KiB
import java.util.ArrayList;
|
|
|
|
public class CredentialRepository implements CredentialRepositoryInterface{
|
|
|
|
private int idCounter = 0;
|
|
private ArrayList<Credential> credentials;
|
|
|
|
public CredentialRepository()
|
|
{
|
|
this.credentials = new ArrayList<Credential>();
|
|
}
|
|
|
|
public int createNewCredential(String name, String password)
|
|
{
|
|
try {
|
|
this.credentials.add(new Credential(name, password, this.idCounter++));
|
|
}
|
|
catch(Exception fail)
|
|
{
|
|
System.err.println(fail.getMessage());
|
|
}
|
|
|
|
return this.getListSize();
|
|
}
|
|
|
|
@Override
|
|
public Credential getCredentialsViaName(String needle) {
|
|
|
|
for(int c = 0; c < this.getListSize(); c++)
|
|
{
|
|
Credential credential = this.credentials.get(c);
|
|
|
|
if(credential.getName().equals(needle))
|
|
return credential;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
|
|
@Override
|
|
public Credential getCredentialsViaId(int id) {
|
|
|
|
try{
|
|
return this.credentials.get(id);
|
|
}
|
|
catch (IndexOutOfBoundsException outOfBoundsException)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
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
|
|
*/
|
|
|
|
|
|
@Override
|
|
public void updatePassword(int index, String newPassword) {
|
|
|
|
try{
|
|
this.credentials.get(index).upDatePassword(newPassword);
|
|
}
|
|
catch (IndexOutOfBoundsException outOfBoundsException)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void updateUsername(int index, String newUsername){
|
|
|
|
}
|
|
|
|
@Override
|
|
public void delete(int index) {
|
|
|
|
}
|
|
|
|
|
|
private int getListSize()
|
|
{
|
|
return this.credentials.size();
|
|
}
|
|
|
|
}
|
|
|
|
|