|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.assertj.core.util.introspection.FieldSupport
public class FieldSupport
Utility methods for fields access.
| Constructor Summary | |
|---|---|
FieldSupport(boolean allowExtractingPrivateFields)
Build a new FieldSupport |
|
| Method Summary | ||
|---|---|---|
|
fieldValue(String fieldName,
Class<T> fieldClass,
Object target)
Return the value of field from a target object. |
|
|
fieldValues(String fieldName,
Class<T> fieldClass,
Iterable<?> target)
Returns a containing the values of the given field name, from the elements of the given
. |
|
|
fieldValues(String fieldName,
Class<T> fieldClass,
Object[] target)
Returns a containing the values of the given field name, from the elements of the given
. |
|
List<Object> |
fieldValues(String fieldName,
Iterable<?> target)
|
|
static FieldSupport |
instance()
Returns the singleton instance of this class. |
|
static void |
setAllowExtractingPrivateFields(boolean allowExtractingPrivateFields)
Globally set whether
and
should be allowed to extract private fields, if not and they try it fails with exception. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FieldSupport(boolean allowExtractingPrivateFields)
FieldSupport
allowExtractingPrivateFields - wether to read private fields or not.| Method Detail |
|---|
public static FieldSupport instance()
public static void setAllowExtractingPrivateFields(boolean allowExtractingPrivateFields)
IterableAssert#extracting(String)
and
ObjectArrayAssert#extracting(String)
should be allowed to extract private fields, if not and they try it fails with exception.
allowExtractingPrivateFields - allow private fields extraction. Default true.
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 List<Object> fieldValues(String fieldName,
Iterable<?> target)
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 <T> T fieldValue(String fieldName,
Class<T> fieldClass,
Object target)
Return null if field is nested and one of the nested value is null, ex :
fieldValue(race.name, String.class, frodo) will return null if frodo.race is 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.target - the given objectclazz - type of field
IntrospectionError - if the given target does not have a field with a matching name.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||