SalesPoint Framework v3.1

data.filters
Class AbstractStockFilter

java.lang.Object
  extended bydata.filters.AbstractStockFilter
All Implemented Interfaces:
Cloneable, Comparable, DataBasketEntryDestination, DataBasketEntrySource, EventListener, ListenableStock, Nameable, Serializable, Stock, StockChangeListener, StockItem
Direct Known Subclasses:
CountingStockFilter, StoringStockFilter

public abstract class AbstractStockFilter
extends Object
implements ListenableStock, StockChangeListener

Abstract superclass of all Stock filters. By using a Stock filter you can present partial views of a Stock to certain parts of your application, e.g., to the GUI elements. However, you cannot use this Stock as a replacement for a 'real' Stock, e.g., as an item in another Stock.

The concrete filter condition is implemented by subclassing either CountingStockFilter or StoringStockFilter and overriding some method. The concrete semantics is documented with the concrete subclass of AbstractStockFilter.

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

Field Summary
protected  ListenerHelper m_lhListeners
          The list of listeners of this Stock.
protected  Stock m_stSource
          The Stock that gets filtered.
 
Fields inherited from interface data.Nameable
NAME_PROPERTY
 
Constructor Summary
protected AbstractStockFilter(Stock stSource)
          Create a new AbstractStockFilter.
 
Method Summary
 void add(StockItem si, DataBasket db)
          Add the given item to the source Stock.
 void addedStockItems(StockChangeEvent e)
          Receive the event from the source Stock, translate and propagate it to any listeners.
 void addNameListener(PropertyChangeListener pcl)
          Register the listener with the source Stock.
 void addPropertyChangeListener(PropertyChangeListener pcl)
          Register the listener with the source Stock.
 void addStock(Stock st, DataBasket db, boolean fRemove)
          Add the given Stock to the source Stock.
 void addStockChangeListener(StockChangeListener scl)
          Register a listener that will receive events when the Stock's contents change.
 NameContext attach(NameContext nc)
          Attach the NameContext to the source Stock.
 void canEditStockItems(StockChangeEvent e)
          Receive the event from the source Stock, translate and propagate it to any listeners.
 void canRemoveStockItems(StockChangeEvent e)
          Receive the event from the source Stock, translate and propagate it to any listeners.
abstract  Object clone()
          Clone the StockItem.
 void commitAddStockItems(StockChangeEvent e)
          Receive the event from the source Stock, translate and propagate it to any listeners.
 void commitEditStockItems(StockChangeEvent e)
          Receive the event from the source Stock, translate and propagate it to any listeners.
 void commitRemoveStockItems(StockChangeEvent e)
          Receive the event from the source Stock, translate and propagate it to any listeners.
 int compareTo(Object o)
          Compare the source Stock to the object.
 boolean contains(String sKey, DataBasket db)
          Returns (countItems (sKey, db) >= 0).
 NameContext detachNC()
          Detach the current NameContext from the source Stock.
 void editingStockItems(StockChangeEvent e)
          Receive the event from the source Stock, translate and propagate it to any listeners.
 Value fillStockWithValue(DataBasket db, Value vTarget, StockFromValueCreator sfvc)
          Fill the source Stock.
protected  void fireCanEditStockItems(StockChangeEvent e)
          Fire an event to any listeners.
protected  void fireCanRemoveStockItems(StockChangeEvent e)
          Fire an event to any listeners.
protected  void fireEditingStockItems(StockChangeEvent e)
          Fire an event to any listeners.
protected  void fireStockItemsAddCommit(StockChangeEvent e)
          Fire an event to any listeners.
protected  void fireStockItemsAdded(StockChangeEvent e)
          Fire an event to any listeners.
protected  void fireStockItemsAddRollback(StockChangeEvent e)
          Fire an event to any listeners.
protected  void fireStockItemsEditCommit(StockChangeEvent e)
          Fire an event to any listeners.
protected  void fireStockItemsEditRollback(StockChangeEvent e)
          Fire an event to any listeners.
protected  void fireStockItemsNoEdit(StockChangeEvent e)
          Fire an event to any listeners.
protected  void fireStockItemsNoRemove(StockChangeEvent e)
          Fire an event to any listeners.
protected  void fireStockItemsRemoveCommit(StockChangeEvent e)
          Fire an event to any listeners.
protected  void fireStockItemsRemoved(StockChangeEvent e)
          Fire an event to any listeners.
