-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataModel.java
More file actions
66 lines (53 loc) · 1.68 KB
/
DataModel.java
File metadata and controls
66 lines (53 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.example.healthsuppliesdonation;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class DataModel {
private static DataModel instance;
private final List<Request> requests;
private final List<Donation> donations;
private DataModel() {
requests = new ArrayList<>();
donations = new ArrayList<>();
}
public static DataModel getInstance() {
if (instance == null) {
instance = new DataModel();
}
return instance;
}
// Requests management
public void addRequest(Request request) {
requests.add(request);
}
public void removeRequest(Request request) {
requests.remove(request);
}
public List<Request> getRequests() {
return new ArrayList<>(requests);
}
// Donations management
public void addDonation(Donation donation) {
donations.add(donation);
}
public List<Donation> getDonations() {
return new ArrayList<>(donations);
}
// Fetch all unique supplies requested
public List<String> getAllSuppliesRequested() {
Set<String> suppliesSet = new HashSet<>();
for (Request request : requests) {
suppliesSet.add(request.getSuppliesNeeded());
}
return new ArrayList<>(suppliesSet);
}
// Fetch all unique organizations that requested supplies
public List<String> getAllOrganizationsRequested() {
Set<String> organizationsSet = new HashSet<>();
for (Request request : requests) {
organizationsSet.add(request.getHospitalName());
}
return new ArrayList<>(organizationsSet);
}
}