diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2012-04-21 18:07:04 +0200 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2012-04-21 18:25:57 +0200 |
commit | 2dbaee334b97ea1123d8a245bc247d918ba2c6fb (patch) | |
tree | b8801f2a24cad81c23fc0e101a7d84b0f622744d /main/src/cgeo/geocaching/geopoint/Geopoint.java | |
parent | 1d1bcd7661e11ef079d8b23f9c531397e835ba3b (diff) | |
download | cgeo-2dbaee334b97ea1123d8a245bc247d918ba2c6fb.zip cgeo-2dbaee334b97ea1123d8a245bc247d918ba2c6fb.tar.gz cgeo-2dbaee334b97ea1123d8a245bc247d918ba2c6fb.tar.bz2 |
Refactoring: keep GeopointParser private to its package
Geopoint exposes everything GeopointParser can do. By calling a Geopoint
constructor instead of a GeopointParser method returning a Geopoint,
Eclipse can do more null checks for free (a constuctor can never return
a null object).
Diffstat (limited to 'main/src/cgeo/geocaching/geopoint/Geopoint.java')
-rw-r--r-- | main/src/cgeo/geocaching/geopoint/Geopoint.java | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java index 106e8a9..2fe7bd2 100644 --- a/main/src/cgeo/geocaching/geopoint/Geopoint.java +++ b/main/src/cgeo/geocaching/geopoint/Geopoint.java @@ -1,6 +1,7 @@ package cgeo.geocaching.geopoint; import cgeo.geocaching.ICoordinates; +import cgeo.geocaching.R; import cgeo.geocaching.geopoint.GeopointFormatter.Format; import cgeo.geocaching.geopoint.direction.DDD; import cgeo.geocaching.geopoint.direction.DMM; @@ -53,12 +54,14 @@ public final class Geopoint implements ICoordinates, Parcelable { * * @param text * string to parse - * @throws GeopointParser.ParseException + * @throws Geopoint.ParseException * if the string cannot be parsed * @see GeopointParser.parse() */ public Geopoint(final String text) { - this(GeopointParser.parseLatitude(text), GeopointParser.parseLongitude(text)); + final Geopoint parsed = GeopointParser.parse(text); + this.latitude = parsed.latitude; + this.longitude = parsed.longitude; } /** @@ -68,7 +71,7 @@ public final class Geopoint implements ICoordinates, Parcelable { * latitude string to parse * @param lonText * longitude string to parse - * @throws GeopointParser.ParseException + * @throws Geopoint.ParseException * if any argument string cannot be parsed * @see GeopointParser.parse() */ @@ -315,6 +318,19 @@ public final class Geopoint implements ICoordinates, Parcelable { } } + public static class ParseException + extends GeopointException + { + private static final long serialVersionUID = 1L; + public final int resource; + + public ParseException(final String msg, final GeopointParser.LatLon faulty) + { + super(msg); + resource = faulty == GeopointParser.LatLon.LAT ? R.string.err_parse_lat : R.string.err_parse_lon; + } + } + public Double getElevation() { try { final String uri = "http://maps.googleapis.com/maps/api/elevation/json"; |