Package org.hcjf.utils
Class Introspection
- java.lang.Object
-
- org.hcjf.utils.Introspection
-
public final class Introspection extends java.lang.ObjectThis class contains a set of utilities to optimize the introspection native methods.- Author:
- javaito
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIntrospection.AccessorThis class groups all the information about getter/setter accessor methods.static classIntrospection.AccessorsThis class contains the instances of getter and setter for a specific resourcestatic interfaceIntrospection.ConsumerThis interface represents a possible implementation of the way to consume a getter method of the some kind of object.static classIntrospection.GetterSub class of the accessor that represents only the getter accessors.static classIntrospection.Invokerstatic classIntrospection.InvokerEntry<I extends Introspection.Invoker>This class represents the object returned by the invoker filter.static interfaceIntrospection.InvokerFilter<I extends Introspection.Invoker>This interface must be implemented to found some kind of methods implemented in the any class.static classIntrospection.SetterSub class of the accessor that represents only the setter accessors.
-
Constructor Summary
Constructors Constructor Description Introspection()
-
Method Summary
Modifier and Type Method Description static <O> Oget(java.lang.Object instance, java.lang.String getterName)Return the value that is the result of invoke the specific getter method.static java.util.Listget(java.lang.Object instance, java.lang.String... getters)Return a list of values that are the results of invoke each of the specific getters.static java.util.Map<java.lang.String,Introspection.Accessors>getAccessors(java.lang.Class clazz)Returns a map with the accessors instance for a specific resource.static java.util.Map<java.lang.String,Introspection.Getter>getGetters(java.lang.Class clazz)Return a map with all the getters accessor instances indexed by the expected name of the field that represents each accessor.static java.util.Map<java.lang.String,Introspection.Getter>getGetters(java.lang.Class clazz, java.lang.String namingImpl)Return a map with all the getters accessor instances indexed by the expected name of the field that represents each accessor.static <I extends Introspection.Invoker>
java.util.Map<java.lang.String,I>getInvokers(java.lang.Class clazz, Introspection.InvokerFilter<I> filter)Return a map with all the methods founded in the class applying the filter, indexed by the filter definition.static java.util.Map<java.lang.String,Introspection.Setter>getSetters(java.lang.Class clazz)Return a map with all the setters accessor instances indexed by the expected name of the field that represents each accessor.static java.util.Map<java.lang.String,Introspection.Setter>getSetters(java.lang.Class clazz, java.lang.String namingImpl)Return a map with all the setters accessor instances indexed by the expected name of the field that represents each accessor.static <O> Oresolve(java.lang.Object instance, java.lang.String path)This method resolve the path using introspection to navigate into the instance finding each element of the path.static <O> Oresolve(java.lang.Object instance, java.lang.String... path)This method resolve the path using introspection to navigate into the instance finding each element of the path.static voidset(java.lang.Object instance, java.lang.String path, java.lang.Object value)static <O> OtoInstance(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.Class<O> clazz)Create an instance of the class from a map.static java.util.Map<java.lang.String,java.lang.Object>toMap(java.lang.Object instance)Creates a mpa using all the getters method of the class.static <O> java.util.Map<java.lang.String,O>toMap(java.lang.Object instance, Introspection.Consumer consumer)Creates a mpa using all the getters method of the class.static java.util.Map<java.lang.String,java.lang.String>toStringsMap(java.lang.Object instance)Creates a mpa (String key and String value) using all the getters method of the class.
-
-
-
Method Detail
-
resolve
public static <O> O resolve(java.lang.Object instance, java.lang.String path)This method resolve the path using introspection to navigate into the instance finding each element of the path. The path is a set of elements that represents a field, key or index each one. This is a path example: field.0.field.field.1- Parameters:
instance- Object to navigate.path- Path to navigate the instance.- Returns:
- Returns the value that point the path.
-
resolve
public static <O> O resolve(java.lang.Object instance, java.lang.String... path)This method resolve the path using introspection to navigate into the instance finding each element of the path. The path is a set of elements that represents a field, key or index each one. This is a path example: field.0.field.field.1- Parameters:
instance- Object to navigate.path- Path to navigate the instance.- Returns:
- Returns the value that point the path.
-
set
public static void set(java.lang.Object instance, java.lang.String path, java.lang.Object value)
-
get
public static <O> O get(java.lang.Object instance, java.lang.String getterName)Return the value that is the result of invoke the specific getter method.- Type Parameters:
O- Expected result type.- Parameters:
instance- Instance to invoke the getter method.getterName- Specific getter name.- Returns:
- Return the value that is a result of the specific getter method.
- Throws:
java.lang.reflect.InvocationTargetException- Invocation target exception.java.lang.IllegalAccessException- Illegal access exception.
-
get
public static java.util.List get(java.lang.Object instance, java.lang.String... getters)Return a list of values that are the results of invoke each of the specific getters.- Parameters:
instance- Instance to invoke each of getters.getters- Specific getter names.- Returns:
- Return a list with each of the results.
- Throws:
java.lang.reflect.InvocationTargetException- Invocation target exception.java.lang.IllegalAccessException- Illegal access exception.
-
toMap
public static java.util.Map<java.lang.String,java.lang.Object> toMap(java.lang.Object instance)
Creates a mpa using all the getters method of the class.- Parameters:
instance- Instance to transform.- Returns:
- Map
-
toStringsMap
public static java.util.Map<java.lang.String,java.lang.String> toStringsMap(java.lang.Object instance)
Creates a mpa (String key and String value) using all the getters method of the class.- Parameters:
instance- Instance to transform.- Returns:
- Map
-
toMap
public static <O> java.util.Map<java.lang.String,O> toMap(java.lang.Object instance, Introspection.Consumer consumer)Creates a mpa using all the getters method of the class.- Type Parameters:
O- Expected return value into the map.- Parameters:
instance- Instance to transform.consumer- Instance of the consumer to transform the values of the instance to the expected values into the map.- Returns:
- Map
-
toInstance
public static <O> O toInstance(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.Class<O> clazz) throws java.lang.IllegalAccessException, java.lang.InstantiationExceptionCreate an instance of the class from a map.- Type Parameters:
O- Expected type.- Parameters:
map- Map with values.clazz- Instance class.- Returns:
- Instance.
- Throws:
java.lang.IllegalAccessException- Illegal access exception.java.lang.InstantiationException- Instantiation exception.
-
getInvokers
public static <I extends Introspection.Invoker> java.util.Map<java.lang.String,I> getInvokers(java.lang.Class clazz, Introspection.InvokerFilter<I> filter)
Return a map with all the methods founded in the class applying the filter, indexed by the filter definition.- Type Parameters:
I- Expected return value into the map.- Parameters:
clazz- Class to be inspected.filter- Filter to apply.- Returns:
- Return the founded invokers.
-
getAccessors
public static java.util.Map<java.lang.String,Introspection.Accessors> getAccessors(java.lang.Class clazz)
Returns a map with the accessors instance for a specific resource.- Parameters:
clazz- Resource class.- Returns:
- Accessors map.
-
getGetters
public static java.util.Map<java.lang.String,Introspection.Getter> getGetters(java.lang.Class clazz, java.lang.String namingImpl)
Return a map with all the getters accessor instances indexed by the expected name of the field that represents each accessor. The fields represented by the name can exists or no. The accessor instances contains all the information about accessor method and the annotation bounded to the method. The found methods comply with the following regular expression and conditions: - ^(get|is)([1,A-Z]|[1,0-9])(.*) - must return something distinct to void type - without parameters - must be a public method- Parameters:
clazz- Class definition to found the getters method.namingImpl- Name of the naming implementation.- Returns:
- All the accessors founded indexed by the possible field name.
-
getGetters
public static java.util.Map<java.lang.String,Introspection.Getter> getGetters(java.lang.Class clazz)
Return a map with all the getters accessor instances indexed by the expected name of the field that represents each accessor. The fields represented by the name can exists or no. The accessor instances contains all the information about accessor method and the annotation bounded to the method. The found methods comply with the following regular expression and conditions: - ^(get|is)([1,A-Z]|[1,0-9])(.*) - must return something distinct to void type - without parameters - must be a public method- Parameters:
clazz- Class definition `to found the getters method.- Returns:
- All the accessors founded indexed by the possible field name.
-
getSetters
public static java.util.Map<java.lang.String,Introspection.Setter> getSetters(java.lang.Class clazz, java.lang.String namingImpl)
Return a map with all the setters accessor instances indexed by the expected name of the field that represents each accessor. The fields represented by the name can exists or no. The accessor instances contains all the information about accessor method and the annotation bounded to the method. The found methods comply with the following regular expression and conditions: - ^(set)([1,A-Z]|[1,0-9])(.*) - must return void type. - with only one parameter - must be a public method- Parameters:
clazz- Class definition to found the setter method.namingImpl- Naming service implementation.- Returns:
- All the accessors founded indexed by the possible field name.
-
getSetters
public static java.util.Map<java.lang.String,Introspection.Setter> getSetters(java.lang.Class clazz)
Return a map with all the setters accessor instances indexed by the expected name of the field that represents each accessor. The fields represented by the name can exists or no. The accessor instances contains all the information about accessor method and the annotation bounded to the method. The found methods comply with the following regular expression and conditions: - ^(set)([1,A-Z]|[1,0-9])(.*) - must return void type. - with only one parameter - must be a public method- Parameters:
clazz- Class definition to found the setter method.- Returns:
- All the accessors founded indexed by the possible field name.
-
-