Implemented channel and product basic stuff.
This commit is contained in:
parent
8a90a07ef7
commit
5a6fc28b76
@ -1,11 +1,69 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.channel;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.requirement.Requirement;
|
||||
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
|
||||
public abstract class ChannelBase implements IChannel {
|
||||
Queue<Requirement> requirements;
|
||||
Queue<Transaction> transactions;
|
||||
public abstract class ChannelBase implements IChannel
|
||||
{
|
||||
protected ProductType productType;
|
||||
protected Queue<Requirement> requirements;
|
||||
protected Queue<Transaction> transactions;
|
||||
|
||||
public ChannelBase(ProductType type)
|
||||
{
|
||||
this.requirements = new PriorityQueue<>();
|
||||
this.transactions = new PriorityQueue<>();
|
||||
this.productType = type;
|
||||
}
|
||||
|
||||
public ChannelBase()
|
||||
{
|
||||
this.requirements = new PriorityQueue<>();
|
||||
this.transactions = new PriorityQueue<>();
|
||||
this.productType = ProductType.OTHER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queue<Transaction> getTransactions()
|
||||
{
|
||||
return this.transactions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queue<Requirement> getCurrentRequirements()
|
||||
{
|
||||
return this.requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new requirement to the requirement Queue
|
||||
* @param requirement requirement
|
||||
*/
|
||||
@Override
|
||||
public void addRequirement(Requirement requirement)
|
||||
{
|
||||
this.requirements.add(requirement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new transaction to the transaction Queue
|
||||
* @param transaction transaction
|
||||
*/
|
||||
@Override
|
||||
public void addTransaction(Transaction transaction)
|
||||
{
|
||||
this.transactions.add(transaction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all requirements from this channel
|
||||
*/
|
||||
public void clearRequirements()
|
||||
{
|
||||
this.requirements.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,26 +1,11 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.channel;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
|
||||
import cz.cvut.fel.sit.omo.foodchain.requirement.Requirement;
|
||||
|
||||
public class FruitChannel extends ChannelBase {
|
||||
@Override
|
||||
public Transaction getNextTransaction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Requirement getNextRequirement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirement(Requirement requirement) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTransaction(Transaction transaction) {
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||
|
||||
public class FruitChannel extends ChannelBase
|
||||
{
|
||||
public FruitChannel()
|
||||
{
|
||||
super(ProductType.FRUIT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,11 +3,20 @@ package cz.cvut.fel.sit.omo.foodchain.channel;
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
|
||||
import cz.cvut.fel.sit.omo.foodchain.requirement.Requirement;
|
||||
|
||||
public interface IChannel {
|
||||
//TODO Daniel
|
||||
public Transaction getNextTransaction();
|
||||
public Requirement getNextRequirement();
|
||||
import java.util.Queue;
|
||||
|
||||
public interface IChannel
|
||||
{
|
||||
//TODO Daniel
|
||||
|
||||
//Transaction getNextTransaction();
|
||||
Queue<Transaction> getTransactions();
|
||||
|
||||
//public Requirement getNextRequirement();
|
||||
Queue<Requirement> getCurrentRequirements();
|
||||
|
||||
void addRequirement(Requirement requirement);
|
||||
|
||||
void addTransaction(Transaction transaction);
|
||||
|
||||
public void addRequirement(Requirement requirement);
|
||||
public void addTransaction(Transaction transaction);
|
||||
}
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.channel;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||
|
||||
public class MeatChannel extends ChannelBase
|
||||
{
|
||||
public MeatChannel()
|
||||
{
|
||||
super(ProductType.MEAT);
|
||||
}
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.channel;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
|
||||
import cz.cvut.fel.sit.omo.foodchain.requirement.Requirement;
|
||||
|
||||
public class MeetChannel extends ChannelBase {
|
||||
@Override
|
||||
public Transaction getNextTransaction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Requirement getNextRequirement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirement(Requirement requirement) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTransaction(Transaction transaction) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.channel;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||
|
||||
public class OtherChannel extends ChannelBase
|
||||
{
|
||||
public OtherChannel()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
@ -1,26 +1,11 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.channel;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
|
||||
import cz.cvut.fel.sit.omo.foodchain.requirement.Requirement;
|
||||
|
||||
public class VegetableChannel extends ChannelBase {
|
||||
@Override
|
||||
public Transaction getNextTransaction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Requirement getNextRequirement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirement(Requirement requirement) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTransaction(Transaction transaction) {
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||
|
||||
public class VegetableChannel extends ChannelBase
|
||||
{
|
||||
public VegetableChannel()
|
||||
{
|
||||
super(ProductType.VEGETABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,111 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.product;
|
||||
|
||||
public class Product {
|
||||
public class Product
|
||||
{
|
||||
private ProductState productState;
|
||||
private ProductType productType;
|
||||
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Creates Product with default state AVAILABLE
|
||||
* @param name name of product
|
||||
* @param productType type of product
|
||||
*/
|
||||
public Product(String name, ProductType productType)
|
||||
{
|
||||
this.name = name;
|
||||
this.productType = productType;
|
||||
this.productState = ProductState.AVAILABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Product
|
||||
* @param name name of product
|
||||
* @param productType type of product
|
||||
* @param productState state of product
|
||||
*/
|
||||
public Product(String name, ProductType productType, ProductState productState)
|
||||
{
|
||||
this.name = name;
|
||||
this.productType = productType;
|
||||
this.productState = productState;
|
||||
}
|
||||
|
||||
// "State machine methods"
|
||||
|
||||
/**
|
||||
* Set current product state to AVAILABLE
|
||||
*/
|
||||
public void setStateToAvailable()
|
||||
{
|
||||
this.productState = ProductState.AVAILABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set current product state to READY_FOR_DISPATCH. Throws IllegalStateException if the product is not AVAILABLE.
|
||||
*/
|
||||
public void setStateToReadyForDispatch()
|
||||
{
|
||||
if(this.productState.equals(ProductState.AVAILABLE))
|
||||
this.productState = ProductState.READY_FOR_DISPATCH;
|
||||
else
|
||||
throw new IllegalStateException("Cannot set state READY_FOR_DISPATCH. Product is not AVAILABLE!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set current product state to IN_TRANSIT. Throws IllegalStateException if the product is not READY_FOR_DISPATCH.
|
||||
*/
|
||||
public void setStateToInTransit()
|
||||
{
|
||||
if(this.productState.equals(ProductState.READY_FOR_DISPATCH))
|
||||
this.productState = ProductState.IN_TRANSIT;
|
||||
else
|
||||
throw new IllegalStateException("Cannot set state IN_TRANSIT. Product is not READY_FOR_DISPATCH!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set current product state to READY_FOR_RECEPTION. Throws IllegalStateException if the product is not READY_FOR_RECEPTION.
|
||||
*/
|
||||
public void setStateToReadyForReception()
|
||||
{
|
||||
if(this.productState.equals(ProductState.IN_TRANSIT))
|
||||
this.productState = ProductState.READY_FOR_RECEPTION;
|
||||
else
|
||||
throw new IllegalStateException("Cannot set state READY_FOR_RECEPTION. Product has not been in transit!");
|
||||
}
|
||||
|
||||
/*
|
||||
public void setProductState(ProductState productState)
|
||||
{
|
||||
this.productState = productState;
|
||||
}*/
|
||||
|
||||
|
||||
//Getters & Setters
|
||||
|
||||
public ProductState getProductState()
|
||||
{
|
||||
return productState;
|
||||
}
|
||||
|
||||
public ProductType getProductType()
|
||||
{
|
||||
return productType;
|
||||
}
|
||||
|
||||
public void setProductType(ProductType productType)
|
||||
{
|
||||
this.productType = productType;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.product;
|
||||
|
||||
public enum ProductState {
|
||||
public enum ProductState
|
||||
{
|
||||
AVAILABLE, READY_FOR_DISPATCH, IN_TRANSIT, READY_FOR_RECEPTION;
|
||||
}
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.product;
|
||||
|
||||
public enum ProductType {
|
||||
public enum ProductType
|
||||
{
|
||||
MEAT, FRUIT, VEGETABLE, OTHER;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user