protected  void fireStockItemsRemoveRollback(StockChangeEvent e)
          Fire an event to any listeners.
 CatalogItem getAssociatedItem(DataBasket db)
          Get the source Stock's associated item.
 Catalog getCatalog(DataBasket db)
          Get the source Stock's Catalog.
 Stock getMainStock()
          Get the source stock.
 String getName()
          Get the source Stock's name.
 Stock getStock()
          Get the source Stock's Stock.
 Iterator iterator(DataBasket db, boolean fForEdit)
          Create an iterator that will return all items that match the condition.
 Set keySet(DataBasket db)
          Get a filtered key set.
 void noEditStockItems(StockChangeEvent e)
          Receive the event from the source Stock, translate and propagate it to any listeners.
 void noRemoveStockItems(StockChangeEvent e)
          Receive the event from the source Stock, translate and propagate it to any listeners.
 StockItem remove(StockItem si, DataBasket db)
          Remove the given item from the source Stock.
 StockItem remove(String sKey, DataBasket db)
          Remove the given item from the source Stock.
 void removedStockItems(StockChangeEvent e)
          Receive the event from the source Stock, translate and propagate it to any listeners.
 void removeNameListener(PropertyChangeListener pcl)
          Un-Register the listener with the source Stock.
 void removePropertyChangeListener(PropertyChangeListener pcl)
          Un-Register the listener with the source Stock.
 void removeStockChangeListener(StockChangeListener scl)
          Un-Register a listener that received events when the Stock's contents changed.
 void rollbackAddStockItems(StockChangeEvent e)
          Receive the event from the source Stock, translate and propagate it to any listeners.
 void rollbackEditStockItems(StockChangeEvent e)
          Receive the event from the source Stock, translate and propagate it to any listeners.
 void rollbackRemoveStockItems(StockChangeEvent e)
          Receive the event from the source Stock, translate and propagate it to any listeners.
 void setName(String sName, DataBasket db)
          Set the source Stock's name.
 int size(DataBasket db)
          Calculate the size of the source Stock, considering only items that match the condition.
 Value sumStock(DataBasket db, CatalogItemValue civ, Value vInit)
          Calculate the total value of the Stock, evaluating only items that match the condition.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface data.Stock
contains, containsStock, countItems, get
 

Field Detail

m_stSource

protected Stock m_stSource
The Stock that gets filtered.


m_lhListeners

protected ListenerHelper m_lhListeners
The list of listeners of this Stock.

Constructor Detail

AbstractStockFilter

protected AbstractStockFilter(Stock stSource)
Create a new AbstractStockFilter. May only be called by subclasses.

Parameters:
stSource - the Stock to be filtered.
Method Detail

add

public void add(StockItem si,
                DataBasket db)
Add the given item to the source Stock.

Specified by:
add in interface Stock
Parameters:
si - the item to be added.
db - the DataBasket relative to which the item will be added.
Override:
Never

addStock

public void addStock(Stock st,
                     DataBasket db,
                     boolean fRemove)
Add the given Stock to the source Stock.

Specified by:
addStock in interface Stock
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.
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

contains

public boolean contains(String sKey,
                        DataBasket db)
Returns (countItems (sKey, db) >= 0).

Specified by:
contains in interface Stock
Parameters:
sKey - the key for which to check containment.
db - the DataBasket used to check visibility.
Override:
Sometimes

remove

public StockItem remove(String sKey,
                        DataBasket db)
                 throws VetoException
Remove the given item from the source Stock.

Specified by:
remove in interface Stock
Parameters:
sKey - the key for which to remove an item.
db - the DataBasket relative to which to remove the item.
Returns:
the removed item
Throws:
VetoException - if a listener vetoed the removal.
Override:
Never

remove

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

Specified by:
remove in interface Stock
Parameters:
si - the StockItem to be removed.
db - the DataBasket relative to which to remove the item.
Returns:
the removed item
Throws:
VetoException - if a listener vetoed the removal.
Override:
Never

iterator

public Iterator iterator(DataBasket db,
                         boolean fForEdit)
Create an iterator that will return all items that match the condition.

Specified by:
iterator in interface Stock
Parameters:
db - the DataBasket relative to which to retrieve the StockItems.
fForEdit - if true, the StockItems will be retrieved for editing.
Override:
Never

keySet

public Set keySet(DataBasket db)
Get a filtered key set.

Specified by:
keySet in interface Stock
Parameters:
db - the DataBasket used for determining visibility.
Override:
Never

sumStock

public Value sumStock(DataBasket db,
                      CatalogItemValue civ,
                      Value vInit)
