You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Ri...@sergas.es on 2013/05/25 17:39:35 UTC

On sorting

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-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: On sorting

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Ricardo,

On 5/25/13 11:39 AM, Ricardo.Julio.Rodriguez.Fernandez@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.

It's worth noting (because you mentioned it in two threads, now), that
Strings *are* Objects.

So, if a String is an Object, and SortTool can sort lists of Objects,
then SortTool can sort a list of Strings ;)

-chris


RE: On sorting

Posted by Ri...@sergas.es.
> ________________________________________
> From: Sergiu Dumitriu [sergiu.dumitriu@gmail.com]
> Sent: 25 May 2013 18:19
> To: Velocity Users List
> Subject: Re: On sorting
>
> On 05/25/2013 11:59 AM, Ricardo.Julio.Rodriguez.Fernandez@sergas.es wrote:
>>> ________________________________________
>>> From: Sergiu Dumitriu [sergiu.dumitriu@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.Fernandez@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.
>

I think I get this. And, as said in [1], these tools are available in XWiki since 4.0M1.

Perhaps I should had been called this thread "On sorting strings" or "On sorting naked strings" or "On sorting pure strings" or anything fitting better what we dealt with?

By the way, [2] is great!

[1]
http://extensions.xwiki.org/xwiki/bin/view/Extension/Velocity+Module#HVelocityTools

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

Thanks!

>
> [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=collectionstool&xpage=embed
>
>> Thanks!
>>
>>>> http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/SortTool.html
>>>>
>>>> Thanks!

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-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: On sorting

Posted by Sergiu Dumitriu <se...@gmail.com>.
On 05/25/2013 11:59 AM, Ricardo.Julio.Rodriguez.Fernandez@sergas.es wrote:
>> ________________________________________
>> From: Sergiu Dumitriu [sergiu.dumitriu@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.Fernandez@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=collectionstool&xpage=embed

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


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


RE: On sorting

Posted by Ri...@sergas.es.
> ________________________________________
> From: Sergiu Dumitriu [sergiu.dumitriu@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.Fernandez@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!

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

Thanks!

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

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-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: On sorting

Posted by Sergiu Dumitriu <se...@gmail.com>.
On 05/25/2013 11:39 AM, Ricardo.Julio.Rodriguez.Fernandez@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-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org