<?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>Pragmatic Programmer Issues - pietrowski.info &#187; java</title>
	<atom:link href="http://pietrowski.info/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://pietrowski.info</link>
	<description></description>
	<lastBuildDate>Tue, 27 Jul 2010 07:31:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Guava &#8211; Google Collections</title>
		<link>http://pietrowski.info/2010/01/guava-google-collections/</link>
		<comments>http://pietrowski.info/2010/01/guava-google-collections/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 17:34:40 +0000</pubDate>
		<dc:creator>pedro</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://pietrowski.info/?p=221</guid>
		<description><![CDATA[Guava Guava is Google Core Libraries for Java 1.5, it include extension libraries which provides many common pieces of code. Long long time ago apache starts with commons-* libraries, but unfortunately most of them lack java 5 support. Currently Google Collection is included into Guava and on 30 Dec google released Google Collection 1.0-fianal version. [...]]]></description>
			<content:encoded><![CDATA[<h3>Guava</h3>
<p style="clear: both">Guava is Google Core Libraries for Java 1.5, it include extension libraries which provides many common pieces of code. Long long time ago apache starts with commons-* libraries, but unfortunately most of them lack java 5 support. </p>
<p style="clear: both">Currently Google Collection is included into Guava and on 30 Dec google released Google Collection 1.0-fianal version. This version is not 1.0 but it has frozen API. It&#8217;s nearly done, but it is used in google production projects now. </p>
<p style="clear: both">So, what&#8217;s inside ?</p>
<p style="clear: both">
<ul style="clear: both">
<li>Immutable Collections</li>
<li>Multisets</li>
<li>Multimaps</li>
<li>New types</li>
<li>Static utilitis</li>
</ul>
<h3>Immutable Collections</h3>
<p>JDK currently has utility wrapper in Collections which can change our map/set/list into unmodifiable, but this is just a partial solution because internally our collection is mutable. Immutable means that we can never change the object state. So there are:
<dl>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableMap.html">com.google.common.collect.ImmutableMap<K,V></a></dt>
<dd>An immutable, hash-based Map</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableSortedMap.html">com.google.common.collect.ImmutableSortedMap<K,V></a></dt>
<dd>An immutable SortedMap</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableBiMap.html">com.google.common.collect.ImmutableBiMap<K,V></a></dt>
<dd>An immutable BiMap</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableCollection.html">com.google.common.collect.ImmutableCollection<e></e></a></dt>
<dd> An immutable collection.</dd>
<dt><a href="com.google.common.collect.ImmutableList<E> http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableList.html&#8221;>com.google.common.collect.ImmutableList<e></e></a></dt>
<dd>A high-performance, immutable, random-access List implementation.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableMultiset.html">com.google.common.collect.ImmutableMultiset<e></e></a></dt>
<dd>An immutable hash-based multiset</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableSet.html">com.google.common.collect.ImmutableSet<e></e></a></dt>
<dd>A high-performance immutable Set</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableSortedSet.html">com.google.common.collect.ImmutableSortedSet<e></e></a></dt>
<dd> An immutable SortedSet that stores its elements in a sorted array.</dd>
</dl>
<p> All this Collections don&#8217;t allow Null values and Maps don&#8217;t allow Null keys or values. </p>
<h3>Multisets</h3>
<p style="clear: both">Multiset is a type of collection which allows duplicate elements and has unordered equality (lists have ordered equality). A multiset is also called bag. Multiset is better from list in such operation as contains(), checking if two collection are equal ignoring order and providing histograms (providing info about element count). Additionally Multiset performance depends on the number of <strong>distinct</strong> elements. </p>
<p style="clear: both">There are a lot of different implementation of <a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Multiset.html">Multiset interface</a>.
<dl>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ConcurrentHashMultiset.html">com.google.common.collect.ConcurrentHashMultiset<E></a></dt>
<dd>A multiset that supports concurrent modifications</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/EnumMultiset.html">com.google.common.collect.EnumMultiset<E></a></dt>
<dd>Multiset implementation backed by an EnumMap.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ForwardingMultiset.html">com.google.common.collect.ForwardingMultiset<E></a></dt>
<dd>A multiset which forwards all its method calls to another multiset. (Decorator pattern alike)</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/HashMultiset.html">com.google.common.collect.HashMultiset<E></a></dt>
<dd>Multiset implementation backed by a HashMap.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableMultiset.html">com.google.common.collect.ImmutableMultiset<E></a></dt>
<dd>Immputable hash-based.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/LinkedHashMultiset.html">com.google.common.collect.LinkedHashMultiset<E></a></dt>
<dd>A Multiset implementation with predictable iteration order.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/TreeMultiset.html">com.google.common.collect.TreeMultiset<E></a></dt>
<dd>Multiset which maintains the ordering of its elements.</dd>
</dl>
<h3>Multimaps</h3>
<p style="clear: both">Similar to Multiset is Multimap iterface. It provides abstraction like a Map but keys aren&#8217;t unique or we can thing about this that unique key has a list of values, so if you have somewhere in the code type such as Map<Key, List<>> Multimap is for you. As 1.0 version we&#8217;ve got <a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Multimap.html">Multimap</a> interface implementation such as:
<ul>
<li>Multimap<K,V></li>
<dl>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ForwardingMultimap.html">com.google.common.collect.ForwardingMultimap<K,V></a></dt>
<dd>A multimap which forwards all its method calls to another multimap.</dd>
</dl>
<li>ListMultimap<K,V>
<dl>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ArrayListMultimap.html">com.google.common.collect.ArrayListMultimap<K,V></a></dt>
<dd>Multimap that uses an ArrayList to store the values for a given key</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableListMultimap.html">com.google.common.collect.ImmutableListMultimap<K,V></a></dt>
<dd>Immutable ListMultimap</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/LinkedListMultimap.html">com.google.common.collect.LinkedListMultimap<K,V></a></dt>
<dd>Implementation of ListMultimap that supports deterministic iteration order for both keys and values.</dd>
</dl>
</li>
<li>SetMultimap<K,V&#038;gt
<dl>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/HashMultimap.html">com.google.common.collect.HashMultimap<K,V></a></dt>
<dd>The multimap does not store duplicate key-value pairs.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableSetMultimap.html">com.google.common.collect.ImmutableSetMultimap<K,V></a></dt>
<dd>Immutable SetMultimap</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/LinkedHashMultimap.html">com.google.common.collect.LinkedHashMultimap<K,V></a></dt>
<dd>Multimap that does not allow duplicate key-value entries and that returns collections whose iterators follow the ordering in which the data was added to the multimap.</dd>
</dl>
</li>
<li>SortedSetMultimap<K,V>
<dl>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/TreeMultimap.html">com.google.common.collect.TreeMultimap<K,V></a></dt>
<dd>Multimap whose keys and values are ordered by their natural ordering or by supplied comparators.</dd>
</dl>
</li>
</ul>
<h3>BiMap</h3>
<p style="clear: both">BiMap is the map with unique values. Than it can be inverted so bimap.inverse().inverse() == bimap. There are few implementation of BiMap interface:
<dl>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/EnumBiMap.html">com.google.common.collect.EnumBiMap<K,V></a></dt>
<dd>BiMap backed by two EnumMap instances</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/EnumHashBiMap.html">com.google.common.collect.EnumHashBiMap<K,V></a></dt>
<dd>BiMap backed by an EnumMap instance for keys-to-values, and a HashMap instance for values-to-keys.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/HashBiMap.html">com.google.common.collect.HashBiMap<K,V></a></dt>
<dd>BiMap backed by two HashMap instances.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableBiMap.html">com.google.common.collect.ImmutableBiMap<K,V></a></dt>
<dd>Immutable BiMap</dd>
</dl>
<h3>Static Utility Class</h3>
<p style="clear: both">In this category there are a lot of class which has only static members to extend and provide function which are useful but not available today.
<dl>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Collections2.html">Collections2</a></dt>
<dd>Provides <strong>filter</strong> with Predicate and <strong>transform</strong> with Function methods</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Functions.html">Functions</a></dt>
<dd>Function extension eg compose</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Lists.html">Lists</a></dt>
<dd>Provides such methods as <strong>new*</strong> for easier List creation and two additional methods <strong>partition</strong>(create sublists of the same size) and <strong>transform</strong> which takes Function as a parameter and apply it to every list element.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Maps.html">Maps</a></dt>
<dd>Provides such methods as <strong>new*</strong> for easier Map creation, <strong>difference</strong> method, <strong>filter*</strong> methods with Predicate, <strong>fromProperties</strong>, <strong>transformValues</strong> with Function parameter. </dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Multimaps.html">Multimaps</a></dt>
<dd>Provides methods such as <strong>new*</strong>, <strong>synchronized*</strong>, <strong>unmodifiable*</strong></dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ObjectArrays.html">ObjectArrays</a></dt>
<dd>Provides <strong>contact</strong> and <strong>newArray</strong> methods</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Sets.html">Sets</a></dt>
<dd>Provides methods: <strong>differece</strong>, <strong>filter</strong>, <strong>intersecton</strong>, <strong>new*</strong>, <strong>union</strong></dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Suppliers.html">Suppliers</a></dt>
<dd>Some Supplier extensions</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Predicates.html">Predicates</a></dt>
<dd>Predicate extension eg. <strong>and</strong>, <strong>or</strong>, <strong>not</strong> etc</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Preconditions.html">Preconditions</a></dt>
<dd>Static methods to be called at beginning of methods to check preconditions.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Objects.html">Objects</a></dt>
<dd>Helper for Object class has great <strong>hashCode(Object &#8230;) </strong>method for generating hash code for multiple objects.</dd>
</dl>
<h3>And more &#8230;</h3>
<dl>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Ordering.html">Ordering<T></a></dt>
<dd>Comparator with added methods to support common functions such as min, max etc. So instead of iterate over list to find min value, we can use min(Iterable) method.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/MapMaker.html">MapMaker</a></dt>
<dd>ConcurrentMap builder, providing any combination of these features: soft or weak keys, soft or weak values, timed expiration, and on-demand computation of values.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Function.html">Function<F,T></a></dt>
<dd>A transformation from one object to another. Used in transform static utility methods for Collection API extension.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Predicate.html">Predicate<T></a></dt>
<dd>Determines a true or false value for a given input. Used in filter static utility methods.</dd>
<dt><a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Supplier.html">Supplier<T></a></dt>
<dd>Class that supply object of single type. Used in new* static utility methods</dd>
</dl>
<h3>Final thoughts</h3>
<p>So&#8230;, in my opinion this library is must have in every project and there are a chance that this library will be standard JDK7 library, there are a lot of structures and static utility methods which makes our code much cleaner and simpler. Googler made great job!</p>
<h3>References</h3>
<ul>
<li><a href="http://www.javalobby.org/articles/google-collections/">What is the Google Collections Library?</a> &#8211; interview with authors Kevin Bourrillion and Jared Levy.
<li><a href="http://google-collections.googlecode.com/">Google Collections Home Page</a></li>
</li>
</ul>
<p><br class="final-break" style="clear: both" />  </p>
]]></content:encoded>
			<wfw:commentRss>http://pietrowski.info/2010/01/guava-google-collections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Long Time</title>
		<link>http://pietrowski.info/2009/01/long-time/</link>
		<comments>http://pietrowski.info/2009/01/long-time/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 14:35:44 +0000</pubDate>
		<dc:creator>pedro</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://pietrowski.info/?p=135</guid>
		<description><![CDATA[I&#8217;m back. Probably you think that I&#8217;m dead but it far from that. Rather I&#8217;ve got so many activities that I can&#8217;t manage writing about it on my blog. What&#8217;s a shame. First at all in November I must finalize training. It was a lot of work to do, and preparing labs is very difficult [...]]]></description>
			<content:encoded><![CDATA[<p style="clear: both">I&#8217;m back.</p>
<p style="clear: both">Probably you think that I&#8217;m dead but it far from that. Rather I&#8217;ve got so many activities that I can&#8217;t manage writing about it on my blog. What&#8217;s a shame. </p>
<p style="clear: both">First at all in November I must finalize training. It was a lot of work to do, and preparing labs is very difficult task. The training was conducted in December and January, after that I&#8217;m very glad because we&#8217;ve got 5.24 note in 1-6 scale. Probably our note will be higher but on one of our training we have frustrated colleague with poor technology knowledge so he get nervous and he give us 2.5 note.</p>
<p style="clear: both">During this preparation, I was on JBoss Training. It was JBoss for Advanced J2EE Developers (<a href="https://www.redhat.com/courses/jb261_jboss_for_advanced_j2ee_developers/" target="_blank">JB261</a>). It was in <a href="http://maps.google.pl/maps?q=Amersfoort&#038;oe=utf-8&#038;client=firefox-a&#038;ie=UTF8&#038;split=0&#038;gl=pl&#038;z=11&#038;iwloc=addr">Amersfoort.</a> It was one of the best training I&#8217;ve had. Maybe the reason was that was only four of us, so after this training participants and trainee is my freind, we have a lot of time to talk, to do extra exercises, it was great time. I have some thoughts about some post from this training. </p>
<p style="clear: both">Few days latter I went to <a href="http://www.devoxx.com/display/JV08/Home">Devoxx</a>. It was quite good conference and we met there our friends so we had hard time, conference from morning to evening and than we tasted <a href="http://en.wikipedia.org/wiki/Belgian_beer">Belgium beers</a>. Belgium beers are famous, if you like beer you should visit Belgium. </p>
<p style="clear: both">First Devoxx day I started with <a href="http://www.briangoetz.com/">Brian Goetz</a> with &#8220;From concurrent to parallel&#8221;. It was very nice but also hard topic. He talk about evolving concurrency API to support multi-core processors. The Brian&#8217;s wisdom is incredible. I&#8217;ve just get familiar with current concurrency API, but he is another step further. Next session I went to &#8220;Introduction to the SpringSource dm Server with <a href="http://blog.springsource.com/author/sbrannen/">Sam Brannen</a>. It was nice talk but I went also to &#8220;How to hack and secure your java web application&#8221;, it was happened due to my involvement into security program in my company. Next session I&#8217;ve chosen &#8220;Envers&#8221; probably because <a href="http://www.warski.org/blog/">Adam Warski</a> is from Poland <img src='http://pietrowski.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Due to training the next session was obvious, so I went on &#8220;What&#8217;s new in Spring Framework 3.0?&#8221; Arjen with Alef was talking about new features in Spring Framework, and where was a lots of questions about schedule sources and new spring license policy. The last slot I was in several session and probably JavaFX with applet out of the browser stay in my mind. There was one quickie about &#8220;MinuteProject&#8221; by Florian Adler. <a href="http://sourceforge.net/projects/minuteproject/">MinuteProject</a> is generator tool. It can generate DAO operation to hibernate/jpa and even iBatis, after this we have a little discussion about MDA and such projects future.</p>
<p style="clear: both">Next day was harder than a day before, but I started with &#8220;Be smart!&#8221; with <a href="http://en.wikipedia.org/wiki/Ivar_Jacobson">Ivar Jacobson</a>. You probably know Jacobson, if not try to get know something about him. It was one of the best session at Devoxx 2008. It will be on <a href="http://www.parleys.com/display/PARLEYS/Home">Parleys.com</a> so Be smart and watch it. Next session was about JavaFX and after first impression I was a disappointed, but it just version 1.0 we&#8217;ll see what happen. Finally there was my favorite session <a href="http://www.javaposse.com/">javaposse.com</a> with Belgium beer from <a href="http://www.atlassian.com/">Atlassian</a>. After that I took break with my friends and we went outside to discuss sessions. Than I went on two sessions about Seem and preventing bugs. The last was about Hibernate Performance Tuning it was quite interesting. This day was quite nice quickies, one about Atlassian Connector for InteliJ and what I didn&#8217;t know that this plugin is developed in Poland.</p>
<p style="clear: both">The last day was short so I with my friends went to Brussels, when we stay for a whole weekend.</p>
<p style="clear: both">Quite long post. I finish it here, because after Devoxx Christmas was came <img src='http://pietrowski.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . </p>
<p style="clear: both">
<p><br class='final-break' style='clear: both' /></p>
]]></content:encoded>
			<wfw:commentRss>http://pietrowski.info/2009/01/long-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
