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)
| 481 | * @throws IllegalArgumentException If value cannot be converted to double |
| 482 | */ |
| 483 | public static Float getFloat(Map<String, Object> map, String key) throws IllegalArgumentException { |
| 484 | Object value = map == null || key == null ? null : map.get(key); |
| 485 | if (value == null) { |
| 486 | return null; |
| 487 | } |
| 488 | |
| 489 | if (value instanceof Number) { |
| 490 | return ((Number) value).floatValue(); |
| 491 | } |
| 492 | |
| 493 | if (value instanceof String) { |
| 494 | try { |
| 495 | return Float.parseFloat((String) value); |
| 496 | } catch (NumberFormatException e) { |
| 497 | throw new IllegalArgumentException("Cannot convert String value '" + value + "' to double: " + e.getMessage()); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | throw new IllegalArgumentException("Cannot convert value of type " + value.getClass().getName() + " to double"); |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * Get a double value from a Map |