Work on Region, RegionView, countries.csv, Country
[Persons_Comparator.git] / src / Region.java
CommitLineData
f56708fa
SP
1import java.io.File;
2import java.io.FileNotFoundException;
6b0be432 3import java.util.ArrayList;
5bdd2996 4import java.util.List;
f56708fa 5import java.util.Scanner;
0af858cf 6
f56708fa 7public class Region {
0af858cf 8
f56708fa
SP
9 private String csvFile = "data/countries.csv";
10 private ArrayList<Country> countryArrayListEurope = new ArrayList<>();
11 private ArrayList<Country> countryArrayListAfrica = new ArrayList<>();
12 private ArrayList<Country> countryArrayListAmericas = new ArrayList<>();
13 private ArrayList<Country> countryArrayListAsia = new ArrayList<>();
14 private ArrayList<Country> countryArrayListOceania = new ArrayList<>();
15
16
17 public Region() {
0af858cf 18 }
d3228894 19
f56708fa
SP
20 public void getCsvFile() {
21 CSVUtils csvUtils = new CSVUtils();
22 Scanner scanner = null;
23 try {
24 scanner = new Scanner(new File(csvFile));
25 } catch (FileNotFoundException e) {
26 e.printStackTrace();
27 }
28 while (scanner.hasNext()) {
29
30 List<String> line = csvUtils.parseLine(scanner.nextLine());
31
32 String c3 = line.get(0);
33 String[] splitArray = c3.split(",");
34 String c2 = line.get(16);
35 String[] splitArray2 = c2.split(",");
36
37 if (line.get(12).equals("Europe")) {
38 Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1]));
39 countryArrayListEurope.add(c);
40 } else if (line.get(12).equals("Africa")) {
41 Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1]));
42 countryArrayListAfrica.add(c);
43 } else if (line.get(12).equals("Americas")) {
44 Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1]));
45 countryArrayListAmericas.add(c);
46 } else if (line.get(12).equals("Asia")) {
47 Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1]));
48 countryArrayListAsia.add(c);
49 } else if (line.get(12).equals("Oceania")) {
50 Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1]));
51 countryArrayListOceania.add(c);
52 }
53
54
55 }
56 scanner.close();
57 /*Utils.displayArrayList(countryArrayListOceania);
58 Utils.displayArrayList(countryArrayListAfrica);
59 Utils.displayArrayList(countryArrayListAmericas);
60 Utils.displayArrayList(countryArrayListAsia);
61 Utils.displayArrayList(countryArrayListEurope);*/
0af858cf 62 }
f56708fa
SP
63
64}