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
superconstructor. -
Implement the
protected boolean match(CatalogItem ci)method. It determines for eachCatalogItem, whether it will be in theCatalogFilteror not. -
Make an instance of your
CatalogFilterwhere you want to use it.
Use it instead of the source catalog, where you only want the unfiltered items. But do not use aCatalogFilteras a replacement for a 'real'Catalog, e.g., as an item in anotherCatalog.
Example Source Code:
CatalogFilter class:
1 public class DataCatalogFilter extends CatalogFilter<DataBasicCatalogItem> { 2 public DataCatalogFilter(Catalog<DataBasicCatalogItem> originalCatalog) { super(originalCatalog); } 3 protected boolean match(DataBasicCatalogItem 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 CountingStock
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
superconstructor. -
Implement the
public int countItems(String key, DataBasket basket)method.
It determines how many items of theStockItemwith the keykeywill be in theCountingStockFilter. -
Implement the
public Object clone()method that will return a copy of the filter. -
Make an instance of your
CountingFilterwhere 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<StockItem, CatalogItem> { 2 public DataCountingStockFilter(CountingStock<StockItem, CatalogItem> 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<StockItem, CatalogItem>) m_stSource.clone()); return dataCountingStockFilter; } }
class that uses the CountingStockFilter:
5
DataCountingStockFilter dataCountingStockFilter =
new DataCountingStockFilter((CountingStock<StockItem, CatalogItem>)
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
superconstructor. -
Implement the
protected boolean match(CatalogItem catalogItem)method.
It determines for eachCurrencyItem, whether it will be in theCurrencyFilteror not. -
Make an instance of your
CurrenyFilterwhere 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<CurrencyItem> { 2 public DataCurrencyFilter(Currency<CurrencyItem> currency) { super(currency); } 3 protected boolean match(CurrencyItem item) { // all notes and coins less worth than 5 Euro are filtered out if(((NumberValue)item.getValue()).getValue().intValue() < 500) return false; else return true; } }
class that uses the CurrencyFilter:
4
DataCurrencyFilter dataCurrencyFilter =
new DataCurrencyFilter((Currency<CurrencyItem>)Shop.getTheShop().getCatalog(EuroCatalog));
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
superconstructor. -
Implement the
public int countItems(String key, DataBasket dataBasket)method.
It determines how money items of theMoneyBagwill be in theMoneyBagFilter. -
Implement the
public Object clone()method that returns a copy of the filter. -
Make an instance of your
MoneyBagFilterwhere 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
superconstructor. -
Implement the
public boolean contains(StockItem stockItem, DataBasket dataBasket)method.
It determines for eachStockItemif it will be in theStoringStockFilteror not. -
Implement the
public Object clone()method that returns a copy of the filter. -
Make an instance of your
StoringStockFilterwhere 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<StockItem, CatalogItem> { 2 public DataStoringStockFilter(StoringStock<StockItem, CatalogItem> 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<StockItem, CatalogItem>) m_stSource.clone()); } }
class that uses the StoringStockFilter:
5
DataStoringStockFilter dataStoringStockFilter =
new DataStoringStockFilter((StoringStock<StockItem, CatalogItem>) Shop.getTheShop().getStock(StoringStock));
Back to:
Data Management: DataBasket | Data Management: Stock ![]() |
Data Management: DataBasket