Commons BeanUtils
  1. Commons BeanUtils
  2. BEANUTILS-375

Provide static methods to simplify usage of BeanToPropertyValueTransformer with CollectionUtils

    Details

    • Type: Improvement Improvement
    • Status: Reopened
    • Priority: Trivial 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"))

        Activity

        Hide
        Tomasz Nurkiewicz added a comment -

        Example usage of this utility method has been explained here: http://nurkiewicz.blogspot.com/2010/05/clean-code-clean-logs-do-you-know-what.html.

        Show
        Tomasz Nurkiewicz added a comment - Example usage of this utility method has been explained here: http://nurkiewicz.blogspot.com/2010/05/clean-code-clean-logs-do-you-know-what.html .
        Hide
        Niall Pemberton added a comment -

        It doesn't really add much benefit - it will just mean one line of your code is slightly shorter

        Show
        Niall Pemberton added a comment - It doesn't really add much benefit - it will just mean one line of your code is slightly shorter
        Hide
        Ondra Žižka added a comment - - edited

        I would like to have this implemented.

        1) IMO that's the most often use case, would be used a lot.

        It doesn't really add much benefit - it will just mean one line of your code is slightly shorter

        Well, that's the purpose of commons, isn't it? To save people from writing boilerplate code.
        You can write whole application to one line. What is the limit of "slightly"?
        It's not about the length of line, it's about making the code more readable.
        When someone decides to use BeanToPropertyValueTransformer, then he usually uses it several times in a class.
        Removing all occurrences of this ugly long name would help improve readability.

        Please reconsider this.

        Show
        Ondra Žižka added a comment - - edited I would like to have this implemented. 1) IMO that's the most often use case, would be used a lot. It doesn't really add much benefit - it will just mean one line of your code is slightly shorter Well, that's the purpose of commons, isn't it? To save people from writing boilerplate code. You can write whole application to one line. What is the limit of "slightly"? It's not about the length of line, it's about making the code more readable. When someone decides to use BeanToPropertyValueTransformer , then he usually uses it several times in a class. Removing all occurrences of this ugly long name would help improve readability. Please reconsider this.
        Hide
        Ondra Žižka added a comment -

        I'd also suggest to allow voting on resolved / closed issues.

        Show
        Ondra Žižka added a comment - I'd also suggest to allow voting on resolved / closed issues.
        Hide
        Henri Yandell added a comment -

        Reopening for reconsideration.

        Btw; I don't see a way to configure voting beyond on/off.

        Show
        Henri Yandell added a comment - Reopening for reconsideration. Btw; I don't see a way to configure voting beyond on/off.

          People

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

            Dates

            • Created:
              Updated:

              Development