From fbb7efedcf0f443f4731f313ac55ce21894195d8 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:21:41 +0100 Subject: [PATCH] Implements search function and test for search --- src/main/java/CredentialRepository.java | 7 ++++++- src/main/java/CredentialRepositoryInterface.java | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index f8f66f3..2c49131 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -33,11 +33,15 @@ public class CredentialRepository implements CredentialRepositoryInterface{ } + @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; @@ -45,8 +49,9 @@ public class CredentialRepository implements CredentialRepositoryInterface{ @Override - public void getCredentialsViaId() { + public Credential getCredentialsViaId() { + return null; } @Override diff --git a/src/main/java/CredentialRepositoryInterface.java b/src/main/java/CredentialRepositoryInterface.java index de543eb..85db2ed 100644 --- a/src/main/java/CredentialRepositoryInterface.java +++ b/src/main/java/CredentialRepositoryInterface.java @@ -3,8 +3,8 @@ public interface CredentialRepositoryInterface { int createNewCredential(String name, String password); void edit(); void delete(); - void getCredentialsViaName(); - void getCredentialsViaId(); + Credential getCredentialsViaName(String needle); + Credential getCredentialsViaId(); void setCredentials(); void getAsJSON(); void loadCredentialsFromJSON();