X-Git-Url: https://git.piment-noir.org/?p=Persons_Comparator.git;a=blobdiff_plain;f=src%2FRegion.java;h=b20d0cb02cede1fbd3c7376759ec9c2bf0bc6247;hp=1deb36d938721e772dba6902620f455859b13f58;hb=f56708fa0a19755ac5ec0313d9ee9c45a9aef0ce;hpb=6187b5ec050a664484d54283fd2612bfaf34cea3 diff --git a/src/Region.java b/src/Region.java index 1deb36d..b20d0cb 100644 --- a/src/Region.java +++ b/src/Region.java @@ -1,15 +1,64 @@ +import java.io.File; +import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; -import java.util.TreeMap; +import java.util.Scanner; -public class Region extends TreeMap> { - private List country; +public class Region { - public void setCountry(List origins) { - this.country = country; + private String csvFile = "data/countries.csv"; + 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() { } - public List getCountry() { - return country; + public void getCsvFile() { + CSVUtils csvUtils = new CSVUtils(); + Scanner scanner = null; + try { + scanner = new Scanner(new File(csvFile)); + } catch (FileNotFoundException e) { + 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(","); + + if (line.get(12).equals("Europe")) { + Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[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])); + 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])); + 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])); + 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])); + countryArrayListOceania.add(c); + } + + + } + scanner.close(); + /*Utils.displayArrayList(countryArrayListOceania); + Utils.displayArrayList(countryArrayListAfrica); + Utils.displayArrayList(countryArrayListAmericas); + Utils.displayArrayList(countryArrayListAsia); + Utils.displayArrayList(countryArrayListEurope);*/ } -} + +} \ No newline at end of file