This repository was archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfectionResults.java
More file actions
132 lines (122 loc) · 3.53 KB
/
Copy pathInfectionResults.java
File metadata and controls
132 lines (122 loc) · 3.53 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.Iterator;
/**
* NB: DO NOT MODIFY THE METHOD NAMES, RETURN TYPES OR
* PARAMETERS IN THIS CLASS IN ANY WAY.
*
* Manage a collection of infection test results.
* An InfectionResults class that is intended to store a collection of
* InfectionTest objects.
*
* @author Ismail Hendryx
* @version (11/11/2021)
*/
public class InfectionResults
{
// An ArrayList for storing the InfectionTest objects.
private ArrayList<InfectionTest> testResults;
/**
* Constructor for objects of class InfectionResults
*/
public InfectionResults()
{
testResults = new ArrayList<>();
}
/**
* Add the given test to the collection.
* @param test The test to be added.
* Takes InfectionTest objects as parameters and adds it to the collection.
*/
public void addTest(InfectionTest test)
{
testResults.add(test);
}
/**
* Get the number of tests currently stored.
* @return the number of tests.
*/
public int getNumberOfTests()
{
return testResults.size();
}
/**
* List the tests in the collection.
*/
public void list()
{
for(InfectionTest listthing:testResults) {
listthing.getDetails();
System.out.println(listthing.getDetails());
}
}
/**
* Set the status of the given test.
* If a test with the id is not found no action is required
* and no error message should be printed.
* @param id The id of the test.
* @param positive Whether the test is positive or not.
*/
public void setStatus(String id, boolean positive)
{
//Searches for the inputted test id and calls its setStatus method
int index = 0;
boolean searching = true;
while(index<testResults.size() && searching){
if(testResults.get(index).getID().equals(id)) {
searching = false;
testResults.get(index).setStatus(positive);
index++;
}
else {
index++;}
}
}
/**
* Find the test (if any) with the given id.
* @return The test with the given id, or null if
* none matches.
*/
public InfectionTest findTest(String id)
{
for(InfectionTest index: testResults) {
if (index.getID() == id) {
return index;
}
}
return null;
}
/**
* Return all the positive tests.
* @return the positive tests.
*/
public HashSet<InfectionTest> getPositiveTests()
{
HashSet<InfectionTest> getPositiveTests = new HashSet <InfectionTest>();
for (InfectionTest p:testResults) {
if (p.isKnown()==true){
if (p.isPositive()==true){
getPositiveTests.add(p);}
}
}
return getPositiveTests;
}
/**
* Remove all the tests with unknown status and return
* those that were removed.
* @return the removed tests.
*/
public LinkedList<InfectionTest> removeUnknownStatus()
{
LinkedList<InfectionTest> removeUnknownStatus = new LinkedList <InfectionTest>();
Iterator<InfectionTest> it = testResults.iterator();
while(it.hasNext()) {
InfectionTest r = it.next();
if(r.isKnown() == false){
it.remove();
removeUnknownStatus.add(r);}
}
return removeUnknownStatus;
}
}