Class InMemoryAccountRepository
- java.lang.Object
-
- de.japrost.jabudget.repository.inmemory.InMemoryAccountRepository
-
- All Implemented Interfaces:
AccountRepository
public class InMemoryAccountRepository extends java.lang.Object implements AccountRepository
AccountRepositorystoring in memory without persistence. Mostly for test and development.
This implementation is not thread safe.
-
-
Constructor Summary
Constructors Constructor Description InMemoryAccountRepository()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description de.japrost.jabudget.domain.account.Accountcreate(de.japrost.jabudget.domain.account.Account account)Create a newAccountwith the given values.de.japrost.jabudget.domain.account.Entrycreate(de.japrost.jabudget.domain.account.Entry entry)Create a newEntrywith the given values.java.lang.Booleandelete(java.lang.String accountId)Delete anAccountby its id.java.util.Set<de.japrost.jabudget.domain.account.Account>findAll()Find allAccounts.java.util.Optional<de.japrost.jabudget.domain.account.Account>findById(java.lang.String id)Find anAccountby id.voidreplaceAll(java.util.Set<de.japrost.jabudget.domain.account.Account> accounts)Replace allAccounts with the given.de.japrost.jabudget.domain.account.Accountupdate(de.japrost.jabudget.domain.account.Account account)Update an existingAccount.
-
-
-
Method Detail
-
create
public de.japrost.jabudget.domain.account.Account create(de.japrost.jabudget.domain.account.Account account) throws de.japrost.jabudget.domain.DomainExceptionCreate a newAccountwith the given values.This implementation stores and gives defensive copies of the given account.
- Specified by:
createin interfaceAccountRepository- Parameters:
account- theAccountto create.- Returns:
- The account as stored in the repository.
- Throws:
de.japrost.jabudget.domain.DomainException- withDomainFailure.DUPLICATE_ENTITYif the given account already exists.
-
update
public de.japrost.jabudget.domain.account.Account update(de.japrost.jabudget.domain.account.Account account) throws de.japrost.jabudget.domain.DomainExceptionUpdate an existingAccount.This implementation stores and gives defensive copies of the given account.
- Specified by:
updatein interfaceAccountRepository- Parameters:
account- theAccountto update.- Returns:
- The account as stored in the repository.
- Throws:
de.japrost.jabudget.domain.DomainException- withDomainFailure.MISSING_ENTITYif the given account does not exist.
-
replaceAll
public void replaceAll(java.util.Set<de.japrost.jabudget.domain.account.Account> accounts)
Replace allAccounts with the given. Intended for imports.
Also replaces clears theEntrys of all accounts.This implementation clears existing and adds defensive copies to store.
- Specified by:
replaceAllin interfaceAccountRepository- Parameters:
accounts- theAccounts to fill the repository.
-
findById
public java.util.Optional<de.japrost.jabudget.domain.account.Account> findById(java.lang.String id)
Find anAccountby id.This implementation gives a defensive copy of the stored accounts.
- Specified by:
findByIdin interfaceAccountRepository- Parameters:
id- theAccountid.- Returns:
- the
Accountwith the id. An emptyOptionalif noAccountis available for the given id.
-
findAll
public java.util.Set<de.japrost.jabudget.domain.account.Account> findAll()
Find allAccounts.This implementation gives defensive copies of all stored accounts.
- Specified by:
findAllin interfaceAccountRepository- Returns:
- all available
Accounts.
-
delete
public java.lang.Boolean delete(java.lang.String accountId)
Delete anAccountby its id.This implementation returns
Boolean.TRUEalways.- Specified by:
deletein interfaceAccountRepository- Parameters:
accountId- the id of theAccountto delete.- Returns:
Boolean.TRUEif the Account does not exist after this operation. It does not indicate that the entity to delete did exist. ReturnsBoolean.FALSEif the entity could not be deleted.
-
create
public de.japrost.jabudget.domain.account.Entry create(de.japrost.jabudget.domain.account.Entry entry) throws de.japrost.jabudget.domain.DomainExceptionDescription copied from interface:AccountRepositoryCreate a newEntrywith the given values.- Specified by:
createin interfaceAccountRepository- Parameters:
entry- the entry to create.- Returns:
- The entry as stored in the repository.
- Throws:
de.japrost.jabudget.domain.DomainException- withDomainFailure.DUPLICATE_ENTITYif the given entry already exists.
-
-