Define a StockItem
Description:
StockItems are Stocks (more precisely: SubStocks) or items itself. If they are used in a
CountingStock, they'll be the representation of a certain amount of items of a special category. If they are used
in a StoringStock, they'll represent an individual item of a special category.
It is often usefull to make a subclass of StockItemImpl, but implementing the interface StockItem
may also be necessary.
If you wanted to use a CountingStock, you may make an instance of StockItemImpl itself.
Used classes:
Related topics:
ToDo:
-
Create a subclass of
StockItemImpl. -
Add constructors to set the items name and other attributes.Every constructor must invoke
super(name), therefore aStockItemhas to have a name. - Add other useful methods.
Example Source Code:
1 public class DataStockItem extends StockItemImpl { 2 public DataStockItem(String name) { super(name); } 3 public void setOwner(User user) { this.setOwner(user); } public User getOwner() { return this.getOwner(); } }
Back to:
Fill a Stock with Values
Description:
Every Stock implements the public method
FillStockWithValue(DataBasket db, Value vTarget, StockFromValueCreator sfvc).
With this method, a CountingStock can be filled with a certain Value by using the
DefaultCountingStockFromValueCreator.
An existing Stock can be filled with the contents of another Stock by using a
StockFromStockCreator.
The transaction will be canceled, if the StockFromValueCreator doesn't find enough fitting items to fill the
Stock with the certain Value. If backtracking is needed to guarantee that a solution will be found
if there is one, use StockFromStockCreatorBT.
These three implementations of the interface StockFromValueCreator are sufficient in most cases.
Used classes:
- Stock
- StockFromValueCreator
- StockFromStockCreator
- StockFromStockCreatorBT
- DefaultCountingStockFromValueCreator
Related topics:
ToDo:
-
Make a new instance of your used implementation of
Stock(or select an existing instance ofStock). -
Use
Stock.fillStockWithValue(DataBasket db, Value vTarget, StockFromValueCreator sfvc)to fill selectedStockwith a certainValue. -
Use the implementation
StockFromStockCreator, if you want to fill oneStockwith theValuesof anotherStock(the needed items will be removed from the secondStock).
Example Source Code:
// first define an AbstractCurrency for the Moneybags AbstractCurrency euroCurrency = new EUROCurrencyImpl("Euro-Catalog"); Shop.getTheShop().addCatalog(euroCurrency); 1 // create a new MoneyBag and add to Shop MoneyBagImpl moneyBag1 = new MoneyBagImpl("MoneyBag1", euroCurrency); Shop.getTheShop().addStock(moneyBag1); 2 // fill the MoneyBag with 357, 12 Euros moneyBag1.fillStockWithValue((DataBasket) null, new IntegerValue(35712), new DefaultCountingStockFromValueCreator( new CatalogItemValue()) ); 1 // create a new MoneyBag and add to Shop MoneyBagImpl moneyBag2 = new MoneyBagImpl("MoneyBag2", euroCurrency); Shop.getTheShop().addStock(moneyBag2); 3 // fill the second Stock with items of the first // using StockFromValueCreator with BackTracking moneyBag2.fillStockWithValue((DataBasket) null, new IntegerValue(17854), new StockFromStockCreatorBT( (Stock) moneyBag1, new CatalogItemValue()) );
Back to:
Incorporate a CountingStock on a Catalog
Description:
This data structure is meant to count the number of entrys in the associated Catalog.
It should be preferred if it was not important to remember differences between single items of a category.
The CountingStock could be displayed in the same way as the Catalog itself.
The use of CountingStockImpl, the implementation of the interface CountingStock, is sufficient in
most cases.
Used classes:
Related topics:
ToDo:
-
Get the instance of
Catalogyou want to incorporate aCountingStockon.
(See also: Incorporate a Catalog). -
Make a new instance of
CountingStockassociated with theCatalog. -
Define (if necessary) a fitting subclass of
StockItemImpl.
(See also Define a StockItem). -
-
Add and remove
StockItemsas you wish. -
It is not always necessary to add
StockItems, but it may also sufficient only to increase the number of countedCatalogItems.
-
Add and remove
-
Add the
Stockto theShop'sglobal list of stocks.
Example Source Code:
1
Catalog<DataBasicCatalogItem> catalog = Shop.getTheShop().getCatalog(SimpleCatalog);
2
CountingStock<StockItemImpl, DataBasicCatalogItem> countingStock =
new CountingStockImpl<StockItemImpl, DataBasicCatalogItem>(
"simpleCatalogCS",
catalog);
4 a
for(int i = 0; i < 5; i++)
{
countingStock.add(new StockItemImpl("Screw"), (DataBasket) null);
}
4 b
countingStock.add("Screw Nut", 5, (DataBasket) null);
5
Shop.getTheShop().addStock(countingStock);
Back to:
Incorporate a StoringStock on a Catalog
Description:
This data structure is meant to store individual representations of entrys in the associated Catalog.
In contrast to the CountingStock it is meant to remember the differences between the StockItems.
The StoringStock could be displayed in the same way as the Catalog itself.
Using StoringStockImpl, the implementation of the interface StoringStock, is sufficient in most cases.
Used classes:
Related topics:
ToDo:
-
Get the instance of
Catalogyou want to incorporate aStoringStockon.
(See also: Incorporate a Catalog). -
Make a new instance of
StoringStockassociated with theCatalog. -
Define a fitting subclass of
StockItemImpl.
(See also: Define a StockItem). -
Add and remove
StockItemsas you wish. -
Add the
Stockto theShop'sglobal list of stocks.
Example Source Code:
1
Catalog<DataBasicCatalogItem> catalog = Shop.getTheShop().getCatalog(SimpleCatalog);
2
StoringStock<StockItemImpl, DataBasicCatalogItem> storingStock =
new StoringStockImpl<StockItemImpl, DataBasicCatalogItem>("simpleCatalogSS", catalog);
4
for(int i = 0; i < 5; i++)
{
storingStock.add(new StockItemImpl("Shoes"), (DataBasket) null);
}
5
Shop.getTheShop().addStock(storingStock);
Back to:
Incorporate a MoneyBag on a Currency
Description:
This data structure is meant to count the number of coins and notes in the associated Currency. It is a special
CountingStock on a special Catalog.
The use of MoneyBagImpl, the implementation of the interface MoneyBag, is sufficient in most cases.
Used classes:
Related topics:
ToDo:
-
Get the instance of
AbstractCurrencyyou want to incorporate aMoneyBagon. -
Make a new instance of
MoneyBagassociated with theCurrency. -
Add the
MoneyBagto theShop'sglobal list of stocks. - Add and remove coins and notes as you wish.
Example Source Code:
1
AbstractCurrency euroCurrency = new EUROCurrencyImpl("Euro_Catalog");
2
MoneyBagImpl moneyBag = new MoneyBagImpl("MoneyBag", euroCurrency);
3
Shop.getTheShop().addStock(moneyBag);
4
for(int i=0; i < euroCurrency.getCurrencyItemData().length; i++)
{
moneyBag.add((euroCurrency.getCurrencyItemData())[i].getName(), 5, (DataBasket) null);
try
{
moneyBag.remove(
(euroCurrency.getCurrencyItemData())[i].getName(),
5,
(DataBasket) null);
}
catch (VetoException e)
{
e.printStackTrace();
}
}
Back to:
Data Management: Filter | Data Management: Common ![]() |
Data Management: Filter