Moving nodes classes to directories, create new enum, limit sellers and purchasers
This commit is contained in:
parent
3aaa5c72e6
commit
853bf05ee5
4
pom.xml
4
pom.xml
@ -17,8 +17,8 @@
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>12</maven.compiler.target>
|
||||
<maven.compiler.source>12</maven.compiler.source>
|
||||
<maven.compiler.target>14</maven.compiler.target>
|
||||
<maven.compiler.source>14</maven.compiler.source>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@ -2,7 +2,7 @@ package cz.cvut.fel.sit.omo.foodchain;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.factory.FactoryManager;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.parser.ConfigurationParser;
|
||||
import cz.cvut.fel.sit.omo.foodchain.parser.ParserResult;
|
||||
import cz.cvut.fel.sit.omo.foodchain.parser.ParserResultElement;
|
||||
|
||||
@ -3,6 +3,8 @@ package cz.cvut.fel.sit.omo.foodchain.factory;
|
||||
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
||||
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelSubscriptionType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.*;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.enums.NodeType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.parser.ParserResultElement;
|
||||
import cz.cvut.fel.sit.omo.foodchain.pool.ChannelPool;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||
@ -12,11 +14,6 @@ import java.util.Objects;
|
||||
public class NodeFactory
|
||||
{
|
||||
|
||||
enum NodeType
|
||||
{
|
||||
Farmer, Processor, Distributor, Seller, Customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Node based on input ParserResultElement
|
||||
* @param input data from Node is created
|
||||
|
||||
@ -3,7 +3,7 @@ package cz.cvut.fel.sit.omo.foodchain.factory;
|
||||
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.Customer;
|
||||
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.node.base.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.ProductOperationType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.TransactionType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.parser.ParserResultElement;
|
||||
|
||||
@ -1,11 +1,16 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.BuyerNodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.enums.NodeType;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Customer extends BuyerNodeBase {
|
||||
|
||||
public Customer(double startMoney) {
|
||||
super();
|
||||
super(startMoney);
|
||||
allowedSeller = NodeType.Distributor;
|
||||
allowedPurchaser = NodeType.None;
|
||||
}
|
||||
|
||||
public void consumeProduct() {
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.RetailerNodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.enums.NodeType;
|
||||
|
||||
public class Distributor extends RetailerNodeBase {
|
||||
|
||||
public Distributor(double startMoney) {
|
||||
super();
|
||||
super(startMoney);
|
||||
allowedSeller = NodeType.Seller;
|
||||
allowedPurchaser = NodeType.Customer;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.SellerNodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.enums.NodeType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.TransactionType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
public class Farmer extends SellerNodeBase {
|
||||
|
||||
public Farmer(double startMoney) {
|
||||
super();
|
||||
super(startMoney);
|
||||
allowedSeller = NodeType.None;
|
||||
allowedPurchaser = NodeType.Processor;
|
||||
}
|
||||
|
||||
public void generateProduct(Product product) {
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.RetailerNodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.enums.NodeType;
|
||||
|
||||
public class Processor extends RetailerNodeBase {
|
||||
|
||||
public Processor(double startMoney) {
|
||||
super();
|
||||
super(startMoney);
|
||||
allowedSeller = NodeType.Farmer;
|
||||
allowedPurchaser = NodeType.Seller;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.RetailerNodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.enums.NodeType;
|
||||
|
||||
public class Seller extends RetailerNodeBase {
|
||||
|
||||
public Seller(double startMoney) {
|
||||
super();
|
||||
super(startMoney);
|
||||
allowedSeller = NodeType.Processor;
|
||||
allowedPurchaser = NodeType.Distributor;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||
package cz.cvut.fel.sit.omo.foodchain.node.base;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.interfaces.IBuyerNode;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
public class BuyerNodeBase extends NodeBase implements IBuyerNode {
|
||||
public BuyerNodeBase(double m){
|
||||
super(m);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void buyProduct(Product product) {
|
||||
@ -1,7 +1,8 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||
package cz.cvut.fel.sit.omo.foodchain.node.base;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelSubscriptionType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.enums.NodeType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.*;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||
@ -21,10 +22,12 @@ import java.util.Map;
|
||||
public class NodeBase implements ChannelObserver {
|
||||
private final Map<ChannelBase, ChannelSubscriptionType> subscribedChannels;
|
||||
private final List<Product> products;
|
||||
private final MonetaryAmount money;
|
||||
|
||||
private final List<Transaction> refusedTransactions;
|
||||
|
||||
private final MonetaryAmount money;
|
||||
protected NodeType allowedSeller;
|
||||
protected NodeType allowedPurchaser;
|
||||
|
||||
public NodeBase() {
|
||||
subscribedChannels = new HashMap<>();
|
||||
products = new LinkedList<>();
|
||||
@ -140,9 +143,17 @@ public class NodeBase implements ChannelObserver {
|
||||
return SignatureManager.validateSignature(transaction);
|
||||
}
|
||||
|
||||
boolean senderPurchaserCheck(Requirement req) {
|
||||
String simpleName = req.getCreator().getClass().getSimpleName();
|
||||
|
||||
return !req.getCreator().equals(this) &&
|
||||
(((allowedSeller == NodeType.valueOf(simpleName) || allowedSeller == NodeType.All) && (req.getTransactionType() == TransactionType.SALE)) ||
|
||||
((allowedPurchaser == NodeType.valueOf(simpleName) || allowedPurchaser == NodeType.All) && req.getTransactionType() == TransactionType.PURCHASE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Requirement requirement) {
|
||||
if (!requirement.getCreator().equals(this))
|
||||
if (senderPurchaserCheck(requirement))
|
||||
acceptRequirement(requirement);
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,14 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||
package cz.cvut.fel.sit.omo.foodchain.node.base;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.interfaces.IBuyerNode;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.interfaces.ISellerNode;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
public class RetailerNodeBase extends NodeBase implements IBuyerNode, ISellerNode {
|
||||
public RetailerNodeBase(double startMoney) {
|
||||
super(startMoney);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sellProduct(Product product) {
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||
package cz.cvut.fel.sit.omo.foodchain.node.base;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.interfaces.ISellerNode;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
public class SellerNodeBase extends NodeBase implements ISellerNode {
|
||||
public SellerNodeBase(double startMoney) {
|
||||
super(startMoney);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sellProduct(Product product) {
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.node.enums;
|
||||
|
||||
public enum NodeType {
|
||||
Farmer, Processor, Distributor, Seller, Customer, None, All
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||
package cz.cvut.fel.sit.omo.foodchain.node.interfaces;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||
package cz.cvut.fel.sit.omo.foodchain.node.interfaces;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
public class Action extends OperationBase {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
|
||||
import javax.money.MonetaryAmount;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
public class ProductTransaction extends Transaction {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.signature.Signature;
|
||||
import cz.cvut.fel.sit.omo.foodchain.signature.SignatureManager;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.pool;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
|
||||
public class NodePool extends PoolListBase<NodeBase> {
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.reporting;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.OperationBase;
|
||||
|
||||
public class ReportTextFileVisitor {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.requirement;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.TransactionType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.scenario;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.ProductOperationType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package cz.cvut.fel.sit.omo.foodchain.scenario;
|
||||
|
||||
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 {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cz.cvut.fel.sit.omo.foodchain.scenario;
|
||||
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.base.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.operation.TransactionType;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user