Calculate the total value of the Stock, evaluating only items that match the condition.

Specified by:
sumStock in interface Stock
Parameters:
db - the DataBasket that is used to determine visibility.
civ - the CatalogItemValue used for determining the value of a CatalogItem.
vInit - the initial value. The sum of the Stock will be added to this value.
Returns:
the resulting total. Usually the returned object is the same as the one passed as vInit, only with a changed value.
Override:
Never

fillStockWithValue

public Value fillStockWithValue(DataBasket db,
                                Value vTarget,
                                StockFromValueCreator sfvc)
Fill the source Stock.

Specified by:
fillStockWithValue in interface Stock
Parameters:
db - the DataBasket relative to which to perform the operation.
vTarget - the value by which to increase the Stock's total value.
sfvc - the strategy used to fill the Stock.
Returns:
the value that remained and could not be represented by StockItems.
Override:
Never

size

public int size(DataBasket db)
Calculate the size of the source Stock, considering only items that match the condition.

Specified by:
size in interface Stock
Parameters:
db - the DataBasket used to determine visibility.
Override:
Never

getCatalog

public Catalog getCatalog(DataBasket db)
Get the source Stock's Catalog.

Specified by:
getCatalog in interface Stock
Parameters:
db - a DataBasket determinig visibility of the stock's catalog.
Override:
Never

getStock

public Stock getStock()
Get the source Stock's Stock.

Specified by:
getStock in interface StockItem
Override:
Never

getMainStock

public Stock getMainStock()
Get the source stock. If the source stock is a StockFilter again, return this Stock's MainStock.

Override:
Never

getAssociatedItem

public CatalogItem getAssociatedItem(DataBasket db)
Get the source Stock's associated item.

Specified by:
getAssociatedItem in interface StockItem
Parameters:
db - the DataBasket that is used for checking visibility.
Override:
Never

attach

public NameContext attach(NameContext nc)
Attach the NameContext to the source Stock.

Specified by:
attach in interface Nameable
Parameters:
nc - the new NameContext of this Nameable object.
Returns:
the previous NameContext, if any.
Override:
Never

detachNC

public NameContext detachNC()
Detach the current NameContext from the source Stock.

Specified by:
detachNC in interface Nameable
Returns:
the previously attached NameContext, if any.
Override:
Never

setName

public void setName(String sName,
                    DataBasket db)
             throws NameContextException
Set the source Stock's name.

Specified by:
setName in interface Nameable
Parameters:
sName - the new name of the object
db - the DataBasket relative to which the operation is to be performed.
Throws:
NameContextException - if the name change was not approved of by the NameContext.
See Also:
NameContext
Override:
Never

getName

public String getName()
Get the source Stock's name.

Specified by:
getName in interface Nameable
Override:
Never

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener pcl)
Register the listener with the source Stock.

Specified by:
addPropertyChangeListener in interface Nameable
Override:
Never

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener pcl)
Un-Register the listener with the source Stock.

Specified by:
removePropertyChangeListener in interface Nameable
Override:
Never

addNameListener

public void addNameListener(PropertyChangeListener pcl)
Register the listener with the source Stock.

Specified by:
addNameListener in interface Nameable
Override:
Never

removeNameListener

public void removeNameListener(PropertyChangeListener pcl)
Un-Register the listener with the source Stock.

Specified by:
removeNameListener in interface Nameable
Override:
Never

compareTo

public int compareTo(Object o)
Compare the source Stock to the object.

Specified by:
compareTo in interface Comparable
Override:
Never

clone

public abstract Object clone()
Description copied from interface: StockItem
Clone the StockItem.

Specified by:
clone in interface StockItem
Override:
Always

addStockChangeListener

public void addStockChangeListener(StockChangeListener scl)
Register a listener that will receive events when the Stock's contents change.

Specified by:
addStockChangeListener in interface ListenableStock
Parameters:
scl - the listener
Override:
Never

removeStockChangeListener

public void removeStockChangeListener(StockChangeListener scl)
Un-Register a listener that received events when the Stock's contents changed.

Specified by:
removeStockChangeListener in interface ListenableStock
Parameters:
scl - the listener
Override:
Never

addedStockItems

public void addedStockItems(StockChangeEvent e)
Receive the event from the source Stock, translate and propagate it to any listeners.

Specified by:
addedStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Override:
Never

commitAddStockItems

public void commitAddStockItems(StockChangeEvent e)
Receive the event from the source Stock, translate and propagate it to any listeners.

