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

Method getDouble

APIJSONORM/src/main/java/apijson/JSON.java:540–559  ·  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

538 * @throws IllegalArgumentException If value cannot be converted to double
539 */
540 public static Double getDouble(Map<String, Object> map, String key) throws IllegalArgumentException {
541 Object value = map == null || key == null ? null : map.get(key);
542 if (value == null) {
543 return null;
544 }
545
546 if (value instanceof Number) {
547 return ((Number) value).doubleValue();
548 }
549
550 if (value instanceof String) {
551 try {
552 return Double.parseDouble((String) value);
553 } catch (NumberFormatException e) {
554 throw new IllegalArgumentException("Cannot convert String value '" + value + "' to double: " + e.getMessage());
555 }
556 }
557
558 throw new IllegalArgumentException("Cannot convert value of type " + value.getClass().getName() + " to double");
559 }
560
561 /**
562 * Get a double value from a Map

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected