Skip to content

Commit

Permalink
feat: added throw exceptions to DonationRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
MatheaGjerde committed Mar 2, 2026
1 parent 3361b26 commit ae7f856
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class DonationRepository extends DBRepository<Integer, Donation> {
* where the key represents the donation ID
*/
public DonationRepository(HashMap<Integer, Donation> content){
if (content == null) {
throw new IllegalArgumentException("Content cannot be null");
}
super(content);
this.content = content;
}
Expand All @@ -42,7 +45,10 @@ public DonationRepository(HashMap<Integer, Donation> content){
* {@code false} if a donation with the same ID already exists
*/
public boolean addDonation(Donation donation) {
if(content.containsKey(donation.donationId())){
if (donation == null) {
throw new IllegalArgumentException("Donation cannot be null");
}
if (content.containsKey(donation.donationId())){
return false;
}
content.put(donation.donationId(), donation);
Expand Down Expand Up @@ -97,6 +103,9 @@ public HashMap<Integer, Donation> sortByAmount() {
* @return a map containing all donations that belong to the given organization
*/
public HashMap<Integer, Donation> filterByOrganization(int orgNumber) {
if (orgNumber <= 0) {
throw new IllegalArgumentException("Organization number must be positive");
}
return content.entrySet()
.stream()
.filter(entry -> entry.getValue().organizationId() == orgNumber)
Expand Down

0 comments on commit ae7f856

Please sign in to comment.