Some more fixes of NodeBase
This commit is contained in:
parent
6a7fc972fd
commit
e73762eec4
@ -19,9 +19,12 @@ public class NodeBase implements ChannelObserver {
|
||||
private final List<Product> products;
|
||||
private MonetaryAmount money;
|
||||
|
||||
private final List<Transaction> refusedTranslations;
|
||||
|
||||
public NodeBase() {
|
||||
subscribedChannels = new LinkedList<>();
|
||||
products = new LinkedList<>();
|
||||
refusedTranslations = new LinkedList<>();
|
||||
}
|
||||
|
||||
|
||||
@ -34,11 +37,11 @@ public class NodeBase implements ChannelObserver {
|
||||
}
|
||||
|
||||
|
||||
public void sendTransaction(MonetaryAmount amount, NodeBase node) {
|
||||
Transaction transaction = new FinancialTransaction(this, node, TransactionType.PURCHASE, amount, );
|
||||
public void sendTransaction(MonetaryAmount amount, NodeBase node, ProductTransaction prevTransaction) {
|
||||
Transaction transaction = new FinancialTransaction(this, node, TransactionType.PURCHASE, amount, prevTransaction);
|
||||
|
||||
subscribedChannels.stream()
|
||||
.filter(ch -> ch.getProductType().equals(product.getProductType()))
|
||||
.filter(ch -> ch.getProductType().equals(prevTransaction.getProduct().getProductType()))
|
||||
.findAny().ifPresent(channel -> channel.addTransaction(transaction));
|
||||
}
|
||||
|
||||
@ -53,26 +56,18 @@ public class NodeBase implements ChannelObserver {
|
||||
}
|
||||
|
||||
|
||||
public void refuseTransaction(ProductTransaction transaction) {
|
||||
|
||||
public void refuseTransaction(Transaction transaction) {
|
||||
transaction.endTransaction();
|
||||
refusedTranslations.add(transaction); //TODO maybe need more work on it
|
||||
}
|
||||
|
||||
|
||||
public void refuseTransaction(FinancialTransaction transaction) {
|
||||
|
||||
}
|
||||
|
||||
//TODO another way to read transaction
|
||||
|
||||
public Transaction readNextTransaction(ChannelBase channel) {
|
||||
|
||||
|
||||
return channel.getNextTransaction();
|
||||
}
|
||||
|
||||
|
||||
public Requirement readNextRequirement(ChannelBase channel) {
|
||||
return channel.getNextRequirement();
|
||||
}
|
||||
|
||||
|
||||
public void acceptRequirement(Requirement requirement) {
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ public class FinancialTransaction extends Transaction {
|
||||
private final MonetaryAmount amount;
|
||||
private final ProductTransaction transactionPaid;
|
||||
|
||||
FinancialTransaction(NodeBase creator, NodeBase receiver, TransactionType type, MonetaryAmount amount, ProductTransaction transactionPaid) {
|
||||
public FinancialTransaction(NodeBase creator, NodeBase receiver, TransactionType type, MonetaryAmount amount, ProductTransaction transactionPaid) {
|
||||
super(creator, receiver, type);
|
||||
this.amount = amount;
|
||||
this.transactionPaid = transactionPaid;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user