| 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 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() { |
| 18 | } |
| 19 | |
| 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);*/ |
| 62 | } |
| 63 | |
| 64 | } |