Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit 4d85c6d

Browse files
authored
Query: Expose parseLatLng method (#135)
* Query: Expose parseLatLng method * Query: Make parseLatLng static
1 parent bd71892 commit 4d85c6d

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Change Log
22
==========
33

4+
## Next version
5+
6+
- Expose parseLatLng method
7+
48
## 3.4.0 (2016-09-05)
59

610
- Implement new user-agent convention

algoliasearch/src/main/java/com/algolia/search/saas/Query.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,7 @@ public int hashCode() {
261261
}
262262

263263
public LatLng getAroundLatLng() {
264-
String value = get(KEY_AROUND_LAT_LNG);
265-
if (value == null) {
266-
return null;
267-
}
268-
String[] components = value.split(",");
269-
if (components.length != 2) {
270-
return null;
271-
}
272-
try {
273-
return new LatLng(Double.valueOf(components[0]), Double.valueOf(components[1]));
274-
} catch (NumberFormatException e) {
275-
return null;
276-
}
264+
return parseLatLng(get(KEY_AROUND_LAT_LNG));
277265
}
278266

279267
private static final String KEY_AROUND_LAT_LNG_VIA_IP = "aroundLatLngViaIP";
@@ -1230,6 +1218,26 @@ private static String[] parseCommaArray(String string) {
12301218
return string == null ? null : string.split(",");
12311219
}
12321220

1221+
/**
1222+
* Parse a LatLng from its String equivalent.
1223+
* @param value a String containing latitude/longitude.
1224+
* @return a LatLng object describing the given value.
1225+
*/
1226+
@Nullable public static LatLng parseLatLng(String value) {
1227+
if (value == null) {
1228+
return null;
1229+
}
1230+
String[] components = value.split(",");
1231+
if (components.length != 2) {
1232+
return null;
1233+
}
1234+
try {
1235+
return new LatLng(Double.valueOf(components[0]), Double.valueOf(components[1]));
1236+
} catch (NumberFormatException e) {
1237+
return null;
1238+
}
1239+
}
1240+
12331241
// ----------------------------------------------------------------------
12341242
// Low-level (untyped) accessors
12351243
// ----------------------------------------------------------------------

0 commit comments

Comments
 (0)