Fixed interface and added some methods
This commit is contained in:
parent
c9c34d4f46
commit
62fa46e6c2
@ -8,10 +8,12 @@ import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
|||||||
import cz.cvut.fel.sit.omo.foodchain.requirement.Requirement;
|
import cz.cvut.fel.sit.omo.foodchain.requirement.Requirement;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.signature.Signature;
|
import cz.cvut.fel.sit.omo.foodchain.signature.Signature;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface INode {
|
public interface INode {
|
||||||
//TODO Nikita
|
List<IChannel> subscribedChannels = new LinkedList<>();
|
||||||
|
|
||||||
void sendTransaction(Product product, INode INode);
|
void sendTransaction(Product product, INode INode);
|
||||||
|
|
||||||
void receiveTransaction(Transaction transaction);
|
void receiveTransaction(Transaction transaction);
|
||||||
@ -34,7 +36,7 @@ public interface INode {
|
|||||||
|
|
||||||
void storeProduct(Product product);
|
void storeProduct(Product product);
|
||||||
|
|
||||||
void storeProducts(List products);
|
void storeProducts(List<Product> products);
|
||||||
|
|
||||||
Product getProductFromStorage(String name, ProductType type);
|
Product getProductFromStorage(String name, ProductType type);
|
||||||
|
|
||||||
|
|||||||
@ -2,23 +2,31 @@ package cz.cvut.fel.sit.omo.foodchain.node;
|
|||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.channel.IChannel;
|
import cz.cvut.fel.sit.omo.foodchain.channel.IChannel;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.Action;
|
import cz.cvut.fel.sit.omo.foodchain.operation.Action;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.operation.ProductTransaction;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
|
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
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.product.ProductType;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.requirement.Requirement;
|
import cz.cvut.fel.sit.omo.foodchain.requirement.Requirement;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.signature.Signature;
|
import cz.cvut.fel.sit.omo.foodchain.signature.Signature;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class NodeBase implements INode {
|
public class NodeBase implements INode {
|
||||||
@Override
|
@Override
|
||||||
public void sendTransaction(Product product, INode node) {
|
public void sendTransaction(Product product, INode node) {
|
||||||
|
Transaction transaction = new ProductTransaction();
|
||||||
|
transaction.setProduct(product);
|
||||||
|
transaction.setGoal(node);
|
||||||
|
|
||||||
|
subscribedChannels.stream()
|
||||||
|
.filter(ch -> ch.getProductType().equals(product.getType()))
|
||||||
|
.findAny().ifPresent(channel -> channel.addTransaction(transaction));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveTransaction(Transaction transaction) {
|
public void receiveTransaction(Transaction transaction) {
|
||||||
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -28,12 +36,12 @@ public class NodeBase implements INode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Transaction readNextTransaction(IChannel channel) {
|
public Transaction readNextTransaction(IChannel channel) {
|
||||||
return null;
|
return channel.getNextTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Requirement readNextRequirement(IChannel channel) {
|
public Requirement readNextRequirement(IChannel channel) {
|
||||||
return null;
|
return channel.getNextRequirement();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,12 +51,12 @@ public class NodeBase implements INode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void subscribeToChannel(IChannel channel) {
|
public void subscribeToChannel(IChannel channel) {
|
||||||
|
subscribedChannels.add(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unsubscribeFromChannel(IChannel channel) {
|
public void unsubscribeFromChannel(IChannel channel) {
|
||||||
|
subscribedChannels.remove(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -67,7 +75,7 @@ public class NodeBase implements INode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeProducts(List products) {
|
public void storeProducts(List<Product> products) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user