Class Storage
- java.lang.Object
-
- cz.cvut.fel.sit.omo.foodchain.node.Storage
-
public class Storage extends java.lang.ObjectStorage sub-node for storing products of other nodes
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<ProductCache>cacheprivate java.util.List<Product>productsprivate NodeBasestorageOwner
-
Method Summary
Modifier and Type Method Description booleancontainsProduct(Product product)Checks whether storage contains provided product.booleancontainsProduct(java.lang.String name, ProductType type)Checks whether storage contains provided product.voiddoAction(ProductOperationType action)Calls specific ProductOperation on each product in stock.voiddoAction(ProductOperationType action, java.lang.String productName)Proceed specific type of action on provided product if its possible.java.util.List<ProductCache>getCache()intgetNumberOfStoredProducts()Returns number of products in storage.ProductgetProduct(java.lang.String name, ProductType type)Finds a product (first if there is multiple of them) based on its name and type.java.util.List<Product>getProducts()voidremoveProduct(Product product)Removes provided product from storage if storage contains this product.voidstoreProduct(Product product)Adds provided product into the storage.voidstoreProducts(java.util.List<Product> products)Adds all of the provided products into the storage.voidtick()
-
-
-
Field Detail
-
storageOwner
private final NodeBase storageOwner
-
products
private final java.util.List<Product> products
-
cache
private final java.util.List<ProductCache> cache
-
-
Constructor Detail
-
Storage
public Storage(NodeBase owner)
-
-
Method Detail
-
storeProduct
public void storeProduct(Product product)
Adds provided product into the storage.- Parameters:
product-
-
storeProducts
public void storeProducts(java.util.List<Product> products)
Adds all of the provided products into the storage.- Parameters:
products-
-
getProduct
public Product getProduct(java.lang.String name, ProductType type)
Finds a product (first if there is multiple of them) based on its name and type.- Parameters:
name- name of product to findtype- type of product to find- Returns:
- product if found, null if product is not in storage
-
getProducts
public java.util.List<Product> getProducts()
-
getCache
public java.util.List<ProductCache> getCache()
-
getNumberOfStoredProducts
public int getNumberOfStoredProducts()
Returns number of products in storage.- Returns:
-
containsProduct
public boolean containsProduct(Product product)
Checks whether storage contains provided product.- Parameters:
product- product to check- Returns:
- true if contains, false if not
-
containsProduct
public boolean containsProduct(java.lang.String name, ProductType type)Checks whether storage contains provided product.- Parameters:
name- name of product to checktype- type of product to check- Returns:
- true if contains, false if not
-
removeProduct
public void removeProduct(Product product)
Removes provided product from storage if storage contains this product. (Removes only first found).- Parameters:
product- product to remove
-
doAction
public void doAction(ProductOperationType action, java.lang.String productName) throws java.lang.IllegalCallerException, javax.naming.InsufficientResourcesException
Proceed specific type of action on provided product if its possible.- Parameters:
action- type of product operation to doproductName- product to process- Throws:
java.lang.IllegalCallerExceptionjavax.naming.InsufficientResourcesException
-
doAction
public void doAction(ProductOperationType action)
Calls specific ProductOperation on each product in stock.- Parameters:
action- ProductOperationType
-
tick
public void tick()
-
-