| 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 | |
| 9 | private String csvFile = "data/countries.csv"; |
| 10 | private String[] continents = {"Africa", "Americas", "Asia", "Europe", "Oceania"}; |
| 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() { |
| 19 | this.loadCSVCountries(); |
| 20 | } |
| 21 | |
| 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() { |
| 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);*/ |
| 88 | |
| 89 | } |
| 90 | |
| 91 | } |