Start working on scenario, steps, iterator
This commit is contained in:
parent
d9d15d2428
commit
5e96891696
@ -4,7 +4,7 @@ import cz.cvut.fel.sit.omo.foodchain.factory.FactoryManager;
|
|||||||
|
|
||||||
public class FoodChain {
|
public class FoodChain {
|
||||||
|
|
||||||
private static FactoryManager factoryManager;
|
private static FactoryManager factoryManager = new FactoryManager();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
|||||||
@ -68,6 +68,12 @@ public class NodeBase implements ChannelObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void createRequirement(TransactionType tType, ProductType pType, String pName) {
|
||||||
|
Requirement req = new Requirement(this, tType, pType, pName);
|
||||||
|
subscribedChannels.stream()
|
||||||
|
.filter(ch -> ch.getProductType().equals(pType))
|
||||||
|
.findAny().ifPresent(channel -> channel.addRequirement(req));
|
||||||
|
}
|
||||||
|
|
||||||
public void acceptRequirement(Requirement requirement) {
|
public void acceptRequirement(Requirement requirement) {
|
||||||
|
|
||||||
|
|||||||
@ -28,13 +28,13 @@ public class ConfigurationParser {
|
|||||||
NodeList elements = activeDocument.getElementsByTagName(tag);
|
NodeList elements = activeDocument.getElementsByTagName(tag);
|
||||||
ParserResult resultList = new ParserResult();
|
ParserResult resultList = new ParserResult();
|
||||||
for (int i = 0; i < elements.getLength(); i++) {
|
for (int i = 0; i < elements.getLength(); i++) {
|
||||||
Node tmp_node = elements.item(i);
|
Node tmpNode = elements.item(i);
|
||||||
ParserResultElement element = new ParserResultElement();
|
ParserResultElement element = new ParserResultElement();
|
||||||
for (int j = 0; j < tmp_node.getAttributes().getLength(); j++) {
|
for (int j = 0; j < tmpNode.getAttributes().getLength(); j++) {
|
||||||
element.addAttribute(tmp_node.getAttributes().item(i).getNodeName(), tmp_node.getAttributes().item(i).getTextContent());
|
element.addAttribute(tmpNode.getAttributes().item(i).getNodeName(), tmpNode.getAttributes().item(i).getTextContent());
|
||||||
}
|
}
|
||||||
for (int j = 0; j < tmp_node.getChildNodes().getLength(); j++) {
|
for (int j = 0; j < tmpNode.getChildNodes().getLength(); j++) {
|
||||||
element.addChild(tmp_node.getChildNodes().item(i).getNodeName(), tmp_node.getChildNodes().item(i).getTextContent());
|
element.addChild(tmpNode.getChildNodes().item(i).getNodeName(), tmpNode.getChildNodes().item(i).getTextContent());
|
||||||
}
|
}
|
||||||
resultList.addElement(element);
|
resultList.addElement(element);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.parser;
|
package cz.cvut.fel.sit.omo.foodchain.parser;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ParserResult {
|
public class ParserResult {
|
||||||
|
|
||||||
private LinkedList<ParserResultElement> elements;
|
private final List<ParserResultElement> elements;
|
||||||
|
|
||||||
public ParserResult() {
|
public ParserResult() {
|
||||||
elements = new LinkedList<>();
|
elements = new LinkedList<>();
|
||||||
@ -15,4 +14,9 @@ public class ParserResult {
|
|||||||
public void addElement(ParserResultElement element) {
|
public void addElement(ParserResultElement element) {
|
||||||
elements.add(element);
|
elements.add(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ParserResultElement> getElements() {
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,12 +9,14 @@ public class Requirement {
|
|||||||
private final NodeBase creator;
|
private final NodeBase creator;
|
||||||
private final TransactionType transactionType;
|
private final TransactionType transactionType;
|
||||||
private final ProductType productType;
|
private final ProductType productType;
|
||||||
|
private final String productName;
|
||||||
private int TTL;
|
private int TTL;
|
||||||
|
|
||||||
public Requirement(NodeBase creator, TransactionType transactionType, ProductType productType) {
|
public Requirement(NodeBase creator, TransactionType transactionType, ProductType productType, String productName) {
|
||||||
this.creator = creator;
|
this.creator = creator;
|
||||||
this.transactionType = transactionType;
|
this.transactionType = transactionType;
|
||||||
this.productType = productType;
|
this.productType = productType;
|
||||||
|
this.productName = productName;
|
||||||
TTL = 2;
|
TTL = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +36,10 @@ public class Requirement {
|
|||||||
return productType;
|
return productType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getProductName() {
|
||||||
|
return productName;
|
||||||
|
}
|
||||||
|
|
||||||
public int getTTL() {
|
public int getTTL() {
|
||||||
return TTL;
|
return TTL;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,32 @@
|
|||||||
|
package cz.cvut.fel.sit.omo.foodchain.scenario;
|
||||||
|
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.operation.ProductOperationType;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
|
||||||
|
public class DoActionStep extends ScenarioStep {
|
||||||
|
private final NodeBase nodeBase;
|
||||||
|
private final ProductOperationType productOperationType;
|
||||||
|
private final Product product;
|
||||||
|
|
||||||
|
public DoActionStep(NodeBase node, ProductOperationType productOperationType, Product product){
|
||||||
|
this.nodeBase = node;
|
||||||
|
this.productOperationType = productOperationType;
|
||||||
|
this.product = product;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DoActionStep(NodeBase node, ProductOperationType productOperationType){
|
||||||
|
this(node, productOperationType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void execute() {
|
||||||
|
if (product != null){
|
||||||
|
nodeBase.doAction(productOperationType, product);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nodeBase.doAction(productOperationType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
package cz.cvut.fel.sit.omo.foodchain.scenario;
|
||||||
|
|
||||||
|
public class GenerateProductStep {
|
||||||
|
}
|
||||||
@ -1,4 +1,26 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.scenario;
|
package cz.cvut.fel.sit.omo.foodchain.scenario;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Scenario {
|
public class Scenario {
|
||||||
|
List<ScenarioStep> steps;
|
||||||
|
Iterator<ScenarioStep> stepIterator;
|
||||||
|
|
||||||
|
public Scenario() {
|
||||||
|
//steps = //TODO init
|
||||||
|
stepIterator = steps.listIterator(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Scenario(List<ScenarioStep> steps) {
|
||||||
|
this.steps = steps;
|
||||||
|
stepIterator = steps.listIterator(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void execute() {
|
||||||
|
if (!stepIterator.hasNext()) {
|
||||||
|
stepIterator = steps.listIterator(0);
|
||||||
|
}
|
||||||
|
stepIterator.next().execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
package cz.cvut.fel.sit.omo.foodchain.scenario;
|
||||||
|
|
||||||
|
public abstract class ScenarioStep {
|
||||||
|
abstract void execute();
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package cz.cvut.fel.sit.omo.foodchain.scenario;
|
||||||
|
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.operation.TransactionType;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||||
|
|
||||||
|
public class SendRequirementStep extends ScenarioStep {
|
||||||
|
private final NodeBase node;
|
||||||
|
private final TransactionType tType;
|
||||||
|
private final ProductType pType;
|
||||||
|
private final String pName;
|
||||||
|
|
||||||
|
public SendRequirementStep(NodeBase node, TransactionType tType, ProductType pType, String pName) {
|
||||||
|
this.node = node;
|
||||||
|
this.tType = tType;
|
||||||
|
this.pType = pType;
|
||||||
|
this.pName = pName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void execute() {
|
||||||
|
node.createRequirement(tType, pType, pName);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user