[jira] Created: (COLLECTIONS-329) Sorting the collection based on bean property in "CollectionUtils"

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (COLLECTIONS-329) Sorting the collection based on bean property in "CollectionUtils"

ASF GitHub Bot (Jira)
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.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (COLLECTIONS-329) Sorting the collection based on bean property in "CollectionUtils"

ASF GitHub Bot (Jira)

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

Henri Yandell commented on COLLECTIONS-329:
-------------------------------------------

Have a look at http://commons.apache.org/beanutils/bean-collections/index.html - it conains a BeanComparator. It's a 'join' package in that it contains the overlap of BeanUtils and Collections.

Possibly I'm not understanding the enhancement request :)

> 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.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (COLLECTIONS-329) Sorting the collection based on bean property in "CollectionUtils"

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ 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.

Reply | Threaded
Open this post in threaded view
|

[jira] Moved: (BEANUTILS-352) Sorting the collection based on bean property in "CollectionUtils"

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/BEANUTILS-352?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell moved COLLECTIONS-329 to BEANUTILS-352:
-----------------------------------------------------

          Component/s:     (was: Comparator)
                           (was: Collection)
                       Bean-Collections
    Affects Version/s:     (was: 3.2)
           Issue Type: Improvement  (was: New Feature)
                  Key: BEANUTILS-352  (was: COLLECTIONS-329)
              Project: Commons BeanUtils  (was: Commons Collections)

> 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
>            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.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (BEANUTILS-352) Sorting the collection based on bean property in "CollectionUtils"

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Henri Yandell commented on BEANUTILS-352:
-----------------------------------------

Moved over to BeanUtils as BeanComparator lives there. At first glance seems like a fine utility method to save developer time.

> 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
>            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.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (BEANUTILS-352) Sorting the collection based on bean property in "CollectionUtils"

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/BEANUTILS-352?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Niall Pemberton updated BEANUTILS-352:
--------------------------------------

    Fix Version/s: LATER THAN 1.8.1

> 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
>            Priority: Minor
>             Fix For: LATER THAN 1.8.1
>
>
> 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.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (BEANUTILS-352) Sorting the collection based on bean property in "CollectionUtils"

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Ganesh Gowtham commented on BEANUTILS-352:
------------------------------------------

Dear Niall Pemberton ,

Thanks for your reply .

infact i have idea to add some more functionalities

i am ready with patch code with junit , Please let me know if can able to contribute for Fix Version/s: LATER THAN 1.8.1

//Picks the highest element from collection of valueObjects based
//on the beanAttribute .
1) public static <T> T min(Collection<T> list, String beanPropertyName)
   {
    ...
    }


//Picks the lowest element from collection of valueObjects based
//on the beanAttribute .
2) public static <T> T min(Collection<T> list, String beanPropertyName)
   {
   ...
    }


// Selects the object from collection based on beanProperty and value
// like select * from Person where name='Ganesh Gowtham' ( i will get the Person Object)
 3 ) public static <T> T selectObjectFromCollection(Collection<T> list,
   String beanPropertyName, Object value)
   {
   ...
   }

// Selects the Collection of objects from main collection
// like select * from Person where salary = 3000  --> returns the List<Person> with salary = 3000
4 ) public static <T> Collection<T> selectFromList(Collection<T> list,
   String beanPropertyName, Object value)
      {
       ...
       }


// higher version of (4) where in (5) will take array of attrbute names and array of values  
5) public static <T> Collection<T> selectFromList(Collection<T> list,
String[] beanPropertyName, Object[] value)
    {
    ...
    }


Thanks for your Good Work .

Gowtham
8 http://ganesh.gowtham.googlepages.com 



From: Niall Pemberton (JIRA)
Sent: Tue 8/4/2009 9:10 PM
To: [hidden email]
Subject: [jira] Updated: (BEANUTILS-352) Sorting the collection based on bean property in "CollectionUtils"


     [ https://issues.apache.org/jira/browse/BEANUTILS-352?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Niall Pemberton updated BEANUTILS-352:
--------------------------------------

    Fix Version/s: LATER THAN 1.8.1


--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


> 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
>            Priority: Minor
>             Fix For: LATER THAN 1.8.1
>
>
> 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.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (BEANUTILS-352) Sorting the collection based on bean property in "CollectionUtils"

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/BEANUTILS-352?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ganesh Gowtham updated BEANUTILS-352:
-------------------------------------

    Priority: Major  (was: Minor)

> 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.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (BEANUTILS-352) Sorting the collection based on bean property in "CollectionUtils"

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/BEANUTILS-352?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ganesh Gowtham updated BEANUTILS-352:
-------------------------------------

    Attachment: CollectionsUtilExt.java
                CollectionsUtilExtTestCase.java

Added CollectionUtilsExt and Test case

> 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.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (BEANUTILS-352) Sorting the collection based on bean property in "CollectionUtils"

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Ganesh Gowtham commented on BEANUTILS-352:
------------------------------------------

hi Henri Yandell  ,  

As there was no update from Apache Side , I had added following files to JIRA

CollectionsUtilExt
CollectionsUtilExtTestCase

Please let me know your view on this .

Thanks
Ganesh Gowtham



> 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.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Issue Comment Edited: (BEANUTILS-352) Sorting the collection based on bean property in "CollectionUtils"

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Ganesh Gowtham edited comment on BEANUTILS-352 at 7/12/10 11:26 PM:
--------------------------------------------------------------------

hi Henri Yandell  ,  

As there was no update from Apache Side , I had added following files to JIRA

http://sites.google.com/site/ganeshgowtham/Home/submissions/collection-utils-extension-to-apache-common-collections

CollectionsUtilExt
CollectionsUtilExtTestCase

Please let me know your view on this .

Thanks
Ganesh Gowtham



      was (Author: ganesh.gowtham):
    hi Henri Yandell  ,  

As there was no update from Apache Side , I had added following files to JIRA

CollectionsUtilExt
CollectionsUtilExtTestCase

Please let me know your view on this .

Thanks
Ganesh Gowtham


 

> 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.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Issue Comment Edited: (BEANUTILS-352) Sorting the collection based on bean property in "CollectionUtils"

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Ganesh Gowtham edited comment on BEANUTILS-352 at 7/12/10 11:30 PM:
--------------------------------------------------------------------

hi Henri Yandell  ,  

As there was no update from Apache Side , So I had added following files to JIRA including jUnit cases .

CollectionsUtilExt
CollectionsUtilExtTestCase


Same has been uploaded at

http://sites.google.com/site/ganeshgowtham/Home/submissions/collection-utils-extension-to-apache-common-collections


Please let me know your view on this .

Thanks
Ganesh Gowtham



      was (Author: ganesh.gowtham):
    hi Henri Yandell  ,  

As there was no update from Apache Side , I had added following files to JIRA

http://sites.google.com/site/ganeshgowtham/Home/submissions/collection-utils-extension-to-apache-common-collections

CollectionsUtilExt
CollectionsUtilExtTestCase

Please let me know your view on this .

Thanks
Ganesh Gowtham


 

> 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.
-
You can reply to this email to add a comment to the issue online.