Merge branch 'feature/node_impl' into develop

This commit is contained in:
Nikita Iryupin 2021-01-03 11:34:56 +01:00
commit a2b5c2bc92
7 changed files with 36 additions and 24 deletions

View File

@ -10,6 +10,7 @@
generate generate
consume consume
doaction <product-operation-type> doaction <product-operation-type>
doaction <product-operation-type> <product-name>
sell <product-type> <product-name> sell <product-type> <product-name>
buy <product-type> <produt-name> <product-price> buy <product-type> <produt-name> <product-price>
pass pass

View File

@ -41,8 +41,6 @@ public class FoodChain
return factoryManager; return factoryManager;
} }
// todo maybe some refactoring needed?
// add other entities
public static void parseChannels() public static void parseChannels()
{ {
try try

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,10 @@ 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); if (action.getProduct().equals(product.getProductType()) || action.getProduct().equals(ProductType.ALL))
//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??? new Action(this.storageOwner, product, action);
else
throw new IllegalCallerException("! IllegalCallerException in NodeBase. " + product.getProductType().toString() + " cannot be processed by action " + action.name() + " only for " + action.getProduct());
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());
} }

View File

@ -1,36 +1,36 @@
package cz.cvut.fel.sit.omo.foodchain.operation; package cz.cvut.fel.sit.omo.foodchain.operation;
import cz.cvut.fel.sit.omo.foodchain.node.enums.NodeType; import cz.cvut.fel.sit.omo.foodchain.node.enums.NodeType;
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
public enum ProductOperationType public enum ProductOperationType
{ {
STORE_MEAT(NodeType.All, 20, -8), STORE_MEAT(NodeType.All, ProductType.MEAT, 20, -8),
STORE_FRUIT(NodeType.All, 8, 2), STORE_FRUIT(NodeType.All, ProductType.FRUIT, 8, 2),
STORE_VEGETABLE(NodeType.All, 10, 2), STORE_VEGETABLE(NodeType.All, ProductType.VEGETABLE, 10, 2),
STORE_OTHER(NodeType.All, 30, 21), STORE_OTHER(NodeType.All, ProductType.OTHER, 30, 21),
WRAP_INTO_GIFT_PACKAGE(NodeType.Seller, 1, -8), WRAP_INTO_GIFT_PACKAGE(NodeType.Seller, ProductType.ALL, 1, -8),
UNWRAP(NodeType.All, 1, 21), UNWRAP(NodeType.All, ProductType.ALL, 1, 21),
CUT_TO_PIECES(NodeType.All, 1, 21), CUT_TO_PIECES(NodeType.All, ProductType.ALL, 1, 21),
BOIL_MEAT(NodeType.All, 1, 21), BOIL_MEAT(NodeType.All, ProductType.MEAT, 1, 21),
GRILL_MEAT(NodeType.All, 1, 21), GRILL_MEAT(NodeType.All, ProductType.MEAT, 1, 21),
SMOKE_MEAT(NodeType.All, 1, 21), SMOKE_MEAT(NodeType.All, ProductType.MEAT, 1, 21),
DRY_MEAT(NodeType.All, 1, 21), DRY_MEAT(NodeType.All, ProductType.MEAT, 1, 21),
DRY_FRUIT(NodeType.All, 1, 21), DRY_FRUIT(NodeType.All, ProductType.FRUIT, 1, 21),
FREEZE_DRY_FRUIT(NodeType.All, 1, 21); FREEZE_DRY_FRUIT(NodeType.All, ProductType.FRUIT, 1, 21);
//todo add product type allowed for this action
private final NodeType node; private final NodeType node;
private final ProductType product;
private final int duration; private final int duration;
private final int temperature; private final int temperature;
ProductOperationType(NodeType node, int duration, int temperature) ProductOperationType(NodeType node, ProductType product, int duration, int temperature)
{ {
this.node = node; this.node = node;
this.product = product;
this.duration = duration; this.duration = duration;
this.temperature = temperature; this.temperature = temperature;
} }
@ -49,4 +49,6 @@ public enum ProductOperationType
{ {
return node; return node;
} }
public ProductType getProduct() { return product; }
} }

View File

@ -2,5 +2,5 @@ package cz.cvut.fel.sit.omo.foodchain.product;
public enum ProductType public enum ProductType
{ {
MEAT, FRUIT, VEGETABLE, OTHER; MEAT, FRUIT, VEGETABLE, OTHER, ALL // ALL is used only for actions
} }

View File

@ -22,7 +22,6 @@ public class DoActionStep extends ScenarioStep {
@Override @Override
void execute() { void execute() {
//todo maybe do a better error handling
try { try {
if (product != null) { if (product != null) {
nodeBase.doAction(productOperationType, product); nodeBase.doAction(productOperationType, product);

View File

@ -8,7 +8,6 @@ public class Scenario {
Iterator<ScenarioStep> stepIterator; Iterator<ScenarioStep> stepIterator;
public Scenario() { public Scenario() {
//steps = //TODO init
stepIterator = steps.listIterator(0); stepIterator = steps.listIterator(0);
} }