<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Robbie's Garbage Collected</title>
	<atom:link href="http://garbagecollected.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://garbagecollected.org</link>
	<description>Name it, read it, tune it, print it, scan it, send it, fax - rename it.</description>
	<pubDate>Sun, 21 Sep 2008 16:32:50 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Lazy Loading For Mere Mortals</title>
		<link>http://garbagecollected.org/2008/08/23/lazy-loading-for-mere-mortals/</link>
		<comments>http://garbagecollected.org/2008/08/23/lazy-loading-for-mere-mortals/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 18:28:29 +0000</pubDate>
		<dc:creator>Robbie</dc:creator>
		
		<category><![CDATA[Guice]]></category>

		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://garbagecollected.wordpress.com/?p=41</guid>
		<description><![CDATA[Easily the #1 mistake people make when using Warp Persist is they forget to start their PersistenceService, which is the API that abstracts the Hibernate SessionFactory. The plan for the next release is to start the PersistenceService lazily. Thus the first time a SessionFactory gets accessed, we will load it for you if you haven&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Easily the #1 mistake people make when using <a href="http://code.google.com/p/warp-persist">Warp Persist</a> is they forget to start their <span style="font-family:Courier New;">PersistenceService</span>, which is the API that abstracts the Hibernate <span style="font-family:Courier New;">SessionFactory</span>. The plan for the next release is to start the <span style="font-family:Courier New;">PersistenceService</span> lazily. Thus the first time a <span style="font-family:Courier New;">SessionFactory</span> gets accessed, we will load it for you if you haven&#8217;t called <span style="font-family:Courier New;">PersistenceService.start()</span> yet. This is a simple change that will help you get your project going in no time.</p>
<p>The obvious choice for implementing this type of lazy loading as of Java 5 is <a href="http://en.wikipedia.org/wiki/Double-checked_locking">Double-Checked Locking</a>. But after coding it up for the Hibernate <span style="font-family:Courier New;">SessionFactory</span>, I realized I would have to do the same for the JPA and DB4O support. Given the relative complexity of DCL, that kind of sucks.</p>
<p>But then I remembered something <a href="http://crazybob.org">Bob Lee</a> said on <a href="http://www.twitter.com">Twitter</a> the other day:</p>
<div id="attachment_42" class="wp-caption aligncenter" style="width: 490px"><img class="size-full wp-image-42" src="http://garbagecollected.files.wordpress.com/2008/08/picture-1.png?w=480&#038;h=71" alt="Bob Lee on Twitter" width="480" height="71" /><p class="wp-caption-text">Bob Lee on Twitter</p></div>
<p>The man has a point.</p>
<p>I decided to roll our own utility class to lazily load object references. So I opened up the bible (<a href="http://java.sun.com/docs/books/effective/">Effective Java, 2nd edition</a>) to look for the original pattern, and there it was. Page 283:<br />
<span style="font-family:Courier New;"><br />
private volatile FieldType field;<br />
FieldType getField() {<br />
&nbsp;&nbsp;FieldType result = field;<br />
&nbsp;&nbsp;if (result == null) {  // First check (no locking)<br />
&nbsp;&nbsp;&nbsp;&nbsp;synchronized(this) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result = field;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (result == null) // Second check (with locking)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;field = result = computeFieldValue();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;return result;<br />
}<br />
</span><br />
Scary. Now, there is no way we can reduce the size of that code much, but as it turns out we can make it a lot simpler to use. I called it <a href="http://code.google.com/p/warp-persist/source/browse/trunk/warp-persist/src/com/wideplay/warp/util/LazyReference.java?r=128">LazyReference</a>, here&#8217;s an example usage:<br />
<span style="font-family:Courier New;"><br />
private final LazyReference&lt;SessionFactory&gt; sessionFactory =<br />
&nbsp;&nbsp;LazyReference.of(new Provider&lt;SessionFactory&gt;() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;public SessionFactory get() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// code to create SessionFactory<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
});<br />
</span><br />
To use this code, you just call <span style="font-family:Courier New;">sessionFactory.get()</span>, and it will handle the lazy loading for you. Even if you are a Java master, there is no reason for you to repeat that complicated DCL code ever again. Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/garbagecollected.wordpress.com/41/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/garbagecollected.wordpress.com/41/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garbagecollected.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garbagecollected.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garbagecollected.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garbagecollected.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garbagecollected.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garbagecollected.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garbagecollected.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garbagecollected.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garbagecollected.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garbagecollected.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garbagecollected.org&blog=1057539&post=41&subd=garbagecollected&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://garbagecollected.org/2008/08/23/lazy-loading-for-mere-mortals/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/vanbrro-128.jpg" medium="image">
			<media:title type="html">vanbrro</media:title>
		</media:content>

		<media:content url="http://garbagecollected.files.wordpress.com/2008/08/picture-1.png" medium="image">
			<media:title type="html">Bob Lee on Twitter</media:title>
		</media:content>
	</item>
		<item>
		<title>Guice&#8217;s toProvider Sometimes Considered Harmful</title>
		<link>http://garbagecollected.org/2008/07/21/guices-toprovider-sometimes-considered-harmful/</link>
		<comments>http://garbagecollected.org/2008/07/21/guices-toprovider-sometimes-considered-harmful/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 14:06:00 +0000</pubDate>
		<dc:creator>Robbie</dc:creator>
		
		<category><![CDATA[Guice]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://garbagecollected.wordpress.com/?p=36</guid>
		<description><![CDATA[Perfection is what I wanted. Writing code examples for a book is harder than you think; Not only does the code need to be right, it also needs to be short and lightweight. Don&#8217;t involve API&#8217;s you don&#8217;t need, don&#8217;t create types if you can do without them, that sort of thing.
So I was nearing [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Perfection is what I wanted. Writing code examples for <a href="http://www.apress.com/book/view/1590599977">a book</a> is harder than you think; Not only does the code need to be right, it also needs to be short and lightweight. Don&#8217;t involve API&#8217;s you don&#8217;t need, don&#8217;t create types if you can do without them, that sort of thing.</p>
<p>So I was nearing the handoff deadline and I was going over my code examples. I corrected some and tried to shorten others. For example, in the Chapter 6 example I saw the following code, which I used to abstract session handling from my view logic*:</p>
<p><font face="Courier New">public class UserTokenProvider implements Provider&lt;UserToken&gt; {<br />&nbsp; @Inject private HttpSession session;<br />&nbsp; public UserToken get() {<br />&nbsp;&nbsp;&nbsp; synchronized (session) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (UserToken) session.getAttribute(UserToken.KEY);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp; }<br />}</font></p>
<p><font face="Courier New">public class WebModule extends AbstractModule {<br />&nbsp; protected void configure() {<br />&nbsp;&nbsp;&nbsp; bind(UserToken.class).toProvider(UserTokenProvider.class);<br />&nbsp; }<br />}</font>
<p>Surely I wasn&#8217;t going to list two classes just for a simple provider, so I quickly decided to get rid of the extra class as follows:</p>
<p><font face="Courier New">public class WebModule extends AbstractModule {<br />&nbsp; protected void configure() {<br />&nbsp;&nbsp;&nbsp; bind(UserToken.class).toProvider(new Provider&lt;UserToken&gt;() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Inject private HttpSession session;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public UserToken get() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; synchronized (session) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (UserToken)session.getAttribute(UserToken.KEY);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }); // no scope!<br />&nbsp; }<br />}</font>
<p>Now, months later it struck me. This is wrong! (and arguably even less readable) In the shortened version I am now giving Guice a provider <em>instance</em> instead of a provider <em>type</em>. Using that <font face="Courier New">toProvider</font> overload is comparable to using Guice&#8217;s <font face="Courier New">toInstance</font>: it will just reuse that instance for all requests to that <font face="Courier New">Key</font>, <strong>disregarding</strong> <strong>all scopes</strong>. And when I say all scopes, I mean all scopes. <strong>It also ignores the default &#8220;no scope&#8221;</strong>. Using the default scope, Guice will create an instance each time that <font face="Courier New">Key</font> gets requested. However, if you bypass all scopes with <font face="Courier New">toInstance</font> or the <font face="Courier New">toProvider</font> instance overload, Guice will simply reuse your instance.</p>
<p>In my example I was depending on the fact that the <font face="Courier New">HttpSession</font> injected in the provider was always going to be the right one. In the original example it worked as expected. I gave Guice a provider type, and used the default &#8220;no scope&#8221; so that a new instance would get created for each incoming HTTP request. Guice would inject the right <font face="Courier New">HttpSession</font> instance depending on the request.</p>
<p>Because the second example uses <font face="Courier New">toProvider</font> with an instance instead of a type, it behaves radically different. Ignoring &#8220;no scope&#8221;, Guice will just inject the first <font face="Courier New">HttpSession</font> instance it finds and from then on it will leave that provider instance alone (a scope widening injection, if you will). Any subsequent requests, from possibly different sessions, will reuse that instance, leading to session corruption and a significant security risk. </p>
<p>Needless to say, I have fixed my code example and published the update to Apress.</p>
<p>Save yourself from such an embarrassment: <strong>Remember that toInstance and the toProvider instance overload ignore all scopes, including &#8220;no scope&#8221;. Avoid using them: use asEagerSingleton to load instances eagerly. </strong>Only use these short cuts to fit code on a slide, or in the case of <font face="Courier New">toInstance</font>, to bind constants with better type safety.</p>
<p><font size="1">* I am not using Guice&#8217;s session scope because the <font face="Courier New">UserToken</font> is used as an authentication token in the session. Using scopes, Guice might end up creating a security token for you when it gets requested, which is obviously not what you&#8217;d want.</font></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/garbagecollected.wordpress.com/36/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/garbagecollected.wordpress.com/36/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garbagecollected.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garbagecollected.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garbagecollected.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garbagecollected.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garbagecollected.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garbagecollected.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garbagecollected.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garbagecollected.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garbagecollected.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garbagecollected.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garbagecollected.org&blog=1057539&post=36&subd=garbagecollected&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://garbagecollected.org/2008/07/21/guices-toprovider-sometimes-considered-harmful/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/vanbrro-128.jpg" medium="image">
			<media:title type="html">vanbrro</media:title>
		</media:content>
	</item>
		<item>
		<title>Guice Productivity</title>
		<link>http://garbagecollected.org/2008/05/08/guice-productivity/</link>
		<comments>http://garbagecollected.org/2008/05/08/guice-productivity/#comments</comments>
		<pubDate>Thu, 08 May 2008 21:40:04 +0000</pubDate>
		<dc:creator>Robbie</dc:creator>
		
		<category><![CDATA[DI]]></category>

		<category><![CDATA[Guice]]></category>

		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://garbagecollected.wordpress.com/?p=32</guid>
		<description><![CDATA[Plugin hell: we&#8217;ve all been there. Large frameworks like Spring, Seam, &#8230; often require IDE plugins for you to be productive. That&#8217;s cool. But installing plugins and getting them to work right, at least when using Eclipse, is utter, utter torture.
Some of them don&#8217;t work as advertised. Some of them don&#8217;t work with your particular [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Plugin hell: we&#8217;ve all been there. Large frameworks like Spring, Seam, &#8230; often require IDE plugins for you to be productive. That&#8217;s cool. But installing plugins and getting them to work right, at least when using Eclipse, is utter, utter torture.<br />
Some of them don&#8217;t work as advertised. Some of them don&#8217;t work with your particular Eclipse version. Some of them make others crash.</p>
<p>What&#8217;s refreshing about a framework like Guice is that you don&#8217;t need all of that. Because Guice is an all-Java framework, you don&#8217;t <em>need</em> to install any IDE plugins. Your Java IDE _is_ the plugin. There&#8217;s years and years of hard work at your fingertips, so why not work _with_ it instead of working against it? Developing with Guice feels like coming home.</p>
<p>Recently I cooked up <a href="http://users.telenet.be/robbiev/multibind/">a screen cast</a> that shows off <a href="http://publicobject.com/2008/04/guice-multibinder-api-proposal.html">Multibindings</a>, a much anticipated Guice 2.0 feature. As I mention in the beginning, I use some IDE templates for my Guice development, and you&#8217;ll probably agree with me that it shows. I&#8217;ll share those with you in a minute. But first, my brain fart of the day: <strong>Know and learn your IDE, and expect the same from the frameworks you use.</strong> 70% of the code generation refactorings/templates in <a href="http://users.telenet.be/robbiev/multibind/">my Multibindings screencast</a> are built right into the IDE. And 100% of them are configurable out of the box.</p>
<p><img src="http://garbagecollected.files.wordpress.com/2008/05/gah.png?w=300&#038;h=116" alt="" width="300" height="116" class="aligncenter size-medium wp-image-33" /></p>
<p>Here&#8217;s what I&#8217;ve currently set up. This configuration is Eclipse specific, but I&#8217;m sure IDEA and others have similar features.</p>
<ul>
<li><strong>Static imports:</strong> <em>Window =&gt; Preferences =&gt; Java =&gt; Editor =&gt; Content Assist =&gt; Favorites</em>.
<ul>
<li>This thing is pure gold. It allows you to specify types that have static methods on them, so that Eclipse can index them and suggest static imports for methods you often use. This feature is an awesome time saver for things like Google Collections, but also for JUnit tests and not surprisingly Guice. For Guice I&#8217;ve added the <code>Matchers</code> class (AOP) and the <code>Names</code> class (eeeviiiil).</li>
</ul>
</li>
<li><strong>Templates:</strong> <em>Window =&gt; Preferences =&gt; Java =&gt; Editor =&gt; Templates</em>. Using this simple IDE feature, all boilerplate is just a <code>CTRL+SPACE</code> away. Important: press save (<code>CTRL+S</code>) and Organize Imports (<code>CTRL+SHIFT+O</code>) after you complete a template. This makes sure that you have all the needed import statements.</li>
<ul>
<li><em>Binding Annotations:</em> creating these is tedious and error prone. One approach is to copy-paste the boilerplate, the other is to have a template. I&#8217;ve set one up that automatically inserts the annotation headers you&#8217;d usually want.</li>
<li><em><code>Injector</code> creation</em>: I tend to run a lot of &#8220;experiments&#8221;, also known as the &#8220;Launching Main893.java&#8221; syndrome. So next to the binding annotation header, I&#8217;ve also set up a template that creates me an Injector with an inline <code>AbstractModule</code>. Also works great for demos.</li>
<li><em>Constructor generation:</em> simple template that creates the default constructor and puts your cursor in between the parenthesis so you can immediately start typing.</li>
</ul>
</ul>
<p><img src="http://garbagecollected.files.wordpress.com/2008/05/gah_after.png?w=480&#038;h=131" alt="" width="480" height="131" class="aligncenter size-full wp-image-34" /></p>
<p>Other notable built-in features are <code>CTRL+1</code> (Quick Fix) on constructor fields, which can create private final instance variables for selected constructor arguments, and typing a method name and hitting <code>CTRL+SPACE</code> to override or implement that method.</p>
<p>Now without further ado, here are some of my templates.</p>
<blockquote><p>
Mapped to &#8216;gah&#8217; (as in Guice Annotation Header):</p>
<pre>
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER})
@BindingAnnotation
</pre>
<p>Mapped to &#8216;gin&#8217; (as in Guice INjector and booze):</p>
<pre>
Injector i = Guice.createInjector(new AbstractModule() {
    protected void configure() {
        ${cursor}
    }
});
</pre>
<p>Mapped to &#8216;constr&#8217; (creates a constructor and sets the cursor where it needs to be):</p>
<pre>
public ${enclosing_type}(${cursor}) {
}
</pre>
</blockquote>
<p>Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/garbagecollected.wordpress.com/32/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/garbagecollected.wordpress.com/32/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garbagecollected.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garbagecollected.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garbagecollected.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garbagecollected.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garbagecollected.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garbagecollected.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garbagecollected.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garbagecollected.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garbagecollected.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garbagecollected.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garbagecollected.org&blog=1057539&post=32&subd=garbagecollected&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://garbagecollected.org/2008/05/08/guice-productivity/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/vanbrro-128.jpg" medium="image">
			<media:title type="html">vanbrro</media:title>
		</media:content>

		<media:content url="http://garbagecollected.files.wordpress.com/2008/05/gah.png?w=300" medium="image" />

		<media:content url="http://garbagecollected.files.wordpress.com/2008/05/gah_after.png" medium="image" />
	</item>
		<item>
		<title>DollarMaps: Easy Map Creation for Java</title>
		<link>http://garbagecollected.org/2008/04/06/dollarmaps/</link>
		<comments>http://garbagecollected.org/2008/04/06/dollarmaps/#comments</comments>
		<pubDate>Sun, 06 Apr 2008 00:17:32 +0000</pubDate>
		<dc:creator>Robbie</dc:creator>
		
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://garbagecollected.wordpress.com/?p=31</guid>
		<description><![CDATA[Inspired by GQuery&#8217;s syntax,  I hacked up some code that uses a similar, dollar sign based syntax for creating Java Map instances. And I have to say that it flows really nicely. But first, let&#8217;s &#8220;respect the classics&#8221; .

Map&#60;Integer, String&#62; map = new HashMap&#60;Integer, String&#62;();
map.put(1, "one");
map.put(2, "two");
map.put(3, "three");

// iterate over all the entries
for (Entry&#60;Integer, String&#62; [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Inspired by <a href="http://timepedia.blogspot.com/2008/04/gwt-road-to-15-language-features-and.html">GQuery</a>&#8217;s syntax,  I hacked up some code that uses a similar, dollar sign based syntax for creating Java Map instances. And I have to say that it flows really nicely. But first, let&#8217;s &#8220;respect the classics&#8221; .</p>
<pre>
Map&lt;Integer, String&gt; map = new HashMap&lt;Integer, String&gt;();
map.put(1, "one");
map.put(2, "two");
map.put(3, "three");

// iterate over all the entries
for (Entry&lt;Integer, String&gt; e : map.entrySet())
    System.out.println(e.getKey() + " " + e.getValue());
</pre>
<p>So, there are three things to notice here.</p>
<ul>
<li>The repeated type parameters on the first line</li>
<li>Having to use three lines of extra code to get the items in</li>
<li>Having to use getKey() and getValue() in the iteration</li>
</ul>
<p>If you didn&#8217;t know yet, most of these issues can be solved by using <a href="http://code.google.com/p/google-collections/">Google Collections</a>. But besides that, I think the dollar sign based syntax, which I called DollarMaps, is slightly more elegant than the usual &#8220;let&#8217;s-do-some-type-inference&#8221; factory method.<br />
Creating a HashMap:</p>
<pre>
        Map&lt;Integer, String&gt; map = $(1,"blah1")
                                  .$(2, "blah2")
                                  .$(3, "blah3").asHashMap();
</pre>
<p>Iteration:</p>
<pre>
        for(Entry&lt;Integer, String&gt; e : $(1,"blah1").$(2, "blah2")) {
            System.out.println(e.getKey() + " " + e.getValue());
        }
</pre>
<p>You can even take iteration further if both the key and the value have the same type. I tried some things out and came up with the double dollar sign syntax to enforce that type rule. So easier, array-based iteration:</p>
<pre>
        for(String[] s : $$("1","blah1").$("2", "blah2").asEasy()) {
            System.out.println(s[0] + " " + s[1]);
        }
</pre>
<p>I did not run any performance tests (I am creating a 2-element array for each entry).<br />
Anyway, I&#8217;ll have this up for grabs at my <a href="http://code.google.com/p/garbagecollected/">Google Code project</a>. For the impatient, here&#8217;s the <a href="http://garbagecollected.googlecode.com/svn/trunk/DollarMaps/dist/DollarMaps-snapshot.zip">download link</a>. Feedback appreciated!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/garbagecollected.wordpress.com/31/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/garbagecollected.wordpress.com/31/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garbagecollected.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garbagecollected.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garbagecollected.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garbagecollected.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garbagecollected.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garbagecollected.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garbagecollected.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garbagecollected.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garbagecollected.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garbagecollected.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garbagecollected.org&blog=1057539&post=31&subd=garbagecollected&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://garbagecollected.org/2008/04/06/dollarmaps/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/vanbrro-128.jpg" medium="image">
			<media:title type="html">vanbrro</media:title>
		</media:content>
	</item>
		<item>
		<title>Guice Book Released!</title>
		<link>http://garbagecollected.org/2008/03/28/guice-book-released/</link>
		<comments>http://garbagecollected.org/2008/03/28/guice-book-released/#comments</comments>
		<pubDate>Fri, 28 Mar 2008 01:05:53 +0000</pubDate>
		<dc:creator>Robbie</dc:creator>
		
		<category><![CDATA[DI]]></category>

		<category><![CDATA[Guice]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://garbagecollected.wordpress.com/?p=27</guid>
		<description><![CDATA[I should really get some sleep, but I can&#8217;t wait to get the word out. The book I was working on &#8220;Google Guice: Agile Lightweight Dependency Injection Framework&#8221; has gone live! It&#8217;s available in ebook and print-on-demand formats.

Apart from the title, I think the book reflects the fact that I&#8217;m a no-nonsense guy. I&#8217;m just [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I should really get some sleep, but I can&#8217;t wait to get the word out. The book I was working on &#8220;<a href="http://www.apress.com/book/view/9781590599976">Google Guice: Agile Lightweight Dependency Injection Framework</a>&#8221; has gone live! It&#8217;s available in ebook and print-on-demand formats.</p>
<div style="text-align:center;"><img src="http://garbagecollected.files.wordpress.com/2008/03/book_small.thumbnail.png?w=102&#038;h=128" alt="Guice Book" height="128" hspace="15" vspace="15" width="102" /></div>
<p>Apart from the title, I think the book reflects the fact that I&#8217;m a no-nonsense guy. I&#8217;m just like you, interested in new technology and I want to see this Guice thing in action. They did <i>that</i> with dependency injection? Hell yes; let&#8217;s see why they did it, and who they killed to get there (just kidding :-)).</p>
<p>So, months later I look on <a href="http://www.amazon.com/Google-Guice-Lightweight-Dependency-Firstpress/dp/1590599977">Amazon</a>, and see this:</p>
<p><img src="http://garbagecollected.files.wordpress.com/2008/03/better_together.png?w=594&#038;h=113" align="middle" border="0" height="113" width="594" /></p>
<p>You can get my humble work together with the best Java book ever. That alone was so worth it :-)</p>
<p>Thanks again to <a href="http://www.apress.com">Apress</a>, <a href="http://crazybob.org">Bob</a>, <a href="http://www.wideplay.com">Dhanji</a> and the Guice community: I couldn&#8217;t have done it without you.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/garbagecollected.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/garbagecollected.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garbagecollected.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garbagecollected.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garbagecollected.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garbagecollected.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garbagecollected.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garbagecollected.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garbagecollected.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garbagecollected.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garbagecollected.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garbagecollected.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garbagecollected.org&blog=1057539&post=27&subd=garbagecollected&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://garbagecollected.org/2008/03/28/guice-book-released/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/vanbrro-128.jpg" medium="image">
			<media:title type="html">vanbrro</media:title>
		</media:content>

		<media:content url="http://garbagecollected.files.wordpress.com/2008/03/book_small.thumbnail.png" medium="image">
			<media:title type="html">Guice Book</media:title>
		</media:content>

		<media:content url="http://garbagecollected.files.wordpress.com/2008/03/better_together.png" medium="image" />
	</item>
		<item>
		<title>Guice, Spring 2.5 and Finding Mistakes Early</title>
		<link>http://garbagecollected.org/2008/03/15/guice-spring-25-and-finding-mistakes-early/</link>
		<comments>http://garbagecollected.org/2008/03/15/guice-spring-25-and-finding-mistakes-early/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 18:21:03 +0000</pubDate>
		<dc:creator>Robbie</dc:creator>
		
		<category><![CDATA[DI]]></category>

		<category><![CDATA[Guice]]></category>

		<category><![CDATA[Spring Framework]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[speaking]]></category>

		<guid isPermaLink="false">http://garbagecollected.wordpress.com/?p=26</guid>
		<description><![CDATA[Yesterday I gave a talk on Guice at the Profict Wintercamp! The goal of the event was to look at how Guice changes the Spring landscape by letting both sides present their framework. From the Guice side there was me (thanks Bob, for not being able to come! ;-)), from the Spring side there was [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Yesterday I gave a talk on <a href="http://code.google.com/p/google-guice/">Guice</a> at the <a href="http://java.profict.nl">Profict Wintercamp</a>! The goal of the event was to look at how Guice changes the <a href="http://www.springframework.org">Spring</a> landscape by letting both sides present their framework. From the Guice side there was me (thanks <a href="http://crazybob.org">Bob</a>, for not being able to come! ;-)), from the Spring side there was <a href="http://blog.arendsen.net/">Alef Arendsen</a>.</p>
<p>Surprisingly, there was only one Guice user present! They should have given us an &#8220;I went to the Profict Wintercamp and I lived.&#8221; t-shirt. :-) No seriously, I had a great time and enjoyed talking to other developers and the guys from SpringSource. Let&#8217;s hope I convinced some people to take a look at Guice!</p>
<p>Right before the talk I had some time to spare, so I quickly threw together a Guice demo application that I then re-implemented using the Spring 2.5 new annotation-driven configuration options. Next, I decided to take a look at how Spring compares with Guice in terms of error detection and error handling. This has always been one of Guice&#8217;s strengths, but it&#8217;s also one of those &#8220;nice-to-haves&#8221;. It&#8217;s like a cell phone. You don&#8217;t miss it until you have one. All those Spring users don&#8217;t know what they are missing!</p>
<p>The example code can be found <a href="http://code.google.com/p/garbagecollected/wiki/GuicySpring">here</a>, and the error handling comparison can be found <a href="http://code.google.com/p/garbagecollected/wiki/SpringAndGuiceErrors">here</a>. I&#8217;ll upload the presentation and the packaged source code soon. Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/garbagecollected.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/garbagecollected.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garbagecollected.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garbagecollected.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garbagecollected.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garbagecollected.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garbagecollected.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garbagecollected.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garbagecollected.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garbagecollected.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garbagecollected.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garbagecollected.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garbagecollected.org&blog=1057539&post=26&subd=garbagecollected&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://garbagecollected.org/2008/03/15/guice-spring-25-and-finding-mistakes-early/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/vanbrro-128.jpg" medium="image">
			<media:title type="html">vanbrro</media:title>
		</media:content>
	</item>
		<item>
		<title>The Last Lecture</title>
		<link>http://garbagecollected.org/2008/02/05/the-last-lecture/</link>
		<comments>http://garbagecollected.org/2008/02/05/the-last-lecture/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 19:13:06 +0000</pubDate>
		<dc:creator>Robbie</dc:creator>
		
		<category><![CDATA[howto]]></category>

		<category><![CDATA[life]]></category>

		<guid isPermaLink="false">http://garbagecollected.wordpress.com/?p=25</guid>
		<description><![CDATA[All the advice you will ever need. This talk is worth the hour of your time, trust me.

More information here. Thanks to John Lam for the link!
       ]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>All the advice you will ever need. This talk is worth the hour of your time, trust me.</p>
<p><span style="text-align:center; display: block;"><a href="http://garbagecollected.org/2008/02/05/the-last-lecture/"><img src="http://img.youtube.com/vi/ji5_MqicxSo/2.jpg" alt="" /></a></span></p>
<p>More information <a href="http://www.cmu.edu/randyslecture/">here</a>. Thanks to <a href="http://www.iunknown.com/2008/02/welcome-wayne-k.html">John Lam</a> for the link!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/garbagecollected.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/garbagecollected.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garbagecollected.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garbagecollected.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garbagecollected.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garbagecollected.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garbagecollected.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garbagecollected.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garbagecollected.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garbagecollected.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garbagecollected.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garbagecollected.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garbagecollected.org&blog=1057539&post=25&subd=garbagecollected&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://garbagecollected.org/2008/02/05/the-last-lecture/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/vanbrro-128.jpg" medium="image">
			<media:title type="html">vanbrro</media:title>
		</media:content>

		<media:content url="http://img.youtube.com/vi/ji5_MqicxSo/2.jpg" medium="image" />
	</item>
		<item>
		<title>A Goldfish&#8217;s Memory of Javapolis 2007</title>
		<link>http://garbagecollected.org/2007/12/13/a-goldfishs-memory-of-javapolis-2007/</link>
		<comments>http://garbagecollected.org/2007/12/13/a-goldfishs-memory-of-javapolis-2007/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 21:33:37 +0000</pubDate>
		<dc:creator>Robbie</dc:creator>
		
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://garbagecollected.wordpress.com/2007/12/13/a-goldfishs-memory-of-javapolis-2007/</guid>
		<description><![CDATA[Conference, day 1-2

The JavaFX programming model is no match for Flex&#8217;s or Silverlight&#8217;s
 Bruce Eckel doesn&#8217;t look like Bruce Eckel
Googlers, Googlers, Googlers (carry an Apple, Apple, Apple)
Neal Gafter has a hat glued to his head
 Bob &#8220;natural currency&#8221; Lee is a nice guy and an excellent presenter
Ola Bini got in the country, despite looking like [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Conference, day 1-2</p>
<ul>
<li>The JavaFX programming model is no match for Flex&#8217;s or Silverlight&#8217;s</li>
<li> Bruce Eckel doesn&#8217;t look like Bruce Eckel</li>
<li>Googlers, Googlers, Googlers (carry an Apple, Apple, Apple)</li>
<li>Neal Gafter has a hat glued to his head</li>
<li> Bob &#8220;natural currency&#8221; Lee is a nice guy and an excellent presenter</li>
<li>Ola Bini got in the country, despite looking like a serial killer</li>
<li>The Java Posse recording was fun, but the audio was terrible</li>
<li> Josh Bloch is always right, even if he&#8217;s not</li>
<li>Effective Java Forever</li>
</ul>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/garbagecollected.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/garbagecollected.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garbagecollected.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garbagecollected.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garbagecollected.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garbagecollected.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garbagecollected.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garbagecollected.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garbagecollected.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garbagecollected.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garbagecollected.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garbagecollected.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garbagecollected.org&blog=1057539&post=24&subd=garbagecollected&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://garbagecollected.org/2007/12/13/a-goldfishs-memory-of-javapolis-2007/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/vanbrro-128.jpg" medium="image">
			<media:title type="html">vanbrro</media:title>
		</media:content>
	</item>
		<item>
		<title>Guice Book</title>
		<link>http://garbagecollected.org/2007/12/13/guice-book/</link>
		<comments>http://garbagecollected.org/2007/12/13/guice-book/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 22:02:13 +0000</pubDate>
		<dc:creator>Robbie</dc:creator>
		
		<category><![CDATA[DI]]></category>

		<category><![CDATA[Guice]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://garbagecollected.wordpress.com/2007/12/13/guice-book/</guid>
		<description><![CDATA[I&#8217;m writing a book on Google Guice, the notorious DI framework created by Bob Lee. I&#8217;ve been active in the Guice community for quite a while now, and I have to say that it&#8217;s an honor to get the opportunity to write about one of the most innovative Java frameworks out there. Now that it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;m writing <a href="http://www.amazon.com/Google-Guice-Lightweight-Dependency-Injection/dp/1590599977/">a book</a> on <a href="http://code.google.com/p/google-guice/">Google Guice</a>, the notorious DI framework created by <a href="http://crazybob.org">Bob Lee</a>. I&#8217;ve been active in the Guice community for quite a while now, and I have to say that it&#8217;s an honor to get the opportunity to write about one of the most innovative Java frameworks out there. Now that it&#8217;s been published on Amazon, I feel like I&#8217;ve reached the point of no return. The world knows, so I&#8217;d damn well better make sure that I deliver some quality. So far I&#8217;m having a blast, so perhaps I&#8217;m still in <a href="http://blogs.tedneward.com/2007/12/08/Quotes+On+Writing.aspx">Ted&#8217;s phase two</a>. :-)</p>
<p align="left"><a href="http://garbagecollected.wordpress.com/2007/12/13/guice-book/guice/" rel="attachment wp-att-23" title="Guice"></a></p>
<p style="text-align:center;"><a href="http://garbagecollected.wordpress.com/2007/12/13/guice-book/guice/" rel="attachment wp-att-23" title="Guice"><img src="http://garbagecollected.files.wordpress.com/2007/12/guice.jpg" alt="Guice" /></a></p>
<p>On a related note, I enjoyed talking to Bob at <a href="http://www.javapolis.com">Javapolis</a> today. <a href="http://crazybob.org/2007/12/guice-javapolis.html">On popular demand</a> he took the advanced route for his <a href="http://www.javapolis.com/confluence/display/JP07/Guice">Guice talk</a>, which I think was appropriate. Too bad he didn&#8217;t have enough time to go through the example though. I was pleased to learn that much of what he talked about already made it into the book, in some form. Which must be a good thing, right? Anyway, one more day at Javapolis, and then back to work. :-)</p>
<p>Wish me luck. I&#8217;ll try to make sure I won&#8217;t need it. ;-)</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/garbagecollected.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/garbagecollected.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garbagecollected.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garbagecollected.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garbagecollected.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garbagecollected.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garbagecollected.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garbagecollected.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garbagecollected.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garbagecollected.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garbagecollected.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garbagecollected.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garbagecollected.org&blog=1057539&post=22&subd=garbagecollected&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://garbagecollected.org/2007/12/13/guice-book/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/vanbrro-128.jpg" medium="image">
			<media:title type="html">vanbrro</media:title>
		</media:content>

		<media:content url="http://garbagecollected.files.wordpress.com/2007/12/guice.jpg" medium="image">
			<media:title type="html">Guice</media:title>
		</media:content>
	</item>
		<item>
		<title>Guice Debug Output</title>
		<link>http://garbagecollected.org/2007/12/08/guice-debug-output/</link>
		<comments>http://garbagecollected.org/2007/12/08/guice-debug-output/#comments</comments>
		<pubDate>Sat, 08 Dec 2007 00:14:51 +0000</pubDate>
		<dc:creator>Robbie</dc:creator>
		
		<category><![CDATA[DI]]></category>

		<category><![CDATA[Guice]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://garbagecollected.wordpress.com/2007/12/08/guice-debug-output/</guid>
		<description><![CDATA[Guice has a dirty little secret: it logs timing information to its JDK Logger. A while ago I created a simple utility class for myself to enable or disable the logging of Guice&#8217;s debug output to the console. Here goes nothing.

/**
* Enable or disable Guice debug output
* on the console.
*/
public class GuiceDebug {
   [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Guice has a dirty little secret: it logs timing information to its JDK Logger. A while ago I created a simple utility class for myself to enable or disable the logging of Guice&#8217;s debug output to the console. Here goes nothing.</p>
<pre>
/**
* Enable or disable Guice debug output
* on the console.
*/
public class GuiceDebug {
    private static final Handler HANDLER;
    static {
        HANDLER = new StreamHandler(System.out, new Formatter() {
            public String format(LogRecord record) {
                return String.format("[Guice %s] %s%n",
                                  record.getLevel().getName(),
                                  record.getMessage());
            }
        });
        HANDLER.setLevel(Level.ALL);
    }

    private GuiceDebug() {}

    public static Logger getLogger() {
        return Logger.getLogger("com.google.inject");
    }

    public static void enable() {
        Logger guiceLogger = getLogger();
        guiceLogger.addHandler(GuiceDebug.HANDLER);
        guiceLogger.setLevel(Level.ALL);
    }

    public static void disable() {
        Logger guiceLogger = getLogger();
        guiceLogger.setLevel(Level.OFF);
        guiceLogger.removeHandler(GuiceDebug.HANDLER);
    }
}</pre>
<p>Output looks something like:</p>
<pre>
[Guice FINE] Configuration: 51ms
[Guice FINE] Binding creation: 53ms
[Guice FINE] Binding indexing: 0ms
[Guice FINE] Validation: 131ms
[Guice FINE] Static validation: 0ms
[Guice FINE] Static member injection: 2ms
[Guice FINE] Instance injection: 2ms
[Guice FINE] Preloading: 1ms</pre>
<p>Listen to the Logger, it&#8217;s making sense. Guice <em>is</em> fine! :-)</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/garbagecollected.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/garbagecollected.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garbagecollected.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garbagecollected.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garbagecollected.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garbagecollected.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garbagecollected.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garbagecollected.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garbagecollected.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garbagecollected.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garbagecollected.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garbagecollected.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garbagecollected.org&blog=1057539&post=21&subd=garbagecollected&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://garbagecollected.org/2007/12/08/guice-debug-output/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/vanbrro-128.jpg" medium="image">
			<media:title type="html">vanbrro</media:title>
		</media:content>
	</item>
	</channel>
</rss>