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.NumberToShortConverter;
|
81
|
13 import org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter;
|
|
14 import org.eclipse.core.internal.databinding.conversion.StringToNumberParser;
|
78
|
15
|
|
16 import java.lang.all;
|
|
17
|
|
18 import com.ibm.icu.text.NumberFormat;
|
|
19
|
|
20 /**
|
|
21 * Converts from a Number to a Short.
|
|
22 * <p>
|
|
23 * Class is thread safe.
|
|
24 * </p>
|
|
25 * @since 1.0
|
|
26 */
|
|
27 public class NumberToShortConverter : NumberToNumberConverter {
|
|
28 /**
|
|
29 * @param numberFormat
|
|
30 * @param fromType
|
|
31 * @param primitive
|
|
32 */
|
|
33 public this(NumberFormat numberFormat, ClassInfo fromType,
|
|
34 bool primitive) {
|
|
35
|
|
36 super(numberFormat, fromType, (primitive) ? Short.TYPE : Short.classinfo);
|
|
37 }
|
|
38
|
|
39 /*
|
|
40 * (non-Javadoc)
|
|
41 *
|
|
42 * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
|
|
43 */
|
|
44 protected Number doConvert(Number number) {
|
|
45 if (StringToNumberParser.inShortRange(number)) {
|
|
46 return new Short(number.shortValue());
|
|
47 }
|
|
48
|
|
49 return null;
|
|
50 }
|
|
51 }
|