Added containsProduct in Storage.

This commit is contained in:
Daniel Poustka 2021-01-03 11:08:23 +01:00
parent ad71021bd5
commit d045767027

View File

@ -76,6 +76,17 @@ public class Storage
return products.contains(product); return products.contains(product);
} }
/**
* Checks whether storage contains provided product
* @param name name of product to check
* @param type type of product to check
* @return true if contains, false if not
*/
public boolean containsProduct(String name, ProductType type)
{
return this.getProduct(name,type) != null;
}
/** /**
* Removes provided product from storage if storage contains this product. (Removes only first found) * Removes provided product from storage if storage contains this product. (Removes only first found)
* @param product product to remove * @param product product to remove
@ -94,8 +105,7 @@ public class Storage
public void doAction(ProductOperationType action, Product product) throws IllegalCallerException public void doAction(ProductOperationType action, Product product) throws IllegalCallerException
{ {
if (action.getNode().equals(this.storageOwner.getNodeType())) if (action.getNode().equals(this.storageOwner.getNodeType()))
new Action(this.storageOwner, this.getProduct(product.getName(), product.getProductType()), action); new Action(this.storageOwner, product, action);
//new Action(this.storageOwner, product, action); //todo má se zpracovat produkt co přichází nebo na jeho základě najít tento produkt ve skladu a ten zpracovat???
else else
throw new IllegalCallerException("! IllegalCallerException in NodeBase. " + this.storageOwner.getNodeType().toString() + " cannot do action available only for " + action.getNode()); throw new IllegalCallerException("! IllegalCallerException in NodeBase. " + this.storageOwner.getNodeType().toString() + " cannot do action available only for " + action.getNode());
} }