<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Kaptain on ... stuff &#187; Collections</title>
	<atom:link href="http://www.kellyrob99.com/blog/tag/collections/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kellyrob99.com/blog</link>
	<description>Tales of development, life and the folly that goes along with both</description>
	<lastBuildDate>Thu, 01 Jul 2010 21:07:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Achieving Groovy-like Fluency in Java with Google Collections</title>
		<link>http://www.kellyrob99.com/blog/2010/05/15/achieving-groovy-like-fluency-in-java-with-google-collections/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=achieving-groovy-like-fluency-in-java-with-google-collections</link>
		<comments>http://www.kellyrob99.com/blog/2010/05/15/achieving-groovy-like-fluency-in-java-with-google-collections/#comments</comments>
		<pubDate>Sun, 16 May 2010 05:33:19 +0000</pubDate>
		<dc:creator>TheKaptain</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[DataProvider]]></category>
		<category><![CDATA[fluent syntax]]></category>
		<category><![CDATA[GMaven]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[google-collections]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[guava]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[kellyrob99]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[MultiMap]]></category>
		<category><![CDATA[mvn]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[TestNG]]></category>
		<category><![CDATA[theKaptain]]></category>

		<guid isPermaLink="false">http://www.kellyrob99.com/blog/?p=1261</guid>
		<description><![CDATA[One of the most compelling things about using Groovy is the fluent and concise syntax, as well as the productivity and readability gains that come out of it. But there&#8217;s no reason not to take advantage of some of the same techniques and some library support, in this case google-collections, to make Java code easy [...]


Related posts:<ol><li><a href='http://www.kellyrob99.com/blog/2009/02/08/my-favorite-new-groovy-trick/' rel='bookmark' title='Permanent Link: My favorite new Groovy trick'>My favorite new Groovy trick</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/04/19/groovy-and-glazed-lists-with-grape/' rel='bookmark' title='Permanent Link: Groovy and Glazed Lists with Grape'>Groovy and Glazed Lists with Grape</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/08/09/using-the-testng-dataprovider-with-groovy/' rel='bookmark' title='Permanent Link: Using the TestNG DataProvider with Groovy'>Using the TestNG DataProvider with Groovy</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>One of the most compelling things about using Groovy is the fluent and concise syntax, as well as the productivity and readability gains that come out of it. But there&#8217;s no reason not to take advantage of some of the same techniques and some library support, in this case <a href="http://code.google.com/p/google-collections/">google-collections</a>, to make Java code easy to write AND to read.</p>
<h2>Creating Collections</h2>
<p>Groovy really shines for this one, making the creation of Lists and Maps, empty or populated, an absolute breeze. Java has some help for creating basic Lists but begins to struggle when creating maps. This is an area that google-collections can help in, especially in regards to creating immutable Maps.</p>
<pre class="brush: groovy;">
//Empty Lists
        List&lt;String&gt; groovyList = []
        List&lt;String&gt; javaList = new ArrayList&lt;String&gt;()
        List&lt;String&gt; googleList = Lists.newArrayList()  //can omit generics

//Populated Lists
        List&lt;String&gt; groovyList = [&quot;1&quot;, &quot;2&quot;]
        List&lt;String&gt; javaList = Arrays.asList(&quot;1&quot;, &quot;2&quot;)
        List&lt;String&gt; googleList = Lists.newArrayList(&quot;1&quot;, &quot;2&quot;)

//Immutable Lists
        List&lt;String&gt; groovyList = [&quot;1&quot;, &quot;2&quot;].asImmutable()
        List&lt;String&gt; javaList = Collections.unmodifiableList(Arrays.asList(&quot;1&quot;, &quot;2&quot;))
        List&lt;String&gt; googleList = ImmutableList.of(&quot;1&quot;, &quot;2&quot;)

//Empty Maps
        Map&lt;String, String&gt; groovyMap = [:]
        Map&lt;String, String&gt; javaMap = new LinkedHashMap&lt;String,String&gt;()
        Map&lt;String, String&gt; googleMap = Maps.newLinkedHashMap()

//Immutable Maps
        Map&lt;String, String&gt; groovyMap = [&quot;a&quot;:&quot;1&quot;, &quot;b&quot;:&quot;2&quot;].asImmutable()

        Map&lt;String, String&gt; javaMap = new LinkedHashMap&lt;String,String&gt;()
        javaMap.put(&quot;a&quot;, &quot;1&quot;)
        javaMap.put(&quot;b&quot;, &quot;2&quot;)
        javaMap = Collections.unmodifiableMap(javaMap)

        //OR(works only in Java, will not compile in Groovy)
        Map&lt;String, String&gt; javaMap = new LinkedHashMap&lt;String, String&gt;()
        {
            {
                put(&quot;a&quot;, &quot;1&quot;);
                put(&quot;b&quot;, &quot;2&quot;);
            }
        };

        Map&lt;String, String&gt; googleMap = ImmutableMap.of(&quot;a&quot;, &quot;1&quot;, &quot;b&quot;, &quot;2&quot;)  //clunky syntax but it works
</pre>
<h2>Filtering Collections</h2>
<p>Groovy provides the very handy &#8216;findAll&#8217; method that allows you to filter a Collection by applying a Closure. Google-collections provides similar facilities using the Predicate interface and two filter methods available statically on Collections2 and Iterables. This would also be a lot more readable if the Predicate definition were extracted but I wanted to show that it&#8217;s still possible to create them in-line quickly.</p>
<pre class="brush: groovy;">
import static com.google.common.collect.Collections2.*

List&lt;Integer&gt; toFilter = [1, 2, 3, 4, 5]
List&lt;Integer&gt; groovyVersion = toFilter.findAll{ it &lt; 3}
List&lt;Integer&gt; googleVersion = filter(toFilter, new Predicate&lt;Integer&gt;()
    {
        public boolean apply(Integer input)
        {
            return input &lt; 3;
        }
    };)
</pre>
<h2>Joining Collections into a String Representation</h2>
<p>This one has come up pretty often over the years, and it&#8217;s not surprising that where the JDK hasn&#8217;t provided, enterprising developers have added support through libraries. The problem is: given a Collection of objects, create a String representation of that Collection suitable for view from a consumer of the system. And admit it &#8211; the first time you hand-coded the algorithm you left a trailing comma, didn&#8217;t you? I know I did.<br />
Groovy has fantastic support for this use-case by simply including the &#8216;join&#8217; method on Lists. Google-collections utilizes static calls on the Joiner class along with a simple DSL-like syntax to achieve the same effect. Throw in a static import to make it even more concise and it does a fine job. These two examples yield the same result.</p>
<pre class="brush: groovy;">
import static com.google.common.base.Joiner.*
def toJoin = ['a', 'b', 'c']
def separator = ', '

//groovy version
def groovyJoin = toJoin.join(separator)

//google-collections version
def googleJoin = on(separator).join(toJoin)
</pre>
<p>And google-collections also supports join for Maps, something missing from Groovy(although not very hard to implement).</p>
<pre class="brush: groovy;">
import static com.google.common.base.Joiner.*
def toJoin = [1: 'a', 2: 'b', 3: 'c']
def separator = ', '
def keyValueSeparator = ':'

//results in '1:a, 2:b, 3:c' which is essentially what is returned from Groovy map.toMapString()
def googleVersion = on(separator).withKeyValueSeparator(keyValueSeparator).join(map)

//results in '1 is a and 2 is b and 3 is c'
googleVersion = on(&quot; and &quot;).withKeyValueSeparator(&quot; is &quot;).join(map)

//doing the same in Groovy is slightly more involved, but really not that bad
def groovyVersion = toJoin.inject([]) {builder, entry -&gt;
            builder &lt;&lt; &quot;${entry.key} is ${entry.value}&quot;
            builder
        }.join(' and ')
</pre>
<h2>Multimaps</h2>
<p>Multimaps are one of the more interesting parts of google-collections, at least to me. Have you ever found yourself writing code to create a Map of keys to Lists? Well the various <a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Multimap.html">Multimap</a> implementations in google-collections mean you never have to write that boilerplate kind of code again. Here&#8217;s a &#8220;first-stab&#8221; effort to simulate a fairly generic Multimap with pure Java code.</p>
<pre class="brush: groovy;">
public class JavaMultimap
{
    private Map&lt;Object, List&lt;Object&gt;&gt; multimap = new LinkedHashMap&lt;Object, List&lt;Object&gt;&gt;();

    public boolean put(Object key, Object value)
    {
        List&lt;object&gt; objects = multimap.get(key);
        objects = objects != null ? objects : new ArrayList&lt;object&gt;();
        objects.add(value);
        multimap.put(key, objects);
        return true;
    }
}
</pre>
<p>
And the same thing in Groovy, achieving a slightly smaller version.</p>
<pre class="brush: groovy;">
class GroovyMultimap
{
    Map map = [:]

    public boolean put(Object key, Object value)
    {
        List list = map.get(key, [])
        list.add(value)
        map.&quot;$key&quot; = list
    }
}
</pre>
<p>I did some primitive timings comparing Java, Groovy and google-collections Multimaps implementations and, as you&#8217;d pretty much expect, google clearly takes the lead.  Where things really start to get interesting though is when you start using the Multimap in Groovy code. Imagine if you will that you want to iterate over a collection of Objects and map some of the properties to a List. Here&#8217;s a contrived example of what I&#8217;m talking about, but applying this same pattern to domain objects in your application or even a directory full of xml files is pretty much the same. If you look closely you&#8217;ll notice that Groovy actually makes this a one liner to extract all values for a property across a List of Objects(used in the assertion), but I imagine that Multimap is probably a better alternative for large data sets.</p>
<pre class="brush: groovy;">
class GoogleCollectionsMultiMapTest
{
    private Random random = new Random()

    @Test
    public void testMultimap()
    {
        def list = []
        10.times {
            list &lt;&lt; createObject()
        }
        List properties = ['value1', 'value2', 'value3']
        Multimap multimap = list.inject(LinkedListMultimap.create()) {Multimap map, object -&gt;
            properties.each {
                map.put(it, object.&quot;$it&quot;)
            }
            map
        }
        properties.each {
            assertEquals (multimap.get(it), list.&quot;$it&quot;)
        }
    }

    Object createObject()
    {
        Expando expando = new Expando()
        expando.value1 =  random.nextInt(10) + 1
        expando.value2 =  random.nextInt(100) + 100
        expando.value3 =  random.nextInt(50) + 50
        return expando
    }
}
</pre>
<h2>So Where Does This Get Us?</h2>
<p>Between google-collections and <a href="http://code.google.com/p/guava-libraries/">the newer guava-libraries</a> that contain it, there&#8217;s lots of help available for simplifying programming problems and making your code more readable. I haven&#8217;t even touched on the newly available support for primitives, Files, Streams and more, but if you&#8217;re interested in reducing the amount of code you write AND simultaneously making it more readable you should probably take a look. There&#8217;s a very nice overview available in <a href="http://codemunchies.com/2009/10/beautiful-code-with-google-collections-guava-and-static-imports-part-1/">part one</a> and <a href="http://codemunchies.com/2009/10/diving-into-the-google-guava-library-part-2/">part two</a> by <a href="http://twitter.com/astensby">Aleksander Stensby</a>.  And here&#8217;s a <a href="http://bwinterberg.blogspot.com/2009/09/introduction-to-google-collections.html">closer look at what google-collections can do for you</a>.</p>
<h2>Source Code</h2>
<p>As per usual, source code is <a href="http://github.com/kellyrob99/groovy-google-collections">available at github as a maven project</a>. Big thanks to the Spock team for sharing <a href="http://old.nabble.com/GMaven-and-Groovy-1.7-td27378212.html">how they configure GMaven to properly utilize Groovy 1.7</a>.  Please feel free to take a look and comment here. Thanks!</p>
<!-- AdSense Now! V1.95 -->
<!-- Post[count: 3] -->
<div class="adsense adsense-leadout" style="float:right;margin: 12px;"><script type="text/javascript"><!--
google_ad_client = "pub-6955914197200080";
/* 728x90, created 8/3/09 */
google_ad_slot = "4051815125";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p align="left"><a class="tt" href="http://twitter.com/home/?status=Achieving+Groovy-like+Fluency+in+Java+with+Google+Collections+http://mzkqi.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.kellyrob99.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Achieving+Groovy-like+Fluency+in+Java+with+Google+Collections+http://mzkqi.th8.us" title="Post to Twitter">Tweet This Post</a></p>

<p>Related posts:<ol><li><a href='http://www.kellyrob99.com/blog/2009/02/08/my-favorite-new-groovy-trick/' rel='bookmark' title='Permanent Link: My favorite new Groovy trick'>My favorite new Groovy trick</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/04/19/groovy-and-glazed-lists-with-grape/' rel='bookmark' title='Permanent Link: Groovy and Glazed Lists with Grape'>Groovy and Glazed Lists with Grape</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/08/09/using-the-testng-dataprovider-with-groovy/' rel='bookmark' title='Permanent Link: Using the TestNG DataProvider with Groovy'>Using the TestNG DataProvider with Groovy</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kellyrob99.com/blog/2010/05/15/achieving-groovy-like-fluency-in-java-with-google-collections/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>A One Day Griffon Application/Presentation</title>
		<link>http://www.kellyrob99.com/blog/2010/02/11/a-one-day-griffon-applicationpresentation/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=a-one-day-griffon-applicationpresentation</link>
		<comments>http://www.kellyrob99.com/blog/2010/02/11/a-one-day-griffon-applicationpresentation/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 05:15:57 +0000</pubDate>
		<dc:creator>TheKaptain</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Griffon]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[kellyrob99]]></category>
		<category><![CDATA[plugin architecture]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[slideware]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[Swing]]></category>
		<category><![CDATA[TestNG]]></category>
		<category><![CDATA[theKaptain]]></category>
		<category><![CDATA[Transitions2D]]></category>

		<guid isPermaLink="false">http://www.kellyrob99.com/blog/?p=1072</guid>
		<description><![CDATA[I took the opportunity this past weekend to test drive the latest beta version of Griffon and along with it the as-of-yet unreleased slideware plugin. If you&#8217;re not already aware, Griffon is a Grails inspired framework for creating Java Swing applications. The project lead, Andres Almiray, has given several presentations using this plugin and it [...]


Related posts:<ol><li><a href='http://www.kellyrob99.com/blog/2009/08/27/vijug-griffongroovy-presentation/' rel='bookmark' title='Permanent Link: VIJUG Griffon/Groovy Presentation'>VIJUG Griffon/Groovy Presentation</a></li>
<li><a href='http://www.kellyrob99.com/blog/2010/05/15/achieving-groovy-like-fluency-in-java-with-google-collections/' rel='bookmark' title='Permanent Link: Achieving Groovy-like Fluency in Java with Google Collections'>Achieving Groovy-like Fluency in Java with Google Collections</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/04/03/swingset-on-griffon/' rel='bookmark' title='Permanent Link: SwingSet on Griffon'>SwingSet on Griffon</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I took the opportunity this past weekend to test drive the latest beta version of <a href="http://griffon.codehaus.org/">Griffon</a> and along with it the as-of-yet unreleased slideware plugin. If you&#8217;re not already aware, Griffon is a Grails inspired framework for creating <a class="zem_slink" href="http://en.wikipedia.org/wiki/Swing_%28Java%29" title="Swing (Java)" rel="wikipedia">Java Swing</a> applications. The project lead, Andres Almiray, has given several presentations using this plugin and it provides an excellent platform for showcasing both the power of Swing and the capabilities of Griffon to make it all look so easy.</p>
<p>The slideware plugin provides a framework for creating presentations with a little twist &#8211; you can execute code live from the presentation software.  If you&#8217;ve ever given a presentation about programming you probably are fully aware of the transition from presentation software to your preferred environment for demonstrating code samples. Well, now you can stay entirely within the same application, editing and running code live.</p>
<p>The plugin itself isn&#8217;t available from the Griffon repository but source code and a built 0.2 version can be <a href="http://github.com/aalmiray/Presentations">found on github</a>.  Considering both the youth of the plugin and the beta status of the framework, it worked impressively well AND had a rich feature set.  All of the expected &#8220;powerpoint&#8221; features are there: themes, layout control, styling, slide transitions and export are all pretty easy to incorporate and configure. The code editor view also works very well. A great variety of additional plugins are harnessed to put all the pieces together and as a result building one of these applications is a great way to tour the platform.</p>
<p></p>
<h2>Theming</h2>
<p>Applying a theme to the presentation is simply selecting a Java Look and Feel to apply in Initialize.groovy. The Substance jar is included with the plugin so I test drove a few of the nice setups in there and finally settled on the SubstanceMagmaLookAndFeel. There is definitely a wide variety of L&amp;F&#8217;s to choose from in that bundle alone and, although I haven&#8217;t done it myself, they seem pretty tweakable as well. Plus any old L&amp;F should plug in nicely, I would imagine. </p>
<pre class="brush: groovy;">
//Initialize.groovy
SwingBuilder.lookAndFeel('org.jvnet.substance.skin.SubstanceMagmaLookAndFeel',
       'mac', 'nimbus', 'gtk', ['metal', [boldFonts: false]])
</pre>
<p></p>
<h2>Layout</h2>
<p>Controlling the page composition is a standard Swing Layout or, in the case of the default slide you get with the included &#8220;create-slide&#8221; script, a MigLayout. Framing the standard variety of slides is very simple. Bulleted pages, title slides, code slides and custom layouts are very easy to accomplish. I don&#8217;t have a lot of experience using this particular layout but the presentations Andres has made available on github have a good diversity of examples of how they look in practice.</p>
<pre class="brush: groovy;">
//the default create-slide generated template
import net.miginfocom.swing.MigLayout

slide(id: &quot;slide0&quot;, layout: new MigLayout(&quot;fill&quot;,&quot;[center]&quot;,&quot;[center]&quot;)) {
    label(&quot;Insert your text here&quot;)
}
</pre>
<p></p>
<h2>Styling</h2>
<p>Styling is supplied by the css plugin, on which slideware has a dependency. The default style.css file sets out just some reasonable defaults for the fonts used in different parts of the app, and I didn&#8217;t see any real need to fiddle with it. Especially happy to see the nice monospace code font. On a totally related note I recently installed the <a href="http://www.levien.com/type/myfonts/inconsolata.html">Inconsolata</a> monospace font to try for development and I&#8217;ve been very happy seeing it in my editor, but it&#8217;s still nice to see this kind of polish applied to the presentation. The code editor view even includes syntax highlighting! More on that coming right up&#8230;</p>
<p></p>
<h2>Slide Transitions</h2>
<p>Moving between slides with style is the responsibility of the <a href="http://griffon.codehaus.org/Transitions+Plugin">transitions plugin</a>. You can see see all of the animations this plugin enables over here at <a href="http://javagraphics.blogspot.com/2007/04/slideshows-transitions-swf.html">this page describing Transitions and Transition2Ds</a>. Pretty slick stuff and defined as simply as a parameter to each &#8220;slide&#8221; node in a script.</p>
<pre class="brush: groovy;">
slide(id: &quot;slide3&quot;, layout: new MigLayout(&quot;fill&quot;,&quot;3%[center]3%&quot;,&quot;3%[center]3%&quot;),
        title: &quot;Junit3&quot;,
        transition: new FlurryTransition2D(Transition2D.OUT)) {
    scrollPane(constraints: &quot;grow&quot;) {
        widget(createEditor(text: script))
    }
}
</pre>
<p></p>
<h2>Code Editor</h2>
<p>Code slides embed an editable widget and allow for composing and executing Groovy scripts or classes of arbitrary complexity. You can execute the code with a keyboard shortcut and a window will open displaying the console output. The code itself is executed through a GroovyShell, enabling pretty much anything you might want to do. If you have an internet connection and the required repositories configured, Grapes simplifies packaging the dependencies for the application as your code samples can directly Grab the jars they need. Basically, the first time you execute a code slide you&#8217;ll have to put up with a small pause while Ivy downloads to your local repository, unless of course the required dependencies are already there.  In my case I changed strategies from including jars in the application lib directory to a Grapes approach and I think it&#8217;s a better way to go.</p>
<p>I was surprised to find that the editor even included undo functionality. It&#8217;s definitely not close to a full blown IDE, and there&#8217;s absolutely no reason that it should be. For the task of demoing simple code examples it&#8217;s more than up to the task, even to the point of maintaining your edits between slide transitions, allowing you to move back and forth through the slide deck without any state problems.<br />

<a href="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/screen-shot-2010-02-11-at-7-47-04-pm.png" title="Code slide with JUnit4 and Hamcrest matcher example" class="shutterset_singlepic38" >
	<img class="ngg-singlepic" src="http://www.kellyrob99.com/blog/wp-content/gallery/cache/38__x_screen-shot-2010-02-11-at-7-47-04-pm.png" alt="Code slide with JUnit4 and Hamcrest matcher example" title="Code slide with JUnit4 and Hamcrest matcher example" />
</a>
</p>
<p></p>
<h2>Export</h2>
<p>The application includes a &#8220;Print&#8221; feature which iterates through the entire slide deck and renders it to a pdf. Distribution of one of these presentations is really very easy, including the ability to create installers for all major platforms simply by adding the packaging plugin.</p>
<p></p>
<h2>Test Application</h2>
<p>The test app I built while looking into this is pretty simple. It&#8217;s got a title slide, a bullet slide and 4 code slides. The code simply demonstrates how you can create test classes and make assertions for Junit 3(with GroovyTestCase), Junit 4 and TestNG. GroovyShell recognizes all 3 of these test files by interface or annotation and executes them appropriately. In each case the console output of the test framework is the result, including the new Spock inspired ascii art assert failure renderings. The Test result files are also written to disk, and that TestNG html output is what I&#8217;m used to looking at anyhow. Show me the Green!</p>
<p>The last code slide is just a slightly updated version of an example script on the Grapes page, using the current version of Google Collections and intentionally introducing a failure- mostly just to show off that new assert rendering I mentioned a moment ago. VERY helpful at highlighting the exact nature of a failure. It also encourages me to pay more attention to how I name variables, something I&#8217;m sure every developer that has ever worked with me will cheer at. Man, I suck at naming things.</p>
<p>I also developed a brute force test that loads each slide and executes scripts if finds embedded there. Failures are hard to detect since the direct output is simply a text block, but some fairly simple regex&#8217;s applied to the output make me at least moderately confident that the code won&#8217;t fail at show time.</p>
<p></p>
<h2>Overall Impression</h2>
<p>It took a couple of afternoons(six hours or so total) to download the source code from github, explore it, create a simple presentation and document the experience. I won&#8217;t begin to suggest that I&#8217;m fully aware of all the details happening behind the scenes, but the end user experience is pretty fluid: create a slide, tailor the layout, add content and then repeat. The included examples were more than enough documentation on how to hit the ground running. The plugin code itself is a great example of the MVC nature of Griffon, not a whole lot of code, but a great deal of power and expressability. There were a couple of glitches happening in the background, mostly just logging to the console with no visible effect to the application, but overall it functioned as well as (not) advertised. For publicly unreleased software it was an absolute pleasure to work with and I plan on continuing with the development of this particular presentation.</p>
<p>Everything you need to build and run this stuff yourself is publicly available. In my case, Griffon generally has a recent Macport available for both the released(griffon @0.2.1) and development versions(griffon-devel @0.3-BETA-2). Switching versions is relatively painless and, for applications this simple, testing out upgrades is basically just going through the presentation once in a functional test. Versions for other platforms can be downloaded from the <a href="http://griffon.codehaus.org/Download">Griffon download page</a>.</p>
<p></p>
<h2>Deliverables</h2>
<p>Source code for the sample application is <a href="http://github.com/kellyrob99/Groovy-Testing-Presentation">available on github here</a>. Please just leave a comment on this page if you have any problems running it.</p>
<p>Here&#8217;s the pdf produced by the application &#8216;Print&#8217; feature: <a class="downloadlink" href="http://www.kellyrob99.com/blog/wp-content/plugins/download-monitor/download.php?id=2" title="Version0.1 downloaded 116 times" >Groovy Testing Presentation (116)</a></p>
<p>And if you don&#8217;t feel like downloading anything, here&#8217;s how it all looks in pretty pictures.<br />

<div class="ngg-galleryoverview" id="ngg-gallery-9-1072">


	<!-- Piclense link -->
	<div class="piclenselink">
		<a class="piclenselink" href="javascript:PicLensLite.start({feedUrl:'http://www.kellyrob99.com/blog/wp-content/plugins/nextgen-gallery/xml/media-rss.php?gid=9&amp;mode=gallery'});">
			[View with PicLens]		</a>
	</div>
	
	<!-- Thumbnails -->
		
	<div id="ngg-image-35" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/screen-shot-2010-02-11-at-7-46-46-pm.png" title="Title slide" class="shutterset_set_9" >
								<img title="Title slide" alt="Title slide" src="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/thumbs/thumbs_screen-shot-2010-02-11-at-7-46-46-pm.png" width="99" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-36" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/screen-shot-2010-02-11-at-7-46-50-pm.png" title="Bullet slide" class="shutterset_set_9" >
								<img title="Bullet slide" alt="Bullet slide" src="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/thumbs/thumbs_screen-shot-2010-02-11-at-7-46-50-pm.png" width="99" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-37" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/screen-shot-2010-02-11-at-7-47-00-pm.png" title="Code slide with JUnit 3 example" class="shutterset_set_9" >
								<img title="Code slide with JUnit 3 example" alt="Code slide with JUnit 3 example" src="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/thumbs/thumbs_screen-shot-2010-02-11-at-7-47-00-pm.png" width="99" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-38" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/screen-shot-2010-02-11-at-7-47-04-pm.png" title="Code slide with JUnit4 and Hamcrest matcher example" class="shutterset_set_9" >
								<img title="Code slide with JUnit4 and Hamcrest matcher example" alt="Code slide with JUnit4 and Hamcrest matcher example" src="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/thumbs/thumbs_screen-shot-2010-02-11-at-7-47-04-pm.png" width="99" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-39" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/screen-shot-2010-02-11-at-7-47-08-pm.png" title="Code slide with TestNG example" class="shutterset_set_9" >
								<img title="Code slide with TestNG example" alt="Code slide with TestNG example" src="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/thumbs/thumbs_screen-shot-2010-02-11-at-7-47-08-pm.png" width="99" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-40" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/screen-shot-2010-02-11-at-7-47-13-pm.png" title="Code slide with Google Collections example" class="shutterset_set_9" >
								<img title="Code slide with Google Collections example" alt="Code slide with Google Collections example" src="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/thumbs/thumbs_screen-shot-2010-02-11-at-7-47-13-pm.png" width="99" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-41" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/screen-shot-2010-02-08-at-8-53-43-pm.png" title="Help screen showing keyboard shortcuts" class="shutterset_set_9" >
								<img title="Help screen showing keyboard shortcuts" alt="Help screen showing keyboard shortcuts" src="http://www.kellyrob99.com/blog/wp-content/gallery/groovy-testing-presentation-with-griffon/thumbs/thumbs_screen-shot-2010-02-08-at-8-53-43-pm.png" width="99" height="75" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>

</p>
<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/a9a507d7-67b9-4178-bf0f-e90f2cc1d0a6/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_c.png?x-id=a9a507d7-67b9-4178-bf0f-e90f2cc1d0a6" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=A+One+Day+Griffon+Application%2FPresentation+http://yi58w.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.kellyrob99.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=A+One+Day+Griffon+Application%2FPresentation+http://yi58w.th8.us" title="Post to Twitter">Tweet This Post</a></p>

<p>Related posts:<ol><li><a href='http://www.kellyrob99.com/blog/2009/08/27/vijug-griffongroovy-presentation/' rel='bookmark' title='Permanent Link: VIJUG Griffon/Groovy Presentation'>VIJUG Griffon/Groovy Presentation</a></li>
<li><a href='http://www.kellyrob99.com/blog/2010/05/15/achieving-groovy-like-fluency-in-java-with-google-collections/' rel='bookmark' title='Permanent Link: Achieving Groovy-like Fluency in Java with Google Collections'>Achieving Groovy-like Fluency in Java with Google Collections</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/04/03/swingset-on-griffon/' rel='bookmark' title='Permanent Link: SwingSet on Griffon'>SwingSet on Griffon</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kellyrob99.com/blog/2010/02/11/a-one-day-griffon-applicationpresentation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>My favorite new Groovy trick</title>
		<link>http://www.kellyrob99.com/blog/2009/02/08/my-favorite-new-groovy-trick/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=my-favorite-new-groovy-trick</link>
		<comments>http://www.kellyrob99.com/blog/2009/02/08/my-favorite-new-groovy-trick/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 04:26:49 +0000</pubDate>
		<dc:creator>TheKaptain</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.kellyrob99.com/blog/?p=8</guid>
		<description><![CDATA[I program primarily in Java, but I must admit I&#8217;m a bit of a fanboy when it comes to the Groovy language. The syntatic sugar helps reduce some of the overhead of doing what should be simple things in Java, like reading Files or parsing XML. In particular the additions to the Collections API make [...]


Related posts:<ol><li><a href='http://www.kellyrob99.com/blog/2010/05/15/achieving-groovy-like-fluency-in-java-with-google-collections/' rel='bookmark' title='Permanent Link: Achieving Groovy-like Fluency in Java with Google Collections'>Achieving Groovy-like Fluency in Java with Google Collections</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/08/18/my-favorite-intellij-resources-tips-and-tricks/' rel='bookmark' title='Permanent Link: My Favorite IntelliJ Resources, Tips and Tricks'>My Favorite IntelliJ Resources, Tips and Tricks</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/10/24/groovy-reverse-map-sort-done-easy/' rel='bookmark' title='Permanent Link: Groovy reverse map sort done easy'>Groovy reverse map sort done easy</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I program primarily in <a class="zem_slink" title="Java (software platform)" rel="homepage" href="http://java.sun.com">Java</a>, but I must admit I&#8217;m a bit of a fanboy when it comes to the Groovy language. The syntatic sugar helps reduce some of the overhead of doing what should be simple things in Java, like reading Files or parsing XML. In particular the additions to the Collections API make things like creating populated data structures and iteration a breeze.</p>
<p>The <a href="http://groovy.codehaus.org/groovy-jdk/java/util/Map.html" target="_blank">Groovy Map API</a> adds a very handy method which allows for specifying a default value on get() for when the Map key may or may not exist. I find this particularly useful for those all too common occasions you need to count occurences of things in a particular domain.</p>
<pre class="brush: groovy;">
//
/**
* Looks up an item in a Map for the given key and returns the value - unless there is no entry for the given key in which case add the default value to the map and return that
*/
get(Object key, Object defaultValue)
</pre>
<p style="text-align: left;">And you can use it like this</p>
<pre class="brush: groovy;">
/* Counting using a map*/
def map = [:]
collection.each{
map[it] = map.get(it, 0) + 1
}
</pre>
<p>Java has this ability for a <a title="Properties javadoc" href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html" target="_blank">Properties object</a> but they still haven&#8217;t gotten around to adding it to Collections. I&#8217;ve seen different ways to accomplish the same thing using <a title=" apache commons-collections" href="http://commons.apache.org/collections/" target="_blank">commons-collections</a> or <a title="google-collections" href="http://code.google.com/p/google-collections/" target="_blank">Google collections</a>, but this is probably the easiest I&#8217;ve used. Thankfully Groovy and Java are pretty much interchangeable, at least for my uses, so I&#8217;ll just continue to try and pick the right one for the right job.</p>
<div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Zemified by Zemanta" href="http://reblog.zemanta.com/zemified/55f162c0-db9a-4258-94e3-112832c20172/"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_c.png?x-id=55f162c0-db9a-4258-94e3-112832c20172" alt="Reblog this post [with Zemanta]" /></a></div></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=My+favorite+new+Groovy+trick+http://3qxya.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.kellyrob99.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=My+favorite+new+Groovy+trick+http://3qxya.th8.us" title="Post to Twitter">Tweet This Post</a></p>

<p>Related posts:<ol><li><a href='http://www.kellyrob99.com/blog/2010/05/15/achieving-groovy-like-fluency-in-java-with-google-collections/' rel='bookmark' title='Permanent Link: Achieving Groovy-like Fluency in Java with Google Collections'>Achieving Groovy-like Fluency in Java with Google Collections</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/08/18/my-favorite-intellij-resources-tips-and-tricks/' rel='bookmark' title='Permanent Link: My Favorite IntelliJ Resources, Tips and Tricks'>My Favorite IntelliJ Resources, Tips and Tricks</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/10/24/groovy-reverse-map-sort-done-easy/' rel='bookmark' title='Permanent Link: Groovy reverse map sort done easy'>Groovy reverse map sort done easy</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kellyrob99.com/blog/2009/02/08/my-favorite-new-groovy-trick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
