diff --git a/src/main/java/Model/TransactionArchive.java b/src/main/java/Model/TransactionArchive.java index 149e2be..db7a50c 100644 --- a/src/main/java/Model/TransactionArchive.java +++ b/src/main/java/Model/TransactionArchive.java @@ -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 transactions; + private List 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 getTransactions(int week) { + return transactions.stream() + .filter(transaction -> transaction.getWeek() == week).collect(Collectors.toList()); + } - public List getTransactions(int week) { - return transactions.stream().filter(transaction -> transaction.getWeek() == week).collect(Collectors.toList()); - } - - public List 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 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 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 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 getAllTransactions() { - return new ArrayList<>(transactions); - } + public List 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(); + } }