Changed constructors

This commit is contained in:
Tomáš Musil 2020-12-26 10:19:30 +01:00
parent 88543d0c68
commit 0bb5af4968
9 changed files with 43 additions and 24 deletions

Binary file not shown.

View File

@ -43,25 +43,24 @@ public class NodeFactory
System.err.println("! Fatal error in NodeFactory: " + e.getMessage()); System.err.println("! Fatal error in NodeFactory: " + e.getMessage());
} }
// switch (Objects.requireNonNull(nodeType)) switch (Objects.requireNonNull(nodeType))
// { {
// //TODO Money constructor case Farmer:
// case Farmer: n = new Farmer(startMoney);
// n = new Farmer(startMoney); break;
// break; case Processor:
// case Processor: n = new Processor(startMoney);
// n = new Processor(startMoney); break;
// break; case Distributor:
// case Distributor: n = new Distributor(startMoney);
// n = new Distributor(startMoney); break;
// break; case Seller:
// case Seller: n = new Seller(startMoney);
// n = new Seller(startMoney); break;
// break; case Customer:
// case Customer: n = new Customer(startMoney);
// n = new Customer(startMoney); break;
// break; }
// }
String[] subs = subsChannels.split(";"); String[] subs = subsChannels.split(";");
//todo Node subscription to channels by parser data //todo Node subscription to channels by parser data

View File

@ -4,6 +4,10 @@ import java.util.Random;
public class Customer extends BuyerNodeBase { public class Customer extends BuyerNodeBase {
public Customer(int startMoney) {
super();
}
public void consumeProduct() { public void consumeProduct() {
int i = new Random().nextInt(getStorage().size()); int i = new Random().nextInt(getStorage().size());
getStorage().remove(i); getStorage().remove(i);

View File

@ -1,4 +1,8 @@
package cz.cvut.fel.sit.omo.foodchain.node; package cz.cvut.fel.sit.omo.foodchain.node;
public class Distributor extends RetailerNodeBase { public class Distributor extends RetailerNodeBase {
public Distributor(int startMoney) {
super();
}
} }

View File

@ -5,6 +5,10 @@ import cz.cvut.fel.sit.omo.foodchain.product.Product;
public class Farmer extends SellerNodeBase { public class Farmer extends SellerNodeBase {
public Farmer(int startMoney) {
super();
}
public void generateProduct(Product product) { public void generateProduct(Product product) {
storeProduct(product); storeProduct(product);
createRequirement(TransactionType.SALE, product.getProductType(), product.getName()); createRequirement(TransactionType.SALE, product.getProductType(), product.getName());

View File

@ -32,7 +32,7 @@ public class NodeBase implements ChannelObserver {
money = Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(0).create(); money = Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(0).create();
} }
public NodeBase(int m) { public NodeBase(double m) {
subscribedChannels = new HashMap<>(); subscribedChannels = new HashMap<>();
products = new LinkedList<>(); products = new LinkedList<>();
refusedTranslations = new LinkedList<>(); refusedTranslations = new LinkedList<>();

View File

@ -1,4 +1,8 @@
package cz.cvut.fel.sit.omo.foodchain.node; package cz.cvut.fel.sit.omo.foodchain.node;
public class Processor extends RetailerNodeBase { public class Processor extends RetailerNodeBase {
public Processor(int startMoney) {
super();
}
} }

View File

@ -1,4 +1,8 @@
package cz.cvut.fel.sit.omo.foodchain.node; package cz.cvut.fel.sit.omo.foodchain.node;
public class Seller extends RetailerNodeBase { public class Seller extends RetailerNodeBase {
public Seller(int startMoney) {
super();
}
} }

View File

@ -28,12 +28,12 @@ public class Product
} }
//TODO money int constructor //TODO money int constructor
public Product(String name, ProductType productType, MonetaryAmount money) public Product(String name, ProductType productType, double m)
{ {
this.name = name; this.name = name;
this.productType = productType; this.productType = productType;
this.productState = ProductState.AVAILABLE; 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(); 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.name = name;
this.productType = productType; this.productType = productType;
this.productState = productState; this.productState = productState;
this.money = money; this.money = Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(m).create();;
} }
// "State machine methods" // "State machine methods"