Re: [tools] Replacement for ListTool?

Christopher Schultz <[email protected]> Thu, 26 Jun 2014 17:32:49 -0400
Newsgroups gmane.comp.jakarta.velocity.user
Message-ID <[email protected]>
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
>>
> 
>
signature.asc (application/pgp-signature, 924 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJTrJGBAAoJEBzwKT+lPKRYDMAQALbbYoXVrhbMAu6AbtyaDWNd
8Ek0D0vLpYpg7w6lecPGwZmBXN/D6C8C5Nu8ZchDrRJeTyZvF2Phn54oo1Ir61z2
MuFU4YHJoXPYiZeXwlWUVTlAXjSdF/WqRKljzVKes5p4SVsXl31lxEBE3/bbkdqT
7+f9dk9qvsGFFqz+E6DcRcjQTBcpvT1SB60voXONQAXZIO5tiV1rdICNbyTQTD19
st7ex1d42JsH7Z2dPSgQefHuJsWl53YTZGWfqzPvQsCx6ZSTF/JxqdABlcDab5g3
0QUymvYdY/4h88BuIEnaC5ChWiWLuZiEsrhYANRHINa4EoAxgnGoC8PNREqTUZIp
2lr8WeOA7Om39/4QhbZYANLCDYDNuP2TM2Hvd6e9Wejt7FfL/RqFu0YMTeZhT5m9
+ZYz/REnfzDfKEF5031lj4hATKuT7vSTxyRZXZKwIhmJe1zJkY2iwgag0/kD54yz
tNz2R0HOdtEVemXsiYgTu+c/n8l76IQ0V7a0HE3hIZJ1qnIKLJUdgnBzX8m8g8ZM
7TJwc2XHC2k1nWt0rfPzlFaRHzs99VYzEZdkVvQ9YT2Aux4+bas8CCfvT3qdQJ2I
sWeGvtOahTtZNGIVIL2ReygzAlKiIYuZBfGak1s4vCTpiBbZxWhipm6108cyHWYF
dwDsmGVi+Bx/qn+2KNpT
=JcVs
-----END PGP SIGNATURE-----