diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/ChannelBase.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/ChannelBase.java index 5ca051c..8e4358c 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/ChannelBase.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/ChannelBase.java @@ -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 requirements; - Queue transactions; +public abstract class ChannelBase implements IChannel +{ + protected ProductType productType; + protected Queue requirements; + protected Queue 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 getTransactions() + { + return this.transactions; + } + + @Override + public Queue 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(); + } } diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/FruitChannel.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/FruitChannel.java index 50d4bcd..d694329 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/FruitChannel.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/FruitChannel.java @@ -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); } } diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/IChannel.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/IChannel.java index 99d1081..c15e2f7 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/IChannel.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/IChannel.java @@ -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 getTransactions(); + + //public Requirement getNextRequirement(); + Queue getCurrentRequirements(); + + void addRequirement(Requirement requirement); + + void addTransaction(Transaction transaction); - public void addRequirement(Requirement requirement); - public void addTransaction(Transaction transaction); } diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/MeatChannel.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/MeatChannel.java new file mode 100644 index 0000000..88d434b --- /dev/null +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/MeatChannel.java @@ -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); + } +} diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/MeetChannel.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/MeetChannel.java deleted file mode 100644 index fae4a81..0000000 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/MeetChannel.java +++ /dev/null @@ -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) { - - } -} diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/OtherChannel.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/OtherChannel.java new file mode 100644 index 0000000..1595bbc --- /dev/null +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/OtherChannel.java @@ -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(); + } +} diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/VegetableChannel.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/VegetableChannel.java index 0a68c83..6790a7b 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/VegetableChannel.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/channel/VegetableChannel.java @@ -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); } } diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/product/Product.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/product/Product.java index 4ed036d..77b281b 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/product/Product.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/product/Product.java @@ -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; + } } diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/product/ProductState.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/product/ProductState.java index 90518fb..2d7b4d1 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/product/ProductState.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/product/ProductState.java @@ -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; } diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/product/ProductType.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/product/ProductType.java index ad4c34c..533c3c3 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/product/ProductType.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/product/ProductType.java @@ -1,4 +1,6 @@ package cz.cvut.fel.sit.omo.foodchain.product; -public enum ProductType { +public enum ProductType +{ + MEAT, FRUIT, VEGETABLE, OTHER; }