X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FRegion.java;h=7c50c89a3184138ed043acb7cd13ccbc81de8328;hb=e16e3b1587a729dd1e2d39bd4426831136376aa7;hp=6522496a9c8bb9bfd9c598a56d1c276e3385e99e;hpb=0af858cfb196b69dc0b3dd38e02df153bfe232f0;p=Persons_Comparator.git diff --git a/src/Region.java b/src/Region.java index 6522496..7c50c89 100644 --- a/src/Region.java +++ b/src/Region.java @@ -1,39 +1,81 @@ -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; - public Region(){ - - - } - @SuppressWarnings("SpellCheckingInspection") - public void lectureOrigine(String continent, String pays){ - Gson gson = new Gson(); - Region r = new Region(); - String contenu = ""; - try{ - InputStream flux = new FileInputStream(continent + ".txt"); - InputStreamReader lecture=new InputStreamReader(flux); - BufferedReader buff=new BufferedReader(lecture); - String ligne; - while ((ligne=buff.readLine())!=null){ - contenu+=ligne; - } - buff.close(); + 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 ArrayList getCountryArrayListEurope() { + return countryArrayListEurope; + } + + public ArrayList getCountryArrayListOceania() { + return countryArrayListOceania; + } + + public void loadCSVCountries() { + Scanner scanner = null; + try { + scanner = new Scanner(new File(csvFile)); + } catch (FileNotFoundException e) { + e.printStackTrace(); } - catch (Exception e){ - System.out.println(e.toString()); + while (scanner.hasNext()) { + 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(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(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(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(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(countryArray[1], line.get(12), Double.parseDouble(latLngArray[0]), Double.parseDouble(latLngArray[1])); + countryArrayListOceania.add(c); + } } - 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