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