On sorting

2013-05-25 Thread Ricardo.Julio.Rodriguez.Fernandez
I'm really getting mad! :-) Of course I know that the only reason for this is 
my lack of skills!!! Catching up...

I do need some kind of security. Please, could you confirm this statement...

Class SortTool can be used to sort any list of objects, but NOT a list of 
strings.

http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/SortTool.html

Thanks!

--
Ricardo Rodríguez
Research Management and Promotion Technician
Technical Secretariat
Health Research Institute of Santiago de Compostela (IDIS)
http://www.idisantiago.es

Nota: A información contida nesta mensaxe e os seus posibles documentos 
adxuntos é privada e confidencial e está dirixida únicamente ó seu 
destinatario/a. Se vostede non é o/a destinatario/a orixinal desta mensaxe, por 
favor elimínea. A distribución ou copia desta mensaxe non está autorizada.

Nota: La información contenida en este mensaje y sus posibles documentos 
adjuntos es privada y confidencial y está dirigida únicamente a su 
destinatario/a. Si usted no es el/la destinatario/a original de este mensaje, 
por favor elimínelo. La distribución o copia de este mensaje no está autorizada.

See more languages: http://www.sergas.es/aviso_confidencialidad.htm

-
To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
For additional commands, e-mail: user-h...@velocity.apache.org



Re: On sorting

2013-05-25 Thread Sergiu Dumitriu
On 05/25/2013 11:39 AM, ricardo.julio.rodriguez.fernan...@sergas.es wrote:
 I'm really getting mad! :-) Of course I know that the only reason for this is 
 my lack of skills!!! Catching up...
 
 I do need some kind of security. Please, could you confirm this statement...
 
 Class SortTool can be used to sort any list of objects, but NOT a list of 
 strings.

Where did you get this from? It is not true, it can sort any list of
comparable things:

#set ($strings = ['a', 'x', 'b', 'r', 'f'])
$sorttool.sort($strings) - [a, b, f, r, x]

 http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/SortTool.html
 
 Thanks!



-
To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
For additional commands, e-mail: user-h...@velocity.apache.org



Re: On sorting

2013-05-25 Thread Sergiu Dumitriu
On 05/25/2013 11:59 AM, ricardo.julio.rodriguez.fernan...@sergas.es wrote:
 
 From: Sergiu Dumitriu [sergiu.dumit...@gmail.com]
 Sent: 25 May 2013 17:49
 To: Velocity Users List
 Subject: Re: On sorting

 On 05/25/2013 11:39 AM, ricardo.julio.rodriguez.fernan...@sergas.es wrote:
 I'm really getting mad! :-) Of course I know that the only reason for this 
 is my lack of skills!!! Catching up...

 I do need some kind of security. Please, could you confirm this statement...

 Class SortTool can be used to sort any list of objects, but NOT a list of 
 strings.

 Where did you get this from? It is not true, it can sort any list of
 comparable things:

 #set ($strings = ['a', 'x', 'b', 'r', 'f'])
 $sorttool.sort($strings) - [a, b, f, r, x]

 
 Great! It is clear my wrong interpretation of this sentence...
 
 SortTool allows a user to sort a collection (or array, iterator, etc) on any 
 arbitary set of properties exposed by the objects contained within the 
 collection.
 
 It is taken from the link below. No reference to strings, it speaks only 
 about objects. But it is great to be wrong!

Yes, that is the more advanced part of the SortTool, the ability to sort
beans [1] by one or more of their properties. Unfortunately Strings
are not beans, so the sort methods that take a second parameter can't be
used for a simple list of strings.


[1] http://en.wikipedia.org/wiki/JavaBeans

 And, in this case, how could I get a reverse/desc order?

It's not possible using the SortTool, but in XWiki we have the
$collectionstool [2, 3] which does provide both a simple sort(List) and
a reverse(List) method, so you could do:

#set ($discard = $collectionstool.sort($list))
#set ($discard = $collectionstool.reverse($list))

Keep in mind that these two methods sort the list in place, and they
return true if the list could be sorted/reversed.


[2]
https://github.com/xwiki/xwiki-commons/blob/xwiki-commons-5.0/xwiki-commons-core/xwiki-commons-velocity/src/main/java/org/xwiki/velocity/tools/CollectionsTool.java

[3]
http://platform.xwiki.org/xwiki/bin/view/SRD/Navigation?api=collectionstoolxpage=embed

 Thanks!
 
 http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/SortTool.html

 Thanks!


-
To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
For additional commands, e-mail: user-h...@velocity.apache.org