X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FRegion.java;h=eac5c9561839d29a74ce91efd0768c24b236616a;hb=822afd4fe0aa1669db1e3be57b277f8aff977254;hp=43e852132dc1ff7487239dbd716c28d756cd4465;hpb=3ae9566eea151fe7560c6b06b07718c83132c75f;p=Persons_Comparator.git diff --git a/src/Region.java b/src/Region.java index 43e8521..eac5c95 100644 --- a/src/Region.java +++ b/src/Region.java @@ -1,38 +1,91 @@ -import com.google.gson.Gson; - -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; public class Region { - private String continent; - private String pays; + + 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; } - @SuppressWarnings("SpellCheckingInspection") - public void lectureOrigine(String continent, String pays) { - Gson gson = new Gson(); - Region r = new Region(); - String contenu = ""; + public ArrayList getCountryArrayListAmericas() { + return countryArrayListAmericas; + } + + public ArrayList getCountryArrayListEurope() { + return countryArrayListEurope; + } + + public ArrayList getCountryArrayListOceania() { + return countryArrayListOceania; + } + + public void loadCSVCountries() { + CSVUtils csvUtils = new CSVUtils(); + Scanner scanner = null; try { - InputStream flux = new FileInputStream(continent + ".json"); - InputStreamReader lecture = new InputStreamReader(flux); - BufferedReader buff = new BufferedReader(lecture); - String ligne; - while ((ligne = buff.readLine()) != null) { - contenu += ligne; + 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); } - buff.close(); - } catch (Exception e) { - System.out.println(e.toString()); + + } - System.out.println("les information du pays" + pays + " du fichier est : " + contenu); - // maintenant je veux deserialiser - Origin coords3 = gson.fromJson(contenu, Origin.class); - //Coordonnees co = gson.fromJson(json,Coordonnees.class); - System.out.println("Resultat = " + coords3); + scanner.close(); + /*Utils.displayArrayList(countryArrayListOceania); + Utils.displayArrayList(countryArrayListAfrica); + Utils.displayArrayList(countryArrayListAmericas); + Utils.displayArrayList(countryArrayListAsia); + Utils.displayArrayList(countryArrayListEurope);*/ + } -} + +} \ No newline at end of file