From 0bb5af4968d27c55fc9fd6add968683ba5417547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Musil?= Date: Sat, 26 Dec 2020 10:19:30 +0100 Subject: [PATCH] Changed constructors --- EAR diagrams/FoodChain.ldb | Bin 64 -> 0 bytes .../omo/foodchain/factory/NodeFactory.java | 37 +++++++++--------- .../fel/sit/omo/foodchain/node/Customer.java | 4 ++ .../sit/omo/foodchain/node/Distributor.java | 4 ++ .../fel/sit/omo/foodchain/node/Farmer.java | 4 ++ .../fel/sit/omo/foodchain/node/NodeBase.java | 2 +- .../fel/sit/omo/foodchain/node/Processor.java | 4 ++ .../fel/sit/omo/foodchain/node/Seller.java | 4 ++ .../sit/omo/foodchain/product/Product.java | 8 ++-- 9 files changed, 43 insertions(+), 24 deletions(-) delete mode 100644 EAR diagrams/FoodChain.ldb diff --git a/EAR diagrams/FoodChain.ldb b/EAR diagrams/FoodChain.ldb deleted file mode 100644 index a4ff92435ca305e40b3e661e5cdcc91ae45519b6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 64 hcmZ>94fYQ456}(qF*0=t@ncXx1BofQnRyJj0RVnI2tEJ+ diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/factory/NodeFactory.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/factory/NodeFactory.java index 91a2c1a..a2e1f7a 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/factory/NodeFactory.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/factory/NodeFactory.java @@ -43,25 +43,24 @@ public class NodeFactory System.err.println("! Fatal error in NodeFactory: " + e.getMessage()); } -// switch (Objects.requireNonNull(nodeType)) -// { -// //TODO Money constructor -// case Farmer: -// n = new Farmer(startMoney); -// break; -// case Processor: -// n = new Processor(startMoney); -// break; -// case Distributor: -// n = new Distributor(startMoney); -// break; -// case Seller: -// n = new Seller(startMoney); -// break; -// case Customer: -// n = new Customer(startMoney); -// break; -// } + switch (Objects.requireNonNull(nodeType)) + { + case Farmer: + n = new Farmer(startMoney); + break; + case Processor: + n = new Processor(startMoney); + break; + case Distributor: + n = new Distributor(startMoney); + break; + case Seller: + n = new Seller(startMoney); + break; + case Customer: + n = new Customer(startMoney); + break; + } String[] subs = subsChannels.split(";"); //todo Node subscription to channels by parser data diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Customer.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Customer.java index 33bbb85..f483c42 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Customer.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Customer.java @@ -4,6 +4,10 @@ import java.util.Random; public class Customer extends BuyerNodeBase { + public Customer(int startMoney) { + super(); + } + public void consumeProduct() { int i = new Random().nextInt(getStorage().size()); getStorage().remove(i); diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Distributor.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Distributor.java index 2945cfc..c7d1c2b 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Distributor.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Distributor.java @@ -1,4 +1,8 @@ package cz.cvut.fel.sit.omo.foodchain.node; public class Distributor extends RetailerNodeBase { + + public Distributor(int startMoney) { + super(); + } } diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Farmer.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Farmer.java index 44064a4..77d60b4 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Farmer.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Farmer.java @@ -5,6 +5,10 @@ import cz.cvut.fel.sit.omo.foodchain.product.Product; public class Farmer extends SellerNodeBase { + public Farmer(int startMoney) { + super(); + } + public void generateProduct(Product product) { storeProduct(product); createRequirement(TransactionType.SALE, product.getProductType(), product.getName()); diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/NodeBase.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/NodeBase.java index cc8af0d..d957c84 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/NodeBase.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/NodeBase.java @@ -32,7 +32,7 @@ public class NodeBase implements ChannelObserver { money = Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(0).create(); } - public NodeBase(int m) { + public NodeBase(double m) { subscribedChannels = new HashMap<>(); products = new LinkedList<>(); refusedTranslations = new LinkedList<>(); diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Processor.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Processor.java index d689077..7307eb9 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Processor.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Processor.java @@ -1,4 +1,8 @@ package cz.cvut.fel.sit.omo.foodchain.node; public class Processor extends RetailerNodeBase { + + public Processor(int startMoney) { + super(); + } } diff --git a/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Seller.java b/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Seller.java index e58d280..8de5909 100644 --- a/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Seller.java +++ b/src/main/java/cz/cvut/fel/sit/omo/foodchain/node/Seller.java @@ -1,4 +1,8 @@ package cz.cvut.fel.sit.omo.foodchain.node; public class Seller extends RetailerNodeBase { + + public Seller(int startMoney) { + super(); + } } 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 6dafc88..6df7cee 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 @@ -28,12 +28,12 @@ public class Product } //TODO money int constructor - public Product(String name, ProductType productType, MonetaryAmount money) + public Product(String name, ProductType productType, double m) { this.name = name; this.productType = productType; this.productState = ProductState.AVAILABLE; - this.money = money; + this.money = Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(m).create(); } /** @@ -50,12 +50,12 @@ public class Product this.money = Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(0).create(); } - public Product(String name, ProductType productType, ProductState productState, MonetaryAmount money) + public Product(String name, ProductType productType, ProductState productState, double m) { this.name = name; this.productType = productType; this.productState = productState; - this.money = money; + this.money = Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(m).create();; } // "State machine methods"