aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSammysHP <sven@sammyshp.de>2011-09-16 14:16:25 +0200
committerSammysHP <sven@sammyshp.de>2011-09-16 14:16:25 +0200
commit96ea21fd50334479c262da692038965d0e4d596a (patch)
tree170b8bdf71e4f649e13ed609ceaa4e372b3f1e64
parent064c8489851040a43e4cbce36e7151377b9940f5 (diff)
downloadcgeo-96ea21fd50334479c262da692038965d0e4d596a.zip
cgeo-96ea21fd50334479c262da692038965d0e4d596a.tar.gz
cgeo-96ea21fd50334479c262da692038965d0e4d596a.tar.bz2
Avoid cast from float to double and improve regex.
-rw-r--r--src/cgeo/geocaching/geopoint/GeopointParser.java19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/cgeo/geocaching/geopoint/GeopointParser.java b/src/cgeo/geocaching/geopoint/GeopointParser.java
index 7a1d87b..aef054e 100644
--- a/src/cgeo/geocaching/geopoint/GeopointParser.java
+++ b/src/cgeo/geocaching/geopoint/GeopointParser.java
@@ -13,8 +13,9 @@ import java.util.regex.Pattern;
*/
public class GeopointParser
{
- private static final Pattern patternLat = Pattern.compile("([NS])\\s*(\\d+)°?(\\s*(\\d+)([\\.,](\\d+)|'?\\s*(\\d+)(''|\")?)?)?", Pattern.CASE_INSENSITIVE);
- private static final Pattern patternLon = Pattern.compile("([WE])\\s*(\\d+)°?(\\s*(\\d+)([\\.,](\\d+)|'?\\s*(\\d+)(''|\")?)?)?", Pattern.CASE_INSENSITIVE);
+ // ( 1 ) ( 2 ) ( 3 ) ( 4 ) ( 5 )
+ private static final Pattern patternLat = Pattern.compile("([NS])\\s*(\\d+)°?(?:\\s*(\\d+)(?:[\\.,](\\d+)|'?\\s*(\\d+(?:[\\.,]\\d+)?)(?:''|\")?)?)?", Pattern.CASE_INSENSITIVE);
+ private static final Pattern patternLon = Pattern.compile("([WE])\\s*(\\d+)°?(?:\\s*(\\d+)(?:[\\.,](\\d+)|'?\\s*(\\d+(?:[\\.,]\\d+)?)(?:''|\")?)?)?", Pattern.CASE_INSENSITIVE);
private enum LatLon
{
@@ -98,17 +99,17 @@ public class GeopointParser
int minutes = 0;
double seconds = 0;
- if (null != matcher.group(4)) {
- minutes = Integer.parseInt(matcher.group(4));
+ if (null != matcher.group(3)) {
+ minutes = Integer.parseInt(matcher.group(3));
- if (null != matcher.group(6)) {
- seconds = Float.parseFloat("0." + matcher.group(6)) * 60;
- } else if (null != matcher.group(7)) {
- seconds = Integer.parseInt(matcher.group(7));
+ if (null != matcher.group(4)) {
+ seconds = Double.parseDouble("0." + matcher.group(4)) * 60;
+ } else if (null != matcher.group(5)) {
+ seconds = Double.parseDouble(matcher.group(5));
}
}
- return (double) sign * ((double) degree + (double) minutes / 60 + (double) seconds / 3600);
+ return (double) sign * ((double) degree + (double) minutes / 60 + seconds / 3600);
} else {