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

Method getLongValue

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

Get a long value from a Map @param map Source map @param key The key @return The long value @throws IllegalArgumentException If value cannot be converted to long

(Map<String, Object> map, String key)

Source from the content-addressed store, hash-verified

453 * @throws IllegalArgumentException If value cannot be converted to long
454 */
455 public static long getLongValue(Map<String, Object> map, String key) throws IllegalArgumentException {
456 Object value = map == null || key == null ? null : map.get(key);
457 if (value == null) {
458 return 0;
459 }
460
461 if (value instanceof Number) {
462 return ((Number) value).longValue();
463 }
464
465 if (value instanceof String) {
466 try {
467 return Long.parseLong((String) value);
468 } catch (NumberFormatException e) {
469 throw new IllegalArgumentException("Cannot convert String value '" + value + "' to long: " + e.getMessage());
470 }
471 }
472
473 throw new IllegalArgumentException("Cannot convert value of type " + value.getClass().getName() + " to long");
474 }
475
476 /**
477 * 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