org.jopendocument.util.convertor
Class NumberConvertor<T extends Number,U extends Number>

java.lang.Object
  extended by org.jopendocument.util.convertor.NumberConvertor<T,U>
All Implemented Interfaces:
ValueConvertor<T,U>

public abstract class NumberConvertor<T extends Number,U extends Number>
extends Object
implements ValueConvertor<T,U>


Nested Class Summary
static class NumberConvertor.OverflowException
           
static class NumberConvertor.RoundingException
           
 
Field Summary
static NumberConvertor<Integer,Long> INT_TO_LONG
           
static BigDecimal MAX_DOUBLE
           
static BigDecimal MAX_FLOAT
           
static BigDecimal MIN_DOUBLE
           
static BigDecimal MIN_FLOAT
           
static NumberConvertor<Short,Integer> SHORT_TO_INT
           
 
Constructor Summary
NumberConvertor()
           
 
Method Summary
static
<N extends Number>
N
convert(Number n, Class<N> clazz)
          Convert from one class of Number to another.
static
<N extends Number>
N
convertExact(Number n, Class<N> clazz)
           
static
<N1 extends Number,N2 extends Number>
NumberConvertor<N1,N2>
create(Class<N1> c1, Class<N2> c2, boolean exact)
           
static BigDecimal toBigDecimal(Number n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jopendocument.util.convertor.ValueConvertor
convert, unconvert
 

Field Detail

INT_TO_LONG

public static final NumberConvertor<Integer,Long> INT_TO_LONG

SHORT_TO_INT

public static final NumberConvertor<Short,Integer> SHORT_TO_INT

MAX_FLOAT

public static final BigDecimal MAX_FLOAT

MIN_FLOAT

public static final BigDecimal MIN_FLOAT

MAX_DOUBLE

public static final BigDecimal MAX_DOUBLE

MIN_DOUBLE

public static final BigDecimal MIN_DOUBLE
Constructor Detail

NumberConvertor

public NumberConvertor()
Method Detail

create

public static final <N1 extends Number,N2 extends Number> NumberConvertor<N1,N2> create(Class<N1> c1,
                                                                                        Class<N2> c2,
                                                                                        boolean exact)

convert

public static <N extends Number> N convert(Number n,
                                           Class<N> clazz)
Convert from one class of Number to another. Necessary since new Integer(123) isn't equal to new Long(123).

Type Parameters:
N - type of desired Number.
Parameters:
n - the instance to convert, e.g. new Integer(123).
clazz - desired class of Number, e.g. Long.class.
Returns:
n as an instance of clazz, e.g. new Long(123).

toBigDecimal

public static BigDecimal toBigDecimal(Number n)

convertExact

public static <N extends Number> N convertExact(Number n,
                                                Class<N> clazz)
                                     throws NumberConvertor.OverflowException,
                                            NumberConvertor.RoundingException
Throws:
NumberConvertor.OverflowException
NumberConvertor.RoundingException


Copyright © 2010 jOpenDocument All Rights Reserved.