MCPcopy Index your code
hub / github.com/Tencent/APIJSON / getDoubleValue

Method getDoubleValue

APIJSONORM/src/main/java/apijson/JSON.java:568–587  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

566 * @throws IllegalArgumentException If value cannot be converted to double
567 */
568 public static double getDoubleValue(Map<String, Object> map, String key) throws IllegalArgumentException {
569 Object value = map == null || key == null ? null : map.get(key);
570 if (value == null) {
571 return 0;
572 }
573
574 if (value instanceof Number) {
575 return ((Number) value).doubleValue();
576 }
577
578 if (value instanceof String) {
579 try {
580 return Double.parseDouble((String) value);
581 } catch (NumberFormatException e) {
582 throw new IllegalArgumentException("Cannot convert String value '" + value + "' to double: " + e.getMessage());
583 }
584 }
585
586 throw new IllegalArgumentException("Cannot convert value of type " + value.getClass().getName() + " to double");
587 }
588
589
590 /**

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected