commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ganesh Gowtham (Issue Comment Edited) (JIRA)" <j...@apache.org>
Subject [jira] [Issue Comment Edited] (BEANUTILS-352) Sorting the collection based on bean property in "CollectionUtils"
Date Wed, 28 Sep 2011 18:17:45 GMT

    [ https://issues.apache.org/jira/browse/BEANUTILS-352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13116657#comment-13116657
] 

Ganesh Gowtham edited comment on BEANUTILS-352 at 9/28/11 6:16 PM:
-------------------------------------------------------------------

Neil ,

Let me know if you need patch file for this release ? , i will attach the
same if you confirm release.

- Ganesh Gowtham


On Wed, Sep 28, 2011 at 7:35 PM, Nick Neuberger (Commented) (JIRA) <



-- 
Thanks
Ganesh GOWTHAM
http://ganesh.gowtham.googlepages.com

                
      was (Author: ganesh.gowtham):
    Neil ,

Let me know if you need patch file for this release ? , i will attach the
same if you confirm release.

- Ganesh Gowtham


On Wed, Sep 28, 2011 at 7:35 PM, Nick Neuberger (Commented) (JIRA) <



-- 
Thanks
Ganesh GOWTHAM
( 98866 46693 | 8 http://ganesh.gowtham.googlepages.com

                  
> Sorting the collection based on bean property in "CollectionUtils"
> ------------------------------------------------------------------
>
>                 Key: BEANUTILS-352
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-352
>             Project: Commons BeanUtils
>          Issue Type: Improvement
>          Components: Bean-Collections
>         Environment: JDK 1.5 and above , Apache Collections 
>            Reporter: Ganesh Gowtham
>             Fix For: LATER THAN 1.8.4
>
>         Attachments: CollectionsUtilExt.java, CollectionsUtilExtTestCase.java
>
>
> Hi Folks , 
> Thanks for your good work done in Collection Framework .
> It would be good if you add functionality to sort the collection based on bean's property
name . ( CollectionsUtils,java)
> For example i have List<Person> , i should be able to sort (ascending or desending
) based on person's salary (or) firstName (or) lastName (or) may be the combination of above

> below is the equivalent in SQL 
> (select * from person order by salary,firtsName,lastName asc ) 
> method looks like 
> public static <T> void sort(List<T> list, boolean isAscending,String... beanPropertyName)
{
> 		Collection<Comparator<T>> beanComparatorCollection = new ArrayList<Comparator<T>>(beanPropertyName.length);
> 		for(int i =0;i<beanPropertyName.length;i++)
> 		{
> 			beanComparatorCollection.add(new BeanComparator(beanPropertyName[i]));
> 		}
> 		Comparator<T> finalComparator = ComparatorUtils.chainedComparator(beanComparatorCollection);
> 		if (!isAscending) {
> 			finalComparator = new ReverseComparator(finalComparator);
> 		}
> 		Collections.sort(list, finalComparator);
> 	}
> Please let me know if you need any details , infact i able to submit patch too .

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message