velocity-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Byron Foster (JIRA)" <>
Subject [jira] Commented: (VELOCITY-692) have #if handle empty strings/arrays/collections/maps more conveniently
Date Sat, 14 Feb 2009 11:37:59 GMT


Byron Foster commented on VELOCITY-692:

To clarify my original comment, yes, I meant that #if would also return true if the object
is non-null and the other conditions did not fail.

Anyway, I wonder if including both length() and isEmpty() too wide a net.  I propose testing
length() only if the object is of type CharSequence, this prevents the call to toString(),
but provides similar functionality.  In fact, my real interest in this issue is to remove
the toString() method call :).  As far as testing for the general emptiness of containers
I could go either way.  One is the Python way, the other is the Ruby way, both have merit.

However,  I noticed that equals and not-equals tests also call toString() as in #if($a ==
$b).  So at least this is consistent.  Maybe a discussion for another Issue.

> have #if handle empty strings/arrays/collections/maps more conveniently
> -----------------------------------------------------------------------
>                 Key: VELOCITY-692
>                 URL:
>             Project: Velocity
>          Issue Type: New Feature
>          Components: Engine
>            Reporter: Nathan Bubna
>            Priority: Trivial
> An idea from the dev list:
> -------------------------------------------------------------------------------------------------
> On Sat, Feb 7, 2009 at 3:41 PM,  <> wrote:
> > Hello,
> > I wanted to share with you a few ideas I have about new simple
> > improvements for DisplayTools. I should be able to make patches for
> > them if you are interested.
> >
> > 1. Add new method
> >
> > isEmpty(object)
> >
> > that will return true if the object is null or empty (for strings it's
> > zero length; for collections, maps and arrays it's zero size). This
> > should help with  annoying null checks. (Probably a better place for
> > this method would be Engine, not Tools)
> yeah, not something for tools.  would be interesting to have the
> Uberspect pretend that every non-null reference has an isEmpty()
> method, or perhaps just add 0-length strings, empty collections, empty
> maps and 0-length arrays to the list of things that #if( $foo )
> considers false.
> -------------------------------------------------------------------------------------------------

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message