diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-12-31 11:41:56 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-12-31 11:41:56 +1300 |
commit | 679c2852e3c4987091e0b84b7e7d80a9f72964a0 (patch) | |
tree | c0fe0ab222bbd251b25e3520c5f62c68669fbaa2 /src/org/traccar/geocoder | |
parent | 68569c05fb4be377baed5cd0ecb1b75176d24f01 (diff) | |
download | traccar-server-679c2852e3c4987091e0b84b7e7d80a9f72964a0.tar.gz traccar-server-679c2852e3c4987091e0b84b7e7d80a9f72964a0.tar.bz2 traccar-server-679c2852e3c4987091e0b84b7e7d80a9f72964a0.zip |
Add exception classes and more renames
Diffstat (limited to 'src/org/traccar/geocoder')
-rw-r--r-- | src/org/traccar/geocoder/BingMapsGeocoder.java (renamed from src/org/traccar/geocoder/BingMapsReverseGeocoder.java) | 4 | ||||
-rw-r--r-- | src/org/traccar/geocoder/FactualGeocoder.java (renamed from src/org/traccar/geocoder/FactualReverseGeocoder.java) | 4 | ||||
-rw-r--r-- | src/org/traccar/geocoder/GeocodeFarmGeocoder.java (renamed from src/org/traccar/geocoder/GeocodeFarmReverseGeocoder.java) | 6 | ||||
-rw-r--r-- | src/org/traccar/geocoder/Geocoder.java (renamed from src/org/traccar/geocoder/ReverseGeocoder.java) | 2 | ||||
-rw-r--r-- | src/org/traccar/geocoder/GeocoderException.java | 24 | ||||
-rw-r--r-- | src/org/traccar/geocoder/GisgraphyGeocoder.java (renamed from src/org/traccar/geocoder/GisgraphyReverseGeocoder.java) | 6 | ||||
-rw-r--r-- | src/org/traccar/geocoder/GoogleGeocoder.java (renamed from src/org/traccar/geocoder/GoogleReverseGeocoder.java) | 8 | ||||
-rw-r--r-- | src/org/traccar/geocoder/JsonGeocoder.java (renamed from src/org/traccar/geocoder/JsonReverseGeocoder.java) | 6 | ||||
-rw-r--r-- | src/org/traccar/geocoder/MapQuestGeocoder.java (renamed from src/org/traccar/geocoder/MapQuestReverseGeocoder.java) | 4 | ||||
-rw-r--r-- | src/org/traccar/geocoder/NominatimGeocoder.java (renamed from src/org/traccar/geocoder/NominatimReverseGeocoder.java) | 8 | ||||
-rw-r--r-- | src/org/traccar/geocoder/OpenCageGeocoder.java (renamed from src/org/traccar/geocoder/OpenCageReverseGeocoder.java) | 4 |
11 files changed, 50 insertions, 26 deletions
diff --git a/src/org/traccar/geocoder/BingMapsReverseGeocoder.java b/src/org/traccar/geocoder/BingMapsGeocoder.java index 46354d06a..a9b36219a 100644 --- a/src/org/traccar/geocoder/BingMapsReverseGeocoder.java +++ b/src/org/traccar/geocoder/BingMapsGeocoder.java @@ -18,9 +18,9 @@ package org.traccar.geocoder; import javax.json.JsonArray; import javax.json.JsonObject; -public class BingMapsReverseGeocoder extends JsonReverseGeocoder { +public class BingMapsGeocoder extends JsonGeocoder { - public BingMapsReverseGeocoder(String url, String key, int cacheSize) { + public BingMapsGeocoder(String url, String key, int cacheSize) { super(url + "/Locations/%f,%f?key=" + key + "&include=ciso2", cacheSize); } diff --git a/src/org/traccar/geocoder/FactualReverseGeocoder.java b/src/org/traccar/geocoder/FactualGeocoder.java index f1137893e..0c76e4625 100644 --- a/src/org/traccar/geocoder/FactualReverseGeocoder.java +++ b/src/org/traccar/geocoder/FactualGeocoder.java @@ -17,9 +17,9 @@ package org.traccar.geocoder; import javax.json.JsonObject; -public class FactualReverseGeocoder extends JsonReverseGeocoder { +public class FactualGeocoder extends JsonGeocoder { - public FactualReverseGeocoder(String url, String key, int cacheSize) { + public FactualGeocoder(String url, String key, int cacheSize) { super(url + "?latitude=%f&longitude=%f&KEY=" + key, cacheSize); } diff --git a/src/org/traccar/geocoder/GeocodeFarmReverseGeocoder.java b/src/org/traccar/geocoder/GeocodeFarmGeocoder.java index ca69a9026..585095606 100644 --- a/src/org/traccar/geocoder/GeocodeFarmReverseGeocoder.java +++ b/src/org/traccar/geocoder/GeocodeFarmGeocoder.java @@ -17,15 +17,15 @@ package org.traccar.geocoder; import javax.json.JsonObject; -public class GeocodeFarmReverseGeocoder extends JsonReverseGeocoder { +public class GeocodeFarmGeocoder extends JsonGeocoder { private static final String URL = "https://www.geocode.farm/v3/json/reverse/"; - public GeocodeFarmReverseGeocoder(int cacheSize) { + public GeocodeFarmGeocoder(int cacheSize) { super(URL + "?lat=%f&lon=%f&country=us&lang=en&count=1", cacheSize); } - public GeocodeFarmReverseGeocoder(String key, int cacheSize) { + public GeocodeFarmGeocoder(String key, int cacheSize) { super(URL + "?lat=%f&lon=%f&country=us&lang=en&count=1&key=" + key, cacheSize); } diff --git a/src/org/traccar/geocoder/ReverseGeocoder.java b/src/org/traccar/geocoder/Geocoder.java index 2f6d6d82b..3ce3fb67f 100644 --- a/src/org/traccar/geocoder/ReverseGeocoder.java +++ b/src/org/traccar/geocoder/Geocoder.java @@ -15,7 +15,7 @@ */ package org.traccar.geocoder; -public interface ReverseGeocoder { +public interface Geocoder { interface ReverseGeocoderCallback { diff --git a/src/org/traccar/geocoder/GeocoderException.java b/src/org/traccar/geocoder/GeocoderException.java new file mode 100644 index 000000000..608916641 --- /dev/null +++ b/src/org/traccar/geocoder/GeocoderException.java @@ -0,0 +1,24 @@ +/* + * Copyright 2016 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.geocoder; + +public class GeocoderException extends RuntimeException { + + public GeocoderException(String message) { + super(message); + } + +} diff --git a/src/org/traccar/geocoder/GisgraphyReverseGeocoder.java b/src/org/traccar/geocoder/GisgraphyGeocoder.java index b656120d9..1432166e9 100644 --- a/src/org/traccar/geocoder/GisgraphyReverseGeocoder.java +++ b/src/org/traccar/geocoder/GisgraphyGeocoder.java @@ -17,13 +17,13 @@ package org.traccar.geocoder; import javax.json.JsonObject; -public class GisgraphyReverseGeocoder extends JsonReverseGeocoder { +public class GisgraphyGeocoder extends JsonGeocoder { - public GisgraphyReverseGeocoder() { + public GisgraphyGeocoder() { this("http://services.gisgraphy.com/reversegeocoding/search", 0); } - public GisgraphyReverseGeocoder(String url, int cacheSize) { + public GisgraphyGeocoder(String url, int cacheSize) { super(url + "?format=json&lat=%f&lng=%f&from=1&to=1", cacheSize); } diff --git a/src/org/traccar/geocoder/GoogleReverseGeocoder.java b/src/org/traccar/geocoder/GoogleGeocoder.java index f644079d3..0506e701a 100644 --- a/src/org/traccar/geocoder/GoogleReverseGeocoder.java +++ b/src/org/traccar/geocoder/GoogleGeocoder.java @@ -19,17 +19,17 @@ import javax.json.JsonArray; import javax.json.JsonObject; import javax.json.JsonString; -public class GoogleReverseGeocoder extends JsonReverseGeocoder { +public class GoogleGeocoder extends JsonGeocoder { - public GoogleReverseGeocoder() { + public GoogleGeocoder() { this(0); } - public GoogleReverseGeocoder(int cacheSize) { + public GoogleGeocoder(int cacheSize) { super("http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f", cacheSize); } - public GoogleReverseGeocoder(String key, int cacheSize) { + public GoogleGeocoder(String key, int cacheSize) { super("https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&key=" + key, cacheSize); } diff --git a/src/org/traccar/geocoder/JsonReverseGeocoder.java b/src/org/traccar/geocoder/JsonGeocoder.java index 808b7c83f..6d1380729 100644 --- a/src/org/traccar/geocoder/JsonReverseGeocoder.java +++ b/src/org/traccar/geocoder/JsonGeocoder.java @@ -27,13 +27,13 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; -public abstract class JsonReverseGeocoder implements ReverseGeocoder { +public abstract class JsonGeocoder implements Geocoder { private final String url; private Map<Map.Entry<Double, Double>, String> cache; - public JsonReverseGeocoder(String url, final int cacheSize) { + public JsonGeocoder(String url, final int cacheSize) { this.url = url; if (cacheSize > 0) { this.cache = Collections.synchronizedMap(new LinkedHashMap<Map.Entry<Double, Double>, String>() { @@ -71,7 +71,7 @@ public abstract class JsonReverseGeocoder implements ReverseGeocoder { } callback.onSuccess(formattedAddress); } else { - callback.onFailure(new IllegalArgumentException("Empty address")); + callback.onFailure(new GeocoderException("Empty address")); } } return null; diff --git a/src/org/traccar/geocoder/MapQuestReverseGeocoder.java b/src/org/traccar/geocoder/MapQuestGeocoder.java index 9c0a0e891..7d7217e91 100644 --- a/src/org/traccar/geocoder/MapQuestReverseGeocoder.java +++ b/src/org/traccar/geocoder/MapQuestGeocoder.java @@ -18,9 +18,9 @@ package org.traccar.geocoder; import javax.json.JsonArray; import javax.json.JsonObject; -public class MapQuestReverseGeocoder extends JsonReverseGeocoder { +public class MapQuestGeocoder extends JsonGeocoder { - public MapQuestReverseGeocoder(String url, String key, int cacheSize) { + public MapQuestGeocoder(String url, String key, int cacheSize) { super(url + "?key=" + key + "&location=%f,%f", cacheSize); } diff --git a/src/org/traccar/geocoder/NominatimReverseGeocoder.java b/src/org/traccar/geocoder/NominatimGeocoder.java index faeaf247f..b0ee39c6a 100644 --- a/src/org/traccar/geocoder/NominatimReverseGeocoder.java +++ b/src/org/traccar/geocoder/NominatimGeocoder.java @@ -17,17 +17,17 @@ package org.traccar.geocoder; import javax.json.JsonObject; -public class NominatimReverseGeocoder extends JsonReverseGeocoder { +public class NominatimGeocoder extends JsonGeocoder { - public NominatimReverseGeocoder() { + public NominatimGeocoder() { this("http://nominatim.openstreetmap.org/reverse", 0); } - public NominatimReverseGeocoder(String url, int cacheSize) { + public NominatimGeocoder(String url, int cacheSize) { super(url + "?format=json&lat=%f&lon=%f&zoom=18&addressdetails=1", cacheSize); } - public NominatimReverseGeocoder(String url, String key, int cacheSize) { + public NominatimGeocoder(String url, String key, int cacheSize) { super(url + "?format=json&lat=%f&lon=%f&zoom=18&addressdetails=1&key=" + key, cacheSize); } diff --git a/src/org/traccar/geocoder/OpenCageReverseGeocoder.java b/src/org/traccar/geocoder/OpenCageGeocoder.java index a913a9288..9fa56a4a3 100644 --- a/src/org/traccar/geocoder/OpenCageReverseGeocoder.java +++ b/src/org/traccar/geocoder/OpenCageGeocoder.java @@ -19,9 +19,9 @@ package org.traccar.geocoder; import javax.json.JsonArray; import javax.json.JsonObject; -public class OpenCageReverseGeocoder extends JsonReverseGeocoder { +public class OpenCageGeocoder extends JsonGeocoder { - public OpenCageReverseGeocoder(String url, String key, int cacheSize) { + public OpenCageGeocoder(String url, String key, int cacheSize) { super(url + "/json?q=%f,%f&key=" + key, cacheSize); } |