diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-15 14:21:08 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-15 14:21:08 +1300 |
commit | d9f6e0fa8ae131574436cf4375d7feb2d7ff76a7 (patch) | |
tree | ebf3e4762d01410b5b30cf9ed45a67eccc4cea69 /src/org/traccar/helper | |
parent | b43f9ae73b1d9f36e5a3ca5de138c696d3109de8 (diff) | |
download | trackermap-server-d9f6e0fa8ae131574436cf4375d7feb2d7ff76a7.tar.gz trackermap-server-d9f6e0fa8ae131574436cf4375d7feb2d7ff76a7.tar.bz2 trackermap-server-d9f6e0fa8ae131574436cf4375d7feb2d7ff76a7.zip |
Clean up some text protocols
Diffstat (limited to 'src/org/traccar/helper')
-rw-r--r-- | src/org/traccar/helper/Parser.java | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/src/org/traccar/helper/Parser.java b/src/org/traccar/helper/Parser.java index e89104094..2fd615ca5 100644 --- a/src/org/traccar/helper/Parser.java +++ b/src/org/traccar/helper/Parser.java @@ -20,7 +20,7 @@ import java.util.regex.Pattern; public class Parser { - private int position = 1; + private int position; private Matcher matcher; public Parser(Pattern pattern, String input) { @@ -28,9 +28,15 @@ public class Parser { } public boolean matches() { + position = 1; return matcher.matches(); } + public boolean find() { + position = 1; + return matcher.find(); + } + public boolean hasNext() { if (matcher.group(position) != null) { return true; @@ -64,15 +70,37 @@ public class Parser { } } - // Format: (degrees)(minutes)(hemisphere) - public double nextCoordinate() { - double coordinate = nextDouble(); - coordinate += nextDouble() / 60; - String hemisphere = next(); - if (hemisphere.equals("S") || hemisphere.equals("W")) { + public enum CoordinateFormat { + DEG_MIN_HEM, + HEM_DEG + } + + public double nextCoordinate(CoordinateFormat format) { + double coordinate; + String hemisphere; + + switch (format) { + case HEM_DEG: + hemisphere = next(); + coordinate = nextDouble(); + break; + case DEG_MIN_HEM: + default: + coordinate = nextDouble(); + coordinate += nextDouble() / 60; + hemisphere = next(); + break; + } + + if (hemisphere != null && (hemisphere.equals("S") || hemisphere.equals("W"))) { coordinate = -coordinate; } + return coordinate; } + public double nextCoordinate() { + return nextCoordinate(CoordinateFormat.DEG_MIN_HEM); + } + } |