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

public Class PropertySupport

extends Object
Class Inheritance
Static Imports
java.lang.String.format, java.util.Collections.emptyList, java.util.stream.Collectors.collectingAndThen, .Collectors.toList, org.assertj.core.util.IterableUtil.isNullOrEmpty, .Preconditions.checkArgument, .Streams.stream, org.assertj.core.util.introspection.Introspection.getPropertyGetter

Utility methods for properties access.
Authors
Joel Costigliola, Alex Ruiz, Nicolas François, Florent Biville

Field Summary

Modifier and TypeField and Description
private static final PropertySupport
private static final String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public static PropertySupport

Returns:

the singleton instance of this class.
instance
()

Returns the singleton instance of this class.

private boolean
isNestedProperty(String propertyName)

private String
nextPropertyNameFrom(String propertyNameChain)

private String
popPropertyNameFrom(String propertyNameChain)

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

Returns:

a the values of the given property name
propertyValue
(String
the name of the property. It may be a nested property. It is left to the clients to validate for null or empty.
propertyName
,
Class<T>
type of property
clazz
,
Object
the given object
target
)

Return the value of a simple property from a target object.

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

Returns:

a the values of the given property name
propertyValueOf
(String
the name of the property. It may be a nested property. It is left to the clients to validate for null or empty.
propertyName
,
Object
the given object
target
,
Class<T>
type of property
clazz
)

Static variant of propertyValueOf(String, Class, Object) for syntactic sugar.

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

Returns:

the value of the given property name given target.
propertyValueOf
(String
the name of the property. It may be a nested property. It is left to the clients to validate for null or empty.
propertyName
,
Class<T>
the class of property.
clazz
,
Object
the given Object to extract property from.
target
)

Returns the value of the given property name given target.

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

Returns:

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

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

public List<Object>

Returns:

an Iterable containing the values of the given property name, from the elements of the given Iterable.
propertyValues
(String
the name of the property. It may be a nested property. It is left to the clients to validate for null or empty.
fieldOrPropertyName
,
Iterable<?>
the given Iterable.
target
)

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

public boolean
publicGetterExistsFor(String fieldName, Object actual)

private <T> List<T>
simplePropertyValues(String propertyName, Class<T> clazz, Iterable<?> target)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
private static final PropertySupport INSTANCE
SEPARATORback to summary
private static final String SEPARATOR

Constructor Detail

PropertySupportback to summary
pack-priv PropertySupport()
Annotations
@VisibleForTesting

Method Detail

instanceback to summary
public static PropertySupport instance()

Returns the singleton instance of this class.

Returns:PropertySupport

the singleton instance of this class.

isNestedPropertyback to summary
private boolean isNestedProperty(String propertyName)
nextPropertyNameFromback to summary
private String nextPropertyNameFrom(String propertyNameChain)
popPropertyNameFromback to summary
private String popPropertyNameFrom(String propertyNameChain)
propertyValueback to summary
public <T> T propertyValue(String propertyName, Class<T> clazz, Object target)

Return the value of a simple property from a target object.

This only works for simple property, nested property are not supported ! use propertyValueOf(String, Class, Object)

Parameters
<T>
the type of the extracted value.
propertyName:String

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

clazz:Class<T>

type of property

target:Object

the given object

Returns:T

a the values of the given property name

Annotations
@SuppressWarnings:unchecked
Exceptions
IntrospectionError:
if the given target does not have a property with a matching name.
propertyValueOfback to summary
public static <T> T propertyValueOf(String propertyName, Object target, Class<T> clazz)

Static variant of propertyValueOf(String, Class, Object) for syntactic sugar.

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

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

target:Object

the given object

clazz:Class<T>

type of property

Returns:T

a the values of the given property name

Exceptions
IntrospectionError:
if the given target does not have a property with a matching name.
propertyValueOfback to summary
public <T> T propertyValueOf(String propertyName, Class<T> clazz, Object target)

Returns the value of the given property name given target. If the given object is null, this method will return null.
This method supports nested properties (e.g. "address.street.number").

Parameters
<T>
the type of the extracted value.
propertyName:String

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

clazz:Class<T>

the class of property.

target:Object

the given Object to extract property from.

Returns:T

the value of the given property name given target.

Exceptions
IntrospectionError:
if target object does not have a property with a matching name.
IllegalArgumentException:
if propertyName is null.
propertyValuesback to summary
public <T> List<T> propertyValues(String propertyName, Class<T> clazz, Iterable<?> target)

Returns a List containing the values of the given property 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 properties (e.g. "address.street.number").

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

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

clazz:Class<T>

type of property

target:Iterable<?>

the given Iterable.

Returns:List<T>

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

Exceptions
IntrospectionError:
if an element in the given Iterable does not have a property with a matching name.
propertyValuesback to summary
public List<Object> propertyValues(String fieldOrPropertyName, Iterable<?> target)

Returns a List containing the values of the given property 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 properties (e.g. "address.street.number").

Parameters
fieldOrPropertyName:String

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

target:Iterable<?>

the given Iterable.

Returns:List<Object>

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

Exceptions
IntrospectionError:
if an element in the given Iterable does not have a property with a matching name.
publicGetterExistsForback to summary
public boolean publicGetterExistsFor(String fieldName, Object actual)
simplePropertyValuesback to summary
private <T> List<T> simplePropertyValues(String propertyName, Class<T> clazz, Iterable<?> target)