01: /*
02: * IntegerParamType.java
03: *
04: * Copyright (C) 2007 Ferran Busquets
05: *
06: * This program is free software: you can redistribute it and/or modify
07: * it under the terms of the GNU General Public License as published by
08: * the Free Software Foundation, either version 3 of the License, or
09: * any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program. If not, see <http://www.gnu.org/licenses/>.
18: *
19: */
20: package org.naturalcli.parameters;
21:
22: import org.naturalcli.IParameterType;
23:
24: /**
25: * The class implements an integer parameter type.
26: *
27: * @author Ferran Busquets
28: *
29: */
30: public class IntegerParamType implements IParameterType {
31:
32: /* (non-Javadoc)
33: * @see org.naturalcli.paramtypes.IParameterType#getParameterTypeName()
34: */
35: @Override
36: public String getParameterTypeName() {
37: return "integer";
38: }
39:
40: /* (non-Javadoc)
41: * @see org.naturalcli.paramtypes.IParameterType#validateParameter(java.lang.String)
42: */
43: @Override
44: public boolean validateParameter(String value) {
45: try {
46: Integer.valueOf(value);
47: return true;
48: } catch (NumberFormatException e) {
49: return false;
50: }
51: }
52:
53: /* (non-Javadoc)
54: * @see org.naturalcli.paramtypes.IParameterType#validationMessage(java.lang.String)
55: */
56: @Override
57: public String validationMessage(String value) {
58: return this .validateParameter(value) ? null : "Bad integer.";
59: }
60:
61: /* (non-Javadoc)
62: * @see org.naturalcli.paramtypes.IParameterType#convertParameterValue(java.lang.String)
63: */
64: @Override
65: public Object convertParameterValue(String strRepresentation) {
66: return new Integer(strRepresentation);
67: }
68: }
|