org.fest.assertions.internal
Class PropertySupport

java.lang.Object
  extended by org.fest.assertions.internal.PropertySupport

public class PropertySupport
extends Object

Utility methods for properties access.

Author:
Joel Costigliola, Alex Ruiz, Nicolas François

Method Summary
static PropertySupport instance()
          Returns the singleton instance of this class.
<T> T
propertyValue(String propertyName, Object target, Class<T> clazz)
          Return the value of property from a target object.
 Object propertyValueOf(String propertyName, Object target)
          Returns the value of the given property name given target.
static
<T> T
propertyValueOf(String propertyName, Object target, Class<T> clazz)
          Static varient of propertyValue(String, Object, Class) for synthetic sugar.
 List<Object> propertyValues(String propertyName, Collection<?> target)
          Returns a List containing the values of the given property name, from the elements of the given Collection.
static List<Object> propertyValuesOf(String propertyName, Collection<?> target)
          Static variant of propertyValue(String, Object) for synthetic sugar.
static List<Object> propertyValuesOf(String propertyName, Object[] target)
          Returns a List containing the values of the given property name, from the elements of the given array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

instance

public static PropertySupport instance()
Returns the singleton instance of this class.

Returns:
the singleton instance of this class.

propertyValues

public List<Object> propertyValues(String propertyName,
                                   Collection<?> target)
Returns a List containing the values of the given property name, from the elements of the given Collection. If the given Collection is empty or null, this method will return an empty List. This method supports nested properties (e.g. "address.street.number").

Parameters:
propertyName - the name of the property. It may be a nested property. It is left to the clients to validate for null or empty.
target - the given Collection.
Returns:
a List containing the values of the given property name, from the elements of the given Collection.
Throws:
org.fest.util.IntrospectionError - if an element in the given Collection does not have a property with a matching name.

propertyValuesOf

public static List<Object> propertyValuesOf(String propertyName,
                                            Collection<?> target)
Static variant of propertyValue(String, Object) for synthetic sugar.

Returns a List containing the values of the given property name, from the elements of the given Collection. If the given Collection is empty or null, this method will return an empty List. This method supports nested properties (e.g. "address.street.number").

Parameters:
propertyName - the name of the property. It may be a nested property. It is left to the clients to validate for null or empty.
target - the given Collection.
Returns:
a List containing the values of the given property name, from the elements of the given Collection.
Throws:
org.fest.util.IntrospectionError - if an element in the given Collection does not have a property with a matching name.

propertyValuesOf

public static List<Object> propertyValuesOf(String propertyName,
                                            Object[] target)
Returns a List containing the values of the given property name, from the elements of the given array. If the given array is empty or null, this method will return an empty List. This method supports nested properties (e.g. "address.street.number").

Parameters:
propertyName - the name of the property. It may be a nested property. It is left to the clients to validate for null or empty.
target - the given array.
Returns:
a List containing the values of the given property name, from the elements of the given array.
Throws:
org.fest.util.IntrospectionError - if an element in the given array does not have a property with a matching name.

propertyValueOf

public static <T> T propertyValueOf(String propertyName,
                                    Object target,
                                    Class<T> clazz)
Static varient of propertyValue(String, Object, Class) for synthetic sugar.

Parameters:
propertyName - the name of the property. It may be a nested property. It is left to the clients to validate for null or empty.
target - the given object
clazz - type of property
Returns:
a the values of the given property name
Throws:
org.fest.util.IntrospectionError - if the given target does not have a property with a matching name.

propertyValue

public <T> T propertyValue(String propertyName,
                           Object target,
                           Class<T> clazz)
Return the value of property from a target object.

Parameters:
propertyName - the name of the property. It may be a nested property. It is left to the clients to validate for null or empty.
target - the given object
clazz - type of property
Returns:
a the values of the given property name
Throws:
org.fest.util.IntrospectionError - if the given target does not have a property with a matching name.

propertyValueOf

public Object propertyValueOf(String propertyName,
                              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:
propertyName - the name of the property. It may be a nested property. It is left to the clients to validate for null or empty.
target - the given Object to extract property from.
Returns:
the value of the given property name given target.
Throws:
org.fest.util.IntrospectionError - if target object does not have a property with a matching name.


Copyright © 2007-2012 FEST (Fixtures for Easy Software Testing). All Rights Reserved.