-
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.
Merge pull request #31 from cathrkri/28-userregistry-charityregistry-…
…and-donationregistry Modifications: Registry classes
- Loading branch information
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 38 additions & 1 deletion
39
helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/CharityRegistry.java
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 +1,38 @@ | ||
| test | ||
| package ntnu.sytemutvikling.team6.models; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| public class CharityRegistry{ | ||
| private final List<Charity> charities; | ||
|
|
||
| public CharityRegistry(){ | ||
| this.charities = new ArrayList<>(); | ||
| } | ||
|
|
||
| public List<Charity> getAllCharities(){ | ||
| return Collections.unmodifiableList(charities); | ||
| } | ||
|
|
||
| public Optional<Charity> findCharityById(UUID charityId){ | ||
| if(charityId == null){ | ||
| throw new IllegalArgumentException("CharityId can not be null."); | ||
| } | ||
| return charities.stream() | ||
| .filter(charity -> charityId.equals(charity.getId())) | ||
| .findFirst(); | ||
| } | ||
|
|
||
| public void addCharity(Charity charity){ | ||
| if(charity == null){ | ||
| throw new IllegalArgumentException("Charity can not be null."); | ||
| } | ||
| charities.add(charity); | ||
| } | ||
|
|
||
| public boolean removeCharity(UUID charityId){ | ||
| if(charityId == null){ | ||
| throw new IllegalArgumentException("CharityId can not be null."); | ||
| } | ||
| return charities.removeIf(charity -> charityId.equals(charity.getId())); | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/DonationRegistry.java
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,5 +1,39 @@ | ||
| package ntnu.sytemutvikling.team6.models; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| public class DonationRegistry { | ||
| private final List<Donation> donations; | ||
|
|
||
| public DonationRegistry(){ | ||
| this.donations = new ArrayList<>(); | ||
| } | ||
|
|
||
| public List<Donation> getAllDonations(){ | ||
| return Collections.unmodifiableList(donations); | ||
| } | ||
|
|
||
| public Optional<Donation> findDonationById(UUID donationId){ | ||
| if(donationId == null){ | ||
| throw new IllegalArgumentException("DonationId can not be null."); | ||
| } | ||
| return donations.stream() | ||
| .filter(donations -> donationId.equals(donations.getId())) | ||
| .findFirst(); | ||
| } | ||
|
|
||
| public void addDonation(Donation donation){ | ||
| if(donation == null){ | ||
| throw new IllegalArgumentException("Donation can not be null."); | ||
| } | ||
| donations.add(donation); | ||
| } | ||
|
|
||
| public boolean removeDonation(UUID donationId){ | ||
| if(donationId == null){ | ||
| throw new IllegalArgumentException("DonationId can not be null."); | ||
| } | ||
| return donations.removeIf(donation -> donationId.equals(donation.getId)); | ||
| } | ||
|
|
||
| } |