Get an int value from a Map @param map Source map @param key The key @return The int value @throws IllegalArgumentException If value cannot be converted to int
(Map<String, Object> map, String key)
| 425 | * @throws IllegalArgumentException If value cannot be converted to int |
| 426 | */ |
| 427 | public static Long getLong(Map<String, Object> map, String key) throws IllegalArgumentException { |
| 428 | Object value = map == null || key == null ? null : map.get(key); |
| 429 | if (value == null) { |
| 430 | return null; |
| 431 | } |
| 432 | |
| 433 | if (value instanceof Number) { |
| 434 | return ((Number) value).longValue(); |
| 435 | } |
| 436 | |
| 437 | if (value instanceof String) { |
| 438 | try { |
| 439 | return Long.parseLong((String) value); |
| 440 | } catch (NumberFormatException e) { |
| 441 | throw new IllegalArgumentException("Cannot convert String value '" + value + "' to int: " + e.getMessage()); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | throw new IllegalArgumentException("Cannot convert value of type " + value.getClass().getName() + " to int"); |
| 446 | } |
| 447 | |
| 448 | /** |
| 449 | * Get a long value from a Map |
no test coverage detected