SalesPoint v3.3 API

data.ooimpl
Class CountingStockImpl<T extends StockItemImpl,CT extends CatalogItemImpl>

java.lang.Object
  extended by data.AbstractNameable
      extended by data.ooimpl.StockItemImpl
          extended by data.ooimpl.StockImpl<Integer,T,CT>
              extended by data.ooimpl.CountingStockImpl<T,CT>
All Implemented Interfaces:
CountingStock<T,CT>, DataBasketEntryDestination, DataBasketEntrySource, DataBasketKeys, ListenableStock<T,CT>, Nameable, NameContext, SelfManagingDBEDestination<T>, SelfManagingDBESource<T>, Stock<T,CT>, StockItem, Serializable, Cloneable, Comparable<Object>
Direct Known Subclasses:
MoneyBagImpl

public class CountingStockImpl<T extends StockItemImpl,CT extends CatalogItemImpl>
extends StockImpl<Integer,T,CT>
implements CountingStock<T,CT>

Pure Java implementation of the CountingStock interface.

Since:
v2.0
Author:
Steffen Zschaler
See Also:
Serialized Form

Field Summary
protected  CatalogChangeListener m_cclReferentialIntegrityListener
          Listens for the Catalog to ensure referential integrity.
 
Fields inherited from class data.ooimpl.StockImpl
m_cclEditListener, m_ciCatalog, m_cinlCatalogItemNameListener, m_dbCatalogValidator, m_lhListeners, m_sclEditCreatorListener
 
Fields inherited from class data.AbstractNameable
m_ncContext, m_pcsPropertyListeners
 
Fields inherited from interface data.Nameable
NAME_PROPERTY
 
Fields inherited from interface data.DataBasketKeys
CATALOG_ITEM_MAIN_KEY, STOCK_ITEM_MAIN_KEY
 
Constructor Summary
CountingStockImpl(StockIdentifier<T,CT> siId, Catalog<CT> ciRef)
          Create a new, initially empty CountingStockImpl.
CountingStockImpl(String sName, Catalog<CT> ciRef)
          Create a new, initially empty CountingStockImpl.
 
Method Summary
 void add(String sKey, int nCount, DataBasket db)
          Add a number of items of a given key to the Stock.
 void add(T si, DataBasket db)
          Add an item to the Stock.
 void addStock(Stock<T,CT> st, DataBasket db, boolean fRemove)
          Overridden for efficiency reasons.
 void commitAdd(DataBasket db, DataBasketEntry dbe)
          Commit the adding of StockItems.
 void commitRemove(DataBasket db, DataBasketEntry dbe)
          Commit the removal of StockItems.
 boolean contains(T si, DataBasket db)
          Check whether the Stock contains the given StockItem.
 boolean containsStock(Stock<T,CT> st, DataBasket db)
          Reimplemented for efficiency reasons.
 int countItems(String sKey, DataBasket db)
          Count the StockItems with a given key that are visible using a given DataBasket.
protected  StockImpl<Integer,T,CT> createPeer()
          Create an empty Stock with the same name, associated Catalog and class.
 Iterator<T> get(String sKey, DataBasket db, boolean fForEdit)
          Iterate all items with a given key.
protected  void internalSetCatalog(CatalogImpl<CT> ciRef)
          Overridden to ensure referential integrity.
 StockItem remove(String sKey, DataBasket db)
          Remove one StockItem with the specified key from the Stock.
 void remove(String sKey, int nCount, DataBasket db)
          Remove a number of items of a given key from the Stock.
 StockItem remove(T si, DataBasket db)
          Remove the given StockItem from the Stock.
 void rollbackAdd(DataBasket db, DataBasketEntry dbe)
          Rollback the adding of StockItems.
 void rollbackRemove(DataBasket db, DataBasketEntry dbe)
          Rollback the removal of StockItems.
 String toString()
          Get a String representation of the Stock.
 
Methods inherited from class data.ooimpl.StockImpl
addStockChangeListener, checkNameChange, clone, compareTo, contains, fillShallowClone, fillStockWithValue, fireCanEditStockItems, fireCanRemoveStockItems, fireEditingStockItems, fireStockItemsAddCommit, fireStockItemsAdded, fireStockItemsAddRollback, fireStockItemsEditCommit, fireStockItemsEditRollback, fireStockItemsRemoveCommit, fireStockItemsRemoved, fireStockItemsRemoveRollback, getCatalog, getEditingItemsContainer, getItemsContainer, getItemsLock, getNCMonitor, getRefIntegrEditContainer, getRefIntegrItemsContainer, getShallowClone, getTemporaryAddedItemsContainer, getTemporaryRemovedItemsContainer, iterator, keySet, nameHasChanged, prepareReferentialIntegrity, removeStockChangeListener, setEditingItemsContainer, setItemsContainer, setRefIntegrEditContainer, setRefIntegrItemsContainer, setStock, setTemporaryAddedItemsContainer, setTemporaryRemovedItemsContainer, size, sumStock
 
