Top Description Fields Constructors Methods
org.assertj.core.util.introspection

public final Enum FieldSupport

extends Enum<FieldSupport>
Class Inheritance
Static Imports
java.lang.String.format, java.lang.reflect.Modifier.isPublic, java.util.Collections.emptyList, java.util.stream.Collectors.collectingAndThen, .Collectors.toList, org.assertj.core.util.ArrayWrapperList.wrap, .IterableUtil.isNullOrEmpty, .Streams.stream, org.assertj.core.util.introspection.FieldUtils.readField

Utility methods for fields access.
Author
Joel Costigliola

Field Summary

Modifier and TypeField and Description
private boolean
private static final String
private static final String
private static final String
public static final FieldSupport
private static final String
public static final FieldSupport
public static final FieldSupport
private static final String
private static final String
private static final String
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
private
FieldSupport(boolean
whether to read private fields or not.
allowUsingPrivateFields
)

Build a new FieldSupport

Method Summary

Modifier and TypeMethod and Description
public static FieldSupport

Returns:

the instance dedicated to comparison of fields.
comparison
()

Returns the instance dedicated to comparison of fields.

public static FieldSupport

Returns:

the instance dedicated to extraction of fields.
extraction
()

Returns the instance dedicated to extraction of fields.

public <
the type of the extracted value.
T
>
T

Returns:

the value of the given field name
fieldValue
(String
the name of the field. It may be a nested field. It is left to the clients to validate for null or empty.
fieldName
,
Class<T>
type of field
fieldClass
,
Object
the given object
target
)

Return the value of field from a target object.

public <
the type of the extracted elements.
T
>
List<T>

Returns:

an Iterable containing the values of the given field name, from the elements of the given Iterable.
fieldValues
(String
the name of the field. It may be a nested field. It is left to the clients to validate for null or empty.
fieldName
,
Class<T>
the expected type of the given field.
fieldClass
,
Iterable<?>
the given Iterable.
target
)

Returns a List containing the values of the given field name, from the elements of the given Iterable.

public List<Object>
fieldValues(String fieldName, Iterable<?> target)

public <
the type of the extracted elements.
T
>
List<T>

Returns:

an Iterable containing the values of the given field name, from the elements of the given Iterable.
fieldValues
(String
the name of the field. It may be a nested field. It is left to the clients to validate for null or empty.
fieldName
,
Class<T>
the expected type of the given field.
fieldClass
,
Object[]
the given Iterable.
target
)

Returns a List containing the values of the given field name, from the elements of the given Iterable.

public boolean
public boolean
private boolean
isNestedField(String fieldName)

private String
nextFieldNameFrom(String fieldNameChain)

private String
popFieldNameFrom(String fieldNameChain)

private <T> T
readSimpleField(String fieldName, Class<T> clazz, Object target)

public void
setAllowUsingPrivateFields(boolean
allow private fields extraction and comparison. Default true.
allowUsingPrivateFields
)

Sets whether the use of private fields is allowed.

private <T> List<T>
simpleFieldValues(String fieldName, Class<T> clazz, Iterable<?> target)

public static FieldSupport
public static FieldSupport[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

allowUsingPrivateFieldsback to summary
private boolean allowUsingPrivateFields
BOOLEANback to summary
private static final String BOOLEAN
BYTEback to summary
private static final String BYTE
CHARback to summary
private static final String CHAR
COMPARISONback to summary
public static final FieldSupport COMPARISON
DOUBLEback to summary
private static final String DOUBLE
EXTRACTIONback to summary
public static final FieldSupport EXTRACTION
EXTRACTION_OF_PUBLIC_FIELD_ONLYback to summary
public static final FieldSupport EXTRACTION_OF_PUBLIC_FIELD_ONLY
FLOATback to summary
private static final String FLOAT
INTback to summary
private static final String INT
LONGback to summary
private static final String LONG
SEPARATORback to summary
private static final String SEPARATOR
SHORTback to summary
private static final String SHORT

Constructor Detail

FieldSupportback to summary
private FieldSupport(boolean allowUsingPrivateFields)

Build a new FieldSupport

Parameters
allowUsingPrivateFields:boolean

whether to read private fields or not.

Method Detail

comparisonback to summary
public static FieldSupport comparison()

Returns the instance dedicated to comparison of fields.

Returns:FieldSupport

the instance dedicated to comparison of fields.

extractionback to summary
public static FieldSupport extraction()

Returns the instance dedicated to extraction of fields.

Returns:FieldSupport

the instance dedicated to extraction of fields.

fieldValueback to summary
public <T> T fieldValue(String fieldName, Class<T> fieldClass, Object target)

Return the value of field from a target object. The field must not be static or synthetic (since 3.19.0).

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
Parameters
<T>
the type of the extracted value.
fieldName:String

the name of the field. It may be a nested field. It is left to the clients to validate for null or empty.

fieldClass:Class<T>

type of field

target:Object

the given object

Returns:T

the value of the given field name

Exceptions
IntrospectionError:
if the given target does not have a field with a matching name.
fieldValuesback to summary
public <T> List<T> fieldValues(String fieldName, Class<T> fieldClass, Iterable<?> target)

Returns a 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").

Parameters
<T>
the type of the extracted elements.
fieldName:String

the name of the field. It may be a nested field. It is left to the clients to validate for null or empty.

fieldClass:Class<T>

the expected type of the given field.

target:Iterable<?>

the given Iterable.

Returns:List<T>

an Iterable containing the values of the given field name, from the elements of the given Iterable.

Exceptions
IntrospectionError:
if an element in the given Iterable does not have a field with a matching name.
fieldValuesback to summary
public List<Object> fieldValues(String fieldName, Iterable<?> target)
fieldValuesback to summary
public <T> List<T> fieldValues(String fieldName, Class<T> fieldClass, Object[] target)

Returns a 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").

Parameters
<T>
the type of the extracted elements.
fieldName:String

the name of the field. It may be a nested field. It is left to the clients to validate for null or empty.

fieldClass:Class<T>

the expected type of the given field.

target:Object[]

the given Iterable.

Returns:List<T>

an Iterable containing the values of the given field name, from the elements of the given Iterable.

Exceptions
IntrospectionError:
if an element in the given Iterable does not have a field with a matching name.
isAllowedToReadback to summary
public boolean isAllowedToRead(Field field)
isAllowedToUsePrivateFieldsback to summary
public boolean isAllowedToUsePrivateFields()
Annotations
@VisibleForTesting
isNestedFieldback to summary
private boolean isNestedField(String fieldName)
nextFieldNameFromback to summary
private String nextFieldNameFrom(String fieldNameChain)
popFieldNameFromback to summary
private String popFieldNameFrom(String fieldNameChain)
readSimpleFieldback to summary
private <T> T readSimpleField(String fieldName, Class<T> clazz, Object target)
Annotations
@SuppressWarnings:unchecked
setAllowUsingPrivateFieldsback to summary
public void setAllowUsingPrivateFields(boolean allowUsingPrivateFields)

Sets whether the use of private fields is allowed. If a method tries to extract/compare private fields and is not allowed to, it will fail with an exception.

Parameters
allowUsingPrivateFields:boolean

allow private fields extraction and comparison. Default true.

simpleFieldValuesback to summary
private <T> List<T> simpleFieldValues(String fieldName, Class<T> clazz, Iterable<?> target)
valueOfback to summary
public static FieldSupport valueOf(String name)
valuesback to summary
public static FieldSupport[] values()