public class FieldSupport extends Object
Modifier and Type | Method and Description |
---|---|
<T> T |
fieldValue(String fieldName,
Class<T> clazz,
Object target)
Return the value of field from a target object.
|
<T> T |
fieldValueOf(String fieldName,
Class<T> clazz,
Object target)
Returns the value of the given field name given target.
|
static <T> T |
fieldValueOf(String fieldName,
Object target,
Class<T> clazz)
Static variant of
fieldValue(String, Class, Object) for syntactic sugar. |
<T> List<T> |
fieldValues(String fieldName,
Class<T> fieldClass,
Iterable<?> target)
|
<T> List<T> |
fieldValues(String fieldName,
Class<T> fieldClass,
Object[] target)
|
List<Object> |
fieldValues(String fieldName,
Iterable<?> target) |
List<Object> |
fieldValues(String fieldName,
Object[] target) |
static FieldSupport |
instance()
Returns the singleton instance of this class.
|
public static FieldSupport instance()
public <T> List<T> fieldValues(String fieldName, Class<T> fieldClass, Iterable<?> target)
List
containing the values of the given field name, from the elements of the given
Iterable
. If the given Iterable
is empty or null
, this method will return an
empty List
. This method supports nested fields (e.g. "address.street.number").fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate for
null
or empty.fieldClass
- the expected type of the given field.target
- the given Iterable
.Iterable
containing the values of the given field name, from the elements of the given
Iterable
.IntrospectionError
- if an element in the given Iterable
does not have a field with a matching name.public <T> List<T> fieldValues(String fieldName, Class<T> fieldClass, Object[] target)
List
containing the values of the given field name, from the elements of the given
Iterable
. If the given Iterable
is empty or null
, this method will return an
empty List
. This method supports nested fields (e.g. "address.street.number").fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate for
null
or empty.fieldClass
- the expected type of the given field.target
- the given Iterable
.Iterable
containing the values of the given field name, from the elements of the given
Iterable
.IntrospectionError
- if an element in the given Iterable
does not have a field with a matching name.public static <T> T fieldValueOf(String fieldName, Object target, Class<T> clazz)
fieldValue(String, Class, Object)
for syntactic sugar.
fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate for
null
or empty.target
- the given objectIntrospectionError
- if the given target does not have a field with a matching name.public <T> T fieldValue(String fieldName, Class<T> clazz, Object target)
fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate for
null
or empty.target
- the given objectclazz
- type of fieldIntrospectionError
- if the given target does not have a field with a matching name.public <T> T fieldValueOf(String fieldName, Class<T> clazz, Object target)
null
, this method will
return null.fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate for
null
or empty.clazz
- the class of field.target
- the given Object to extract field from.IntrospectionError
- if target object does not have a field with a matching name.Copyright © 2013 AssertJ. All Rights Reserved.