Implemented more Steps, fixed some bugs, added helper methods
This commit is contained in:
parent
5e96891696
commit
e3e289b9fd
@ -3,13 +3,9 @@ package cz.cvut.fel.sit.omo.foodchain.node;
|
|||||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
|
||||||
public class BuyerNodeBase extends NodeBase implements IBuyerNode {
|
public class BuyerNodeBase extends NodeBase implements IBuyerNode {
|
||||||
@Override
|
|
||||||
public void sellProduct(Product product) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addMargin(Product product) {
|
public void buyProduct(Product product) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,11 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class Customer extends BuyerNodeBase {
|
public class Customer extends BuyerNodeBase {
|
||||||
|
|
||||||
|
public void consumeProduct() {
|
||||||
|
int i = new Random().nextInt(getStorage().size());
|
||||||
|
getStorage().remove(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,12 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||||
|
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.operation.TransactionType;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
|
||||||
public class Farmer extends SellerNodeBase {
|
public class Farmer extends SellerNodeBase {
|
||||||
|
|
||||||
|
public void generateProduct(Product product) {
|
||||||
|
storeProduct(product);
|
||||||
|
createRequirement(TransactionType.SALE, product.getProductType(), product.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,5 @@ import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
|||||||
|
|
||||||
public interface IBuyerNode {
|
public interface IBuyerNode {
|
||||||
|
|
||||||
void sellProduct(Product product);
|
void buyProduct(Product product);
|
||||||
|
|
||||||
void addMargin(Product product);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,5 +4,7 @@ import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
|||||||
|
|
||||||
public interface ISellerNode {
|
public interface ISellerNode {
|
||||||
|
|
||||||
void buyProduct(Product product);
|
void sellProduct(Product product);
|
||||||
|
|
||||||
|
void addMargin(Product product);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,7 +91,7 @@ public class NodeBase implements ChannelObserver {
|
|||||||
|
|
||||||
|
|
||||||
public void doAction(ProductOperationType action, Product product) {
|
public void doAction(ProductOperationType action, Product product) {
|
||||||
Action actionProcess = new Action(this, product);
|
Action actionProcess = new Action(this, product, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -114,6 +114,9 @@ public class NodeBase implements ChannelObserver {
|
|||||||
return products.stream().filter(ch -> ch.getProductType() == type && ch.getName().equals(name)).findFirst().orElse(null);
|
return products.stream().filter(ch -> ch.getProductType() == type && ch.getName().equals(name)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Product> getStorage() {
|
||||||
|
return products;
|
||||||
|
}
|
||||||
|
|
||||||
public Signature generateSignature(Transaction transaction) {
|
public Signature generateSignature(Transaction transaction) {
|
||||||
return SignatureManager.signTransaction(transaction);
|
return SignatureManager.signTransaction(transaction);
|
||||||
|
|||||||
@ -4,7 +4,12 @@ import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
|||||||
|
|
||||||
public class SellerNodeBase extends NodeBase implements ISellerNode {
|
public class SellerNodeBase extends NodeBase implements ISellerNode {
|
||||||
@Override
|
@Override
|
||||||
public void buyProduct(Product product) {
|
public void sellProduct(Product product) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addMargin(Product product) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ public class Action extends OperationBase {
|
|||||||
private final ProductOperationType type;
|
private final ProductOperationType type;
|
||||||
private int duration;
|
private int duration;
|
||||||
|
|
||||||
Action(NodeBase node, Product product, ProductOperationType type) {
|
public Action(NodeBase node, Product product, ProductOperationType type) {
|
||||||
super(node);
|
super(node);
|
||||||
this.product = product;
|
this.product = product;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|||||||
@ -1,6 +1,11 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.pool;
|
package cz.cvut.fel.sit.omo.foodchain.pool;
|
||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||||
|
|
||||||
public class ChannelPool extends PoolListBase<ChannelBase> {
|
public class ChannelPool extends PoolListBase<ChannelBase> {
|
||||||
|
|
||||||
|
public ChannelBase findByType(ProductType type) {
|
||||||
|
return findAll().stream().filter(ch -> ch.getProductType().equals(type)).findFirst().orElse(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.pool;
|
package cz.cvut.fel.sit.omo.foodchain.pool;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -11,7 +10,7 @@ public abstract class PoolListBase<T> {
|
|||||||
pool = new LinkedList<T>();
|
pool = new LinkedList<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<T> findAll() {
|
public List<T> findAll() {
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
package cz.cvut.fel.sit.omo.foodchain.scenario;
|
||||||
|
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.node.Customer;
|
||||||
|
|
||||||
|
public class ConsumeProductStep extends ScenarioStep {
|
||||||
|
|
||||||
|
private Customer node;
|
||||||
|
|
||||||
|
public ConsumeProductStep(Customer node) {
|
||||||
|
this.node = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void execute() {
|
||||||
|
node.consumeProduct();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,24 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.scenario;
|
package cz.cvut.fel.sit.omo.foodchain.scenario;
|
||||||
|
|
||||||
public class GenerateProductStep {
|
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.node.Farmer;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
|
||||||
|
public class GenerateProductStep extends ScenarioStep {
|
||||||
|
|
||||||
|
private Farmer node;
|
||||||
|
private Product product;
|
||||||
|
|
||||||
|
public GenerateProductStep(Farmer node) {
|
||||||
|
this.node = node;
|
||||||
|
product = FoodChain.getFactoryManager().getPoolDatabaseInstance().getProductPoolInstance().findAll()
|
||||||
|
.stream().findFirst().orElse(null);
|
||||||
|
FoodChain.getFactoryManager().getPoolDatabaseInstance().getProductPoolInstance().remove(product);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void execute() {
|
||||||
|
node.generateProduct(product);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user