-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Solveig Natvig
committed
Mar 22, 2026
1 parent
32b5cb7
commit 5ec6c53
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.stream.Collectors; | ||
| import java.util.List; | ||
|
|
||
| public class TransactionArchive { | ||
| private List<Transaction> transactions; | ||
|
|
||
| public TransactionArchive() { | ||
| this.transactions = new ArrayList<>(); | ||
| } | ||
|
|
||
| public boolean add(Transaction transaction) { | ||
| if (transaction == null) { | ||
| throw new IllegalArgumentException("Should not be null"); // Eller NullPointerExeption? | ||
| } | ||
|
|
||
| return transactions.add(transaction); | ||
|
|
||
| } | ||
|
|
||
| public boolean isEmpty() { | ||
| return transactions.isEmpty(); | ||
| } | ||
|
|
||
| public List<Transaction> getTransactions(int week) { | ||
| return transactions.stream().filter(transaction -> transaction.getWeek() == week).collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public List<Purchase> getPurchase(int week) { | ||
| return transactions.stream().filter(transaction -> transaction.getWeek() == week).filter(purchase -> transactions instanceof Purchase).map(transaction -> (Purchase) transaction).collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public List<Sale> getSale(int week) { | ||
| return transactions.stream().filter(transaction -> transaction.getWeek() == week).filter(sale -> transactions instanceof Sale).map(transaction -> (Sale) transaction).collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public int countDistinctWeeks() { | ||
| return (int) transactions.stream().map(Transaction::getWeek).distinct().count(); | ||
| } | ||
| } |