Merge branch 'feature/operation_impl' into develop
This commit is contained in:
commit
2013cad84a
@ -1,7 +1,16 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain;
|
package cz.cvut.fel.sit.omo.foodchain;
|
||||||
|
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.factory.FactoryManager;
|
||||||
|
|
||||||
public class FoodChain {
|
public class FoodChain {
|
||||||
|
|
||||||
|
private static FactoryManager factoryManager;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static FactoryManager getFactoryManager() {
|
||||||
|
return factoryManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,21 +8,28 @@ public class Action extends OperationBase {
|
|||||||
private final OperationBase lastOperation;
|
private final OperationBase lastOperation;
|
||||||
private final Product product;
|
private final Product product;
|
||||||
private final ProductOperationType type;
|
private final ProductOperationType type;
|
||||||
|
private int duration;
|
||||||
|
|
||||||
Action(NodeBase node, Product product) {
|
Action(NodeBase node, Product product, ProductOperationType type) {
|
||||||
super(node);
|
super(node);
|
||||||
this.product = product;
|
this.product = product;
|
||||||
type = null;
|
this.type = type;
|
||||||
lastOperation = product.getCurrentOperation();
|
lastOperation = product.getCurrentOperation();
|
||||||
|
duration = type.getDuration();
|
||||||
product.setCurrentOperation(this);
|
product.setCurrentOperation(this);
|
||||||
product.setStateToReadyForDispatch();
|
product.setStateToReadyForDispatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endAction() {
|
private void endAction() {
|
||||||
this.setTimeEnd();
|
this.setTimeEnd();
|
||||||
product.setStateToAvailable();
|
product.setStateToAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void tick() {
|
||||||
|
if (duration == 0) endAction();
|
||||||
|
else duration--;
|
||||||
|
}
|
||||||
|
|
||||||
public OperationBase getLastOperation() {
|
public OperationBase getLastOperation() {
|
||||||
return lastOperation;
|
return lastOperation;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,22 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.operation;
|
package cz.cvut.fel.sit.omo.foodchain.operation;
|
||||||
|
|
||||||
public enum ProductOperationType {
|
public enum ProductOperationType {
|
||||||
|
|
||||||
|
STORE_MEAT(10, -8);
|
||||||
|
|
||||||
|
private final int duration;
|
||||||
|
private final int temperature;
|
||||||
|
|
||||||
|
ProductOperationType(int duration, int temperature) {
|
||||||
|
this.duration = duration;
|
||||||
|
this.temperature = temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDuration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTemperature() {
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,40 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.requirement;
|
package cz.cvut.fel.sit.omo.foodchain.requirement;
|
||||||
|
|
||||||
|
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 Requirement {
|
public class Requirement {
|
||||||
|
|
||||||
|
private final NodeBase creator;
|
||||||
|
private final TransactionType transactionType;
|
||||||
|
private final ProductType productType;
|
||||||
|
private int TTL;
|
||||||
|
|
||||||
|
public Requirement(NodeBase creator, TransactionType transactionType, ProductType productType) {
|
||||||
|
this.creator = creator;
|
||||||
|
this.transactionType = transactionType;
|
||||||
|
this.productType = productType;
|
||||||
|
TTL = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick() {
|
||||||
|
TTL--;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NodeBase getCreator() {
|
||||||
|
return creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TransactionType getTransactionType() {
|
||||||
|
return transactionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductType getProductType() {
|
||||||
|
return productType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTTL() {
|
||||||
|
return TTL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/main/java/cz/cvut/fel/sit/omo/foodchain/util/Ticker.java
Normal file
26
src/main/java/cz/cvut/fel/sit/omo/foodchain/util/Ticker.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package cz.cvut.fel.sit.omo.foodchain.util;
|
||||||
|
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.pool.PoolDatabase;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Ticker {
|
||||||
|
|
||||||
|
private static Timer timer;
|
||||||
|
|
||||||
|
public static void start() {
|
||||||
|
timer = new Timer(500, actionEvent -> {
|
||||||
|
PoolDatabase db = FoodChain.getFactoryManager().getPoolDatabaseInstance();
|
||||||
|
db.getChannelPoolInstance().findAll().forEach(ch -> ch.tick()); // change TTL of requirements
|
||||||
|
db.getNodePoolInstance().findAll().forEach(ch -> ch.tick()); // do next step in scenario
|
||||||
|
db.getProductPoolInstance().findAll().forEach(ch -> ch.tick()); // change duration of action
|
||||||
|
db.getScenarioPoolInstance().findAll().forEach(ch -> ch.tick()); // maybe unnecessary
|
||||||
|
});
|
||||||
|
timer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stop() {
|
||||||
|
timer.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user