<?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>Just Java &#187; Java</title>
	<atom:link href="http://blog.cedarsoft.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cedarsoft.com</link>
	<description>Johannes Schneider (cedarsoft GmbH) about Java and related stuff</description>
	<lastBuildDate>Wed, 25 Aug 2010 09:46:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Code Generation done right&#8230;</title>
		<link>http://blog.cedarsoft.com/2010/08/code-generation-done-right/</link>
		<comments>http://blog.cedarsoft.com/2010/08/code-generation-done-right/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 11:34:33 +0000</pubDate>
		<dc:creator>johannes</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[codemodel]]></category>
		<category><![CDATA[generation]]></category>
		<category><![CDATA[mda]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=381</guid>
		<description><![CDATA[Code Generation solves a lot of problems. And everybody uses it all the day: Ever generated Getters/Setters using your IDE? Or method stubs? Or constructors? 
And sometimes complete classes are generated. One famous example is Hibernate that is able to generate Java classes from a database schema.
Most of the projects I have seen so far ]]></description>
			<content:encoded><![CDATA[<p>Code Generation solves a lot of problems. And everybody uses it all the day: Ever generated Getters/Setters using your IDE? Or method stubs? Or constructors? </p>
<p>And sometimes complete classes are generated. One famous example is Hibernate that is able to generate Java classes from a database schema.</p>
<p>Most of the projects I have seen so far use a templating engine (<a href="http://freemarker.sourceforge.net/">FreeMarker</a> or <a href="http://velocity.apache.org/">Velocity</a>) to create the source files. Hibernate switched from Velocity to FreeMarker some years ago&#8230;</p>
<p>This approach is quite good for simple cases. Those can be solved quite fast using that approach.</p>
<h3>Complexity</h3>
<p>But things get worse, if you have to generate more sophisticated code. Of course FreeMarker supports conditions and you can do quite amazing things using complex model classes. On the other hand those templates start to get really complicated and hard to debug over time.<br />
And of course you always have two sources: The template file and your data model.</p>
<h3>Imports</h3>
<p>One thing special to Java source files are the imports. When you conditionally use a class somewhere, you also have to add the import statement conditionally&#8230; Nothing that can be solved easily using FreeMarker.</p>
<p>So sometimes one might wish to have a nice API that does all the dirty work for you&#8230;</p>
<h1>The alternative: Codemodel</h1>
<p>I have looked around to find such an API. And it took me quite a long time to find one.<br />
And that API is quite near beside you. Just a little bit hidden.</p>
<p>JAXB has a sub project called <a href="https://codemodel.dev.java.net/">codemodel</a>. This is an API that allows you to create Java classes by just using an API&#8230;</p>
<h2>How to use Codemodel</h2>
<p>There is no separate jar for codemodel. But the classes are shipped with every JAXB installation. So since JDK 1.6 the classes are just here and waiting to be used. But since they have renamed the package as &#8220;internal&#8221; I suggest to import the JAXB jar manually:</p>
<p>For Maven users this should be enough:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.xml.bind<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jaxb-xjc<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.2.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<h3>A quick introduction</h3>
<p>The API is not perfect yet. And it is not documented very well. But it is nearly complete and I didn&#8217;t miss much.<br />
Here is a short example that should give you a fast start:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">JCodeModel codeModel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JCodeModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
JDefinedClass foo <span style="color: #339933;">=</span> codeModel._class<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;a.b.c.Foo&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Creates a new class</span><br />
<br />
JMethod method <span style="color: #339933;">=</span> foo.<span style="color: #006633;">method</span><span style="color: #009900;">&#40;</span> JMod.<span style="color: #000000; font-weight: bold;">PUBLIC</span>, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Avoid+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Void</span></a>.<span style="color: #006633;">TYPE</span>, <span style="color: #0000ff;">&quot;doFoo&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Adds a method to the class</span><br />
method.<span style="color: #006633;">body</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>._return<span style="color: #009900;">&#40;</span> JExpr.<span style="color: #006633;">lit</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">42</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//the return statement</span></div></td></tr></tbody></table></div>
<p>The code can be written to the file system. But it can also be written to a single output stream. This is great for testing:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abytearrayoutputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ByteArrayOutputStream</span></a> out <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abytearrayoutputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ByteArrayOutputStream</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
codeModel.<span style="color: #006633;">build</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> SingleStreamCodeWriter<span style="color: #009900;">&#40;</span> out <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>This code outputs that code:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">-----------------------------------</span>a.<span style="color: #006633;">b</span>.<span style="color: #006633;">c</span>.<span style="color: #006633;">Foo</span>.<span style="color: #006633;">java</span><span style="color: #339933;">-----------------------------------</span><br />
<br />
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">a.b.c</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Foo <span style="color: #009900;">&#123;</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doFoo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> &nbsp;<span style="color: #cc66cc;">42</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Great, isn&#8217;t it?</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.cedarsoft.com/2010/01/google-collections-released-finally/" rel="bookmark" class="crp_title">Google Collections released (finally)</a></li><li><a href="http://blog.cedarsoft.com/2010/08/junit-rules/" rel="bookmark" class="crp_title">JUnit: Rules</a></li><li><a href="http://blog.cedarsoft.com/2010/05/javafx-internals-part-2/" rel="bookmark" class="crp_title">JavaFX Internals Part 2</a></li><li><a href="http://blog.cedarsoft.com/2010/08/unit-testing-time-zone-and-stuff/" rel="bookmark" class="crp_title">[Unit Testing]: Time zone and stuff&#8230;</a></li><li><a href="http://blog.cedarsoft.com/2010/05/closing-the-gap-between-java-and-javafx/" rel="bookmark" class="crp_title">Closing the gap between Java and JavaFX</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2010/08/code-generation-done-right/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Java Surprise: Setters/Getters and Collections</title>
		<link>http://blog.cedarsoft.com/2010/08/java-surprise-settersgetters-and-collections/</link>
		<comments>http://blog.cedarsoft.com/2010/08/java-surprise-settersgetters-and-collections/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 09:27:08 +0000</pubDate>
		<dc:creator>johannes</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[puzzle]]></category>
		<category><![CDATA[surprise]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=385</guid>
		<description><![CDATA[Inspired by the Java Killers series, I wanted to post a problem I stumbled across some years ago:
Imagine a bean containing a field.
12345678910111213141516class Car &#123;
&#160; private final List&#60;Tire&#62; tires = new ArrayList&#60;Tire&#62;&#40;&#41;;

&#160; public void setTires&#40; List&#60;Tire&#62; tires &#41; &#123;
&#160; &#160; this.tires.clear&#40;&#41;;
&#160; &#160; this.tires.addAll&#40; tires &#41;;
&#160; &#125;

&#160; public void addTire&#40; Tire tires &#41; &#123;
&#160; &#160; this.tires.add&#40; ]]></description>
			<content:encoded><![CDATA[<p>Inspired by the Java Killers series, I wanted to post a problem I stumbled across some years ago:</p>
<p>Imagine a bean containing a field.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> Car <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> List<span style="color: #339933;">&lt;</span>Tire<span style="color: #339933;">&gt;</span> tires <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Tire<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setTires<span style="color: #009900;">&#40;</span> List<span style="color: #339933;">&lt;</span>Tire<span style="color: #339933;">&gt;</span> tires <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">tires</span>.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">tires</span>.<span style="color: #006633;">addAll</span><span style="color: #009900;">&#40;</span> tires <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addTire<span style="color: #009900;">&#40;</span> Tire tires <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">tires</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span> tires <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Tire<span style="color: #339933;">&gt;</span> getTires<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acollections+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Collections</span></a>.<span style="color: #006633;">unmodifiableList</span><span style="color: #009900;">&#40;</span> tires <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>What is the output of that code?</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Car car <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Car<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
car.<span style="color: #006633;">addTire</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> Tire<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
car.<span style="color: #006633;">addTire</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> Tire<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
List<span style="color: #339933;">&lt;</span>Tire<span style="color: #339933;">&gt;</span> carTires <span style="color: #339933;">=</span> car.<span style="color: #006633;">getTires</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;before: &quot;</span> <span style="color: #339933;">+</span> carTires.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
car.<span style="color: #006633;">setTires</span><span style="color: #009900;">&#40;</span> carTires <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;after1: &quot;</span> <span style="color: #339933;">+</span> car.<span style="color: #006633;">getTires</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;after2: &quot;</span> <span style="color: #339933;">+</span> carTires.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>The first part is easy:</p>
<pre>before: 2</pre>
<p>But the rest?</p>
<p><span id="more-385"></span></p>
<pre>
before: 2
after1: 0
after2: 0
</pre>
<p>We have managed to empty the collection accidentally &#8211; even if it is unmodifiable.<br />
The problem lies in the setter and how <em>Collections.unmodifiableList()</em> is implemented:</p>
<p>Collections.unmodifiableList returns a list that is backed by the original list. Every change to the original collections is reflected.<br />
Therefore the &#8220;clear&#8221; call empties also the unmodifiable list.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setTires<span style="color: #009900;">&#40;</span> List<span style="color: #339933;">&lt;</span>Tire<span style="color: #339933;">&gt;</span> tires <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">tires</span>.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//the list is cleared! But since the method parameter is a view of this.tires, it is emptied, too.</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">tires</span>.<span style="color: #006633;">addAll</span><span style="color: #009900;">&#40;</span> tires <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//since tires is empty now, addAll doesn't do anything...</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>So be careful with collections. They might change a really surprising moments&#8230;</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.cedarsoft.com/2010/01/wildcards-and-collections-part-1/" rel="bookmark" class="crp_title">Generics and Wildcards: Part 1</a></li><li><a href="http://blog.cedarsoft.com/2008/01/why-you-should-only-return-collections-with-bounded-wildcards/" rel="bookmark" class="crp_title">Why you should only return Collections with bounded wildcards</a></li><li><a href="http://blog.cedarsoft.com/2008/01/generics-and-collections-done-right-1-foolproof-step/" rel="bookmark" class="crp_title">Generics and Collections done right (1 foolproof step)&#8230;</a></li><li><a href="http://blog.cedarsoft.com/2010/05/javafx-internals-part-2/" rel="bookmark" class="crp_title">JavaFX Internals Part 2</a></li><li><a href="http://blog.cedarsoft.com/2010/08/junit-rules/" rel="bookmark" class="crp_title">JUnit: Rules</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2010/08/java-surprise-settersgetters-and-collections/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>cedarsoft Serialization 1.0.0 released</title>
		<link>http://blog.cedarsoft.com/2010/01/cedarsoft-serialization-1-0-0-released/</link>
		<comments>http://blog.cedarsoft.com/2010/01/cedarsoft-serialization-1-0-0-released/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 18:04:36 +0000</pubDate>
		<dc:creator>johannes</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[serialization]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=142</guid>
		<description><![CDATA[cedarsoft Serialization (GPL with Classpath Exception) offers version aware serialization of java object trees with maximum control. Its goal is to provide some simple classes (very small framework) that enables rapid development of versioned serialization.
Serialized XML contains version informations and might look like that:
&#60;?xml version="1.0" encoding="UTF-8"?&#62;
&#60;businessObject xmlns="http://yourcompany.com/path/2.0.1"&#62;
  &#60;name&#62;theName&#60;/name&#62;
  ...
&#60;/businessObject&#62;
It does not contain any ]]></description>
			<content:encoded><![CDATA[<p><a title="cedarsoft Serialization" href="http://serialization.cedarsoft.org/">cedarsoft Serialization</a> (GPL with Classpath Exception) offers version aware serialization of java object trees with maximum control. Its goal is to provide some simple classes (very small framework) that enables rapid development of versioned serialization.</p>
<p>Serialized XML contains version informations and might look like that:</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;businessObject xmlns="http://yourcompany.com/path/2.0.1"&gt;
  &lt;name&gt;theName&lt;/name&gt;
  ...
&lt;/businessObject&gt;</pre>
<p>It does not contain any &#8220;magic&#8221; code. It just offers plain and very fast serialization.</p>
<p>It follows those main ideas:</p>
<ul>
<li>Version support as first class citizen (Every serialized object gets its version information attached &#8211;&gt;necessary for stability)</li>
<li>Minimized boiler plate code (&#8211;&gt; fast results), but:</li>
<li>No magic (no bad surprises)</li>
<li>KISS</li>
<li>Performance, performance!</li>
<li>Flexibility and therefore stability: Serialized objects can be read with all future versions.</li>
</ul>
<p>Do not believe the wrong &#8220;everything can be done automatically&#8221; promise. Write that code that matters. And nothing more.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.cedarsoft.com/2009/12/cedarsoft-serialization-1-0-0-beta1-released/" rel="bookmark" class="crp_title">cedarsoft Serialization 1.0.0-beta1 released</a></li><li><a href="http://blog.cedarsoft.com/2009/12/whats-wrong-with-xstream-and-similar-tools/" rel="bookmark" class="crp_title">What&#8217;s wrong with XStream and similar tools?</a></li><li><a href="http://blog.cedarsoft.com/2010/07/junit-theory-oddities/" rel="bookmark" class="crp_title">JUnit @Theory oddities</a></li><li><a href="http://blog.cedarsoft.com/2010/05/binding-propertychangesupport-to-javafx-objects/" rel="bookmark" class="crp_title">Binding PropertyChangeSupport to JavaFX objects transparently</a></li><li><a href="http://blog.cedarsoft.com/2010/08/maven-git-relasing-and-branching-done-right/" rel="bookmark" class="crp_title">[Maven + Git] Releasing and Branching done right&#8230;</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2010/01/cedarsoft-serialization-1-0-0-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Splitting up your pom.xml into multiple files</title>
		<link>http://blog.cedarsoft.com/2007/09/splitting-up-your-pom-xml-into-multiple-files/</link>
		<comments>http://blog.cedarsoft.com/2007/09/splitting-up-your-pom-xml-into-multiple-files/#comments</comments>
		<pubDate>Mon, 10 Sep 2007 22:35:00 +0000</pubDate>
		<dc:creator>johannes</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=3</guid>
		<description><![CDATA[Ever had to deal with a really, really huge pom.xml? As soon as you start not only to declare the dependencies but also to add informations about the distribution (repositories, site), mailinglists or developers, the pom.xml starts to become really huge.
It is hard to find the informations you search. And it is much harder to ]]></description>
			<content:encoded><![CDATA[<p>Ever had to deal with a really, really huge pom.xml? As soon as you start not only to declare the dependencies but also to add informations about the distribution (repositories, site), mailinglists or developers, the pom.xml starts to become really huge.</p>
<p>It is hard to find the informations you search. And it is much harder to find that revision a dependecy has changed if there is so much noise due to changes in other sections.<br />
Many applications with huge configuration files started to convert their files into directories over the last years. Apache now has its &#8220;conf.d&#8221; directory, crontab uses &#8220;cron.d&#8221; and so on.</p>
<p>Why not take the same step, too? Why not split up the pom.xml into several files that are placed within a directory called &#8220;pom.d&#8221;?<br />
So I have created a <a title=" Optional support for splitting up pom.xml in multiple files" href="http://docs.codehaus.org/display/MAVENUSER/Optional+support+for+splitting+up+pom.xml+in+multiple+files" target="_blank">proposal for Maven 2.1</a>.</p>
<p>What do you think?</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.cedarsoft.com/2007/09/java-image-manipulation-tutorial/" rel="bookmark" class="crp_title">Java Image manipulation tutorial</a></li><li><a href="http://blog.cedarsoft.com/2010/08/code-generation-done-right/" rel="bookmark" class="crp_title">Code Generation done right&#8230;</a></li><li><a href="http://blog.cedarsoft.com/2009/12/whats-wrong-with-xstream-and-similar-tools/" rel="bookmark" class="crp_title">What&#8217;s wrong with XStream and similar tools?</a></li><li><a href="http://blog.cedarsoft.com/2010/01/top-10-why-subversion-is-better-than-git/" rel="bookmark" class="crp_title">Top 10: Why Subversion is better than Git</a></li><li><a href="http://blog.cedarsoft.com/2010/08/junit-rules/" rel="bookmark" class="crp_title">JUnit: Rules</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2007/09/splitting-up-your-pom-xml-into-multiple-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
