KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.core.databinding.conversion.IConverter;
15
16 import com.ibm.icu.text.NumberFormat;
17
18 /**
19  * Converts from a Number to a Integer.
20  * <p>
21  * Class is thread safe.
22  * </p>
23  * @since 1.0
24  */

25 public class NumberToIntegerConverter extends NumberToNumberConverter implements
26         IConverter {
27
28     /**
29      * @param numberFormat
30      * @param fromType
31      * @param primitive
32      */

33     public NumberToIntegerConverter(NumberFormat numberFormat,
34             Class JavaDoc fromType, boolean primitive) {
35         super(numberFormat, fromType, (primitive) ? Integer.TYPE : Integer JavaDoc.class);
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
40      */

41     protected Number JavaDoc doConvert(Number JavaDoc number) {
42         if (StringToNumberParser.inIntegerRange(number)) {
43             return new Integer JavaDoc(number.intValue());
44         }
45         
46         return null;
47     }
48 }
49
Popular Tags