Skip to content

Commit 2892e26

Browse files
committed
New MapUtils.getMapDouble/getMapFloat methods
1 parent acc6a07 commit 2892e26

File tree

1 file changed

+22
-0
lines changed
  • WordPressUtils/src/main/java/org/wordpress/android/util

1 file changed

+22
-0
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/MapUtils.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ public static long getMapLong(final Map<?, ?> map, final String key, long defaul
4747
}
4848
}
4949

50+
public static float getMapFloat(final Map<?, ?> map, final String key) {
51+
return getMapFloat(map, key, 0);
52+
}
53+
public static float getMapFloat(final Map<?, ?> map, final String key, long defaultValue) {
54+
try {
55+
return Float.parseFloat(getMapStr(map, key));
56+
} catch (NumberFormatException e) {
57+
return defaultValue;
58+
}
59+
}
60+
61+
public static double getMapDouble(final Map<?, ?> map, final String key) {
62+
return getMapDouble(map, key, 0);
63+
}
64+
public static double getMapDouble(final Map<?, ?> map, final String key, long defaultValue) {
65+
try {
66+
return Double.parseDouble(getMapStr(map, key));
67+
} catch (NumberFormatException e) {
68+
return defaultValue;
69+
}
70+
}
71+
5072
/*
5173
* returns a date object from the passed key in the passed map
5274
* returns null if key doesn't exist or isn't a date

0 commit comments

Comments
 (0)