78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2007 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 ******************************************************************************/
|
|
11
|
|
12 module org.eclipse.core.internal.databinding.conversion.NumberToIntegerConverter;
|
|
13
|
|
14 import java.lang.all;
|
|
15
|
|
16 import org.eclipse.core.databinding.conversion.IConverter;
|
|
17
|
|
18 import com.ibm.icu.text.NumberFormat;
|
|
19
|
|
20 /**
|
|
21 * Converts from a Number to a Integer.
|
|
22 * <p>
|
|
23 * Class is thread safe.
|
|
24 * </p>
|
|
25 * @since 1.0
|
|
26 */
|
|
27 public class NumberToIntegerConverter : NumberToNumberConverter ,
|
|
28 IConverter {
|
|
29
|
|
30 /**
|
|
31 * @param numberFormat
|
|
32 * @param fromType
|
|
33 * @param primitive
|
|
34 */
|
|
35 public this(NumberFormat numberFormat,
|
|
36 ClassInfo fromType, bool primitive) {
|
|
37 super(numberFormat, fromType, (primitive) ? Integer.TYPE : Integer.classinfo);
|
|
38 }
|
|
39
|
|
40 /* (non-Javadoc)
|
|
41 * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
|
|
42 */
|
|
43 protected Number doConvert(Number number) {
|
|
44 if (StringToNumberParser.inIntegerRange(number)) {
|
|
45 return new Integer(number.intValue());
|
|
46 }
|
|
47
|
|
48 return null;
|
|
49 }
|
|
50 }
|