01: /*
02: * OctalParamType.java
03: *
04: * Copyright (C) 2008 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 octal number parameter type.
26: *
27: * @see java.lang.Byte#valueOf(String, int)
28: * @author Ferran Busquets
29: *
30: */
31: public class OctalParamType implements IParameterType {
32:
33: /* (non-Javadoc)
34: * @see org.naturalcli.paramtypes.IParameterType#getParameterTypeName()
35: */
36: @Override
37: public String getParameterTypeName() {
38: return "octal";
39: }
40:
41: /* (non-Javadoc)
42: * @see org.naturalcli.paramtypes.IParameterType#validateParameter(java.lang.String)
43: */
44: @Override
45: public boolean validateParameter(String value) {
46: try {
47: Integer.valueOf(value, 8);
48: return true;
49: } catch (NumberFormatException e) {
50: return false;
51: }
52: }
53:
54: /* (non-Javadoc)
55: * @see org.naturalcli.paramtypes.IParameterType#validationMessage(java.lang.String)
56: */
57: @Override
58: public String validationMessage(String value) {
59: return this .validateParameter(value) ? null : "Bad octal.";
60: }
61:
62: /* (non-Javadoc)
63: * @see org.naturalcli.paramtypes.IParameterType#convertParameterValue(java.lang.String)
64: */
65: @Override
66: public Object convertParameterValue(String strRepresentation) {
67: return Integer.valueOf(strRepresentation, 8);
68: }
69: }
|