This repository was archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathCodingCompCSVUtil.java
More file actions
91 lines (77 loc) · 3.3 KB
/
CodingCompCSVUtil.java
File metadata and controls
91 lines (77 loc) · 3.3 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
package codingcompetition2019;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CodingCompCSVUtil {
public List<List<String>> readCSVFileByCountry(String fileName, String countryName) throws IOException {
String tempStr = "";
BufferedReader br = new BufferedReader(new FileReader(fileName));
ArrayList<ArrayList<String>> row = new ArrayList<ArrayList<String>>();
ArrayList<ArrayList<String>> selected = new ArrayList<ArrayList<String>>();
while((tempStr = br.readLine()) != null) {
String [] tempCol = tempStr.split(",");
ArrayList<String> col = new ArrayList<String>(Arrays.asList(tempCol));
row.add(col);
}
for (int i = 0; i < row.size(); i++) {
if (row.get(i).get(0).contains(countryName)) {
selected.add(row.get(i));
}
}
List<List<String>> result = (List)selected;
return result;
}
public List<List<String>> readCSVFileWithHeaders(String fileName) throws IOException {
String tempStr = "";
BufferedReader br = new BufferedReader(new FileReader(fileName));
ArrayList<ArrayList<String>> row = new ArrayList<ArrayList<String>>();
ArrayList<ArrayList<String>> selected = new ArrayList<ArrayList<String>>();
while((tempStr = br.readLine()) != null) {
String [] tempCol = tempStr.split(",");
ArrayList<String> col = new ArrayList<String>(Arrays.asList(tempCol));
row.add(col);
}
List<List<String>> result = (List)row;
return result;
}
public List<List<String>> readCSVFileWithoutHeaders(String fileName) throws IOException {
ArrayList<ArrayList<String>> row = new ArrayList<ArrayList<String>>((ArrayList)readCSVFileWithHeaders("src/main/resources/natural-disasters-by-type.csv"));
row.remove(0);
List<List<String>> result = (List)row;
return result;
}
public DisasterDescription getMostImpactfulYear(List<List<String>> records) {
DisasterDescription highest = new DisasterDescription(records);
return highest;
}
public DisasterDescription getMostImpactfulYearByCategory(String category, List<List<String>> records) {
DisasterDescription high = new DisasterDescription(category, records);
return high;
}
public DisasterDescription getMostImpactfulDisasterByYear(String year, List<List<String>> records) {
DisasterDescription byYear = new DisasterDescription(0, year, records);
return byYear;
}
public DisasterDescription getTotalReportedIncidentsByCategory(String category, List<List<String>> records) {
DisasterDescription byCat = new DisasterDescription(0, 0, category, records);
return byCat;
}
/**
* This method will return the count if the number of incident falls within the provided range.
* To simplify the problem, we assume:
* + A value of -1 is provided if the max range is NOT applicable.
* + A min value can be provided, without providing a max value (which then has to be -1 like indicated above).
* + If a max value is provided, then a max value is also needed.
*/
public int countImpactfulYearsWithReportedIncidentsWithinRange(List<List<String>> records, int min, int max) {
// TODO implement this method
return -1;
}
public boolean firstRecordsHaveMoreReportedIndicents(List<List<String>> records1, List<List<String>> records2) {
// TODO implement this method
return false;
}
}