Methods inherited from class data.ooimpl.StockItemImpl
equals, getAssociatedItem, getStock
 
Methods inherited from class 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 data.Stock
contains, fillStockWithValue, getCatalog, iterator, keySet, size, sumStock
 
Methods inherited from interface data.StockItem
clone, getAssociatedItem, getStock
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface data.Nameable
addNameListener, addPropertyChangeListener, attach, detachNC, getName, removeNameListener, removePropertyChangeListener, setName
 

Field Detail

m_cclReferentialIntegrityListener

protected CatalogChangeListener m_cclReferentialIntegrityListener
Listens for the Catalog to ensure referential integrity.

Constructor Detail

CountingStockImpl

public CountingStockImpl(StockIdentifier<T,CT> siId,
                         Catalog<CT> ciRef)
Create a new, initially empty CountingStockImpl.

Parameters:
siId - the id of the Stock.
ciRef - the Catalog referenced by the Stock.

CountingStockImpl

public CountingStockImpl(String sName,
                         Catalog<CT> ciRef)
Create a new, initially empty CountingStockImpl.

Parameters:
sName - the name of the Stock.
ciRef - the Catalog referenced by the Stock.
Method Detail

internalSetCatalog

protected void internalSetCatalog(CatalogImpl<CT> ciRef)
Overridden to ensure referential integrity.

Overrides:
internalSetCatalog in class StockImpl<Integer,T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
ciRef - the Catalog to refer to from now on.
Override:
Never

add

public void add(T si,
                DataBasket db)
Add an item to the Stock.

The item will only be visible to users of the same DataBasket. Only after a DataBasket.commit() was performed on the DataBasket, the item will become visible to other users.

A addedStockItems event will be fired.

Specified by:
add in interface Stock<T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
si - the item to be added.
db - the DataBasket relative to which the item will be added. Must be either null or a descendant of DataBasketImpl.
Throws:
CatalogConflictException - if the items key is not contained in the corresponding Catalog.
DataBasketConflictException - if the item has already been added/removed using another DataBasket.
Override:
Never

addStock

public void addStock(Stock<T,CT> st,
                     DataBasket db,
                     boolean fRemove)
Overridden for efficiency reasons.

Specified by:
addStock in interface Stock<T extends StockItemImpl,CT extends CatalogItemImpl>
Overrides:
addStock in class StockImpl<Integer,T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
st - the Stock whose contents is to be added to this Stock.
db - the DataBasket relative to which to perform the actions. addStock will add all items from the source Stock that are visible using this DataBasket. Must be either null or a descendant of DataBasketImpl.
fRemove - if true, the items will be removed from the source Stock prior to adding them to this Stock. Otherwise, they will be cloned prior to adding them to the Stock.
Override:
Never

get

public Iterator<T> get(String sKey,
                       DataBasket db,
                       boolean fForEdit)
Iterate all items with a given key.

This method, together with StockImpl.iterator(data.DataBasket, boolean) is the only way of accessing the individual StockItems contained in a Stock. The iterator will deliver all items that have the specified key and are visible using the given DataBasket. Depending on the fForEdit parameter, the items will be retrieved in different ways. See DataBasket for an explanation of the different possibilities.

canEditStockItems and editingStockItems events will be fired if fForEdit == true. VetoExceptions will be converted into UnSupportedOperationExceptions.

Specified by:
get in interface Stock<T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
sKey - the key for which to retrieve the StockItems.
db - the DataBasket relative to which to retrieve the StockItems. Must be either null or a descendant of DataBasketImpl.
fForEdit - if true, the StockItems will be retrieved for editing.
Override:
Never

countItems

public int countItems(String sKey,
                      DataBasket db)
Count the StockItems with a given key that are visible using a given DataBasket.

Specified by:
countItems in interface Stock<T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
sKey - the key for which to count the StockItems.
db - the DataBasket that is used to determine visibility. Must be either null or a descendant of DataBasketImpl.
Override:
Never

contains

public boolean contains(T si,
                        DataBasket db)
Check whether the Stock contains the given StockItem.

Return true if the Stock contains a StockItem that is equal to the given one.

Specified by:
contains in interface Stock<T extends StockItemImpl,CT extends CatalogItemImpl>
Overrides:
contains in class StockImpl<Integer,T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
si - the StockItem for which to check containment.
db - the DataBasket used to check visibility. Must be either null or a descendant of DataBasketImpl.
Override:
Never

containsStock

public boolean containsStock(Stock<T,CT> st,
                             DataBasket db)
Reimplemented for efficiency reasons.

Specified by:
containsStock in interface Stock<T extends StockItemImpl,CT extends CatalogItemImpl>
Overrides:
containsStock in class StockImpl<Integer,T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
st - the Stock for which to check containment.
db - the DataBasket used to determine visibility. Must be either null or a descendant of DataBasketImpl.
Override:
Never

remove

public StockItem remove(String sKey,
                        DataBasket db)
                 throws VetoException
Remove one StockItem with the specified key from the Stock.

