Package org.cyclos.server.utils
Class ClassHelper
- java.lang.Object
-
- org.cyclos.server.utils.ClassHelper
-
public class ClassHelper extends Object
Helper methods for handling classes
-
-
Constructor Summary
Constructors Constructor Description ClassHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tconvert(Object object, Class<T> type)Converts a bean, handling both getters / setters and public fieldsstatic Map<String,Object>describe(Object object)Reads all properties and public fields from the given object, returning an empty map for null inputstatic voidfill(Object object, Map<String,Object> values)Sets each property / public field in the map, ignoring errorsstatic Class<?>forName(String name)Returns the class for the given name, wrapping any exceptions in anIllegalStateExceptionstatic <T> Tinstantiate(Class<T> type)Instantiates a bean of the given class, using the default constructorstatic <T> Tinstantiate(Class<T> type, Supplier<T> supplier)Instantiates a bean of the given class, using the default constructor or from the given supplier if an instantiate error occursstatic <T,D extends T>
TinstantiateDynamic(Class<T> expectedType, String classProperty, Class<D> defaultType)Instantiates a class, reading the class name from the environment, then a system property, then using a default type
-
-
-
Method Detail
-
convert
public static <T> T convert(Object object, Class<T> type)
Converts a bean, handling both getters / setters and public fields
-
describe
public static Map<String,Object> describe(Object object)
Reads all properties and public fields from the given object, returning an empty map for null input
-
fill
public static void fill(Object object, Map<String,Object> values)
Sets each property / public field in the map, ignoring errors
-
forName
public static Class<?> forName(String name)
Returns the class for the given name, wrapping any exceptions in anIllegalStateException
-
instantiate
public static <T> T instantiate(Class<T> type)
Instantiates a bean of the given class, using the default constructor- Throws:
IllegalStateException- When there was a checked exception (used as cause)
-
instantiate
public static <T> T instantiate(Class<T> type, Supplier<T> supplier)
Instantiates a bean of the given class, using the default constructor or from the given supplier if an instantiate error occurs
-
-