Transaction.java
package edu.ntnu.idi.idatt.model.transaction;
import edu.ntnu.idi.idatt.model.player.Player;
import edu.ntnu.idi.idatt.model.portfolio.Share;
import edu.ntnu.idi.idatt.service.transaction.TransactionCalculator;
/**
* Transaction class
*
* <p>
* An abstract class that handles a transaction
* based on week and share. Utilizes the calculators
* to perform calculations.
* </p>
*
* @see TransactionCalculator
*/
public abstract class Transaction {
private final Share share;
private int week;
private TransactionCalculator calculator;
protected boolean commited;
/**
* Constructor for a Transaction
*
* @param share - The share the transaction is about.
* @param week - The current week
* @param calculator - Transaction (Purchasae/Sale)
*/
Transaction(Share share, int week, TransactionCalculator calculator) {
this.share = share;
this.week = week;
this.calculator = calculator;
}
/**
* Getter for share.
*
* @return Share;
*/
public Share getShare() {
return share;
}
/**
* Getter for week.
*
* @return int;
*/
public int getWeek() {
return week;
}
/**
* Getter for calculator.
*
* @return TransactionCalculator;
*/
public TransactionCalculator getCalculator() {
return calculator;
}
/**
* Getter for commited.
*
* @return boolean;
*/
public boolean isCommited() {
return commited;
}
/**
* Abstract commit method to set the isCommited flag that symbolizes a unique
* transaction.
*
* @param player - The player that does the transaction
*/
abstract public void commit(Player player);
}