Incorporate a CatalogFilter on a Catalog
Description:
A CatalogFilter
is a Catalog
itself, in which defined elements are filtered.
This CatalogFilter could be used in the same way as a normal Catalog.
Used classes:
Related topics:
ToDo:
-
Create a subclass of
CatalogFilter
. -
Add the constructor and invoke the
super
constructor. -
Implement the
protected boolean match(CatalogItem ci)
method. It determines for eachCatalogItem
, whether it will be in theCatalogFilter
or not. -
Make an instance of your
CatalogFilter
where you want to use it.
Use it instead of the source catalog, where you only want the unfiltered items. But do not use aCatalogFilter
as a replacement for a 'real'Catalog
, e.g., as an item in anotherCatalog
.
Example Source Code:
CatalogFilter class:
1 public class DataCatalogFilter extends CatalogFilter { 2 public DataCatalogFilter(Catalog originalCatalog) { super(originalCatalog); } 3 protected boolean match(CatalogItem catalogItem) { if (catalogItem.getName().equals("Item which is unfiltered")) return true; else return false; } }
class that uses the CatalogFilter:
4
DataCatalogFilter dataCatalogFilter =
new DataCatalogFilter(Shop.getTheShop().getCatalog(("SimpleCatalog")));
Back to:
Incorporate a CountingStockFilter on a Catalog
Description:
A CountingStockFilter
is a CountingStock
itself, in which a certain number of elements are filtered.
Thereby the public int countItems(String key, DataBasket dataBasket)
defines which items should be displayed or not.
This CountingStockFilter
could be used in the same way as a normal CountingStock
.
Used classes:
Related topics:
ToDo:
-
Create a subclass of
CountingStockFilter
. -
Add the constructor and invoke the
super
constructor. -
Implement the
public int countItems(String key, DataBasket basket)
method.
It determines how many items of theStockItem
with the keykey
will be in theCountingStockFilter
. -
Implement the
public Object clone()
method that will return a copy of the filter. -
Make an instance of your
CountingFilter
where you want to use it.
Use it instead of the source stock, where you only want the unfiltered items.
Example Source Code:
CountingStockFilter class:
1 public class DataCountingStockFilter extends CountingStockFilter { 2 public DataCountingStockFilter(CountingStock sourceStock) { super(sourceStock); } 3 public int countItems(String key, DataBasket dataBasket) { // create iterator for all StockItems with the given key Iterator iterator = m_stSource.get(key, dataBasket, false); // instantiate a number for the items which should not be filtered int number = 0; // search for items that should not be filtered by iterating through the StockItems StockItem stockItem; while (iterator.hasNext()) { stockItem = (StockItem) iterator.next(); if(stockItem.getName().equals("Item which is unfiltered")) number ++; } return number; } 4 public Object clone() { DataCountingStockFilter dataCountingStockFilter = new DataCountingStockFilter((CountingStock) m_stSource.clone()); return dataCountingStockFilter; } }
class that uses the CountingStockFilter:
5
DataCountingStockFilter dataCountingStockFilter =
new DataCountingStockFilter(
(CountingStock) Shop.getTheShop().getStock("CountingStock"));
Back to:
Incorporate a CurrenyFilter on a Currency
Description:
A CurrencyFilter
is a Currency
itself, in which defined elements are filtered.
The procedure is very similar to Incorporate a CatalogFilter on a Catalog.
This CurrencyFilter
could be used in the same way as a normal Currency
.
Used classes:
Related topics:
ToDo:
-
Create a subclass of
CurrenyFilter
. -
Add the constructor and invoke the
super
constructor. -
Implement the
protected boolean match(CatalogItem catalogItem)
method.
It determines for eachCurrencyItem
, whether it will be in theCurrencyFilter
or not. -
Make an instance of your
CurrenyFilter
where you want to use it.
Use it instead of the source catalog, where you only want the unfiltered items.
Example Source Code:
CurrenyFilter class:
1 public class DataCurrencyFilter extends CurrencyFilter { 2 public DataCurrencyFilter(Currency currency) { super(currency); } 3 protected boolean match(CatalogItem catalogItem) { // all notes and coins less worth than 5 Euro are filtered out if(((NumberValue)catalogItem.getValue()).getValue().intValue() < 500) return false; else return true; } }
class that uses the CurrencyFilter:
4
DataCurrencyFilter dataCurrencyFilter =
new DataCurrencyFilter((Currency) Shop.getTheShop().getCatalog("Euro_Catalog"));
Back to:
Incorporate a MoneyBagFilter on a MoneyBag
Description:
A MoneyBagFilter
is a MoneyBag
itself, in which a certain number of coins and notes are filtered.
This MoneyBagFilter
could be used in the same way as a normal MoneyBag
.
Used classes:
Related topics:
ToDo:
-
Create a subclass of
MoneyBagFilter
. -
Add the constructor and invoke the
super
constructor. -
Implement the
public int countItems(String key, DataBasket dataBasket)
method.
It determines how money items of theMoneyBag
will be in theMoneyBagFilter
. -
Implement the
public Object clone()
method that returns a copy of the filter. -
Make an instance of your
MoneyBagFilter
where you want to use it.
Use it instead of the sourceMoneyBag
, where you only want the unfiltered items.
Example Source Code:
MoneyBagFilter class:
1 public class DataMoneyBagFilter extends MoneyBagFilter { 2 public DataMoneyBagFilter(MoneyBag moneyBag) { super(moneyBag); } 3 public int countItems(String key, DataBasket dataBasket) { // get the item codes of the currency (EUROCurrencyImpl is used here) int currencyItemCode = -1; AbstractCurrency euroCurrency = new EUROCurrencyImpl("Euro_Catalog"); CurrencyItemData[] euroData = euroCurrency.getCurrencyItemData(); for(int i = 0; i < euroData.length; i++) { if (((CurrencyItemData) euroData[i]).getName().equals(key)) { currencyItemCode = i; } } // filter all item less worth than 5 Euro if (currencyItemCode == -1) { return 0; } else { if (((CurrencyItemData) euroData[currencyItemCode]).getValue() < 500) return 0; else return m_stSource.countItems(key, dataBasket); } } 4 public Object clone() { return new DataMoneyBagFilter((MoneyBag) m_stSource.clone()); } }
class that uses the MoneyBagFilter:
5
DataMoneyBagFilter dataMoneyBagFilter =
new DataMoneyBagFilter((MoneyBag) Shop.getTheShop().getCatalog("MoneyBag"));
Back to:
Incorporate a StoringStockFilter on a StoringStock
Description:
A StoringStockFilter
is a StoringStock
itself, in which defined elements are filtered.
This StoringStockFilter
could be used in the same way as a normal StoringStock
.
Used classes:
Related topics:
ToDo:
-
Create a subclass of
StoringStockFilter
. -
Add the constructor and invoke the
super
constructor. -
Implement the
public boolean contains(StockItem stockItem, DataBasket dataBasket)
method.
It determines for eachStockItem
if it will be in theStoringStockFilter
or not. -
Implement the
public Object clone()
method that returns a copy of the filter. -
Make an instance of your
StoringStockFilter
where you want to use it.
Use it instead of the sourceStoringStock
, where you only want the unfiltered items.
Example Source Code:
StoringStockFilter class:
1 public class DataStoringStockFilter extends StoringStockFilter { 2 public DataStoringStockFilter(StoringStock sourceStock) { super(sourceStock); } 3 public boolean contains(StockItem stockItem, DataBasket dataBasket) { if(stockItem.getName().equals("Item which is unfiltered")) return true; else return false; } 4 public Object clone() { return new DataStoringStockFilter((StoringStock) m_stSource.clone()); } }
class that uses the StoringStockFilter:
5
DataStoringStockFilter dataStoringStockFilter =
new DataStoringStockFilter((StoringStock) Shop.getTheShop().getStock("StoringStock"));
Back to:
Data Management: DataBasket | Data Management: Stock |