-
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.
Added Checkstyle to TransactionArchive
- Loading branch information
Showing
1 changed file
with
52 additions
and
30 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 |
|---|---|---|
| @@ -1,45 +1,67 @@ | ||
| package Model; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.stream.Collectors; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * TransactionArchive class. | ||
| */ | ||
| public class TransactionArchive { | ||
| private List<Transaction> transactions; | ||
| private List<Transaction> transactions; | ||
|
|
||
| public TransactionArchive() { | ||
| this.transactions = new ArrayList<>(); | ||
| } | ||
| public TransactionArchive() { | ||
| this.transactions = new ArrayList<>(); | ||
| } | ||
|
|
||
| public boolean add(Transaction transaction) { | ||
| if (transaction == null) { | ||
| throw new IllegalArgumentException("Should not be null"); // Eller NullPointerExeption? | ||
| } | ||
| public boolean add(Transaction transaction) { | ||
| if (transaction == null) { | ||
| throw new IllegalArgumentException("Should not be null"); // Eller NullPointerExeption? | ||
| } | ||
|
|
||
| return transactions.add(transaction); | ||
| return transactions.add(transaction); | ||
| } | ||
|
|
||
| } | ||
| public boolean isEmpty() { | ||
| return transactions.isEmpty(); | ||
| } | ||
|
|
||
| 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<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 -> purchase instanceof Purchase).map(transaction -> (Purchase) transaction).collect(Collectors.toList()); | ||
| } | ||
| /** | ||
| * List of all purchases in one week. | ||
| * | ||
| * @param week the week to find purchases for | ||
| * @return returns the purchases | ||
| */ | ||
| public List<Purchase> getPurchase(int week) { | ||
| return transactions.stream() | ||
| .filter(transaction -> transaction.getWeek() == week) | ||
| .filter(purchase -> purchase 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 -> sale instanceof Sale).map(transaction -> (Sale) transaction).collect(Collectors.toList()); | ||
| } | ||
| /** | ||
| * Gets sales for that week. | ||
| * | ||
| * @param week the week to find sales for | ||
| * @return returns the sales | ||
| */ | ||
| public List<Sale> getSale(int week) { | ||
| return transactions.stream() | ||
| .filter(transaction -> transaction.getWeek() == week) | ||
| .filter(sale -> sale instanceof Sale) | ||
| .map(transaction -> (Sale) transaction).collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public List<Transaction> getAllTransactions() { | ||
| return new ArrayList<>(transactions); | ||
| } | ||
| public List<Transaction> getAllTransactions() { | ||
| return new ArrayList<>(transactions); | ||
| } | ||
|
|
||
| public int countDistinctWeeks() { | ||
| return (int) transactions.stream().map(Transaction::getWeek).distinct().count(); | ||
| } | ||
| public int countDistinctWeeks() { | ||
| return (int) transactions.stream().map(Transaction::getWeek).distinct().count(); | ||
| } | ||
| } |