Commit | Line | Data |
---|---|---|
f56708fa SP |
1 | import java.io.File; |
2 | import java.io.FileNotFoundException; | |
6b0be432 | 3 | import java.util.ArrayList; |
5bdd2996 | 4 | import java.util.List; |
f56708fa | 5 | import java.util.Scanner; |
0af858cf | 6 | |
f56708fa | 7 | public class Region { |
0af858cf | 8 | |
f56708fa | 9 | private String csvFile = "data/countries.csv"; |
822afd4f | 10 | private String[] continents = {"Africa", "Americas", "Asia", "Europe", "Oceania"}; |
f56708fa SP |
11 | private ArrayList<Country> countryArrayListEurope = new ArrayList<>(); |
12 | private ArrayList<Country> countryArrayListAfrica = new ArrayList<>(); | |
13 | private ArrayList<Country> countryArrayListAmericas = new ArrayList<>(); | |
14 | private ArrayList<Country> countryArrayListAsia = new ArrayList<>(); | |
15 | private ArrayList<Country> countryArrayListOceania = new ArrayList<>(); | |
16 | ||
17 | ||
18 | public Region() { | |
822afd4f | 19 | this.loadCSVCountries(); |
0af858cf | 20 | } |
d3228894 | 21 | |
822afd4f SP |
22 | public String[] getContinents() { |
23 | return continents; | |
24 | } | |
25 | ||
26 | public ArrayList<Country> getCountryArrayListAfrica() { | |
27 | return countryArrayListAfrica; | |
28 | } | |
29 | ||
30 | public ArrayList<Country> getCountryArrayListAsia() { | |
31 | return countryArrayListAsia; | |
32 | } | |
33 | ||
34 | public ArrayList<Country> getCountryArrayListAmericas() { | |
35 | return countryArrayListAmericas; | |
36 | } | |
37 | ||
38 | public ArrayList<Country> getCountryArrayListEurope() { | |
39 | return countryArrayListEurope; | |
40 | } | |
41 | ||
42 | public ArrayList<Country> getCountryArrayListOceania() { | |
43 | return countryArrayListOceania; | |
44 | } | |
45 | ||
46 | public void loadCSVCountries() { | |
f56708fa SP |
47 | CSVUtils csvUtils = new CSVUtils(); |
48 | Scanner scanner = null; | |
49 | try { | |
50 | scanner = new Scanner(new File(csvFile)); | |
51 | } catch (FileNotFoundException e) { | |
52 | e.printStackTrace(); | |
53 | } | |
54 | while (scanner.hasNext()) { | |
55 | ||
56 | List<String> line = csvUtils.parseLine(scanner.nextLine()); | |
57 | ||
58 | String c3 = line.get(0); | |
59 | String[] splitArray = c3.split(","); | |
60 | String c2 = line.get(16); | |
61 | String[] splitArray2 = c2.split(","); | |
62 | ||
63 | if (line.get(12).equals("Europe")) { | |
64 | Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); | |
65 | countryArrayListEurope.add(c); | |
66 | } else if (line.get(12).equals("Africa")) { | |
67 | Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); | |
68 | countryArrayListAfrica.add(c); | |
69 | } else if (line.get(12).equals("Americas")) { | |
70 | Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); | |
71 | countryArrayListAmericas.add(c); | |
72 | } else if (line.get(12).equals("Asia")) { | |
73 | Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); | |
74 | countryArrayListAsia.add(c); | |
75 | } else if (line.get(12).equals("Oceania")) { | |
76 | Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); | |
77 | countryArrayListOceania.add(c); | |
78 | } | |
79 | ||
80 | ||
81 | } | |
82 | scanner.close(); | |
83 | /*Utils.displayArrayList(countryArrayListOceania); | |
84 | Utils.displayArrayList(countryArrayListAfrica); | |
85 | Utils.displayArrayList(countryArrayListAmericas); | |
86 | Utils.displayArrayList(countryArrayListAsia); | |
87 | Utils.displayArrayList(countryArrayListEurope);*/ | |
822afd4f | 88 | |
0af858cf | 89 | } |
f56708fa SP |
90 | |
91 | } |