Skip to content

Commit

Permalink
Merge pull request #30 from einaskoi/einar/transactionArchive
Browse files Browse the repository at this point in the history
implement logic in the TransactionArchive class
  • Loading branch information
peretr authored Feb 23, 2026
2 parents 19899ac + 74e694c commit 9fa686b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
14 changes: 11 additions & 3 deletions src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Portfolio.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public Portfolio() {
* @return true or false based on if the operation was successful or not.
*/
public boolean addShare(Share share) {
return true;
if (share == null) {
return false;
} else {
return shares.add(share);
}
}

/**
Expand All @@ -32,7 +36,11 @@ public boolean addShare(Share share) {
* @return true or false based on if the operation was successful or not.
*/
public boolean removeShare(Share share) {
return false;
if (share == null || !shares.contains(share)) {
return false;
} else {
return shares.remove(share);
}
}

public List<Share> getShares() {
Expand All @@ -45,6 +53,6 @@ public List<Share> getShares() {
* @return true or false based on if the share was found or not.
*/
public boolean contains(Share share) {
return true;
return share != null && shares.contains(share);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package edu.ntnu.idi.idatt2003.gruppe42.Model.Transaction;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class TransactionArchive {
private List<Transaction> transactions;
Expand All @@ -11,26 +13,60 @@ public TransactionArchive() {
}

public boolean add(Transaction transaction) {
return true;
if (transaction == null) {
return false;
} else {
return transactions.add(transaction);
}
}

public boolean isEmpty() {
return true;
return transactions.isEmpty();
}

public List<Transaction> getTransactions(int week) {
return transactions;
List<Transaction> transactionsThisWeek = new ArrayList<>();

for (Transaction transaction : transactions) {
if (transaction.getWeek() == week) {
transactionsThisWeek.add(transaction);
}
}

return transactionsThisWeek;
}

public List<Purchase> getPurchases(int week) {
return null;
List<Purchase> purchasesThisWeek = new ArrayList<>();

for (Transaction transaction : transactions) {
if (transaction.getWeek() == week && transaction instanceof Purchase) {
purchasesThisWeek.add((Purchase) transaction);
}
}

return purchasesThisWeek;
}

public List<Sale> getSales(int week) {
return null;
List<Sale> salesThisWeek = new ArrayList<>();

for (Transaction transaction : transactions) {
if (transaction.getWeek() == week && transaction instanceof Sale) {
salesThisWeek.add((Sale) transaction);
}
}

return salesThisWeek;
}

public int countDistinctWeeks() {
return 0;
Set<Integer> distinctWeeks = new HashSet<>();

for (Transaction transaction : transactions) {
distinctWeeks.add(transaction.getWeek());
}

return distinctWeeks.size();
}
}

0 comments on commit 9fa686b

Please sign in to comment.