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());
}
// 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

View File

@ -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);

View File

@ -1,4 +1,8 @@
package cz.cvut.fel.sit.omo.foodchain.node;
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 Farmer(int startMoney) {
super();
}
public void generateProduct(Product product) {
storeProduct(product);
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();
}
public NodeBase(int m) {
public NodeBase(double m) {
subscribedChannels = new HashMap<>();
products = new LinkedList<>();
refusedTranslations = new LinkedList<>();

View File

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

View File

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

View File

@ -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"