Package org.refcodes.structure
Class TypeUtility
- java.lang.Object
-
- org.refcodes.structure.TypeUtility
-
public class TypeUtility extends java.lang.ObjectThe Class TypeUtility.
-
-
Constructor Summary
Constructors Constructor Description TypeUtility()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static java.lang.StringfromGetter(java.lang.reflect.Method aMethod)static booleanisGetter(java.lang.reflect.Method aMethod)Tests whether we have a getter method.static booleanisSetter(java.lang.reflect.Method aMethod)Tests whether we have a setter method.static booleanisSimpleType(java.lang.Class<?> aType)Tests whether the provided type represents a primitive type or the object representation the such or aStringwhich we consider to be a simple type as well.static <T> voidtoInstance(java.lang.Object aValue, T aInstance)Updates the provided instance with the data provided by the given value (a mixture of array andMapobjects).static java.lang.StringtoPropertyName(java.lang.reflect.Field aField)Converts a field's name to a property name.static java.lang.StringtoPropertyName(java.lang.reflect.Method aMethod)Converts a method's name to a property name.static <T> TtoType(java.lang.Object aValue, java.lang.Class<T> aType)Creates an instance of the given type filled with the data provided by the given Data-Structure (a mixture of array andMapobjects).
-
-
-
Method Detail
-
toType
public static <T> T toType(java.lang.Object aValue, java.lang.Class<T> aType) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.NoSuchMethodException, java.lang.SecurityException, java.lang.reflect.InvocationTargetException, java.lang.ClassNotFoundExceptionCreates an instance of the given type filled with the data provided by the given Data-Structure (a mixture of array andMapobjects).- Type Parameters:
T- the generic type- Parameters:
aValue- The Data-Structure, a mixture of arrays andMapinstance, from which to construct the instance of the given type.aType- The type for which an instance is to be created.- Returns:
- The instance filled by the data from the given Data-Structure
- Throws:
java.lang.InstantiationException- thrown when an application tries to create an instance of a class using the newInstance method in classClass, but the specified class object cannot be instantiated.java.lang.IllegalAccessException- thrown when an application tries to reflectively create an instance (other than an array), set or get a field, or invoke a method, but the currently executing method does not have access to the definition of the specified class, field, method or constructor.java.lang.NoSuchMethodException- thrown when a particular method cannot be found.java.lang.SecurityException- thrown by the security manager to indicate a security violation.java.lang.reflect.InvocationTargetException- wraps an exception thrown by an invoked method or constructor.java.lang.ClassNotFoundException- thrown when an application tries to load in a class through its string name but no definition for the class with the specified name could be found.
-
toInstance
public static <T> void toInstance(java.lang.Object aValue, T aInstance) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.NoSuchMethodException, java.lang.SecurityException, java.lang.reflect.InvocationTargetException, java.lang.ClassNotFoundExceptionUpdates the provided instance with the data provided by the given value (a mixture of array andMapobjects). In case the instance to be updated represents an array, then at most it is filled with the provided value's elements, even if the value provides more elements than would fit. On the other hand, if the instance's array to be updated provides room for more elements than the value can provide, then the remaining instance's elements are left as are.- Type Parameters:
T- the generic type- Parameters:
aValue- The Data-Structure, a mixture of arrays andMapinstance, from which to update the instance of the given type.aInstance- The instance to be updated.- Throws:
java.lang.InstantiationException- thrown when an application tries to create an instance of a class using the newInstance method in classClass, but the specified class object cannot be instantiated.java.lang.IllegalAccessException- thrown when an application tries to reflectively create an instance (other than an array), set or get a field, or invoke a method, but the currently executing method does not have access to the definition of the specified class, field, method or constructor.java.lang.NoSuchMethodException- thrown when a particular method cannot be found.java.lang.SecurityException- thrown by the security manager to indicate a security violation.java.lang.reflect.InvocationTargetException- wraps an exception thrown by an invoked method or constructor.java.lang.ClassNotFoundException- thrown when an application tries to load in a class through its string name but no definition for the class with the specified name could be found.
-
isSetter
public static boolean isSetter(java.lang.reflect.Method aMethod)
Tests whether we have a setter method. A setter method must not return a value and expect exactly one argument. It also must be public.- Parameters:
aMethod- TheMethodto be tested.- Returns:
- True in case we have a setter method, else false.
-
isGetter
public static boolean isGetter(java.lang.reflect.Method aMethod)
Tests whether we have a getter method. A getter method must return a value (other thanVoid) and expect none arguments. It also must be public.- Parameters:
aMethod- TheMethodto be tested.- Returns:
- True in case we have a getter method, else false.
-
toPropertyName
public static java.lang.String toPropertyName(java.lang.reflect.Method aMethod)
Converts a method's name to a property name.- Parameters:
aMethod- TheMethodwhich's name is to be converted to a property name.- Returns:
- The according property name or null if we do not have a property method.
-
toPropertyName
public static java.lang.String toPropertyName(java.lang.reflect.Field aField)
Converts a field's name to a property name.- Parameters:
aField- TheFieldwhich's name is to be converted to a property name.- Returns:
- The according property name or null if we do not have a property method.
-
fromGetter
protected static java.lang.String fromGetter(java.lang.reflect.Method aMethod)
-
isSimpleType
public static boolean isSimpleType(java.lang.Class<?> aType)
Tests whether the provided type represents a primitive type or the object representation the such or aStringwhich we consider to be a simple type as well.- Parameters:
aType- The type to test whether it is a simple type.- Returns:
- True in case we have a simple type, else false.
-
-