Skip to content

Commit

Permalink
Adding TransactionArchive methods
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed Mar 5, 2026
1 parent 3172a5e commit 687ffae
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/temppackage/TransactionArchive.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ public List<Transaction> getTransactions(int week) {
}

public List<Purchase> getPurchases(int week) {
// TODO
return null;
return transactions.stream()
.filter(t -> t.getWeek() == week && t instanceof Purchase)
.map(t -> (Purchase) t)
.collect(Collectors.toList());
}

public List<Sale> getSales(int week) {
// TODO
return null;
return transactions.stream()
.filter(t -> t.getWeek() == week && t instanceof Sale)
.map(t -> (Sale) t)
.collect(Collectors.toList());
}

public int countDistinctWeeks() {
// TODO
return 0;
return (int) transactions.stream().map(Transaction::getWeek).distinct().count();
}
}

0 comments on commit 687ffae

Please sign in to comment.