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

Method getInteger

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

369 * @throws IllegalArgumentException If value cannot be converted to int
370 */
371 public static Integer getInteger(Map<String, Object> map, String key) throws IllegalArgumentException {
372 Object value = map == null || key == null ? null : map.get(key);
373 if (value == null) {
374 return null;
375 }
376
377 if (value instanceof Number) {
378 return ((Number) value).intValue();
379 }
380
381 if (value instanceof String) {
382 try {
383 return Integer.parseInt((String) value);
384 } catch (NumberFormatException e) {
385 throw new IllegalArgumentException("Cannot convert String value '" + value + "' to int: " + e.getMessage());
386 }
387 }
388
389 throw new IllegalArgumentException("Cannot convert value of type " + value.getClass().getName() + " to int");
390 }
391
392 /**
393 * Get an int value from a Map

Callers 2

onArrayParseMethod · 0.80
onJoinParseMethod · 0.80

Calls 2

getMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected