Add mutable & immutable transaction interfaces and implementations, replacing copy()

This commit is contained in:
Allink
2023-05-20 20:20:39 +01:00
parent 95df78da6f
commit 036ddf3e04
9 changed files with 77 additions and 50 deletions

View File

@ -1,8 +1,7 @@
package me.totalfreedom.economy;
public interface CompletedTransaction
public interface CompletedTransaction extends Transaction
{
Transaction getTransaction();
TransactionResult getResult();
}

View File

@ -0,0 +1,13 @@
package me.totalfreedom.economy;
/**
* Please ensure that all modifications of {@link MutableTransaction} happen BEFORE it is passed to a {@link Transactor} implementation
*/
public interface MutableTransaction extends Transaction
{
long addToBalance(final long amount);
long removeFromBalance(final long amount);
void setBalance(final long newBalance);
}

View File

@ -2,17 +2,10 @@ package me.totalfreedom.economy;
public interface Transaction
{
Transaction copy();
EconomicEntity getSource();
EconomicEntity getDestination();
long getBalance();
long addToBalance(final long amount);
long removeFromBalance(final long amount);
void setBalance(final long newBalance);
}

View File

@ -2,5 +2,5 @@ package me.totalfreedom.economy;
public interface Transactor
{
CompletedTransaction handleTransaction(Transaction transaction);
CompletedTransaction handleTransaction(MutableTransaction transaction);
}