Feb 17 2008

GroovyCacheMap

Published by Robert Fischer at 5:45 pm under Uncategorized

Since it was easy enough to do, I just created a GroovyCacheMap, which takes a Groovy Closure (see info at “Closures“).

Someone with a Groovy background wanna make sure that it’s sufficiently groovy-esque for users, and start fishing for those really horrible surprises?

I should really be working on the pipelines. But there’s a lot of annoyance there, and I miss being productive.

Popularity: 5% [?]

3 Responses to “GroovyCacheMap”

  1. Hamlet D'Arcyon 19 Feb 2008 at 5:07 pm

    You can just as easily use the “as” keyword when passing the original CacheMap a groovy closure to make a groovy closure convert into a one-method interface (in this case a Transformer). This runs fine if you classpath is set up correctly… check it out:

    import jconch.cache.CacheMap;
    import org.apache.commons.collections.Transformer;
    import org.apache.commons.lang.StringUtils;

    def transformer = { stringToValidate ->
        if (stringToValidate == null) return false;

        return ((!StringUtils.isBlank(stringToValidate.toString())) &&
            (!StringUtils.isAlpha(stringToValidate.toString())));
    }

    CacheMap validationCache = new CacheMap(transformer as Transformer);

    assert false == validationCache.get(null);
    assert false == validationCache.get(”");
    assert false == validationCache.get(”A”);
    assert true == validationCache.get(”2″);
    assert true == validationCache.get(2);
    assert true == validationCache.get(”A2A”);
    assert true == validationCache.get(”2A2″);
    assert true == validationCache.get(new StringBuffer(”2A2″));
    println “Success!”

  2. Robert Fischeron 20 Feb 2008 at 6:26 am

    Wow. Seriously.

  3. Robert Fischeron 20 Feb 2008 at 1:26 pm

    Pipelines in Groovy are going to be crazy simple. :)

Trackback URI | Comments RSS

Leave a Reply

Green Web Hosting! This site hosted by DreamHost.