Transformer that outputs a property value.
An implementation of org.apache.commons.collections.Transformer that transforms
the object provided by returning the value of a specified property of the object. The
constructor for BeanToPropertyValueTransformer requires the name of the property
that will be used in the transformation. The property can be a simple, nested, indexed, or
mapped property as defined by org.apache.commons.beanutils.PropertyUtils . If any
object in the property path specified by propertyName is null then the
outcome is based on the value of the ignoreNull attribute.
A typical usage might look like:
// create the transformer
BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer( "person.address.city" );
// transform the Collection
Collection peoplesCities = CollectionUtils.collect( peopleCollection, transformer );
This would take a Collection of person objects and return a Collection
of objects which represents the cities in which each person lived. Assuming...
-
The top level object in the
peeopleCollection is an object which represents a
person.
-
The person object has a
getAddress() method which returns an object which
represents a person's address.
-
The address object has a
getCity() method which returns an object which
represents the city in which a person lives.
author: Norm Deane See Also: org.apache.commons.beanutils.PropertyUtils See Also: org.apache.commons.collections.Transformer |