topdown.service
Class BankMemDB

java.lang.Object
  extended bytopdown.service.BankMemDB
All Implemented Interfaces:
Bank

public class BankMemDB
extends java.lang.Object
implements Bank

An in-memory bank implementation.


Field Summary
private static BankMemDB DB_INSTANCE
          The bank singleton.
private  java.util.List m_accounts
          The list of accounts managed by this bank.
 
Constructor Summary
private BankMemDB()
          Creates a bank instance.
 
Method Summary
 java.lang.String addNewAccount(java.lang.String name, float initBalance)
          Adds a new account.
 Account getAccount(java.lang.String id)
          Returns the account that has the given ID.
 java.util.List getAccounts()
          Returns a list of all account in the bank.
static BankMemDB newInstance()
          Provides access to the bank singleton.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DB_INSTANCE

private static BankMemDB DB_INSTANCE
The bank singleton.


m_accounts

private java.util.List m_accounts
The list of accounts managed by this bank.

Constructor Detail

BankMemDB

private BankMemDB()
Creates a bank instance.

Method Detail

newInstance

public static BankMemDB newInstance()
Provides access to the bank singleton.

Returns:
the bank instance.

addNewAccount

public java.lang.String addNewAccount(java.lang.String name,
                                      float initBalance)
                               throws AccountException
Adds a new account.

Specified by:
addNewAccount in interface Bank
Parameters:
name - the account owner's name.
initBalance - the initial balance for the account.
Returns:
the generated account ID.
Throws:
AccountException - if the initial balance is insufficent (<= 0).

getAccount

public Account getAccount(java.lang.String id)
Returns the account that has the given ID.

Specified by:
getAccount in interface Bank
Parameters:
id - the account ID.
Returns:
the account.

getAccounts

public java.util.List getAccounts()
Returns a list of all account in the bank.

Specified by:
getAccounts in interface Bank
Returns:
the list of accounts.