If there are any StockItems with the specified key, one will be removed. There is no guarantee as to which StockItem will be removed. The removed item, if any, will be returned.

canRemoveStockItems and removedStockItems events will be fired.

Specified by:
remove in interface Stock<T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
sKey - the key for which to remove an item.
db - the DataBasket relative to which to remove the item. Must be either null or a descendant of DataBasketImpl.
Returns:
the removed item
Throws:
VetoException - if a listener vetoed the removal.
DataBasketConflictException - if the item cannot be removed due to conflicts from DataBasket usage.
Override:
Never

remove

public StockItem remove(T si,
                        DataBasket db)
                 throws VetoException
Remove the given StockItem from the Stock.

If the given StockItem is contained in the Stock, it will be removed. The removed item, if any, will be returned.

canRemoveStockItems and removedStockItems events will be fired.

Specified by:
remove in interface Stock<T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
si - the StockItem to be removed.
db - the DataBasket relative to which to remove the item. Must be either null or a descendant of DataBasketImpl.
Returns:
the removed item
Throws:
VetoException - if a listener vetoed the removal.
DataBasketConflictException - if the item cannot be removed due to conflicts from DataBasket usage.
Override:
Never

createPeer

protected StockImpl<Integer,T,CT> createPeer()
Description copied from class: StockImpl
Create an empty Stock with the same name, associated Catalog and class.

Specified by:
createPeer in class StockImpl<Integer,T extends StockItemImpl,CT extends CatalogItemImpl>
Override:
Always

add

public void add(String sKey,
                int nCount,
                DataBasket db)
Add a number of items of a given key to the Stock.

As with any Stock the added items will not at once be visible to users of other DataBaskets.

In general the method behaves as though it would call Stock.add(T, data.DataBasket) nCount times. Especially, the same exceptions might occur and the same constraints hold.

Specified by:
add in interface CountingStock<T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
sKey - the key for which to add a number of items.
nCount - how many items are to be added?
db - the DataBasket relative to which the adding is performed. Must be either null or a descendant of DataBasketImpl.
Throws:
IllegalArgumentException - if nCount <= 0.
CatalogConflictException - if the key cannot be found in the Catalog.
Override:
Never

remove

public void remove(String sKey,
                   int nCount,
                   DataBasket db)
            throws VetoException
Remove a number of items of a given key from the Stock.

In general the method behaves as though it would call Stock.remove(java.lang.String, data.DataBasket) nCount times. Especially, the same exceptions might occur and the same constraints hold.

Specified by:
remove in interface CountingStock<T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
sKey - the key for which to remove a number of items.
nCount - how many items are to be removed?
db - the DataBasket relative to which the removal is performed. Must be either null or a descendant of DataBasketImpl.
Throws:
VetoException - if a listener vetos the removal.
NotEnoughElementsException - if there are not enough elements to fulfill the request. If this exception is thrown no items will have been removed.
IllegalArgumentException - if nCount <= 0
Override:
Never

toString

public String toString()
Get a String representation of the Stock.

Overrides:
toString in class StockItemImpl
Override:
Sometimes

commitRemove

public void commitRemove(DataBasket db,
                         DataBasketEntry dbe)
Commit the removal of StockItems.

A commitRemoveStockItems will be fired.

Specified by:
commitRemove in interface SelfManagingDBESource<T extends StockItemImpl>
Parameters:
db - the DataBasket that issued the rollback request
dbe - the DataBasketEntry describing the operation to rollback.
Override:
Never

rollbackRemove

public void rollbackRemove(DataBasket db,
                           DataBasketEntry dbe)
Rollback the removal of StockItems.

A rollbackRemoveStockItems will be fired. Also, the Stock will try to make sure, that a corresponding CatalogItem exists.

Specified by:
rollbackRemove in interface SelfManagingDBESource<T extends StockItemImpl>
Parameters:
db - the DataBasket that issued the commit request
dbe - the DataBasketEntry describing the operation to commit.
Override:
Never

commitAdd

public void commitAdd(DataBasket db,
                      DataBasketEntry dbe)
Commit the adding of StockItems.

A commitAddStockItems will be fired. A commitEditStockItems event may be fired as a consequence of this method. Also, the Stock will try to make sure, that a corresponding CatalogItem exists.

Specified by:
commitAdd in interface SelfManagingDBEDestination<T extends StockItemImpl>
Parameters:
db - the DataBasket that issued the commit request
dbe - the DataBasketEntry describing the operation to commit.
Override:
Never

rollbackAdd

public void rollbackAdd(DataBasket db,
                        DataBasketEntry dbe)
Rollback the adding of StockItems.

A commitAddStockItems will be fired. A commitEditStockItems event may be fired as a consequence of this method.

Specified by:
rollbackAdd in interface SelfManagingDBEDestination<T extends StockItemImpl>
Parameters:
db - the DataBasket that issued the rollback request
dbe - the DataBasketEntry describing the operation to rollback.
Override:
Never

SalesPoint v3.3 API