org.salespointframework.core.data
Class MoneyBagImpl

java.lang.Object
  extended by org.salespointframework.core.data.AbstractNameable
      extended by org.salespointframework.core.data.StockItemImpl
          extended by org.salespointframework.core.data.StockImpl<java.lang.Integer,T,CT>
              extended by org.salespointframework.core.data.CountingStockImpl<StockItemImpl,CurrencyItemImpl>
                  extended by org.salespointframework.core.data.MoneyBagImpl
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<java.lang.Object>, java.lang.Iterable<StockItemImpl>, Recoverable, DatasourceChangeListener, ExternalModificationListener, CountingStock<StockItemImpl,CurrencyItemImpl>, DataBasketEntryDestination, DataBasketEntrySource, DataBasketKeys, ListenableStock<StockItemImpl,CurrencyItemImpl>, MoneyBag, Nameable, NameContext, SpAggregate, SpItem, Stock<StockItemImpl,CurrencyItemImpl>, StockItem, SelfManagingDBEDestination<StockItemImpl>, SelfManagingDBESource<StockItemImpl>

public class MoneyBagImpl
extends CountingStockImpl<StockItemImpl,CurrencyItemImpl>
implements MoneyBag

Pure Java implementation of the MoneyBag interface.

Since:
v2.0
Version:
2.0 19/08/1999
Author:
Steffen Zschaler

Nested Class Summary
 
Nested classes/interfaces inherited from class org.salespointframework.core.data.StockImpl
StockImpl.CatalogItemNameListener
 
Field Summary
 
Fields inherited from class org.salespointframework.core.data.CountingStockImpl
m_cclReferentialIntegrityListener
 
Fields inherited from class org.salespointframework.core.data.StockImpl
m_cclEditListener, m_ciCatalog, m_cinlCatalogItemNameListener, m_dbCatalogValidator, m_lhListeners, m_sclEditCreatorListener
 
Fields inherited from class org.salespointframework.core.data.StockItemImpl
COMMIT_ACTION, ROLLBACK_ACTION, STARTEDIT_ACTION
 
Fields inherited from class org.salespointframework.core.data.AbstractNameable
m_ncContext, m_pcsPropertyListeners, SOME_PROPERTY
 
Fields inherited from interface org.salespointframework.core.data.interfaces.Nameable
NAME_PROPERTY
 
Fields inherited from interface org.salespointframework.core.data.interfaces.DataBasketKeys
CATALOG_ITEM_MAIN_KEY, STOCK_ITEM_MAIN_KEY
 
Constructor Summary
  MoneyBagImpl(java.lang.String sName, AbstractCurrency ac, boolean temporary)
           
private MoneyBagImpl(java.lang.String sName, Catalog c)
          Create a new MoneyBagImpl.
  MoneyBagImpl(java.lang.String sName, Catalog c, boolean temporary)
           
 
Method Summary
private  CatalogItem nextLowerUnit(Value vLimit)
          Helper method for getChange.
private  int nextUnit(MoneyBag mbSrc, MoneyBag mbDest, DataBasket db, Value vToChange, Value vLimit)
          Searches the optimal way to return the change.
 java.lang.String toString()
          Return a String representation of the MoneyBag.
 void transferMoney(MoneyBag mbDest, DataBasket db, NumberValue nvAmount)
          Tries to transfer money from this DataBasket into another one.
 
Methods inherited from class org.salespointframework.core.data.CountingStockImpl
add, add, addStock, commitAdd, commitRemove, contains, containsStock, countItems, createPeer, get, internalSetCatalog, remove, remove, remove, rollbackAdd, rollbackRemove
 
