commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ganesh Gowtham (JIRA)" <j...@apache.org>
Subject [jira] Commented: (COLLECTIONS-329) Sorting the collection based on bean property in "CollectionUtils"
Date Mon, 13 Jul 2009 09:19:14 GMT

    [ https://issues.apache.org/jira/browse/COLLECTIONS-329?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12730266#action_12730266
] 

Ganesh Gowtham commented on COLLECTIONS-329:
--------------------------------------------

Henri Yandell  Thanks in advance to spend time for this enhancement.

well as you said we have BeanComparator,ComparatorUtils as seperate .

public static <T> void sort(List<T> list, boolean isAscending,String... beanPropertyName)

{
.....
}

This method will take for example List<Persons> and sorts on Person's property(ies)
in any order by just invoking one method....

Please let me know your comment 

> Sorting the collection based on bean property in "CollectionUtils"
> ------------------------------------------------------------------
>
>                 Key: COLLECTIONS-329
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-329
>             Project: Commons Collections
>          Issue Type: New Feature
>          Components: Collection, Comparator
>    Affects Versions: 3.2
>         Environment: JDK 1.5 and above , Apache Collections 
>            Reporter: Ganesh Gowtham
>            Priority: Minor
>
> 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.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message