velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: [tools] Replacement for ListTool?
Date Thu, 26 Jun 2014 21:32:49 GMT
Sergiu,

On 6/26/14, 3:34 PM, Sergiu Dumitriu wrote:
> This should work without any tools:
> 
> $bundleType.class.getName().startsWith('[')

Oh, that's cool.. but it doesn't check for java.util.List (I'd need to
either do the ugliness I have below, or check for each expected List
implementation which of course makes no sense).

Any other suggestions? If not, I'll do what I have below plus checking
against '['.

Thanks,
-chris

> 
> On 06/26/2014 03:27 PM, Christopher Schultz wrote:
>> All,
>>
>> ListTool is marked as deprecated because Velocity 1.6 and later treat
>> arrays and lists as first-class collections and can perform appropriate
>> operations on them.
>>
>> One thing it's not easy to do is determine if an object is an List or an
>> Array.
>>
>> I have something hacked-together using ClassTool like this:
>>
>> #set($bundleType=$class.inspect($bundle).type)
>> #if($bundleType &&
>> $class.inspect('java.util.List').type.isAssignableFrom($bundleType))
>>
>> [the $bundle object is a List]
>> #end
>>
>> But it's kind of verbose, plus I need to check to see if it's an array
>> as well.
>>
>> Any suggestions using existing tools?
>>
>> Thanks,
>> -chris
>>
> 
> 


Mime
View raw message