Break a loop once the work is done.
[Persons_Comparator.git] / src / Country.java
index 8a41df6ad2281a454b63af19135e2c97aea4a3c4..3b8735dfce66161bbd3e5f82c6eef10be3e09edb 100644 (file)
@@ -27,48 +27,50 @@ public class Country {
         setFlag(flag);
     }
 
-    public void setName(String name) {
-        this.name = name;
-    }
-
     public String getName() {
         return name;
     }
 
-    public void setRegion(String region) {
-        this.region = region;
+    public void setName(String name) {
+        this.name = name;
     }
 
-    public void setLat(double lat) {
-        this.lat = lat;
+    public void setRegion(String region) {
+        this.region = region;
     }
 
     public double getLat() {
         return lat;
     }
 
-    public void setLng(double lng) {
-        this.lng = lng;
+    public void setLat(double lat) {
+        this.lat = lat;
     }
 
     public double getLng() {
         return lng;
     }
 
-    public void setFlag(String flag) {
-        this.flag = flag;
+    public void setLng(double lng) {
+        this.lng = lng;
     }
 
     public String getFlag() {
         return flag;
     }
 
+    public void setFlag(String flag) {
+        this.flag = flag;
+    }
+
     public int distanceTo(Country country) {
         if ((this.getLat() == country.getLat()) && (this.getLng() == country.getLng())) {
             return 0;
         } else {
             double theta = this.getLng() - country.getLng();
-            Double dist = Math.sin(Math.toRadians(this.getLat())) * Math.sin(Math.toRadians(country.getLat())) + Math.cos(Math.toRadians(this.getLat())) * Math.cos(Math.toRadians(country.getLat())) * Math.cos(Math.toRadians(theta));
+            Double dist = Math.sin(Math.toRadians(this.getLat())) * Math.sin(Math.toRadians(country.getLat())) +
+                    Math.cos(Math.toRadians(this.getLat())) * Math.cos(Math.toRadians(country.getLat())) *
+                            Math.cos(Math.toRadians(theta));
             dist = Math.acos(dist);
             dist = Math.toDegrees(dist);
             dist = dist * 60 * 1.1515;
@@ -85,18 +87,24 @@ public class Country {
         } catch (FileNotFoundException e) {
             e.printStackTrace();
         }
+        boolean found = false;
         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)) {
+            if (countryArray[0].equals(name)) {
+                found = true;
                 setRegion(line.get(12));
                 setLat(Double.parseDouble(latLngArray[0]));
                 setLng(Double.parseDouble(latLngArray[1]));
+                setFlag(line.get(21));
+                break;
             }
         }
+        if (!found)
+            System.out.println("Country " + name + " not found");
         scanner.close();
     }