Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-375

Provide static methods to simplify usage of BeanToPropertyValueTransformer with CollectionUtils

    Details

    • Type: Improvement
    • Status: Reopened
    • Priority: Trivial
    • Resolution: Unresolved
    • Affects Version/s: 1.8.3
    • Fix Version/s: None
    • Component/s: Bean-Collections
    • Labels:
      None

      Description

      Provide static BeanToPropertyValueTransformer#collect methods to simplify the usage of BeanToPropertyValueTransformer with CollectionUtils#collect. See attached implementation. This is how such a utility method could be used (pay attention to static import):

      import org.junit.Test;
      
      import java.util.Arrays;
      import java.util.Collection;
      import java.util.List;
      import java.util.Locale;
      
      import static org.apache.commons.beanutils.BeanToPropertyValueTransformer.collect;
      import static org.fest.assertions.Assertions.assertThat;
      
      public class TestCollect {
      
      	@Test
      	public void proofOfConcept() throws Exception {
      		//given
      		List<Locale> locales = Arrays.asList(
      				Locale.FRANCE,
      				Locale.GERMANY,
      				Locale.ITALY,
      				new Locale("pl", "PL"));
      
      		//when: calls Locale.getCounty() on each item
      		Collection countries = collect(locales, "country");
      
      		//then
      		assertThat(countries).containsOnly("FR", "DE", "IT", "PL");
      	}
      
      }

      Without proposed method:

      Collection countries = CollectionUtils.collect(locales, new BeanToPropertyValueTransformer("country"))

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              nurkiewicz Tomasz Nurkiewicz
            • Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: