Merge branch 'feature/factory_impl' into develop
# Conflicts: # src/main/java/cz/cvut/fel/sit/omo/foodchain/product/Product.java
This commit is contained in:
commit
624b18bd79
@ -1,5 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE channels [
|
||||||
|
<!ELEMENT channels (channel)*>
|
||||||
|
<!ELEMENT channel (#PCDATA)>
|
||||||
|
<!ATTLIST channel
|
||||||
|
type CDATA #REQUIRED>
|
||||||
|
]>
|
||||||
<channels>
|
<channels>
|
||||||
<channel type="MEET"></channel>
|
<channel type="MEAT"></channel>
|
||||||
<channel type="VEGETABLE"></channel>
|
<channel type="VEGETABLE"></channel>
|
||||||
<channel type="FRUIT"></channel>
|
<channel type="FRUIT"></channel>
|
||||||
</channels>
|
</channels>
|
||||||
@ -1,18 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE nodes [
|
||||||
|
<!ELEMENT nodes (node)*>
|
||||||
|
<!ELEMENT node (money|channels)*>
|
||||||
|
<!ATTLIST node
|
||||||
|
type CDATA #REQUIRED>
|
||||||
|
<!ELEMENT money (#PCDATA)>
|
||||||
|
<!ELEMENT channels (#PCDATA)>
|
||||||
|
]>
|
||||||
<nodes>
|
<nodes>
|
||||||
<node type = "Farmer">
|
<node type = "Farmer">
|
||||||
<money>100</money>
|
<money>100</money>
|
||||||
<channels>MEET PURCHASE;VEGETABLE PURCHASE;FRUIT PURCHASE</channels>
|
<channels>MEAT PURCHASE;VEGETABLE PURCHASE;FRUIT PURCHASE</channels>
|
||||||
</node>
|
</node>
|
||||||
<node type = "Processor">
|
<node type = "Processor">
|
||||||
<money>0</money>
|
<money>0</money>
|
||||||
<channels>MEET SALE_AND_PURCHASE;VEGETABLE SALE_AND_PURCHASE;FRUIT SALE_AND_PURCHASE</channels>
|
<channels>MEAT SALE_AND_PURCHASE;VEGETABLE SALE_AND_PURCHASE;FRUIT SALE_AND_PURCHASE</channels>
|
||||||
</node>
|
</node>
|
||||||
<node type = "Distributor">
|
<node type = "Distributor">
|
||||||
<money>1500</money>
|
<money>1500</money>
|
||||||
<channels>MEET SALE_AND_PURCHASE;VEGETABLE SALE_AND_PURCHASE;FRUIT SALE_AND_PURCHASE</channels>
|
<channels>MEAT SALE_AND_PURCHASE;VEGETABLE SALE_AND_PURCHASE;FRUIT SALE_AND_PURCHASE</channels>
|
||||||
</node>
|
</node>
|
||||||
<node type = "Customer">
|
<node type = "Customer">
|
||||||
<money>250</money>
|
<money>250</money>
|
||||||
<channels>MEET SALE;VEGETABLE SALE;FRUIT SALE</channels>
|
<channels>MEAT SALE;VEGETABLE SALE;FRUIT SALE</channels>
|
||||||
</node>
|
</node>
|
||||||
</nodes>
|
</nodes>
|
||||||
@ -1,3 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE products [
|
||||||
|
<!ELEMENT products (product)*>
|
||||||
|
<!ELEMENT product (name|type|price)*>
|
||||||
|
<!ELEMENT name (#PCDATA)>
|
||||||
|
<!ELEMENT type (#PCDATA)>
|
||||||
|
<!ELEMENT price (#PCDATA)>
|
||||||
|
]>
|
||||||
<products>
|
<products>
|
||||||
<product>
|
<product>
|
||||||
<name>jablko</name>
|
<name>jablko</name>
|
||||||
@ -31,17 +39,17 @@
|
|||||||
</product>
|
</product>
|
||||||
<product>
|
<product>
|
||||||
<name>vepřové</name>
|
<name>vepřové</name>
|
||||||
<type>MEET</type>
|
<type>MEAT</type>
|
||||||
<price>20</price>
|
<price>20</price>
|
||||||
</product>
|
</product>
|
||||||
<product>
|
<product>
|
||||||
<name>hovězí</name>
|
<name>hovězí</name>
|
||||||
<type>MEET</type>
|
<type>MEAT</type>
|
||||||
<price>50</price>
|
<price>50</price>
|
||||||
</product>
|
</product>
|
||||||
<product>
|
<product>
|
||||||
<name>kuřecí</name>
|
<name>kuřecí</name>
|
||||||
<type>MEET</type>
|
<type>MEAT</type>
|
||||||
<price>30</price>
|
<price>30</price>
|
||||||
</product>
|
</product>
|
||||||
</products>
|
</products>
|
||||||
@ -1,15 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE scenarios [
|
||||||
|
<!ELEMENT scenarios (scenario)*>
|
||||||
|
<!ELEMENT scenario (steps)*>
|
||||||
|
<!ATTLIST scenario
|
||||||
|
type CDATA #REQUIRED>
|
||||||
|
<!ELEMENT steps (#PCDATA)>
|
||||||
|
]>
|
||||||
<scenarios>
|
<scenarios>
|
||||||
<scenario type="Farmer">
|
<scenario type="Farmer">
|
||||||
<steps>
|
<steps>
|
||||||
generate jablko
|
generate
|
||||||
generate hovězí
|
generate
|
||||||
generate hruška
|
generate
|
||||||
generate rajče
|
generate
|
||||||
generate paprika
|
generate
|
||||||
generate kuřecí
|
generate
|
||||||
generate vepřové
|
generate
|
||||||
generate banán
|
generate
|
||||||
generate okurka
|
generate
|
||||||
</steps>
|
</steps>
|
||||||
</scenario>
|
</scenario>
|
||||||
</scenarios>
|
</scenarios>
|
||||||
@ -1,11 +1,14 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain;
|
package cz.cvut.fel.sit.omo.foodchain;
|
||||||
|
|
||||||
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.factory.ChannelFactory;
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.factory.FactoryManager;
|
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.parser.ConfigurationParser;
|
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.ParserResult;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.parser.ParserResultElement;
|
import cz.cvut.fel.sit.omo.foodchain.parser.ParserResultElement;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.scenario.Scenario;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.util.Ticker;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
@ -18,18 +21,39 @@ public class FoodChain
|
|||||||
private static FactoryManager factoryManager = new FactoryManager();
|
private static FactoryManager factoryManager = new FactoryManager();
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
parseChannels();
|
||||||
|
parseNodes();
|
||||||
|
parseProducts();
|
||||||
|
parseScenarios();
|
||||||
|
|
||||||
|
Ticker.start();
|
||||||
|
|
||||||
|
getFactoryManager().getPoolDatabaseInstance().getChannelPoolInstance().findAll().stream().forEach(ch -> System.out.println(ch.getProductType()));
|
||||||
|
getFactoryManager().getPoolDatabaseInstance().getNodePoolInstance().findAll().stream().forEach(ch -> System.out.println(ch));
|
||||||
|
getFactoryManager().getPoolDatabaseInstance().getProductPoolInstance().findAll().stream().forEach(ch -> System.out.println(ch.getProductType() + " " + ch.getName()));
|
||||||
|
getFactoryManager().getPoolDatabaseInstance().getScenarioPoolInstance().findAll().stream().forEach(ch -> ch.getSteps().stream().forEach(s -> System.out.println(s)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FactoryManager getFactoryManager()
|
||||||
|
{
|
||||||
|
return factoryManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo maybe some refactoring needed?
|
||||||
|
// add other entities
|
||||||
|
public static void parseChannels()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// parse channel configuration
|
// parse channel configuration
|
||||||
ConfigurationParser.parseDocument("channels");
|
ConfigurationParser.parseDocument("conf/channels.xml");
|
||||||
ParserResult parserResult = ConfigurationParser.getElements("channels");
|
ParserResult parserResult = ConfigurationParser.getElements("channel");
|
||||||
//todo need getter for elemtens...
|
|
||||||
List<ParserResultElement> elements = parserResult.getElements();
|
List<ParserResultElement> elements = parserResult.getElements();
|
||||||
for (ParserResultElement el : elements)
|
for (ParserResultElement el : elements)
|
||||||
{
|
{
|
||||||
ChannelBase c = getFactoryManager().getChannelFactoryInstance().makeChannel(el);
|
ChannelBase res = getFactoryManager().getChannelFactoryInstance().makeChannel(el);
|
||||||
getFactoryManager().getPoolDatabaseInstance().getChannelPoolInstance().add(c);
|
getFactoryManager().getPoolDatabaseInstance().getChannelPoolInstance().add(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -37,16 +61,68 @@ public class FoodChain
|
|||||||
{
|
{
|
||||||
System.err.println(e.getMessage());
|
System.err.println(e.getMessage());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
}
|
||||||
|
|
||||||
|
public static void parseNodes()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// parse channel configuration
|
||||||
|
ConfigurationParser.parseDocument("conf/nodes.xml");
|
||||||
|
ParserResult parserResult = ConfigurationParser.getElements("node");
|
||||||
|
List<ParserResultElement> elements = parserResult.getElements();
|
||||||
|
for (ParserResultElement el : elements)
|
||||||
|
{
|
||||||
|
NodeBase res = getFactoryManager().getNodeFactoryInstance().makeNode(el);
|
||||||
|
getFactoryManager().getPoolDatabaseInstance().getNodePoolInstance().add(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (ParserConfigurationException | SAXException | IOException e)
|
||||||
{
|
{
|
||||||
System.err.println(e.getMessage());
|
System.err.println(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FactoryManager getFactoryManager()
|
public static void parseProducts()
|
||||||
{
|
{
|
||||||
return factoryManager;
|
try
|
||||||
|
{
|
||||||
|
// parse channel configuration
|
||||||
|
ConfigurationParser.parseDocument("conf/products.xml");
|
||||||
|
ParserResult parserResult = ConfigurationParser.getElements("product");
|
||||||
|
List<ParserResultElement> elements = parserResult.getElements();
|
||||||
|
for (ParserResultElement el : elements)
|
||||||
|
{
|
||||||
|
Product res = getFactoryManager().getProductFactoryInstance().makeProduct(el);
|
||||||
|
getFactoryManager().getPoolDatabaseInstance().getProductPoolInstance().add(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (ParserConfigurationException | SAXException | IOException e)
|
||||||
|
{
|
||||||
|
System.err.println(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void parseScenarios()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// parse channel configuration
|
||||||
|
ConfigurationParser.parseDocument("conf/scenarios.xml");
|
||||||
|
ParserResult parserResult = ConfigurationParser.getElements("scenario");
|
||||||
|
List<ParserResultElement> elements = parserResult.getElements();
|
||||||
|
for (ParserResultElement el : elements)
|
||||||
|
{
|
||||||
|
Scenario res = getFactoryManager().getScenarioFactoryInstance().makeScenario(el);
|
||||||
|
getFactoryManager().getPoolDatabaseInstance().getScenarioPoolInstance().add(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (ParserConfigurationException | SAXException | IOException e)
|
||||||
|
{
|
||||||
|
System.err.println(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,18 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.factory;
|
package cz.cvut.fel.sit.omo.foodchain.factory;
|
||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
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.*;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.parser.ParserResultElement;
|
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.pool.ChannelPool;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class NodeFactory
|
public class NodeFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
private enum NodeType
|
enum NodeType
|
||||||
{
|
{
|
||||||
Farmer, Processor, Distributor, Seller, Customer;
|
Farmer, Processor, Distributor, Seller, Customer;
|
||||||
}
|
}
|
||||||
@ -25,14 +27,14 @@ public class NodeFactory
|
|||||||
NodeBase n = null;
|
NodeBase n = null;
|
||||||
NodeType nodeType = null;
|
NodeType nodeType = null;
|
||||||
String subsChannels = "";
|
String subsChannels = "";
|
||||||
int startMoney = 0;
|
double startMoney = 0;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
nodeType = NodeType.valueOf(input.getAttribute("type"));
|
nodeType = NodeType.valueOf(input.getAttribute("type"));
|
||||||
|
|
||||||
subsChannels = input.getChild("subscribed_channels");
|
subsChannels = input.getChild("channels");
|
||||||
startMoney = Integer.getInteger(input.getChild("money"));
|
startMoney = Double.parseDouble(input.getChild("money"));
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e)
|
catch (IllegalArgumentException e)
|
||||||
{
|
{
|
||||||
@ -63,12 +65,13 @@ public class NodeFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
String[] subs = subsChannels.split(";");
|
String[] subs = subsChannels.split(";");
|
||||||
//todo Node subscription to channels by parser data
|
|
||||||
|
|
||||||
for (String s : subs)
|
for (String s : subs)
|
||||||
{
|
{
|
||||||
|
String[] el = s.split(" ");
|
||||||
|
|
||||||
ChannelPool temp = FoodChain.getFactoryManager().getPoolDatabaseInstance().getChannelPoolInstance();
|
ChannelPool temp = FoodChain.getFactoryManager().getPoolDatabaseInstance().getChannelPoolInstance();
|
||||||
// n.subscribeToChannel(temp.findByType(s)); //TODO String to enum
|
n.subscribeToChannel(temp.findByType(ProductType.valueOf(el[0])), ChannelSubscriptionType.valueOf(el[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
|
|||||||
@ -18,10 +18,10 @@ public class ProductFactory
|
|||||||
Product p = null;
|
Product p = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String name = input.getAttribute("name");
|
String name = input.getChild("name");
|
||||||
ProductType productType = ProductType.valueOf(input.getChild("type"));
|
ProductType productType = ProductType.valueOf(input.getChild("type"));
|
||||||
//ProductState productState = ProductState.valueOf(input.getChild("state"));
|
//ProductState productState = ProductState.valueOf(input.getChild("state"));
|
||||||
int price = Integer.getInteger(input.getChild("price"));
|
double price = Double.parseDouble(input.getChild("price"));
|
||||||
|
|
||||||
//p = new Product(name, price, productType, productState);
|
//p = new Product(name, price, productType, productState);
|
||||||
p = new Product(name, productType, price);
|
p = new Product(name, productType, price);
|
||||||
|
|||||||
@ -2,16 +2,24 @@ package cz.cvut.fel.sit.omo.foodchain.factory;
|
|||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.node.*;
|
import cz.cvut.fel.sit.omo.foodchain.node.*;
|
||||||
|
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;
|
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.pool.ChannelPool;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.scenario.Scenario;
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.scenario.*;
|
||||||
|
|
||||||
import javax.money.Monetary;
|
import javax.money.Monetary;
|
||||||
import javax.money.MonetaryAmount;
|
import javax.money.MonetaryAmount;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ScenarioFactory
|
public class ScenarioFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates Scenario based on input ParserResultElement
|
* Creates Scenario based on input ParserResultElement
|
||||||
* @param input data from Scenario is created
|
* @param input data from Scenario is created
|
||||||
@ -20,7 +28,52 @@ public class ScenarioFactory
|
|||||||
public Scenario makeScenario(ParserResultElement input)
|
public Scenario makeScenario(ParserResultElement input)
|
||||||
{
|
{
|
||||||
Scenario s = null;
|
Scenario s = null;
|
||||||
|
NodeBase node = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String nodeType = input.getAttribute("type");
|
||||||
|
node = FoodChain.getFactoryManager().getPoolDatabaseInstance().getNodePoolInstance().findAll().stream()
|
||||||
|
.filter(ch -> ch.getClass().getSimpleName().equals(nodeType)).findFirst().orElse(null);
|
||||||
|
|
||||||
|
String[] steps = Arrays.stream(input.getChild("steps").split("\n")).filter(st -> !st.strip().equals("")).toArray(String[]::new);
|
||||||
|
List<ScenarioStep> scenarioSteps = new LinkedList<>();
|
||||||
|
ScenarioStep scenarioStep = null;
|
||||||
|
for (String step : steps) {
|
||||||
|
String[] parts = step.strip().split(" ");
|
||||||
|
switch (parts[0]) {
|
||||||
|
case "generate":
|
||||||
|
scenarioStep = new GenerateProductStep((Farmer) node);
|
||||||
|
break;
|
||||||
|
case "consume":
|
||||||
|
scenarioStep = new ConsumeProductStep((Customer) node);
|
||||||
|
break;
|
||||||
|
case "doaction":
|
||||||
|
if (parts.length == 2) {
|
||||||
|
scenarioStep = new DoActionStep(node, ProductOperationType.valueOf(parts[1]));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Product p = FoodChain.getFactoryManager().getPoolDatabaseInstance().getProductPoolInstance().findAll().stream()
|
||||||
|
.filter(pr -> pr.getName().equals(parts[2])).findFirst().orElse(null);
|
||||||
|
scenarioStep = new DoActionStep(node, ProductOperationType.valueOf(parts[1]), p);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "sendreq":
|
||||||
|
scenarioStep = new SendRequirementStep(node, TransactionType.valueOf(parts[1]), ProductType.valueOf(parts[2]), parts[3]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
scenarioSteps.add(scenarioStep);
|
||||||
|
}
|
||||||
|
s = new Scenario(scenarioSteps);
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException e)
|
||||||
|
{
|
||||||
|
System.err.println("! Wrong type of enum in ProductFactory: " + e);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.err.println("! Fatal error in ProductFactory: " + e);
|
||||||
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class Customer extends BuyerNodeBase {
|
public class Customer extends BuyerNodeBase {
|
||||||
|
|
||||||
public Customer(int startMoney) {
|
public Customer(double startMoney) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package cz.cvut.fel.sit.omo.foodchain.node;
|
|||||||
|
|
||||||
public class Distributor extends RetailerNodeBase {
|
public class Distributor extends RetailerNodeBase {
|
||||||
|
|
||||||
public Distributor(int startMoney) {
|
public Distributor(double startMoney) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
|||||||
|
|
||||||
public class Farmer extends SellerNodeBase {
|
public class Farmer extends SellerNodeBase {
|
||||||
|
|
||||||
public Farmer(int startMoney) {
|
public Farmer(double startMoney) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package cz.cvut.fel.sit.omo.foodchain.node;
|
|||||||
|
|
||||||
public class Processor extends RetailerNodeBase {
|
public class Processor extends RetailerNodeBase {
|
||||||
|
|
||||||
public Processor(int startMoney) {
|
public Processor(double startMoney) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package cz.cvut.fel.sit.omo.foodchain.node;
|
|||||||
|
|
||||||
public class Seller extends RetailerNodeBase {
|
public class Seller extends RetailerNodeBase {
|
||||||
|
|
||||||
public Seller(int startMoney) {
|
public Seller(double startMoney) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,10 +31,19 @@ public class ConfigurationParser {
|
|||||||
Node tmpNode = elements.item(i);
|
Node tmpNode = elements.item(i);
|
||||||
ParserResultElement element = new ParserResultElement();
|
ParserResultElement element = new ParserResultElement();
|
||||||
for (int j = 0; j < tmpNode.getAttributes().getLength(); j++) {
|
for (int j = 0; j < tmpNode.getAttributes().getLength(); j++) {
|
||||||
element.addAttribute(tmpNode.getAttributes().item(i).getNodeName(), tmpNode.getAttributes().item(i).getTextContent());
|
element
|
||||||
|
.addAttribute(
|
||||||
|
tmpNode
|
||||||
|
.getAttributes()
|
||||||
|
.item(j)
|
||||||
|
.getNodeName(),
|
||||||
|
tmpNode
|
||||||
|
.getAttributes()
|
||||||
|
.item(j)
|
||||||
|
.getTextContent());
|
||||||
}
|
}
|
||||||
for (int j = 0; j < tmpNode.getChildNodes().getLength(); j++) {
|
for (int j = 0; j < tmpNode.getChildNodes().getLength(); j++) {
|
||||||
element.addChild(tmpNode.getChildNodes().item(i).getNodeName(), tmpNode.getChildNodes().item(i).getTextContent());
|
element.addChild(tmpNode.getChildNodes().item(j).getNodeName(), tmpNode.getChildNodes().item(j).getTextContent());
|
||||||
}
|
}
|
||||||
resultList.addElement(element);
|
resultList.addElement(element);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ public class ParserResultElement {
|
|||||||
private Map<String, String> children;
|
private Map<String, String> children;
|
||||||
|
|
||||||
public ParserResultElement() {
|
public ParserResultElement() {
|
||||||
|
children = new HashMap<>();
|
||||||
attributes = new HashMap<>();
|
attributes = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,5 +3,4 @@ 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.NodeBase;
|
||||||
|
|
||||||
public class NodePool extends PoolListBase<NodeBase> {
|
public class NodePool extends PoolListBase<NodeBase> {
|
||||||
//TODO Tomas Angelo
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,12 +9,18 @@ public class GenerateProductStep extends ScenarioStep {
|
|||||||
|
|
||||||
private final Farmer node;
|
private final Farmer node;
|
||||||
private final Product product;
|
private final Product product;
|
||||||
|
private static int counter = 0;
|
||||||
|
|
||||||
public GenerateProductStep(Farmer node) {
|
public GenerateProductStep(Farmer node) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
product = FoodChain.getFactoryManager().getPoolDatabaseInstance().getProductPoolInstance().findAll()
|
if (counter < FoodChain.getFactoryManager().getPoolDatabaseInstance().getProductPoolInstance().findAll().size()) {
|
||||||
.stream().findFirst().orElse(null);
|
product = FoodChain.getFactoryManager().getPoolDatabaseInstance().getProductPoolInstance().findAll().get(counter);
|
||||||
FoodChain.getFactoryManager().getPoolDatabaseInstance().getProductPoolInstance().remove(product);
|
counter++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
product = null;
|
||||||
|
System.err.println("Insufficient products in pool");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -23,4 +23,8 @@ public class Scenario {
|
|||||||
}
|
}
|
||||||
stepIterator.next().execute();
|
stepIterator.next().execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ScenarioStep> getSteps() {
|
||||||
|
return steps;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,10 +12,10 @@ public class Ticker {
|
|||||||
public static void start() {
|
public static void start() {
|
||||||
timer = new Timer(500, actionEvent -> {
|
timer = new Timer(500, actionEvent -> {
|
||||||
PoolDatabase db = FoodChain.getFactoryManager().getPoolDatabaseInstance();
|
PoolDatabase db = FoodChain.getFactoryManager().getPoolDatabaseInstance();
|
||||||
db.getChannelPoolInstance().findAll().forEach(ch -> ch.tick()); // change TTL of requirements
|
// db.getChannelPoolInstance().findAll().forEach(ch -> ch.tick()); // change TTL of requirements
|
||||||
db.getNodePoolInstance().findAll().forEach(ch -> ch.tick()); // do next step in scenario
|
// db.getNodePoolInstance().findAll().forEach(ch -> ch.tick()); // do next step in scenario
|
||||||
db.getProductPoolInstance().findAll().forEach(ch -> ch.tick()); // change duration of action
|
// db.getProductPoolInstance().findAll().forEach(ch -> ch.tick()); // change duration of action
|
||||||
db.getScenarioPoolInstance().findAll().forEach(ch -> ch.tick()); // maybe unnecessary
|
// db.getScenarioPoolInstance().findAll().forEach(ch -> ch.tick()); // maybe unnecessary
|
||||||
});
|
});
|
||||||
timer.start();
|
timer.start();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user