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.signature.Signature;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public interface INode {
|
||||
//TODO Nikita
|
||||
List<IChannel> subscribedChannels = new LinkedList<>();
|
||||
|
||||
void sendTransaction(Product product, INode INode);
|
||||
|
||||
void receiveTransaction(Transaction transaction);
|
||||
@ -34,7 +36,7 @@ public interface INode {
|
||||
|
||||
void storeProduct(Product product);
|
||||
|
||||
void storeProducts(List products);
|
||||
void storeProducts(List<Product> products);
|
||||
|
||||
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.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.product.Product;
|
||||
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.signature.Signature;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class NodeBase implements INode {
|
||||
@Override
|
||||
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
|
||||
public void receiveTransaction(Transaction transaction) {
|
||||
|
||||
//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -28,12 +36,12 @@ public class NodeBase implements INode {
|
||||
|
||||
@Override
|
||||
public Transaction readNextTransaction(IChannel channel) {
|
||||
return null;
|
||||
return channel.getNextTransaction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Requirement readNextRequirement(IChannel channel) {
|
||||
return null;
|
||||
return channel.getNextRequirement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,12 +51,12 @@ public class NodeBase implements INode {
|
||||
|
||||
@Override
|
||||
public void subscribeToChannel(IChannel channel) {
|
||||
|
||||
subscribedChannels.add(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribeFromChannel(IChannel channel) {
|
||||
|
||||
subscribedChannels.remove(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,7 +75,7 @@ public class NodeBase implements INode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeProducts(List products) {
|
||||
public void storeProducts(List<Product> products) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user