Package org.red5.io.utils
Class ConversionUtils
- java.lang.Object
-
- org.red5.io.utils.ConversionUtils
-
public class ConversionUtils extends Object
Misc utils for conversions- Author:
- The Red5 Project, Luke Hubbard, Codegent Ltd (luke@codegent.com), Paul Gregoire (mondain@gmail.com)
-
-
Constructor Summary
Constructors Constructor Description ConversionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Objectconvert(Object source, Class<?> target)Convert source to given classstatic List<?>convertArrayToList(Object[] source)static Set<?>convertArrayToSet(Object[] source)Convert array to set, removing duplicatesstatic Map<?,?>convertBeanToMap(Object source)Convert bean to mapstatic ObjectconvertMapToBean(Map<String,? extends Object> source, Class<?> target)Convert map to beanstatic List<Object>convertMapToList(Map<?,?> map)static ObjectconvertNumberToWrapper(Number num, Class<?> wrapper)Convert number to primitive wrapper like Boolean or Floatstatic Class<?>[]convertParams(Object[] source)Convert parameters using methods of this utility class.static Object[]convertParams(Object[] source, Class<?>[] target)Convert parameters using methods of this utility classstatic ObjectconvertStringToWrapper(String str, Class<?> wrapper)Convert string to primitive wrapper like Boolean or Floatstatic ObjectconvertToArray(Object source, Class<?> target)Convert to arraystatic ObjectconvertToWrappedPrimitive(Object source, Class<?> wrapper)Convert to wrapped primitivestatic List<Method>findMethodsByNameAndNumParams(Object object, String method, int numParam)Find method by name and number of parametersstatic booleanisBaseTypeOrArray(Object obj)Returns true for base types or arrays of base type.protected static ObjectnewInstance(String className)Create new class instance
-
-
-
Method Detail
-
isBaseTypeOrArray
public static boolean isBaseTypeOrArray(Object obj)
Returns true for base types or arrays of base type.- Parameters:
obj- Object- Returns:
- true if base-type or array and false otherwise
-
convert
public static Object convert(Object source, Class<?> target) throws org.apache.commons.beanutils.ConversionException
Convert source to given class- Parameters:
source- Source objecttarget- Target class- Returns:
- Converted object
- Throws:
org.apache.commons.beanutils.ConversionException- If object can't be converted
-
convertToArray
public static Object convertToArray(Object source, Class<?> target) throws org.apache.commons.beanutils.ConversionException
Convert to array- Parameters:
source- Source objecttarget- Target class- Returns:
- Converted object
- Throws:
org.apache.commons.beanutils.ConversionException- If object can't be converted
-
convertToWrappedPrimitive
public static Object convertToWrappedPrimitive(Object source, Class<?> wrapper)
Convert to wrapped primitive- Parameters:
source- Source objectwrapper- Primitive wrapper type- Returns:
- Converted object
-
convertStringToWrapper
public static Object convertStringToWrapper(String str, Class<?> wrapper)
Convert string to primitive wrapper like Boolean or Float- Parameters:
str- String to convertwrapper- Primitive wrapper type- Returns:
- Converted object
-
convertNumberToWrapper
public static Object convertNumberToWrapper(Number num, Class<?> wrapper)
Convert number to primitive wrapper like Boolean or Float- Parameters:
num- Number to converwrapper- Primitive wrapper type- Returns:
- Converted object
-
findMethodsByNameAndNumParams
public static List<Method> findMethodsByNameAndNumParams(Object object, String method, int numParam)
Find method by name and number of parameters- Parameters:
object- Object to find method onmethod- Method namenumParam- Number of parameters- Returns:
- List of methods that match by name and number of parameters
-
convertParams
public static Object[] convertParams(Object[] source, Class<?>[] target) throws org.apache.commons.beanutils.ConversionException
Convert parameters using methods of this utility class- Parameters:
source- Array of source objecttarget- Array of target classes- Returns:
- Array of converted objects
- Throws:
org.apache.commons.beanutils.ConversionException- If object can't be converted
-
convertParams
public static Class<?>[] convertParams(Object[] source)
Convert parameters using methods of this utility class. Special handling is afforded to classes that implement IConnection.- Parameters:
source- Array of source object- Returns:
- Array of converted objects
-
convertArrayToList
public static List<?> convertArrayToList(Object[] source) throws org.apache.commons.beanutils.ConversionException
- Parameters:
source- source arra- Returns:
- list
- Throws:
org.apache.commons.beanutils.ConversionException- on failure
-
convertMapToBean
public static Object convertMapToBean(Map<String,? extends Object> source, Class<?> target) throws org.apache.commons.beanutils.ConversionException
Convert map to bean- Parameters:
source- Source maptarget- Target class- Returns:
- Bean of that class
- Throws:
org.apache.commons.beanutils.ConversionException- on failure
-
convertBeanToMap
public static Map<?,?> convertBeanToMap(Object source)
Convert bean to map- Parameters:
source- Source bean- Returns:
- Converted map
-
convertArrayToSet
public static Set<?> convertArrayToSet(Object[] source)
Convert array to set, removing duplicates- Parameters:
source- Source array- Returns:
- Set
-
-