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

Method getIntValue

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

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)

Source from the content-addressed store, hash-verified

397 * @throws IllegalArgumentException If value cannot be converted to int
398 */
399 public static int getIntValue(Map<String, Object> map, String key) throws IllegalArgumentException {
400 Object value = map == null || key == null ? null : map.get(key);
401 if (value == null) {
402 return 0;
403 }
404
405 if (value instanceof Number) {
406 return ((Number) value).intValue();
407 }
408
409 if (value instanceof String) {
410 try {
411 return Integer.parseInt((String) value);
412 } catch (NumberFormatException e) {
413 throw new IllegalArgumentException("Cannot convert String value '" + value + "' to int: " + e.getMessage());
414 }
415 }
416
417 throw new IllegalArgumentException("Cannot convert value of type " + value.getClass().getName() + " to int");
418 }
419
420 /**
421 * Get an int value from a Map

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected