org.test4j.tools.commons
类 FieldHelper

java.lang.Object
  继承者 org.test4j.tools.commons.FieldHelper

public final class FieldHelper
extends Object


构造方法摘要
FieldHelper()
           
 
方法摘要
static List<Field> getAllFields(Class clazz)
          返回类所有的字段(包括父类的)
Gets all fields of the given class and all its super-classes.
static Field getField(Class cls, String name)
          test4j method to search for a field starting from the specified class and going up the hierarchy until the field is found or the Object class is reached.
static Set<Field> getFieldsAssignableFrom(Class clazz, Type type)
          Returns all declared fields of the given class that are assignable from the given type.
static Set<Field> getFieldsOfType(Class clazz, Type type)
          Returns the fields in the given class that have the exact given type.
static Object getFieldValue(Object target, Field field)
           
static Object getFieldValue(Object target, String fieldName)
          Returns the value of the given field (may be private) in the given object
获得对象obj的属性名为fieldname的字段值
static Object getStaticFieldValue(Class claz, String fieldName)
           
static void setFieldValue(Object target, Field field, Object fieldValue)
           
static void setFieldValue(Object target, String fieldName, Object fieldValue)
          设置实例target的字段值
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

FieldHelper

public FieldHelper()
方法详细信息

getField

public static Field getField(Class cls,
                             String name)
test4j method to search for a field starting from the specified class and going up the hierarchy until the field is found or the Object class is reached.

参数:
cls - the class from which to start
name - the field name
返回:
the Field found
抛出:
NoSuchFieldException - if the field cannot be found within the specified class hierarchy.

setFieldValue

public static void setFieldValue(Object target,
                                 String fieldName,
                                 Object fieldValue)
设置实例target的字段值

参数:
target -
fieldName -
fieldValue -

setFieldValue

public static void setFieldValue(Object target,
                                 Field field,
                                 Object fieldValue)

getFieldValue

public static Object getFieldValue(Object target,
                                   String fieldName)
Returns the value of the given field (may be private) in the given object
获得对象obj的属性名为fieldname的字段值

参数:
target - The object containing the field, null for static fields
fieldName - The field, not null
返回:
The value of the given field in the given object

getStaticFieldValue

public static Object getStaticFieldValue(Class claz,
                                         String fieldName)

getFieldValue

public static Object getFieldValue(Object target,
                                   Field field)

getAllFields

public static List<Field> getAllFields(Class clazz)
返回类所有的字段(包括父类的)
Gets all fields of the given class and all its super-classes.

参数:
clazz - The class
返回:
The fields, not null

getFieldsAssignableFrom

public static Set<Field> getFieldsAssignableFrom(Class clazz,
                                                 Type type)
Returns all declared fields of the given class that are assignable from the given type.

参数:
clazz - The class to get fields from, not null
type - The type, not null
isStatic - True if static fields are to be returned, false for non-static
返回:
A list of Fields, empty list if none found

getFieldsOfType

public static Set<Field> getFieldsOfType(Class clazz,
                                         Type type)
Returns the fields in the given class that have the exact given type. The class's superclasses are also investigated.

参数:
clazz - The class to get the field from, not null
type - The type, not null
isStatic - True if static fields are to be returned, false for non-static
返回:
The fields with the given type


Copyright © 2013. All rights reserved.