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.

87 lines
1.5 KiB

  1. import java.util.ArrayList;
  2. public class CredentialRepository implements CredentialRepositoryInterface{
  3. private int idCounter = 0;
  4. private ArrayList<Credential> credentials;
  5. public CredentialRepository()
  6. {
  7. this.credentials = new ArrayList<Credential>();
  8. }
  9. public int createNewCredential(String name, String password)
  10. {
  11. try {
  12. this.credentials.add(new Credential(name, password, this.idCounter++));
  13. }
  14. catch(Exception fail)
  15. {
  16. System.err.println(fail.getMessage());
  17. }
  18. return this.getListSize();
  19. }
  20. @Override
  21. public void edit() {
  22. }
  23. @Override
  24. public void delete() {
  25. }
  26. @Override
  27. public Credential getCredentialsViaName(String needle) {
  28. for(int c = 0; c < this.getListSize(); c++)
  29. {
  30. Credential credential = this.credentials.get(c);
  31. if(credential.getName().equals(needle))
  32. return credential;
  33. }
  34. return null;
  35. }
  36. @Override
  37. public Credential getCredentialsViaId(int id) {
  38. try{
  39. return this.credentials.get(id);
  40. }
  41. catch (IndexOutOfBoundsException outOfBoundsException)
  42. {
  43. return null;
  44. }
  45. }
  46. @Override
  47. public void setCredentials() {
  48. }
  49. @Override
  50. public void getAsJSON() {
  51. }
  52. @Override
  53. public void loadCredentialsFromJSON() {
  54. }
  55. private int getListSize()
  56. {
  57. return this.credentials.size();
  58. }
  59. }