X-Git-Url: https://git.piment-noir.org/?p=Persons_Comparator.git;a=blobdiff_plain;f=src%2FRegion.java;fp=src%2FRegion.java;h=7c50c89a3184138ed043acb7cd13ccbc81de8328;hp=eac5c9561839d29a74ce91efd0768c24b236616a;hb=e16e3b1587a729dd1e2d39bd4426831136376aa7;hpb=822afd4fe0aa1669db1e3be57b277f8aff977254 diff --git a/src/Region.java b/src/Region.java index eac5c95..7c50c89 100644 --- a/src/Region.java +++ b/src/Region.java @@ -5,7 +5,6 @@ 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<>(); @@ -14,7 +13,6 @@ public class Region { private ArrayList countryArrayListAsia = new ArrayList<>(); private ArrayList countryArrayListOceania = new ArrayList<>(); - public Region() { this.loadCSVCountries(); } @@ -44,7 +42,6 @@ public class Region { } public void loadCSVCountries() { - CSVUtils csvUtils = new CSVUtils(); Scanner scanner = null; try { scanner = new Scanner(new File(csvFile)); @@ -52,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[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1])); 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[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1])); 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[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1])); 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[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1])); 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[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1])); countryArrayListOceania.add(c); } - - } scanner.close(); /*Utils.displayArrayList(countryArrayListOceania); @@ -85,7 +77,5 @@ public class Region { Utils.displayArrayList(countryArrayListAmericas); Utils.displayArrayList(countryArrayListAsia); Utils.displayArrayList(countryArrayListEurope);*/ - } - } \ No newline at end of file