Methods inherited from class org.salespointframework.core.data.StockImpl
addStockChangeListener, checkNameChange, clone, compareTo, contains, DatasourceChanged, externalModificationOccurred, fillShallowClone, fillStockWithValue, fireCanEditStockItems, fireCanRemoveStockItems, fireEditingStockItems, fireStockItemsAddCommit, fireStockItemsAdded, fireStockItemsAddRollback, fireStockItemsEditCommit, fireStockItemsEditRollback, fireStockItemsRemoveCommit, fireStockItemsRemoved, fireStockItemsRemoveRollback, getCatalog, getEditingItemsContainer, getItemsContainer, getItemsLock, getNCMonitor, getRefIntegrEditContainer, getRefIntegrItemsContainer, getShallowClone, getTemporaryAddedItemsContainer, getTemporaryRemovedItemsContainer, iterator, iterator, keySet, nameHasChanged, prepareReferentialIntegrity, relinkCatalog, removeStockChangeListener, setEditingItemsContainer, setItemsContainer, setRefIntegrEditContainer, setRefIntegrItemsContainer, setStock, setTemporaryAddedItemsContainer, setTemporaryRemovedItemsContainer, size, sumStock, unsubscribe
 
Methods inherited from class org.salespointframework.core.data.StockItemImpl
equals, firePropertyChanged, getAssociatedItem, getStock, internalSetName, recover
 
Methods inherited from class org.salespointframework.core.data.AbstractNameable
addNameListener, addPropertyChangeListener, attach, detachNC, getName, removeNameListener, removePropertyChangeListener, setName
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.salespointframework.core.data.interfaces.CountingStock
add, remove
 
Methods inherited from interface org.salespointframework.core.data.interfaces.Stock
add, addStock, contains, contains, containsStock, countItems, fillStockWithValue, get, getCatalog, iterator, keySet, remove, remove, size, sumStock
 
Methods inherited from interface org.salespointframework.core.data.interfaces.StockItem
clone, getAssociatedItem, getStock
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface org.salespointframework.core.data.interfaces.Nameable
addNameListener, addPropertyChangeListener, attach, detachNC, getName, removeNameListener, removePropertyChangeListener, setName
 
Methods inherited from interface org.salespointframework.core.data.interfaces.SpItem
getName
 
Methods inherited from interface org.salespointframework.core.data.events.DatasourceChangeListener
DatasourceChanged
 
Methods inherited from interface org.salespointframework.core.data.events.ExternalModificationListener
externalModificationOccurred
 
Methods inherited from interface java.lang.Iterable
iterator
 

Constructor Detail

MoneyBagImpl

private MoneyBagImpl(java.lang.String sName,
                     Catalog c)
Create a new MoneyBagImpl.

Parameters:
sName - the name of the MoneyBag.
ac - the Currency associated to the MoneyBag.
temporary - true, if moneybag should not be persisted

MoneyBagImpl

public MoneyBagImpl(java.lang.String sName,
                    AbstractCurrency ac,
                    boolean temporary)

MoneyBagImpl

public MoneyBagImpl(java.lang.String sName,
                    Catalog c,
                    boolean temporary)
Method Detail

transferMoney

public void transferMoney(MoneyBag mbDest,
                          DataBasket db,
                          NumberValue nvAmount)
Tries to transfer money from this DataBasket into another one.

Specified by:
transferMoney in interface MoneyBag
Parameters:
mbDest - the MoneyBag to transfer the money to
db - a transaction DataBasket
nvAmount - the amount of money to transfer

nextUnit

private int nextUnit(MoneyBag mbSrc,
                     MoneyBag mbDest,
                     DataBasket db,
                     Value vToChange,
                     Value vLimit)
Searches the optimal way to return the change.

Parameters:
mbSrc - the source MoneyBag from which money is removed
mbDest - the destination MoneyBag to which money is added
vToChange - the amount of money to change
vLimit - the maximum value of currency units to be considered
Returns:
an NumberValue indicating success (0) or failure (-1).

nextLowerUnit

private CatalogItem nextLowerUnit(Value vLimit)
Helper method for getChange. Searches and returns the biggest currency unit in this MoneyBag which is worth less than vLimit. If there is no matching currency unit, null is returnded.

Parameters:
vLimit - the limit which the returned currency unit must not exceed.
Returns:
a CatalogItem that represents the greatest available currency unit which does not exceed vLimit

toString

public java.lang.String toString()
Return a String representation of the MoneyBag.

In addition to the representation created by the super class this will calculate the total amount of this MoneyBag and append this in formatted form to the end of the representation.

Overrides:
toString in class CountingStockImpl<StockItemImpl,CurrencyItemImpl>