commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Pugh" <ep...@upstate.com>
Subject RE: [collections] InvokerClosure
Date Thu, 02 Dec 2004 20:22:18 GMT
Is the final result:

 CollectionUtils.forAllDo(configList, new InvokerClosure("clearProperty",
 String.class, key));

Compared to the original really that much cleaner?:
 for (Iterator i = configList.iterator(); i.hasNext();)
 {
      Configuration config = (Configuration) i.next();
      config.clearProperty(key);
 }

Things like this are cool..  But..  within the context of java, they just
seem more difficult to read..  Requiring the user to know what an
InvokerClosure is and does.  It's neat..  I just haven't seen the use case
that requires it...


Eric

> -----Original Message-----
> From: Emmanuel Bourg [mailto:smanux@lfjr.net]
> Sent: Thursday, December 02, 2004 6:17 PM
> To: Jakarta Commons Developers List
> Subject: [collections] InvokerClosure
>
>
> Hi all, I decided to play a bit with closures today and tried replacing
> a trivial loop in [configuration] :
>
> for (Iterator i = configList.iterator(); i.hasNext();)
> {
>      Configuration config = (Configuration) i.next();
>      config.clearProperty(key);
> }
>
> I thought a closure would help reducing the code, but actually I ended
> with something much longer :
>
> CollectionUtils.forAllDo(configList, new TransformerClosure(new
> InvokerTransformer("clearProperty", new Class[] { String.class }, new
> Object[] { key })));
>
> Then I found the invokerClosure method in ClosureUtils, the code turned
> into :
>
> CollectionUtils.forAllDo(configList,
> ClosureUtils.invokerClosure("clearProperty", new Class[] { String.class
> }, new Object[] { key }));
>
> Slightly better but still quite long. Why is there no InvokerClosure
> class ? This is the only closure in ClosureUtils that has no
> corresponding class, this could make the code a bit shorter:
>
> CollectionUtils.forAllDo(configList, new InvokerClosure("clearProperty",
> new Class[] { String.class }, new Object[] { key }));
>
> Also the Class[] and Object[] are quite cumbersome, that would be nice
> to add methods/constructors to invoke simple methods with only one or
> two parameters. Thus my example could look like this:
>
> CollectionUtils.forAllDo(configList, new InvokerClosure("clearProperty",
> String.class, key));
>
> which is much more readable.
>
> What do you think ?
>
> Emmanuel Bourg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message