Get a double value from a Map @param map Source map @param key The key @return The double value @throws IllegalArgumentException If value cannot be converted to double
(Map<String, Object> map, String key)
| 509 | * @throws IllegalArgumentException If value cannot be converted to double |
| 510 | */ |
| 511 | public static float getFloatValue(Map<String, Object> map, String key) throws IllegalArgumentException { |
| 512 | Object value = map == null || key == null ? null : map.get(key); |
| 513 | if (value == null) { |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | if (value instanceof Number) { |
| 518 | return ((Number) value).floatValue(); |
| 519 | } |
| 520 | |
| 521 | if (value instanceof String) { |
| 522 | try { |
| 523 | return Float.parseFloat((String) value); |
| 524 | } catch (NumberFormatException e) { |
| 525 | throw new IllegalArgumentException("Cannot convert String value '" + value + "' to double: " + e.getMessage()); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | throw new IllegalArgumentException("Cannot convert value of type " + value.getClass().getName() + " to double"); |
| 530 | } |
| 531 | |
| 532 | |
| 533 | /** |