org.zeroexchange.money
Class DefaultMoneyManager

java.lang.Object
  extended by org.zeroexchange.common.AbstractBeansRegistry<T>
      extended by org.zeroexchange.common.TypedBeansRegistry<CurrencyManager>
          extended by org.zeroexchange.money.DefaultMoneyManager
All Implemented Interfaces:
org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.beans.factory.InitializingBean, BeansRegistry<CurrencyManager>, MoneyManager

public class DefaultMoneyManager
extends TypedBeansRegistry<CurrencyManager>
implements MoneyManager

Author:
black

Constructor Summary
DefaultMoneyManager()
           
 
Method Summary
 void afterPropertiesSet()
           
 void freeAmount(BigDecimal amount, ZECurrency currencyCode, User user)
          Frees amount of money in the specified currency.
 BigDecimal getAllowedDebt(ZECurrency currencyCode, User user)
          Returns maximum allowed debt for user in the specified currency.
 BigDecimal getAvailableAmount(ZECurrency currencyCode, User user)
          Returns available amount of the specified current user for the specified code.
protected  Class<?> getBeanClass()
           
protected  Map<String,CurrencyManager> getCurrencyCode2AmountProvider()
          Returns map of currencies 2 money amount managers.
protected  CurrencyManager getCurrencyManager(ZECurrency currencyCode)
          Returns currency manager by the currency code.
 ZECurrency getDefaultCurrency()
          Returns default currency.
 BigDecimal getHourPrice(BigDecimal rate, ZECurrency currencyCode, User user)
          Returns price of the hour according the specified rate.
 BigDecimal getHourRate(BigDecimal hoursPrice, ZECurrency currencyCode, User user)
          Returns the hour rate.
 Set<String> getSupportedCurrencies()
          Returns the codes of the supported currencies.
 boolean isAutoMovementEnabled(ZECurrency currencyCode)
          Returns true if the money movement is enabled for the specified currency.
 boolean isCurrencyManagetExists(ZECurrency currencyCode)
          Returns true if the currency manager exists.
 boolean isOutlayAllowed(ZECurrency currencyCode, User user, BigDecimal amount)
          Returns true if user is allowed outlay of the specified amount.
 void performAutoMovement(Collection<PayerData> payersData, Collection<User> consumers)
          Performs money movement.
 void reconcile(Set<PayerData> usersEfforts)
          Reconcile users.
 void reserveAmount(BigDecimal amount, ZECurrency currencyCode, User user)
          Reserves amount of money in the specified currency.
 void setDefaultCurrency(ZECurrency defaultCurrency)
           
 
Methods inherited from class org.zeroexchange.common.TypedBeansRegistry
isElected
 
Methods inherited from class org.zeroexchange.common.AbstractBeansRegistry
createBeansCollection, getBeans, postProcessAfterInitialization, postProcessBeforeInitialization
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultMoneyManager

public DefaultMoneyManager()
Method Detail

getAvailableAmount

public BigDecimal getAvailableAmount(ZECurrency currencyCode,
                                     User user)
Returns available amount of the specified current user for the specified code.

Specified by:
getAvailableAmount in interface MoneyManager

reserveAmount

public void reserveAmount(BigDecimal amount,
                          ZECurrency currencyCode,
                          User user)
Reserves amount of money in the specified currency.

Specified by:
reserveAmount in interface MoneyManager

freeAmount

public void freeAmount(BigDecimal amount,
                       ZECurrency currencyCode,
                       User user)
Frees amount of money in the specified currency.

Specified by:
freeAmount in interface MoneyManager

performAutoMovement

@Transactional
public void performAutoMovement(Collection<PayerData> payersData,
                                              Collection<User> consumers)
Performs money movement.

Specified by:
performAutoMovement in interface MoneyManager

isAutoMovementEnabled

public boolean isAutoMovementEnabled(ZECurrency currencyCode)
Returns true if the money movement is enabled for the specified currency.

Specified by:
isAutoMovementEnabled in interface MoneyManager

getSupportedCurrencies

public Set<String> getSupportedCurrencies()
Returns the codes of the supported currencies.

Specified by:
getSupportedCurrencies in interface MoneyManager

isCurrencyManagetExists

public boolean isCurrencyManagetExists(ZECurrency currencyCode)
Returns true if the currency manager exists.

Specified by:
isCurrencyManagetExists in interface MoneyManager

getHourRate

public BigDecimal getHourRate(BigDecimal hoursPrice,
                              ZECurrency currencyCode,
                              User user)
Returns the hour rate.

Specified by:
getHourRate in interface MoneyManager

getHourPrice

public BigDecimal getHourPrice(BigDecimal rate,
                               ZECurrency currencyCode,
                               User user)
Returns price of the hour according the specified rate.

Specified by:
getHourPrice in interface MoneyManager

getCurrencyManager

protected CurrencyManager getCurrencyManager(ZECurrency currencyCode)
Returns currency manager by the currency code.


getCurrencyCode2AmountProvider

protected Map<String,CurrencyManager> getCurrencyCode2AmountProvider()
Returns map of currencies 2 money amount managers. Initializes map if necessary.


reconcile

public void reconcile(Set<PayerData> usersEfforts)
Reconcile users. Bring efforts of all users to the equal state.

Specified by:
reconcile in interface MoneyManager

getAllowedDebt

public BigDecimal getAllowedDebt(ZECurrency currencyCode,
                                 User user)
Returns maximum allowed debt for user in the specified currency.

Specified by:
getAllowedDebt in interface MoneyManager

isOutlayAllowed

public boolean isOutlayAllowed(ZECurrency currencyCode,
                               User user,
                               BigDecimal amount)
Returns true if user is allowed outlay of the specified amount.

Specified by:
isOutlayAllowed in interface MoneyManager

getDefaultCurrency

public ZECurrency getDefaultCurrency()
Returns default currency.

Specified by:
getDefaultCurrency in interface MoneyManager

setDefaultCurrency

public void setDefaultCurrency(ZECurrency defaultCurrency)

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Overrides:
afterPropertiesSet in class TypedBeansRegistry<CurrencyManager>
Throws:
Exception

getBeanClass

protected Class<?> getBeanClass()
Specified by:
getBeanClass in class TypedBeansRegistry<CurrencyManager>


Copyright © 2013. All Rights Reserved.