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

Method getFloatValue

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

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 /**

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected