+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.List;
+import java.util.Scanner;
+
public class Country {
private String name;
private String region;
private double lat;
private double lng;
private String flag;
+ private String csvFile = "data/countries.csv";
public Country(String name, String region, double lat, double lng, String flag) {
setName(name);
setFlag(flag);
}
+ public Country(String name) {
+ setName(name);
+ loadCSVOneCountry(this.name);
+
+ }
+
public void setName(String name) {
this.name = name;
}
}
}
+ public void loadCSVOneCountry(String name) {
+ Scanner scanner = null;
+ try {
+ 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 (countryArray[1].equals(name)) {
+ setRegion(line.get(12));
+ setLat(Double.parseDouble(latLngArray[0]));
+ setLng(Double.parseDouble(latLngArray[1]));
+ }
+ }
+ scanner.close();
+ /*Utils.displayArrayList(countryArrayListOceania);
+ Utils.displayArrayList(countryArrayListAfrica);
+ Utils.displayArrayList(countryArrayListAmericas);
+ Utils.displayArrayList(countryArrayListAsia);
+ Utils.displayArrayList(countryArrayListEurope);*/
+ }
+
+
@Override
public String toString() {
return "Country{" +