You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jspwiki.apache.org by Andrew Jaquith <an...@gmail.com> on 2009/05/12 06:57:45 UTC

Re: [jira] Commented: (JSPWIKI-528) Rationalise the use of Collections, particularly with regard to pages

In applying the patches, I mostly stuck to the stated purpose of the
original filing, which was to reduce the need to pack/unpack
collections of WikiPages and the like by using narrower Collection
return types. New methods for sorting are just that, new methods; it
wasn't clear to me you wanted to add features in addition to just
optimizing.

What is the use case you have in mind? It it's just name order than
you need, you can just call filterCollection() and then
Collections.sort() on the returned collection because WikiPage
implements Comparable<WikiPage>, the default implementation of which
sorts by name. Collections.sort( Comparator) would allow other orders.

Andrew

On Mon, May 11, 2009 at 3:20 AM, Greg Kable <gr...@serapsys.com> wrote:
>> Andrew Jaquith commented on JSPWIKI-528:
>> ----------------------------------------
>> Also, I chose a different idiom for the method signatures
>> that indicate when Lists should be sorted. Instead of
>> creating a method ContentManager.getAllPagesSorted(
>> String space ) as suggested in the patch, I created an
>> alternate method getAllPages(String,Comparator<WikiPage>)
>> that makes the sort request explicit (via the Comparator)
>> and is also customizable. In addition, to allowed returned
>> Lists to be sorted simply using Collections,sort(), WikiPage
>> now extends Comparable<WikiPage>, as does JCRWikiPage.
>
> Just spotted a problem...
>
> Since my patches add multiple ways of sorting pages, including a plugin
> parameter, the logical place to do that is in AbstractFilteredPlugin. If
> it's not done there, we'll end up with a ton of cut and paste code to find
> and use the correct comparator.
>
> Does anybody have any objection to me adding a filterAndSortCollection
> method to AbstractFilteredPlugin?
>
> Thanks,
>        Greg
>

Re: [jira] Commented: (JSPWIKI-528) Rationalise the use of Collections, particularly with regard to pages

Posted by Janne Jalkanen <Ja...@ecyrd.com>.
> getAllPages
> filterCollection
> findComparator
> sort
>
> This is such a common pattern in the Plugins that it really should  
> be a separate API on the AbstractFilteredPlugin.

+1.  It is true that it's a common enough pattern.

/Janne

Re: [jira] Commented: (JSPWIKI-528) Rationalise the use of Collections, particularly with regard to pages

Posted by Harry Metske <ha...@gmail.com>.
+1 from me too



2009/5/12 Greg Kable <gr...@jspwiki.arbler.com>

> Andrew Jaquith wrote:
>
>> .... New methods for sorting are just that, new methods; it
>> wasn't clear to me you wanted to add features in addition to just
>> optimizing.
>>
>> What is the use case you have in mind? It it's just name order than
>> you need, you can just call filterCollection() and then
>> Collections.sort() on the returned collection because WikiPage
>> implements Comparable<WikiPage>, the default implementation of which
>> sorts by name. Collections.sort( Comparator) would allow other orders.
>>
>
> JSPWiki-528 was about refactoring.  This is for the 3.0 port of JSPWiki-526
> which adds new features and a new parameter to filtered plugins (sortorder).
>  The big issue is finding the right Comparator which really should be
> abstracted in to AbstractFilteredPlugin the same as filterCollection.
>
> Even if I didn't want AbstractFilteredPlugin to handle finding the
> Comparator, I also personally dislike cut-and-paste coding where everybody
> ends up writing the same four lines of code:
>
> getAllPages
> filterCollection
> findComparator
> sort
>
> This is such a common pattern in the Plugins that it really should be a
> separate API on the AbstractFilteredPlugin.
>
> regards,
>        Greg
>
>
>

Re: [jira] Commented: (JSPWIKI-528) Rationalise the use of Collections, particularly with regard to pages

Posted by Greg Kable <gr...@jspwiki.arbler.com>.
Andrew Jaquith wrote:
> .... New methods for sorting are just that, new methods; it
> wasn't clear to me you wanted to add features in addition to just
> optimizing.
> 
> What is the use case you have in mind? It it's just name order than
> you need, you can just call filterCollection() and then
> Collections.sort() on the returned collection because WikiPage
> implements Comparable<WikiPage>, the default implementation of which
> sorts by name. Collections.sort( Comparator) would allow other orders.

JSPWiki-528 was about refactoring.  This is for the 3.0 port of 
JSPWiki-526 which adds new features and a new parameter to filtered 
plugins (sortorder).  The big issue is finding the right Comparator 
which really should be abstracted in to AbstractFilteredPlugin the same 
as filterCollection.

Even if I didn't want AbstractFilteredPlugin to handle finding the 
Comparator, I also personally dislike cut-and-paste coding where 
everybody ends up writing the same four lines of code:

getAllPages
filterCollection
findComparator
sort

This is such a common pattern in the Plugins that it really should be a 
separate API on the AbstractFilteredPlugin.

regards,
	Greg