Mercurial > projects > dwt2
annotate org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigIntegerConverter.d @ 88:9e0ab372d5d8
Revert from TypeInfo/ClassInfo to java.lang.Class
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 19 Apr 2009 11:10:09 +0200 |
parents | 6be48cf9f95c |
children |
rev | line source |
---|---|
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 */ | |
88
9e0ab372d5d8
Revert from TypeInfo/ClassInfo to java.lang.Class
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
35 public this(NumberFormat numberFormat, Class fromType) { |
9e0ab372d5d8
Revert from TypeInfo/ClassInfo to java.lang.Class
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
36 super(numberFormat, fromType, Class.fromType!(BigInteger)); |
78 | 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 } |