Added new ProductState and improved product state machine

This commit is contained in:
Tomáš Musil 2020-12-27 19:06:57 +01:00
parent 4cef005934
commit 1771fc0fdb
2 changed files with 8 additions and 3 deletions

View File

@ -71,11 +71,16 @@ public class Product
// "State machine methods"
/**
* Set current product state to AVAILABLE
* Set current product state to AVAILABLE. Throws IllegalStateException if the product is not IN_ACTION, READY_FOR_RECEPTION or IN_REQUIREMENT.
*/
public void setStateToAvailable()
{
if (this.productState.equals(ProductState.IN_ACTION) ||
this.productState.equals(ProductState.READY_FOR_RECEPTION) ||
this.productState.equals(ProductState.IN_REQUIREMENT))
this.productState = ProductState.AVAILABLE;
else
throw new IllegalStateException("Cannot set state AVAILABLE. Product is not IN_ACTION, READY_FOR_RECEPTION or IN_REQUIREMENT");
}
/**

View File

@ -2,5 +2,5 @@ package cz.cvut.fel.sit.omo.foodchain.product;
public enum ProductState
{
AVAILABLE, READY_FOR_DISPATCH, IN_TRANSIT, READY_FOR_RECEPTION, IN_ACTION
AVAILABLE, READY_FOR_DISPATCH, IN_TRANSIT, READY_FOR_RECEPTION, IN_ACTION, IN_REQUIREMENT
}