[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge pull request #9 from wordpress-mobile/issue/default-value-types
Browse files Browse the repository at this point in the history
Matching type of defaultValue to the method return type
  • Loading branch information
aforcier committed Sep 6, 2016
2 parents 62c3515 + 54e9c48 commit ff55402
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 ff55402

Please sign in to comment.