Skip to content

Commit

Permalink
TransactionsArchive class doc
Browse files Browse the repository at this point in the history
javadoc
  • Loading branch information
EspenTinius committed Feb 19, 2026
1 parent f98702e commit 445c753
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,44 @@
import java.util.ArrayList;
import java.util.List;

/**
* Stores completed transactions.
*/
public class TransactionArchive {

private final List<Transaction> transactions = new ArrayList<>();

/**
* Creates an empty transaction archive.
*/
public TransactionArchive() {
}

/**
* Adds a transaction to the archive.
*
* @param transaction the transaction to add
* @return true if the transaction was added
*/
public boolean add(Transaction transaction) {
return transactions.add(transaction);
}

/**
* Checks whether the archive is empty.
*
* @return true if no transactions exist
*/
public boolean isEmpty() {
return transactions.isEmpty();
}

/**
* Returns all transactions from a given week.
*
* @param week the week number
* @return list of transactions from the given week
*/
public List<Transaction> getTransactions(int week) {
List<Transaction> result = new ArrayList<>();
for (Transaction transaction : transactions) {
Expand All @@ -28,6 +51,12 @@ public List<Transaction> getTransactions(int week) {
return result;
}

/**
* Returns all purchase transactions from a given week.
*
* @param week the week number
* @return list of purchases from the given week
*/
public List<Purchase> getPurchases(int week) {
List<Purchase> result = new ArrayList<>();
for (Transaction transaction : transactions) {
Expand All @@ -38,6 +67,12 @@ public List<Purchase> getPurchases(int week) {
return result;
}

/**
* Returns all sale transactions from a given week.
*
* @param week the week number
* @return list of sales from the given week
*/
public List<Sale> getSales(int week) {
List<Sale> result = new ArrayList<>();
for (Transaction transaction : transactions) {
Expand All @@ -48,6 +83,11 @@ public List<Sale> getSales(int week) {
return result;
}

/**
* Counts the number of distinct weeks with transactions.
*
* @return number of distinct weeks
*/
public int countDistinctWeeks() {
List<Integer> weeks = new ArrayList<>();
for (Transaction transaction : transactions) {
Expand Down

0 comments on commit 445c753

Please sign in to comment.