-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.TreeMap;
+import java.util.List;
+import java.util.Scanner;
-public class Region extends TreeMap<String, ArrayList<Country>> {
+public class Region {
+ private String csvFile = "data/countries.csv";
+ private String[] continents = {"Africa", "Americas", "Asia", "Europe", "Oceania"};
+ private ArrayList<Country> countryArrayListEurope = new ArrayList<>();
+ private ArrayList<Country> countryArrayListAfrica = new ArrayList<>();
+ private ArrayList<Country> countryArrayListAmericas = new ArrayList<>();
+ private ArrayList<Country> countryArrayListAsia = new ArrayList<>();
+ private ArrayList<Country> countryArrayListOceania = new ArrayList<>();
public Region() {
+ this.loadCSVCountries();
+ }
+
+ public String[] getContinents() {
+ return continents;
+ }
+
+ public ArrayList<Country> getCountryArrayListAfrica() {
+ return countryArrayListAfrica;
+ }
+
+ public ArrayList<Country> getCountryArrayListAsia() {
+ return countryArrayListAsia;
}
- @SuppressWarnings("SpellCheckingInspection")
- public void lectureOrigine(String continent, String pays) {
- Gson gson = new Gson();
- Region r = new Region();
- String contenu = "";
+ public ArrayList<Country> getCountryArrayListAmericas() {
+ return countryArrayListAmericas;
+ }
+
+ public ArrayList<Country> getCountryArrayListEurope() {
+ return countryArrayListEurope;
+ }
+
+ public ArrayList<Country> getCountryArrayListOceania() {
+ return countryArrayListOceania;
+ }
+
+ public void loadCSVCountries() {
+ 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<String> 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]), line.get(21));
+ 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]), line.get(21));
+ 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]), line.get(21));
+ 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]), line.get(21));
+ 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]), line.get(21));
+ 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