org.spicefactory.cinnamon.reflect.convert
Class NumberConverter

java.lang.Object
  extended by org.spicefactory.cinnamon.reflect.convert.NumberConverter
All Implemented Interfaces:
Converter<Number>

public class NumberConverter
extends Object
implements Converter<Number>

Converter implementation for converting number types.

Author:
Jens Halm

Constructor Summary
NumberConverter()
           
 
Method Summary
 Number convert(Object obj, TypeContext typeContext)
          Converts the given value to the target type of this converter.
 boolean supports(Class<?> type)
          Checks if this converter can convert instances of the given class to the target type of this converter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberConverter

public NumberConverter()
Method Detail

convert

public Number convert(Object obj,
                      TypeContext typeContext)
               throws ConversionException
Description copied from interface: Converter
Converts the given value to the target type of this converter. The TypeContext parameter serves as an additional hint for the required type of the converted value. Example: If a Converter implementation handles all kinds of Collections (implements Converter<Collection>) the given TypeContext might provide information for the exact nature of the Collection (like List<String>).

Specified by:
convert in interface Converter<Number>
Parameters:
obj - the value to be converted
typeContext - additional information for the required type of the converted value
Returns:
the converted value
Throws:
ConversionException - if the conversion fails

supports

public boolean supports(Class<?> type)
Description copied from interface: Converter
Checks if this converter can convert instances of the given class to the target type of this converter. Of course this does not give any guarantee that conversion will succeed for any instance of the given type.

Specified by:
supports in interface Converter<Number>
Parameters:
type - the class to be checked
Returns:
true if this converter can convert instances of the given class