* Code cleanup;
[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 {
f56708fa 8 private String csvFile = "data/countries.csv";
822afd4f 9 private String[] continents = {"Africa", "Americas", "Asia", "Europe", "Oceania"};
f56708fa
SP
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
f56708fa 16 public Region() {
822afd4f 17 this.loadCSVCountries();
0af858cf 18 }
d3228894 19
822afd4f
SP
20 public String[] getContinents() {
21 return continents;
22 }
23
24 public ArrayList<Country> getCountryArrayListAfrica() {
25 return countryArrayListAfrica;
26 }
27
28 public ArrayList<Country> getCountryArrayListAsia() {
29 return countryArrayListAsia;
30 }
31
32 public ArrayList<Country> getCountryArrayListAmericas() {
33 return countryArrayListAmericas;
34 }
35
36 public ArrayList<Country> getCountryArrayListEurope() {
37 return countryArrayListEurope;
38 }
39
40 public ArrayList<Country> getCountryArrayListOceania() {
41 return countryArrayListOceania;
42 }
43
44 public void loadCSVCountries() {
f56708fa
SP
45 Scanner scanner = null;
46 try {
47 scanner = new Scanner(new File(csvFile));
48 } catch (FileNotFoundException e) {
49 e.printStackTrace();
50 }
51 while (scanner.hasNext()) {
e16e3b15
JB
52 List<String> line = CSVUtils.parseLine(scanner.nextLine());
53 String countryList = line.get(0);
54 String[] countryArray = countryList.split(",");
55 String latLng = line.get(16);
56 String[] latLngArray = latLng.split(",");
f56708fa 57 if (line.get(12).equals("Europe")) {
e16e3b15 58 Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
f56708fa
SP
59 countryArrayListEurope.add(c);
60 } else if (line.get(12).equals("Africa")) {
e16e3b15 61 Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
f56708fa
SP
62 countryArrayListAfrica.add(c);
63 } else if (line.get(12).equals("Americas")) {
e16e3b15 64 Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
f56708fa
SP
65 countryArrayListAmericas.add(c);
66 } else if (line.get(12).equals("Asia")) {
e16e3b15 67 Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
f56708fa
SP
68 countryArrayListAsia.add(c);
69 } else if (line.get(12).equals("Oceania")) {
e16e3b15 70 Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
f56708fa
SP
71 countryArrayListOceania.add(c);
72 }
f56708fa
SP
73 }
74 scanner.close();
75 /*Utils.displayArrayList(countryArrayListOceania);
76 Utils.displayArrayList(countryArrayListAfrica);
77 Utils.displayArrayList(countryArrayListAmericas);
78 Utils.displayArrayList(countryArrayListAsia);
79 Utils.displayArrayList(countryArrayListEurope);*/
0af858cf 80 }
f56708fa 81}