Specified by:
commitAddStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Override:
Never

rollbackAddStockItems

public void rollbackAddStockItems(StockChangeEvent e)
Receive the event from the source Stock, translate and propagate it to any listeners.

Specified by:
rollbackAddStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Override:
Never

canRemoveStockItems

public void canRemoveStockItems(StockChangeEvent e)
                         throws VetoException
Receive the event from the source Stock, translate and propagate it to any listeners.

Specified by:
canRemoveStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Throws:
VetoException - if the listener wants to veto the removal.
Override:
Never

noRemoveStockItems

public void noRemoveStockItems(StockChangeEvent e)
Receive the event from the source Stock, translate and propagate it to any listeners.

Specified by:
noRemoveStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Override:
Never

removedStockItems

public void removedStockItems(StockChangeEvent e)
Receive the event from the source Stock, translate and propagate it to any listeners.

Specified by:
removedStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Override:
Never

commitRemoveStockItems

public void commitRemoveStockItems(StockChangeEvent e)
Receive the event from the source Stock, translate and propagate it to any listeners.

Specified by:
commitRemoveStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Override:
Never

rollbackRemoveStockItems

public void rollbackRemoveStockItems(StockChangeEvent e)
Receive the event from the source Stock, translate and propagate it to any listeners.

Specified by:
rollbackRemoveStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Override:
Never

canEditStockItems

public void canEditStockItems(StockChangeEvent e)
                       throws VetoException
Receive the event from the source Stock, translate and propagate it to any listeners.

Specified by:
canEditStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Throws:
VetoException - if the listener wants to veto the editing.
Override:
Never

noEditStockItems

public void noEditStockItems(StockChangeEvent e)
Receive the event from the source Stock, translate and propagate it to any listeners.

Specified by:
noEditStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Override:
Never

editingStockItems

public void editingStockItems(StockChangeEvent e)
Receive the event from the source Stock, translate and propagate it to any listeners.

Specified by:
editingStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Override:
Never

commitEditStockItems

public void commitEditStockItems(StockChangeEvent e)
Receive the event from the source Stock, translate and propagate it to any listeners.

Specified by:
commitEditStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Override:
Never

rollbackEditStockItems

public void rollbackEditStockItems(StockChangeEvent e)
Receive the event from the source Stock, translate and propagate it to any listeners.

Specified by:
rollbackEditStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Override:
Never

fireStockItemsAdded

protected void fireStockItemsAdded(StockChangeEvent e)
Fire an event to any listeners.

Override:
Never

fireStockItemsAddCommit

protected void fireStockItemsAddCommit(StockChangeEvent e)
Fire an event to any listeners.

Override:
Never

fireStockItemsAddRollback

protected void fireStockItemsAddRollback(StockChangeEvent e)
Fire an event to any listeners.

Override:
Never

fireStockItemsNoRemove

protected void fireStockItemsNoRemove(StockChangeEvent e)
Fire an event to any listeners.

Override:
Never

fireStockItemsRemoved

protected void fireStockItemsRemoved(StockChangeEvent e)
Fire an event to any listeners.

Override:
Never

fireStockItemsRemoveCommit

protected void fireStockItemsRemoveCommit(StockChangeEvent e)
Fire an event to any listeners.

Override:
Never

fireStockItemsRemoveRollback

protected void fireStockItemsRemoveRollback(StockChangeEvent e)
Fire an event to any listeners.

Override:
Never

fireCanRemoveStockItems

protected void fireCanRemoveStockItems(StockChangeEvent e)
                                throws VetoException
Fire an event to any listeners.

Throws:
VetoException
Override:
Never

fireCanEditStockItems

protected void fireCanEditStockItems(StockChangeEvent e)
                              throws VetoException
Fire an event to any listeners.

Throws:
VetoException
Override:
Never

fireStockItemsNoEdit

protected void fireStockItemsNoEdit(StockChangeEvent e)
Fire an event to any listeners.

Override:
Never

fireEditingStockItems

protected void fireEditingStockItems(StockChangeEvent e)
Fire an event to any listeners.

Override:
Never

fireStockItemsEditCommit

protected void fireStockItemsEditCommit(StockChangeEvent e)
Fire an event to any listeners.

Override:
Never

fireStockItemsEditRollback

protected void fireStockItemsEditRollback(StockChangeEvent e)
Fire an event to any listeners.

Override:
Never

SalesPoint Framework v3.1