Class PropertySupport

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

final class PropertySupport extends Object
Understands utility methods related to properties.
Since:
1.3
  • Field Details

  • Constructor Details

    • PropertySupport

      private PropertySupport()
  • Method Details

    • propertyValues

      static 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 collection.

      For example, given the nested property "address.street.number", this method will:

      1. extract a collection of "address" from the given collection (remaining property is 'street.number')
      2. extract a collection of "street" from the "address" collection (remaining property is 'number')
      3. extract a collection of "number" from the "street" collection

      Parameters:
      propertyName - the name of the property. It may be a nested property.
      target - the given collection.
      Returns:
      a list containing the values of the given property name, from the elements of the given collection.
      Throws:
      NullPointerException - if given property name is null.
      org.fest.util.IntrospectionError - if an element in the given collection does not have a matching property.
    • isNestedProperty

      static boolean isNestedProperty(String propertyName)
      Returns true if property is nested, false otherwise.

      Examples:

       isNestedProperty("address.street"); // true
       isNestedProperty("address.street.name"); // true
       isNestedProperty("person"); // false
       isNestedProperty(".name"); // false
       isNestedProperty("person."); // false
       isNestedProperty("person.name."); // false
       isNestedProperty(".person.name"); // false
       isNestedProperty("."); // false
       isNestedProperty(""); // false
       
      Parameters:
      propertyName - the given property name.
      Returns:
      true if property is nested, false otherwise.
      Throws:
      NullPointerException - if given property name is null.
    • removeFirstPropertyIfNested

      static String removeFirstPropertyIfNested(String propertyName)
      Removes the first property from the given property name only if the given property name belongs to a nested property. For example, given the nested property "address.street.name", this method will return "street.name". This method returns an empty String if the given property name does not belong to a nested property.
      Parameters:
      propertyName - the given property name.
      Returns:
      the given property name without its first property, if the property name belongs to a nested property; otherwise, it will return an empty String.
      Throws:
      NullPointerException - if given property name is null.
    • firstPropertyIfNested

      static String firstPropertyIfNested(String propertyName)
      Returns the first property from the given property name only if the given property name belongs to a nested property. For example, given the nested property "address.street.name", this method will return "address". This method returns the given property name unchanged if it does not belong to a nested property.
      Parameters:
      propertyName - the given property name.
      Returns:
      the first property from the given property name, if the property name belongs to a nested property; otherwise, it will return the given property name unchanged.
      Throws:
      NullPointerException - if given property name is null.
    • simplePropertyValues

      private static List<Object> simplePropertyValues(String propertyName, Collection<?> target)
    • propertyValue

      private static Object propertyValue(String propertyName, Object target)