KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > databinding > conversion > NumberToBigIntegerConverter


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 package org.eclipse.core.internal.databinding.conversion;
13
14 import java.math.BigDecimal JavaDoc;
15 import java.math.BigInteger JavaDoc;
16
17 import com.ibm.icu.text.NumberFormat;
18
19 /**
20  * Converts from a Number to a BigInteger.
21  * <p>
22  * Class is thread safe.
23  * </p>
24  *
25  * @since 1.0
26  */

27 public class NumberToBigIntegerConverter extends NumberToNumberConverter {
28     /**
29      * @param numberFormat
30      * @param fromType
31      */

32     public NumberToBigIntegerConverter(NumberFormat numberFormat, Class JavaDoc fromType) {
33         super(numberFormat, fromType, BigInteger JavaDoc.class);
34     }
35
36     /* (non-Javadoc)
37      * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
38      */

39     protected Number JavaDoc doConvert(Number JavaDoc number) {
40         return toBigDecimal(number).toBigInteger();
41     }
42     
43     private static BigDecimal JavaDoc toBigDecimal(Number JavaDoc number) {
44         if (number instanceof BigDecimal JavaDoc) {
45             return (BigDecimal JavaDoc) number;
46         }
47         
48         return new BigDecimal JavaDoc(number.doubleValue());
49     }
50 }
51
Popular Tags