|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.uci.ics.inf111.dvdvendor.app.ProductDB
public class ProductDB
The ProductDB class encapsulates the list of all products sold in the store. In a real system, this would likely be a wrapper around a database of products which would be managed elsewhere. In our sample system, we have a method which can provide a sample DB, and the capability to add items to the DB using an addItem() method. The ProductDB is instantiated only once and it uses the singleton pattern to guarantee this characteristic.
Field Summary | |
---|---|
private static ProductDB |
instance
Private instance of this class |
private java.util.Hashtable<java.lang.String,Product> |
productsHT
This Hashtable is the core of our sample DB. |
Constructor Summary | |
---|---|
private |
ProductDB()
Constructs an empty database. |
Method Summary | |
---|---|
void |
addItem(Product item)
This method is called to add items directly to the database in our example. |
static ProductDB |
getInstance()
It returns a new class if the instance is null, else it returns the instance already created and initialized |
void |
initializeTestDB()
This test method constructs a sample database which is useful for testing purposes. |
java.util.Hashtable<java.lang.String,Product> |
listAll()
This method returns a copy of the ProductDB Hashtable. |
Product |
lookUpItem(BarCode barCode)
This method looks up a product in the database. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static ProductDB instance
private java.util.Hashtable<java.lang.String,Product> productsHT
Constructor Detail |
---|
private ProductDB()
Method Detail |
---|
public static ProductDB getInstance() throws java.lang.Exception
java.lang.Exception
public void initializeTestDB() throws java.lang.Exception
java.lang.Exception
public java.util.Hashtable<java.lang.String,Product> listAll()
public Product lookUpItem(BarCode barCode)
code
- The bar code of the product.
public void addItem(Product item) throws ProductDBException
item
- The product to be added.
ProductDBException
- If the product already exist in the DB.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |