Package org.cyclos.utils.coercion
Class CoercionHelper
- java.lang.Object
-
- org.cyclos.utils.coercion.CoercionHelper
-
public class CoercionHelper extends Object
Helper for converting values
-
-
Constructor Summary
Constructors Constructor Description CoercionHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tcoerce(Class<T> type, Object value)Coerces the given value to the given typestatic <T> List<T>coerceList(Class<T> elementType, Object value)Coerces a value collection to a list of the given typestatic <K,V>
Map<K,V>coerceMap(Class<K> keyType, Class<V> valueType, Object value)Coerces a value Map to a list of the given typestatic <T> Page<T>coercePage(Class<T> elementType, Object object)Converts the given object into aPagestatic <T> Set<T>coerceSet(Class<T> elementType, Object value)Coerces a value collection to a set of the given typestatic booleanisCollection(String name)Returns whether the given class name represents a generic collectionstatic booleanisList(String name)Returns whether the given class name represents a Liststatic booleanisSet(String name)Returns whether the given class name represents a Setstatic Iterator<?>toIterator(Object value)Returns an iterator for the given valuestatic booleanunderstands(Class<?> type)Checks whether the given type have a registered coercerstatic Class<?>wrapperClass(Class<?> primitiveClass)Returns the wrapper class of a given primitive class, or null if not a primitive class
-
-
-
Method Detail
-
coerce
public static <T> T coerce(Class<T> type, Object value) throws CoercionException
Coerces the given value to the given type- Throws:
CoercionException
-
coerceList
public static <T> List<T> coerceList(Class<T> elementType, Object value)
Coerces a value collection to a list of the given type
-
coerceMap
public static <K,V> Map<K,V> coerceMap(Class<K> keyType, Class<V> valueType, Object value)
Coerces a value Map to a list of the given type
-
coercePage
public static <T> Page<T> coercePage(Class<T> elementType, Object object)
Converts the given object into aPage
-
coerceSet
public static <T> Set<T> coerceSet(Class<T> elementType, Object value)
Coerces a value collection to a set of the given type
-
isCollection
public static boolean isCollection(String name)
Returns whether the given class name represents a generic collection
-
isList
public static boolean isList(String name)
Returns whether the given class name represents a List
-
isSet
public static boolean isSet(String name)
Returns whether the given class name represents a Set
-
toIterator
public static Iterator<?> toIterator(Object value)
Returns an iterator for the given value
-
understands
public static boolean understands(Class<?> type)
Checks whether the given type have a registered coercer
-
-