Package org.cyclos.server.utils
Class FieldHelper
- java.lang.Object
-
- org.cyclos.server.utils.FieldHelper
-
public class FieldHelper extends Object
Contains helper methods for accessing java fields
-
-
Constructor Summary
Constructors Constructor Description FieldHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,E extends T>
voidcopyFields(T srcObj, E targetObj)Copy all fields from the given source to the target objectsstatic <T> Tget(Class<?> clazz, String name)Returns the value of a static fieldstatic <T> Tget(Object object, String name)Returns the value of a fieldstatic FieldgetAnnotatedField(Class<? extends Object> clazz, Class<? extends Annotation> annotation)Returns the first field with the given annotation or null if there is no such field.
If there are more than one field annotated it returns the first one according to themethodstatic <T extends Annotation>
TgetAnnotation(Class<? extends Object> clazz, String name, Class<T> annotation)Returns the given annotation for the given field, if anystatic FieldgetField(Class<? extends Object> clazz, String name)Returns whether the given field has the given annotation class, or null if the field doesn't existstatic booleanhasAnnotation(Class<? extends Object> clazz, String name, Class<? extends Annotation> annotation)Returns whether the given field has the given annotation classstatic Map<Field,Object>readFields(Object object)Reads all fields (even private ones) of the given objectstatic voidset(Class<?> clazz, String name, Object value)Sets the value of a static fieldstatic voidset(Object object, String name, Object value)Sets the value of a field
-
-
-
Method Detail
-
copyFields
public static <T,E extends T> void copyFields(T srcObj, E targetObj)Copy all fields from the given source to the target objects
-
getAnnotatedField
public static Field getAnnotatedField(Class<? extends Object> clazz, Class<? extends Annotation> annotation)
Returns the first field with the given annotation or null if there is no such field.
If there are more than one field annotated it returns the first one according to themethod
-
getAnnotation
public static <T extends Annotation> T getAnnotation(Class<? extends Object> clazz, String name, Class<T> annotation)
Returns the given annotation for the given field, if any
-
getField
public static Field getField(Class<? extends Object> clazz, String name)
Returns whether the given field has the given annotation class, or null if the field doesn't exist
-
hasAnnotation
public static boolean hasAnnotation(Class<? extends Object> clazz, String name, Class<? extends Annotation> annotation)
Returns whether the given field has the given annotation class
-
readFields
public static Map<Field,Object> readFields(Object object)
Reads all fields (even private ones) of the given object
-
set
public static void set(Class<?> clazz, String name, Object value)
Sets the value of a static field
-
-