/** * Looks up the given key in the given map, converting the result into * an integer, using the default value if the conversion fails. * * @param <K> the key type * @param map the map whose value to look up * @param key the key of the value to look up in that map * @param defaultValue what to return if the value is null or if the * conversion fails * @return the value in the map as a number, or defaultValue if the * original value is null, the map is null or the number conversion fails */ public static <K> Integer getInteger(final Map<? super K, ?> map, final K key, final Integer defaultValue) { Integer answer = getInteger(map, key); if (answer == null) { answer = defaultValue; } return answer; }
/** * Gets an int from a Map in a null-safe manner. * <p> * The int is obtained from the results of {@link #getNumber(Map,Object)}. * * @param <K> the key type * @param map the map to use * @param key the key to look up * @return the value in the Map as an int, <code>0</code> if null map input */ public static <K> int getIntValue(final Map<? super K, ?> map, final K key) { final Integer integerObject = getInteger(map, key); if (integerObject == null) { return 0; } return integerObject.intValue(); }
/** * Gets an int from a Map in a null-safe manner, * using the default value if the conversion fails. * <p> * The int is obtained from the results of {@link #getNumber(Map,Object)}. * * @param <K> the key type * @param map the map to use * @param key the key to look up * @param defaultValue return if the value is null or if the conversion fails * @return the value in the Map as an int, <code>defaultValue</code> if null map input */ public static <K> int getIntValue(final Map<? super K, ?> map, final K key, final int defaultValue) { final Integer integerObject = getInteger(map, key); if (integerObject == null) { return defaultValue; } return integerObject.intValue(); }
/** * @param context * @param viewIndexName * @param defaultValue * @return value of viewIndexName in context map (as an int) or return defaultValue */ public static Integer getViewIndex(final Map<String, ? extends Object> context, final String viewIndexName, final int defaultValue) { return MapUtils.getInteger(context, viewIndexName, defaultValue); }
/** * @param context * @param viewSizeName * @return value of viewSizeName in context map (as an int) or return * default value from widget.properties */ public static Integer getViewSize(Map<String, ? extends Object> context, String viewSizeName) { int defaultSize = UtilProperties.getPropertyAsInteger("widget", "widget.form.defaultViewSize", 20); if (context.containsKey(viewSizeName)) { return MapUtils.getInteger(context, viewSizeName, defaultSize); } return defaultSize; }