aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2014-04-15 10:07:27 +0200
committerSamuel Tardieu <sam@rfc1149.net>2014-04-15 10:07:27 +0200
commitb4853116e776bc22b9138b13e2fd4a0d60aba063 (patch)
tree70703f6ecaf5599564c0c8b18d57fd6216ea7513 /main
parent92ff170541101212a6a71cf6892508e0cb3c4a83 (diff)
downloadcgeo-b4853116e776bc22b9138b13e2fd4a0d60aba063.zip
cgeo-b4853116e776bc22b9138b13e2fd4a0d60aba063.tar.gz
cgeo-b4853116e776bc22b9138b13e2fd4a0d60aba063.tar.bz2
refactoring: factor out coordinates validity checks
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/geopoint/Geopoint.java27
-rw-r--r--main/src/cgeo/geocaching/geopoint/GeopointParser.java4
2 files changed, 29 insertions, 2 deletions
diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java
index c718a5f..1655343 100644
--- a/main/src/cgeo/geocaching/geopoint/Geopoint.java
+++ b/main/src/cgeo/geocaching/geopoint/Geopoint.java
@@ -572,4 +572,31 @@ public final class Geopoint implements ICoordinates, Parcelable {
return angdeg * DEG_TO_RAD;
}
+ /**
+ * Check whether a latitude built from user supplied data is valid. We accept both N90/S90.
+ *
+ * @return <tt>true</tt> if the latitude looks valid, <tt>false</tt> otherwise
+ */
+ public static boolean isValidLatitude(final double latitude) {
+ return latitude >= -90 && latitude <= 90;
+ }
+
+ /**
+ * Check whether a lo bngitudeuilt from user supplied data is valid. We accept both E180/W180.
+ *
+ * @return <tt>true</tt> if the longitude looks valid, <tt>false</tt> otherwise
+ */
+ public static boolean isValidLongitude(final double longitude) {
+ return longitude >= -180 && longitude <= 180;
+ }
+
+ /**
+ * Check whether a geopoint built from user supplied data is valid. We accept both N90/S90 and E180/W180.
+ *
+ * @return <tt>true</tt> if the geopoint looks valid, <tt>false</tt> otherwise
+ */
+ public boolean isValid() {
+ return isValidLatitude(latitude) && isValidLongitude(longitude);
+ }
+
}
diff --git a/main/src/cgeo/geocaching/geopoint/GeopointParser.java b/main/src/cgeo/geocaching/geopoint/GeopointParser.java
index 2809598..b486f01 100644
--- a/main/src/cgeo/geocaching/geopoint/GeopointParser.java
+++ b/main/src/cgeo/geocaching/geopoint/GeopointParser.java
@@ -66,10 +66,10 @@ class GeopointParser {
final double lat = latitudeWrapper.result;
final double lon = longitudeWrapper.result;
- if (lat > 90 || lat < -90) {
+ if (!Geopoint.isValidLatitude(lat)) {
throw new Geopoint.ParseException(text, LatLon.LAT);
}
- if (lon > 180 || lon < -180) {
+ if (!Geopoint.isValidLongitude(lon)) {
throw new Geopoint.ParseException(text, LatLon.LON);
}
return new Geopoint(lat, lon);