org.ijsberg.iglu.util.types
Class Converter

java.lang.Object
  extended by org.ijsberg.iglu.util.types.Converter

public abstract class Converter
extends Object

Helper class that converts all kinds of primitives, primitive objects and strings.


Constructor Summary
Converter()
           
 
Method Summary
static Boolean convertToBoolean(Object input)
           
static Byte convertToByte(Object input)
           
static Character convertToCharacter(Object input)
           
static Double convertToDouble(Object input)
           
static Float convertToFloat(Object input)
           
static Integer convertToInteger(Object input)
           
static Long convertToLong(Object input)
           
static Object[] convertToMatchingTypes(Object[] objects, Class<?>[] targetTypes)
          Tries to convert the objects in the array into the types specified.
static Object convertToObject(Object source, Class<?> type)
           
protected static Object convertToPrimitive(Object source, Class<?> type)
           
static Short convertToShort(Object input)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Converter

public Converter()
Method Detail

convertToInteger

public static Integer convertToInteger(Object input)
Parameters:
input -
Returns:

convertToLong

public static Long convertToLong(Object input)
Parameters:
input -
Returns:

convertToShort

public static Short convertToShort(Object input)
Parameters:
input -
Returns:

convertToByte

public static Byte convertToByte(Object input)
Parameters:
input -
Returns:

convertToFloat

public static Float convertToFloat(Object input)
Parameters:
input -
Returns:

convertToDouble

public static Double convertToDouble(Object input)
Parameters:
input -
Returns:

convertToBoolean

public static Boolean convertToBoolean(Object input)
Parameters:
input -
Returns:

convertToCharacter

public static Character convertToCharacter(Object input)
Parameters:
input -
Returns:

convertToPrimitive

protected static Object convertToPrimitive(Object source,
                                           Class<?> type)

convertToObject

public static Object convertToObject(Object source,
                                     Class<?> type)
Parameters:
source -
type - desired type
Returns:
converted source object
Throws:
IllegalArgumentException - in case the object can not be converted to the desired type

convertToMatchingTypes

public static Object[] convertToMatchingTypes(Object[] objects,
                                              Class<?>[] targetTypes)
Tries to convert the objects in the array into the types specified. This is typically useful if a method is invoked command-line by reflection.

Parameters:
objects -
targetTypes - needed input types
Returns:
the converted objects
Throws:
IllegalArgumentException - in case conversion is not possible


Copyright © 2011. All Rights Reserved.