1 | long getLongParameter(String name) throws NumberFormatException {↵ | | 1 | int getIntParameter(String name) throws NumberFormatException {↵
|
2 | if (params == null || !params.containsKey(name)) {↵ | | 2 | if (params == null || !params.containsKey(name)) {↵
|
3 | throw new NumberFormatException("No value for parameter named '" + name + "'.");↵ | | 3 | throw new NumberFormatException("No value for parameter named '" + name + "'.");↵
|
4 | }↵ | | 4 | }↵
|
|
5 | return Long.decode((String) params.get(name)).longValue();↵ | | 5 | return Integer.decode((String) params.get(name)).intValue();↵
|
6 | }↵ | | 6 | }↵
|
|
7 | /**↵ | | 7 | /**↵
|
8 | * Get the value of a specified parameter as along, or return the↵ | | 8 | * Get the value of a specified parameter as an integer, or return the↵
|
9 | specified↵ | | 9 | * specified↵
|
10 | * default value if the value was not specified or is not a long↵ | | 10 | default value if the value was not specified or is not an↵
|
11 | . A warning↵ | | 11 | * integer. A warning↵
|
12 | * will be logged if the value is not a long. The↵ | | 12 | will be logged if the value is not an integer. The↵
|
13 | value may be specified in↵ | | 13 | * value may be specified in↵
|
14 | * decimal, hexadecimal, or octal, as defined by Long↵ | | 14 | decimal, hexadecimal, or octal, as defined by↵
|
15 | .decode().↵ | | 15 | * Integer.decode().↵
|
16 | * ↵ | | 16 | * ↵
|
17 | * @param name↵ | | 17 | * @param name↵
|
18 | * the name of the parameter whose value should be retrieved↵ | | 18 | * the name of the parameter whose value should be retrieved↵
|
19 | * @param defaultValue↵ | | 19 | * @param defaultValue↵
|
20 | * the default value to return if the value of this parameter was↵ | | 20 | * the default value to return if the value of this parameter was↵
|
21 | * not specified↵ | | 21 | * not specified↵
|
22 | * @return the value of the parameter, or the default value if the parameter↵ | | 22 | * @return the value of the parameter, or the default value if the parameter↵
|
23 | * was not specified↵ | | 23 | * was not specified↵
|
24 | * ↵ | | 24 | * ↵
|
25 | * @see Long#decode(String)↵ | | 25 | * @see java.lang.Integer#decode(java.lang.String)↵
|
26 | */↵ | | 26 | */↵
|
27 | public long getLongParameter(String name, long defaultValue) {↵ | | 27 | public int getIntParameter(String name, int defaultValue) {↵
|
28 | if (params == null || !params.containsKey(name)) {↵ | | 28 | if (params == null || !params.containsKey(name)) {↵
|
29 | return defaultValue;↵ | | 29 | return defaultValue;↵
|
30 | }↵ | | 30 | }↵
|
|
31 | try {↵ | | 31 | try {↵
|
32 | return Long.decode((String) params.get(name)).longValue();↵ | | 32 | return Integer.decode((String) params.get(name)).intValue();↵
|
33 | } catch (NumberFormatException e) {↵ | | 33 | } catch (NumberFormatException e) {↵
|
34 | log.warn("Value for parameter '" + name + "' not a long: '" + params.get(name) + "'. Using default: '"↵ | | 34 | log.warn("Value for parameter '" + name + "' not an integer: '" + params.get(name) + "'. Using default: '"↵
|
35 | + defaultValue + "'.", e);↵ | | 35 | + defaultValue + "'.", e);↵
|
36 | return defaultValue;↵ | | 36 | return defaultValue;↵
|
37 | }↵ | | 37 | }↵
|
38 | | | 38 |
|