Skip to content

Commit

Permalink
Converting type of default value for float/double map getters
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyr59h committed Sep 6, 2016
1 parent 62c3515 commit 54e9c48
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,27 @@ public static long getMapLong(final Map<?, ?> map, final String key, long defaul
}
}

/*
* float version of above
*/
public static float getMapFloat(final Map<?, ?> map, final String key) {
return getMapFloat(map, key, 0);
}
public static float getMapFloat(final Map<?, ?> map, final String key, long defaultValue) {
public static float getMapFloat(final Map<?, ?> map, final String key, float defaultValue) {
try {
return Float.parseFloat(getMapStr(map, key));
} catch (NumberFormatException e) {
return defaultValue;
}
}

/*
* double version of above
*/
public static double getMapDouble(final Map<?, ?> map, final String key) {
return getMapDouble(map, key, 0);
}
public static double getMapDouble(final Map<?, ?> map, final String key, long defaultValue) {
public static double getMapDouble(final Map<?, ?> map, final String key, double defaultValue) {
try {
return Double.parseDouble(getMapStr(map, key));
} catch (NumberFormatException e) {
Expand All @@ -74,7 +80,7 @@ public static double getMapDouble(final Map<?, ?> map, final String key, long de
* returns null if key doesn't exist or isn't a date
*/
public static Date getMapDate(final Map<?, ?> map, final String key) {
if (map==null || key==null || !map.containsKey(key))
if (map == null || key == null || !map.containsKey(key))
return null;
try {
return (Date) map.get(key);
Expand Down

0 comments on commit 54e9c48

Please sign in to comment.