HowTos Data Management
Aus Salespoint
Inhaltsverzeichnis |
Catalog
Define a simple CatalogItem
Description: CatalogItems are Catalogs/SubCatalogs or items itself. They are meant to represent a named category of items and to be stored in a Catalog. It is often usefull to subclass CatalogItemImpl, but implementing the interface CatalogItem may also be necessary. This tutorial shows you a basic implementation of CatalogItemImpl for a simple CatalogItem.
ToDo:
- Create a subclass of CatalogItemImpl.
- Define the constructor. In this case the item will have a name and a value as the standard implementation of CatalogItemImpl offers. You have to invoke the super constructor either with name or name and value. Thus the simplest implementation of CatalogItemImpl would only have a name.
- You also have to implement the protected CatalogItemImpl getShallowClone() method that will return a copy of the current CatalogItemImpl. Simply instantiate a new CatalogItemImpl of your class and set the current values to the constructor.
- mark a constructor for recovery
Example Source Code:
import org.salespointframework.data.ooimpl.CatalogItemImpl;
1
public class DataBasicCatalogItem extends CatalogItemImpl
{
4
@RecoveryConstructor(parameters = {"m_sName", "m_vValue"})
2
public DataBasicCatalogItem(String name, Value value)
{
super(name, value);
}
3
protected CatalogItemImpl getShallowClone()
{
return (CatalogItemImpl)
new DataBasicCatalogItem(this.getName(), this.getValue());
}
}
Define an advanced CatalogItem
Description: As shown in #Define a simple CatalogItem now a CatalogItemImpl will be defined with some more possibilities. Normally you will need more than just a name and a value for your item. You can define as many values as you want for your item, in this case there are two prices defined in addition to the name and value. You can as well define values that not directly represent the item and you can add some helper/setter/getter methods as needed.
ToDo:
- Create a subclass of CatalogItemImpl.
- Define the variables for the additional values. price1 and price2 are the values that directly represent the CatalogItem (and therefore later will be set in the constructor). comparePrice is an additional variable used for internal calculations and does not represent the item.
- Define the constructor and invoke the super constructor with the name. Assign the CatalogItem values as defined before.
- Implement the protected CatalogItemImpl getShallowClone() method and return a copy of your current CatalogItemImpl class.
- Sometimes it is needful to define a toString() method that will output the items values as string.
- You can calculate with your item variables and so define a get method for returning the sum of the two prices in this case.
- As mentioned before, comparePrice is not a representating variable of the item and thus not set by the items constructor. Define set-methods if you need to initialize your other variables.
- Mark a constructor for recovery
Example Source Code:
1
public class DataAdvancedCatalogItem extends CatalogItemImpl
{
2
private int price1;
private int price2;
private int comparePrice;
8
@RecoveryConstructor(parameters = {"m_sName", "price1", "price2"})
3
public DataAdvancedCatalogItem(String name, int price1, int price2)
{
super(name);
this.price1 = price1;
this.price2 = price2;
}
4
protected CatalogItemImpl getShallowClone()
{
return (CatalogItemImpl)
new DataAdvancedCatalogItem(this.getName(), this.price1, this.price2);
}
5
public String toString()
{
return this.getName() + "-" + this.price1 + "-" +
this.price2;
}
6
public int getSum()
{
return (this.price1 + this.price2);
}
7
public void setComparePrice(int value)
{
this.comparePrice = value;
}
}
Incorporate a Catalog
Description: An important data structure is the Catalog. It provides all what is needed to store and administrate the Shop´s goods. It is also easy to display a Catalog´s contents with already implemented FormSheets, the JCatalogTable and the DefaultCatalogItemTED for example. The use of CatalogImpl, the implementation of the interface Catalog is recommended.
ToDo:
- Create a new instance of CatalogItemImpl.
- Define a fitting subclass of CatalogItemImpl and add it to the newly created CatalogImpl. Therefore refer to Define a simple CatalogItem or Define an advanced CatalogItem.
In this case the simple CatalogItemImpl from above is used.
Assign an instance of DataBasket if the addition to the catalog is performed within a SaleProcess. - Add the catalog to the shop's global list of catalogs.
- If you remove an item do not forget to catch the VetoException that can be possible if another process currently handles the catalog.
Example Source Code:
1
Catalog<DataBasicCatalogItem> simpleCatalog = new CatalogImpl<DataBasicCatalogItem>(SimpleCatalog);
2
simpleCatalog.add(
new DataBasicCatalogItem("item1", new IntegerValue(10)),
null);
3
Shop.getTheShop().addCatalog(simpleCatalog);
4
try
{
simpleCatalog.remove("item1", null);
}
catch (VetoException e)
{
e.printStackTrace();
}
Define a new AbstractCurrency
Description: EUROCurrencyImpl provides the recent german currency EURO. If you want to incorporate a new currency you will have two alternatives. You may implement interface Currency extending CatalogImpl and make your own implementation of CurrencyImpl. But this would force you to define your own MoneyBag extending CountingStockImpl, because MoneyBagImpl needs an instance of CurrencyImpl in it´s constructor. Second alternative is create a subclass of AbstractCurrency and to overwrite the key methods like done here.
ToDo:
- Create a subclass of AbstractCurrency.
- Add the currency's constructor and invoke the super constructor with the fitting Locale.
- Implement the protected CurrencyItemData[] getCurrencyItemData() method. Therein you define the names and values of your currency as CurrencyItemData.
Example Source Code:
1
public class DataAbstractCurrency extends AbstractCurrency
{
2
public DataAbstractCurrency(String name)
{
super(name, Locale.GERMANY);
}
3
protected CurrencyItemData[] getCurrencyItemData()
{
CurrencyItemData[] currencyArrayReturn =
{
// add CurrencyItemData with name and value
new CurrencyItemData("1-Bronze-Taler", 10),
new CurrencyItemData("1-Silber-Taler", 100),
new CurrencyItemData("1-Gold-Taler", 1000)
};
return currencyArrayReturn;
}
}
Incorporate a Currency
Description: A Currency is a special Catalog. Its CatalogItems are CurrencyItems that represent the different denominations of the Currency.
ToDo:
- Eventually create a new Currency. Therefore refer to Define a new AbstractCurrency.
- Create a new instance of CurrencyImpl. In this case the above defined CurrencyEuro class was used.
- Add the currency to the Shop's global list of catalogs.
Example Source Code:
2
AbstractCurrency abstractCurrency = new DataAbstractCurrency("SimpleCurrency");
3
Shop.getTheShop().addCatalog(abstractCurrency);
DataBasket
Use a DataBasket
Description: The task of this data structure is to backup transactions between framework components. It enables undo actions called RollBack. Remember that DataBaskets can't undo actions with components which doesn´t belong to the framework. This components have to be restored manually. To ensure that a framework component is able to be rolled back, the protected getShallowClone() method of the Item will have to be overwritten if the Item has additional attributes (Note: Be careful with the clone method, mistakes could be hard to detect). Use the public get(String sKey, DataBasket db, boolean fForEdit) method implemented in Catalog and Stock to get the Item which is to be modified. A DataBasket could be displayed like Catalogs and Stocks with the JDataBasketTable, the DefaultCatalogItemDBETableEntryDescriptor , the DefaultCountingStockDBETableEntryDescriptor and the DefaultStoringStockDBETableEntryDescriptor.
ToDo:
- Make a new instance of DataBasket or use the relevant of your class. In this case the use is implemented in a SaleProcess so the DataBasket of the process is used by getBasket().
- Get the object to be modified. In this case we first get the catalog and then the desired item.
(the structure of Incorporate a Catalog and Define a simple CatalogItem is used) - Modifiy the item.
- If you want to keep the changes, commit the DataBasket by calling basket.commit(). This will force the basket to go through the Commit-Gate and commit the modifications. If you do not want to keep the changes, rollback the DataBasket by calling basket.rollback(). This will force the basket to go through the RollBack-Gate and rollback the modifications.
Example Source Code:
1
final DataBasket basket = this.getBasket();
2
// get the catalog from the shop's global list of catalogs
final Catalog catalog = Shop.getTheShop().getCatalog("SimpleCatalog");
// define the CatalogItemImpl and set to null
DataBasicCatalogItem item = null;
// get the item with the DataBasket "watching" the action
try
{
item = (DataBasicCatalogItem) catalog.get("item1", basket, true);
}
// catch the relevant exceptions
catch(VetoException ve)
{
// exception handling here
}
catch(NotEditableException nee)
{
// exception handling here
}
catch(DataBasketConflictException dbce)
{
// exception handling here
}
3
item.setValue(new IntegerValue(99));
4
// decide whether to commit or to rollback (doCommit is ot type boolean)
if(doCommit)
{
// commit the changes
basket.commit();
}
else
{
// rollback the changes
basket.rollback();
}
Use a DataBasketCondition
Description: DataBasketConditions are important to display the contents of a DataBasket in a FormSheet (e.g. JDataBasketTable). They could also be used to summ the content's values using public Value sumBasket(DataBasketCondition dbc, BasketEntryValue bev, Value vInit). The already implemented DataBasketConditionImpl provides all what is needed.
ToDo:
- There are three ways to use a DataBasketCondition:
- Use the constructor to create an instance of DataBasketConditionImpl.
- Use the provided static fields:
- ALL_CATALOG_ITEMS
- ALL_STOCK_ITEMS
- ALL_ENTRIES
- Use provided static methods to get the needed instance:
- allCatalogItemsWithDest(Catalog cDest)
- allCatalogItemsWithSource(Catalog cSource)
- allStockItemsWithDest(Stock stDest)
- allStockItemsWithSource(Stock stSource)
- specificCatalogItem(CatalogItem ci)
- specificStockItem(StockItem si)
Example Source Code:
DataBasketCondition dbc;
1 a
dbc = new DataBasketConditionImpl(
// filters entries of a certain kind
// (DataBasketKeys.CATALOG_ITEM_MAIN_KEY, DataBasketKeys.STOCK_ITEM_MAIN_KEY)
(String) mainKey,
// filters Entrys with given name ((StockItem) si).getName()
(String) secondaryKey,
// filters Entrys from given source (Catalog or Stock)
(DataBasketEntrySource) dbesSource,
// filters Entrys from given destination (Catalog or Stock)
(DataBasketEntryDestination) dbedDestination,
// filters only given object (if it is null, all DataBasketEntrys will be checked)
(Object) value);
1 b
dbc = DataBasketConditionImpl.ALL_CATALOG_ITEMS;
1 c
dbc = DataBasketConditionImpl.allCatalogItemsWithSource(catalog);
Create a DataBasketEntryGrouper
Description: DataBasketEntryGroupers are important to display the contents of a DataBasket in a FormSheet. Every movement creates a new DataBasketEntry. So it could happen, that one CatalogItem for example has created many CatalogItemDataBasketEntrys in the DataBasket. If you want to display a DataBasket with DBEntrys of StockItems in a CountingStock, the already implemented CountingStockDBEGrouper will be sufficent. If you don´t want grouping at all, use the NOPDataBasketEntryGrouper. If you want to implement your own grouping, follow the instructions.
ToDo:
- Implement the interface DataBasketEntryGrouper in a class.
- Implement the method public boolean canGroup(DataBasketEntry dbe0, DataBasketEntry dbe1).
Here you have to decide which DataBasketEntrys should be grouped and which not. - Implement the method public DataBasketEntry group(DataBasketEntry dbe0, DataBasketEntry dbe1).
Here you have to implement how two DataBasketEntrys merge into one Entry.
Example Source Code:
import org.salespointframework.data.swing.DataBasketEntryGrouper;
import org.salespointframework.data.DataBasketEntry;
1
public class DataDataBasketEntryGrouper implements DataBasketEntryGrouper
{
2
public boolean canGroup(DataBasketEntry dbe0, DataBasketEntry dbe1)
{
// items of same kind (MainKey) and same name (SecondaryKey) can be grouped
if(dbe0.getMainKey().equals(dbe1.getMainKey()) &&
dbe0.getSecondaryKey().equals(dbe1.getSecondaryKey()))
{
return true;
}
else
{
return false;
}
}
3
public DataBasketEntry group(DataBasketEntry dbe0, DataBasketEntry dbe1)
{
// the first item will be displayed for both
return dbe0;
}
}
Filter
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.
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 each CatalogItem, whether it will be in the CatalogFilter 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 a CatalogFilter as a replacement for a 'real' Catalog, e.g., as an item in another Catalog.
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));
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.
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 the StockItem with the key key will be in the CountingStockFilter. - 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<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));
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.
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 each CurrencyItem, whether it will be in the CurrencyFilter 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<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));
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.
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 the MoneyBag will be in the MoneyBagFilter. - 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 source MoneyBag, 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"));
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.
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 each StockItem if it will be in the StoringStockFilter 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 source StoringStock, 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));
Stock
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.
ToDo:
- Create a subclass of StockItemImpl.
- Add constructors to set the items name and other attributes.Every constructor must invoke super(name), therefore a StockItem has 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();
}
}
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.
ToDo:
- Make a new instance of your used implementation of Stock (or select an existing instance of Stock).
- Use Stock.fillStockWithValue(DataBasket db, Value vTarget, StockFromValueCreator sfvc) to fill selected Stock with a certain Value.
- Use the implementation StockFromStockCreator, if you want to fill one Stock with the Values of another Stock (the needed items will be removed from the second Stock).
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())
);
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.
ToDo:
- Get the instance of Catalog you want to incorporate a CountingStock on.
(See also: #Incorporate a Catalog). - Make a new instance of CountingStock associated with the Catalog.
- Define (if necessary) a fitting subclass of StockItemImpl.
(See also Define a #StockItem). -
- Add and remove StockItems as you wish.
- It is not always necessary to add StockItems, but it may also sufficient only to increase the number of counted CatalogItems.
- Add the Stock to the Shop's global 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);
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.
ToDo:
- Get the instance of Catalog you want to incorporate a StoringStock on.
(See also: #Incorporate a Catalog). - Make a new instance of StoringStock associated with the Catalog.
- Define a fitting subclass of StockItemImpl.
(See also: Define a #StockItem). - Add and remove StockItems as you wish.
- Add the Stock to the Shop's global 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);
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.
ToDo:
- Get the instance of AbstractCurrency you want to incorporate a MoneyBag on.
- Make a new instance of MoneyBag associated with the Currency.
- Add the MoneyBag to the Shop's global 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();
}
}
Common
Common information about generic SalesPoint containers
Description:
Since Version 3.3, SalesPoint containers are generic. In order to use this functionality most conveniently, there are special identifiers that store the generic information. So the developer will not have to take care of casting to appropriate container types. Container types in SalesPoint are Catalogs and Stocks.
Catalogs: Catalogs are typed by the kind of CatalogItem they will contain. The same goes for their identifiers.
CatalogIdentifier<DataBasicCatalogItem> SimpleCatalog = new CatalogIdentifier<DataBasicCatalogItem>("SimpleCatalog");
Catalog<DataBasicCatalogItem> simpleCatalog = new CatalogImpl<DataBasicCatalogItem>(SimpleCatalog);
Once they are created you can register them with the Shop and get them back with the identifier they were created with:
Shop.getTheShop().addCatalog(simpleCatalog);
Catalog<DataBasicCatalogItem> catalog = Shop.getTheShop().getCatalog(SimpleCatalog);
Stocks:
Catalogs are typed by the kind of StockItem they will contain and the kind of CatalogItem the Catalog contains that is associated with the stock. The same goes for their identifiers.
StockIdentifier<StockItemImpl, DataBasicCatalogItem> Stock =
new StockIdentifier<StockItemImpl, DataBasicCatalogItem>("CountingStock");
CountingStock<StockItemImpl, DataBasicCatalogItem> stock =
new CountingStockImpl<StockItemImpl, DataBasicCatalogItem>(Stock, simpleCatalog);
Once they are created you can register them with the Shop and get them back with the identifier they were created with in a similar manner as you can do that with Catalogs.
As you can see (especially in the case of Stocks), setting these up can easily get quite extensive. Therefore it is recommended to derive your own classes from CatalogImpl, CountingStockImpl and/or StoringStockImpl and fit their generic parameters to your needs. You simply have to implement the constructor that takes the corresponding identifier and delegate it to the super constructor.