summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnil Dahiya <anil_dahiya@infosys.com>2016-10-25 14:00:41 +0530
committerAnil Dahiya <anil_dahiya@infosys.com>2016-10-25 14:00:41 +0530
commit7951e1c6cdfca1b4af084e33bbff97b965177e75 (patch)
tree45c4b27c5ccc39f5c3434a08007a90556de86bfc
parent9015487d2f878691b9e1312875b95e2d5ec0063e (diff)
downloadsdl_android-feature/last_mile_navigation.tar.gz
Changes for having lat and long in Coordinate as Float instead of Double.feature/last_mile_navigation
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/proxy/rpc/Coordinate.java12
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/util/SdlDataTypeConverter.java53
2 files changed, 47 insertions, 18 deletions
diff --git a/sdl_android_lib/src/com/smartdevicelink/proxy/rpc/Coordinate.java b/sdl_android_lib/src/com/smartdevicelink/proxy/rpc/Coordinate.java
index b1fe5eeb6..7e899168c 100644
--- a/sdl_android_lib/src/com/smartdevicelink/proxy/rpc/Coordinate.java
+++ b/sdl_android_lib/src/com/smartdevicelink/proxy/rpc/Coordinate.java
@@ -16,12 +16,12 @@ public class Coordinate extends RPCStruct{
super(hash);
}
- public Double getLatitudeDegrees() {
+ public Float getLatitudeDegrees() {
Object value = store.get(KEY_LATITUDE_DEGREES);
- return SdlDataTypeConverter.objectToDouble(value);
+ return SdlDataTypeConverter.objectToFloat(value);
}
- public void setLatitudeDegrees(Double latitudeDegrees) {
+ public void setLatitudeDegrees(Float latitudeDegrees) {
if (latitudeDegrees != null) {
store.put(KEY_LATITUDE_DEGREES, latitudeDegrees);
} else {
@@ -29,12 +29,12 @@ public class Coordinate extends RPCStruct{
}
}
- public Double getLongitudeDegrees() {
+ public Float getLongitudeDegrees() {
Object value = store.get(KEY_LONGITUDE_DEGREES);
- return SdlDataTypeConverter.objectToDouble(value);
+ return SdlDataTypeConverter.objectToFloat(value);
}
- public void setLongitudeDegrees(Double longitudeDegrees) {
+ public void setLongitudeDegrees(Float longitudeDegrees) {
if (longitudeDegrees != null) {
store.put(KEY_LONGITUDE_DEGREES, longitudeDegrees);
} else {
diff --git a/sdl_android_lib/src/com/smartdevicelink/util/SdlDataTypeConverter.java b/sdl_android_lib/src/com/smartdevicelink/util/SdlDataTypeConverter.java
index fa958596e..0b47a59cd 100644
--- a/sdl_android_lib/src/com/smartdevicelink/util/SdlDataTypeConverter.java
+++ b/sdl_android_lib/src/com/smartdevicelink/util/SdlDataTypeConverter.java
@@ -14,21 +14,50 @@ public class SdlDataTypeConverter {
* the Object, or null if the value could not be converted.
*/
public static Double objectToDouble(Object originalValue) {
-
- if (originalValue == null) {
- return null;
- }
-
+
+ if (originalValue == null) {
+ return null;
+ }
+
Double result = null;
-
+
// Uses reflection to determine if the object is a valid type.
- if (originalValue instanceof Integer) {
- result = ((Integer) originalValue).doubleValue();
- } else if (originalValue instanceof Double){
+ if (originalValue instanceof Integer) {
+ result = ((Integer) originalValue).doubleValue();
+ } else if (originalValue instanceof Float){
+ result = ((Float) originalValue).doubleValue();
+ } else if (originalValue instanceof Double){
result = (Double) originalValue;
}
-
- return result;
- }
+ return result;
+ }
+
+ /**
+ * Converts values that are retrieved from an RPC parameters Hashtable as an
+ * Object into the standard number value of the mobile API, Float.
+ *
+ * @param originalValue The value retrieved from an RPC parameters Hashtable.
+ * @return The Float representation of an integer or float value stored in
+ * the Object, or null if the value could not be converted.
+ */
+ public static Float objectToFloat(Object originalValue) {
+
+ if (originalValue == null) {
+ return null;
+ }
+
+ Float result = null;
+
+ // Uses reflection to determine if the object is a valid type.
+ if (originalValue instanceof Integer) {
+ result = ((Integer) originalValue).floatValue();
+ } else if (originalValue instanceof Double){
+ result = ((Double) originalValue).floatValue();
+ } else if (originalValue instanceof Float){
+ result = (Float) originalValue;
+ }
+
+ return result;
+ }
}