advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the Code!
Partners & Affiliates
advertisement
advertisement
Rate this item | 0 users have rated this item.
 Print Print
 
Comparing the Google Collections Library with the Apache Commons Collections
Like Apache's Jakarta Commons Collections, the recently released Google Collections Library also enhances the Java Collections Framework but offers some unique enhancements you may prefer. 

advertisement
hen I first learned about the Google Collections Library, I was puzzled. The Google Collections Library enhances the JDK's Java Collections Framework, and its developers plan to make it part of JDK 7. As a user of Apache's Jakarta Commons Collections, I didn't understand why Google created an API to enhance the Java Collections Framework when Apache had already done so. I read in an interview with one of the Google Collections Library creators that a motivation for creating a new library was to provide JDK 5 Generics support, which Jakarta Commons Collections lacks. I also read that Jakarta Commons Collections contains a few classes that violate the Java Collections Framework specification.


Upon investigating these claims I found that Jakarta Commons Collections indeed doesn't support JDK 5 Generics—a definite flaw. However, I found this SourceForge project, which claims to be a JDK 5 Generics-enabled version of Jakarta Commons Collections.

As for Java Collections Framework violations, I found that only the Bag interface methods in Jakarta Commons Collections violate the spec (as per the JavaDoc), and the Bag interface by its nature warrants this violation. Take the add method in the Bag interface as an example. The Java Collections Framework spec stipulates that the add method must always return true, but Bag does not do this when an object of the same type as one already in Bag is added. In that case, it only increases the count and the method returns false.

Coincidently, I discovered the src folder of the Jakarta Commons Collections project had not been updated in two months.

So I decided to explore the Google Collections Library further and find out what it had to offer a Java developer like me who's been using Jakarta Commons Collections. In this article, I describe the packages and classes in the Google Collections Library (hereafter referred to simply as the Library). I then compare and contrast these classes with those in the Apache Jakarta Commons Collections (hereafter referred to simply as Commons Collections).

Google Collections Library Packages
The Library is organized into two packages:

  • com.google.common.base – This package contains a few common utility classes, which can be used even without the Java Collections Framework.
  • com.google.common.collect – This package hosts all the enhancements to the Java Collections Framework.

This organization enables a programmer to grasp the Library quicker than he or she would learn Commons Collections. For instance, whereas decorator classes are scattered throughout all the packages in Commons Collections, the Library keeps them all in one package (com.google.common.collect) and prefixes them with 'Forwarding<decorator type>'.

  Next Page: The com.google.common.base Package


Page 1: IntroductionPage 3: The com.google.common.collect Package
Page 2: The com.google.common.base PackagePage 4: What's Missing in Google Collections Library?
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES