Class Properties<T>


  • public class Properties<T>
    extends java.lang.Object
    Extracts the values of a specified property from the elements of a given Iterable or array.
    Author:
    Yvonne Wang, Mikhail Mazursky, Joel Costigliola, Florent Biville, Olivier Michallat
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Properties<java.lang.Object> extractProperty​(java.lang.String propertyName)
      Creates a new Properties with given propertyName and Object as property type..
      static <T> Properties<T> extractProperty​(java.lang.String propertyName, java.lang.Class<T> propertyType)
      Creates a new Properties.
      java.lang.Iterable<T> from​(java.lang.Iterable<?> c)
      Extracts the values of the property (specified previously in extractProperty(String)) from the elements of the given Iterable.
      java.lang.Iterable<T> from​(java.lang.Object[] array)
      Extracts the values of the property (specified previously in extractProperty(String)) from the elements of the given array.
      <U> Properties<U> ofType​(java.lang.Class<U> propertyType)
      Specifies the target type of an instance that was previously created with extractProperty(String).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • extractProperty

        public static <T> Properties<T> extractProperty​(java.lang.String propertyName,
                                                        java.lang.Class<T> propertyType)
        Creates a new Properties.
        Parameters:
        propertyName - the name of the property to be read from the elements of a Iterable. It may be a nested property (e.g. "address.street.number").
        propertyType - the type of property to extract
        Returns:
        the created Properties.
        Throws:
        java.lang.NullPointerException - if the given property name is null.
        java.lang.IllegalArgumentException - if the given property name is empty.
      • extractProperty

        public static Properties<java.lang.Object> extractProperty​(java.lang.String propertyName)
        Creates a new Properties with given propertyName and Object as property type..
        Parameters:
        propertyName - the name of the property to be read from the elements of a Iterable. It may be a nested property (e.g. "address.street.number").
        Returns:
        the created Properties.
        Throws:
        java.lang.NullPointerException - if the given property name is null.
        java.lang.IllegalArgumentException - if the given property name is empty.
      • ofType

        public <U> Properties<U> ofType​(java.lang.Class<U> propertyType)
        Specifies the target type of an instance that was previously created with extractProperty(String).

        This is so that you can write:

         extractProperty("name").ofType(String.class).from(fellowshipOfTheRing)
         
        instead of:
         extractProperty("name", String.class).from(fellowshipOfTheRing)
         

        Parameters:
        propertyType - the type of property to extract.
        Returns:
        a new Properties with the given type.
      • from

        public java.lang.Iterable<T> from​(java.lang.Iterable<?> c)
        Extracts the values of the property (specified previously in extractProperty(String)) from the elements of the given Iterable.
        Parameters:
        c - the given Iterable.
        Returns:
        the values of the previously specified property extracted from the given Iterable.
        Throws:
        org.fest.util.IntrospectionError - if an element in the given Iterable does not have a property with a matching name.
      • from

        public java.lang.Iterable<T> from​(java.lang.Object[] array)
        Extracts the values of the property (specified previously in extractProperty(String)) from the elements of the given array.
        Parameters:
        array - the given array.
        Returns:
        the values of the previously specified property extracted from the given array.
        Throws:
        org.fest.util.IntrospectionError - if an element in the given array does not have a property with a matching name.