* Code cleanup;
[Persons_Comparator.git] / src / Region.java
1 import java.io.File;
2 import java.io.FileNotFoundException;
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.Scanner;
6
7 public class Region {
8 private String csvFile = "data/countries.csv";
9 private String[] continents = {"Africa", "Americas", "Asia", "Europe", "Oceania"};
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 public Region() {
17 this.loadCSVCountries();
18 }
19
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() {
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()) {
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(",");
57 if (line.get(12).equals("Europe")) {
58 Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
59 countryArrayListEurope.add(c);
60 } else if (line.get(12).equals("Africa")) {
61 Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
62 countryArrayListAfrica.add(c);
63 } else if (line.get(12).equals("Americas")) {
64 Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
65 countryArrayListAmericas.add(c);
66 } else if (line.get(12).equals("Asia")) {
67 Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
68 countryArrayListAsia.add(c);
69 } else if (line.get(12).equals("Oceania")) {
70 Country c = new Country(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]));
71 countryArrayListOceania.add(c);
72 }
73 }
74 scanner.close();
75 /*Utils.displayArrayList(countryArrayListOceania);
76 Utils.displayArrayList(countryArrayListAfrica);
77 Utils.displayArrayList(countryArrayListAmericas);
78 Utils.displayArrayList(countryArrayListAsia);
79 Utils.displayArrayList(countryArrayListEurope);*/
80 }
81 }