X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FRegion.java;h=2233e557ebf64b100e1279284f15ad64ffd465fd;hb=b340a28fcacc7c2d230897ec810b88718b954f42;hp=b20d0cb02cede1fbd3c7376759ec9c2bf0bc6247;hpb=f56708fa0a19755ac5ec0313d9ee9c45a9aef0ce;p=Persons_Comparator.git diff --git a/src/Region.java b/src/Region.java index b20d0cb..2233e55 100644 --- a/src/Region.java +++ b/src/Region.java @@ -5,20 +5,43 @@ import java.util.List; import java.util.Scanner; public class Region { - private String csvFile = "data/countries.csv"; + private String[] continents = {"Africa", "Americas", "Asia", "Europe", "Oceania"}; private ArrayList countryArrayListEurope = new ArrayList<>(); private ArrayList countryArrayListAfrica = new ArrayList<>(); private ArrayList countryArrayListAmericas = new ArrayList<>(); private ArrayList countryArrayListAsia = new ArrayList<>(); private ArrayList countryArrayListOceania = new ArrayList<>(); - public Region() { + this.loadCSVCountries(); + } + + public String[] getContinents() { + return continents; + } + + public ArrayList getCountryArrayListAfrica() { + return countryArrayListAfrica; + } + + public ArrayList getCountryArrayListAsia() { + return countryArrayListAsia; + } + + public ArrayList getCountryArrayListAmericas() { + return countryArrayListAmericas; } - public void getCsvFile() { - CSVUtils csvUtils = new CSVUtils(); + public ArrayList getCountryArrayListEurope() { + return countryArrayListEurope; + } + + public ArrayList getCountryArrayListOceania() { + return countryArrayListOceania; + } + + public void loadCSVCountries() { Scanner scanner = null; try { scanner = new Scanner(new File(csvFile)); @@ -26,32 +49,27 @@ public class Region { e.printStackTrace(); } while (scanner.hasNext()) { - - List line = csvUtils.parseLine(scanner.nextLine()); - - String c3 = line.get(0); - String[] splitArray = c3.split(","); - String c2 = line.get(16); - String[] splitArray2 = c2.split(","); - + List line = CSVUtils.parseLine(scanner.nextLine()); + String countryList = line.get(0); + String[] countryArray = countryList.split(","); + String latLng = line.get(16); + String[] latLngArray = latLng.split(","); if (line.get(12).equals("Europe")) { - Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); + Country c = new Country(countryArray[0], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21)); countryArrayListEurope.add(c); } else if (line.get(12).equals("Africa")) { - Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); + Country c = new Country(countryArray[0], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21)); countryArrayListAfrica.add(c); } else if (line.get(12).equals("Americas")) { - Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); + Country c = new Country(countryArray[0], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21)); countryArrayListAmericas.add(c); } else if (line.get(12).equals("Asia")) { - Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); + Country c = new Country(countryArray[0], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21)); countryArrayListAsia.add(c); } else if (line.get(12).equals("Oceania")) { - Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); + Country c = new Country(countryArray[0], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1]), line.get(21)); countryArrayListOceania.add(c); } - - } scanner.close(); /*Utils.displayArrayList(countryArrayListOceania); @@ -60,5 +78,4 @@ public class Region { Utils.displayArrayList(countryArrayListAsia); Utils.displayArrayList(countryArrayListEurope);*/ } - } \ No newline at end of file