velocity-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergiy Kovalchuk (JIRA)" <...@velocity.apache.org>
Subject [jira] Commented: (VELOCITY-692) have #if handle empty strings/arrays/collections/maps more conveniently
Date Fri, 13 Feb 2009 17:32:59 GMT

    [ https://issues.apache.org/jira/browse/VELOCITY-692?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12673318#action_12673318
] 

Sergiy Kovalchuk commented on VELOCITY-692:
-------------------------------------------

On second thought the whole checking for emptiness in #if statement feature looks to me now
like not a good idea after all.

It is nice to be able to write:
#if($list)
    ...list has elements, display...
#else
   empty or null, nothing to display...
#end

But you won't be able to check specifically for null now, because null and empty are now equal
(both false), plus this will not be backward compatible. In the old code you could write:
#if($list == $null)
   ...list is null... (but also empty now which is unexpected)
#else if($list.size() == 0)
   ...list has no elements (this will never execute now)
#else
   ..list is not empty
#end

(Until I have bad understanding of how it works)

What about new operator #ifEmpty() (or #ifNotEmpty())? 
So instead of:
#if(#list && $list.size() > 0) 
you can write:
#ifNotEmpty($list)
   ...not empty
#else
   ...empty
#end

Kinda mess :)

> have #if handle empty strings/arrays/collections/maps more conveniently
> -----------------------------------------------------------------------
>
>                 Key: VELOCITY-692
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-692
>             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,  <serg472@gmail.com> 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: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


Mime
View raw message