forked from UCLComputerScience/COMP0004JavaWebAppExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel.java
More file actions
executable file
·50 lines (44 loc) · 1.49 KB
/
Copy pathModel.java
File metadata and controls
executable file
·50 lines (44 loc) · 1.49 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
package uk.ac.ucl.model;
import java.io.Reader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
public class Model
{
// The example code in this class should be replaced by your Model class code.
// The data should be stored in a suitable data structure.
public List<String> getPatientNames()
{
return readFile("data/patients100.csv");
}
// This method illustrates how to read csv data from a file.
// The data files are stored in the root directory of the project (the directory your project is in),
// in the directory named data.
public List<String> readFile(String fileName)
{
List<String> data = new ArrayList<>();
try (Reader reader = new FileReader(fileName);
CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT))
{
for (CSVRecord csvRecord : csvParser)
{
// The first row of the file contains the column headers, so is not actual data.
data.add(csvRecord.get(0));
}
} catch (IOException e)
{
e.printStackTrace();
}
return data;
}
// This also returns dummy data. The real version should use the keyword parameter to search
// the data and return a list of matching items.
public List<String> searchFor(String keyword)
{
return List.of("Search keyword is: "+ keyword, "result1", "result2", "result3");
}
}