01: /*
02: * $Id: IntegerConverter.java 457783 2005-10-02 10:06:33Z jcompagner $
03: * $Revision: 457783 $ $Date: 2005-10-02 12:06:33 +0200 (Sun, 02 Oct 2005) $
04: *
05: * ==============================================================================
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07: * use this file except in compliance with the License. You may obtain a copy of
08: * the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.util.convert.converters;
19:
20: import java.util.Locale;
21:
22: import wicket.util.convert.ITypeConverter;
23:
24: /**
25: * Converts from Object to Integer.
26: *
27: * @author Eelco Hillenius
28: * @author Jonathan Locke
29: */
30: public final class IntegerConverter extends AbstractIntegerConverter {
31: private static final long serialVersionUID = 1L;
32:
33: /**
34: * The singleton instance for a integer converter
35: */
36: public static final ITypeConverter INSTANCE = new IntegerConverter();
37:
38: /**
39: * @see wicket.util.convert.ITypeConverter#convert(java.lang.Object,java.util.Locale)
40: */
41: public Object convert(final Object value, Locale locale) {
42: final Number number = value instanceof Number ? (Number) value
43: : parse(value, Integer.MIN_VALUE, Integer.MAX_VALUE,
44: locale);
45:
46: if (number == null) {
47: return null;
48: }
49:
50: return new Integer(number.intValue());
51: }
52:
53: /**
54: * @see wicket.util.convert.converters.AbstractConverter#getTargetType()
55: */
56: protected Class getTargetType() {
57: return Integer.class;
58: }
59: }
|