Class PropertySupport

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

public class PropertySupport extends Object
Utility methods for properties access.
Author:
Joel Costigliola, Alex Ruiz, Nicolas François, Florent Biville
  • Method Details

    • instance

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

      public <T> Iterable<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:
      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 Iterable.
      Returns:
      an Iterable containing the values of the given property name, from the elements of the given Iterable.
      Throws:
      org.fest.util.IntrospectionError - if an element in the given Iterable does not have a property with a matching name.
    • propertyValueOf

      public static <T> T propertyValueOf(String propertyName, Object target, Class<T> clazz)
      Static variant of propertyValue(String, Class, Object) for syntactic 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, Class<T> clazz, Object target)
      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 <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:
      propertyName - the name of the property. It may be a nested property. It is left to the clients to validate for null or empty.
      clazz - the class of property.
      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.