The document discusses different Java collection frameworks and compares their performance when implementing a deck of cards problem. It presents sample code for creating an immutable sorted set of cards and grouping them by suit using various frameworks, including JDK, Apache Commons, Eclipse Collections, Google Guava, and Javaslang. Benchmark results show that Eclipse Collections has the best performance for the Cartesian product operation to generate all combinations of cards, followed by Google Guava and Javaslang.
2. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
About the Speakers
Donald Raab
• Husband and Father
• Managing Director at BNY Mellon in New Jersey
• Creator of Eclipse Collections
• Member of JSR 335 Expert Group (Lambdas 4 Java)
• Presenter at JavaOne, EclipseCon, JVM Language Summit, GIDS
3. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
About the Speakers
Leonardo Lima
• Computer engineer, server & embedded sw developer
• From São Paulo, Brasil, currently in Austin, TX
• CTO at V2COM
• Spec Lead – JSR363 – Units of Measurement
• Representative at JCP Executive Committee
[about.me/leomrlima]
4. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
Nikhil J. Nanivadekar
• Mechanical Engineer
• Software developer
• Vice President Technology at Goldman Sachs
• From Pune, India, currently in Salt Lake City, Utah
About the Speakers
6. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
java.util Collections
Java Collection Framework has been around since 1998/JDK 1.2. Very
basic but critical collection support for Java.
Interfaces: Maps and Collections (List, Set, Queue, Deque)
Implementations: Basic and Concurrent versions of the interfaces,
sorted and concurrent as well
Algorithms: Sorting, Shuffling, Routine Data Manipulation, Searching,
Composition
Best way to get started is using the simple and concurrent tutorials
13. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
Problem Statement – Deck of Cards
1. Create Deck of Cards
• Store Cards in an “Immutable” SortedSet (Cartesian product of Suit x Rank)
• Group the cards by Suit in an “Immutable” SortedSet “Multimap” (Group By)
2. Get the number of cards
• Count By Suit returning “Multiset” or “Bag”
• Count By Rank returning “Multiset” or “Bag”
3. Deal five hands of five cards each
• Return the cards as an “Immutable” List of five Sets of five cards
14. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
Performance Benchmarks
• JMH - Java Microbenchmark Harness
• http://openjdk.java.net/projects/code-tools/jmh/
• Measure Reported – Operations per second
• Bigger numbers are better
• 4 Core Intel I7, 50 Warm-up iterations, 30 measurement iterations,
two forks
15. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
Problem Statement – Deck of Cards
1. Create Deck of Cards
• Store Cards in an “Immutable” SortedSet (Cartesian product of Suit x Rank)
• Group the cards by Suit in an “Immutable” SortedSet “Multimap” (Group By)
2. Get the number of cards
• Count By Suit returning “Multiset” or “Bag”
• Count By Rank returning “Multiset” or “Bag”
3. Deal five hands of five cards each
• Return the cards as an “Immutable” List of five Sets of five cards
17. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
public class JDK8DeckOfCards {
private SortedSet<Card> cards;
private Map<Suit, SortedSet<Card>> cardsBySuit;
A Deck of Cards – Only the Types
public class ApacheCommonsDeckOfCards {
private SortedSet<Card> cards;
private MultiValuedMap<Suit, Card> cardsBySuit;
public class EclipseCollectionsDeckOfCards {
private ImmutableSortedSet<Card> cards;
private ImmutableSortedSetMultimap<Suit, Card> cardsBySuit;
public class GoogleGuavaDeckOfCards {
private ImmutableSortedSet<Card> cards;
private ImmutableSetMultimap<Suit, Card> cardsBySuit;
public class JavaSlangDeckOfCards {
private SortedSet<Card> cards;
private Map<Suit, ? extends SortedSet<Card>> cardsBySuit;
18. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
public class JDK8DeckOfCards {
private SortedSet<Card> cards;
private Map<Suit, SortedSet<Card>> cardsBySuit;
A Deck of Cards – Only the Types
public class ApacheCommonsDeckOfCards {
private SortedSet<Card> cards;
private MultiValuedMap<Suit, Card> cardsBySuit;
public class EclipseCollectionsDeckOfCards {
private ImmutableSortedSet<Card> cards;
private ImmutableSortedSetMultimap<Suit, Card> cardsBySuit;
public class GoogleGuavaDeckOfCards {
private ImmutableSortedSet<Card> cards;
private ImmutableSetMultimap<Suit, Card> cardsBySuit;
public class JavaSlangDeckOfCards {
private SortedSet<Card> cards;
private Map<Suit, ? extends SortedSet<Card>> cardsBySuit;
19. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
public class JDK8DeckOfCards {
private SortedSet<Card> cards;
private Map<Suit, SortedSet<Card>> cardsBySuit;
A Deck of Cards – Only the Types
public class ApacheCommonsDeckOfCards {
private SortedSet<Card> cards;
private MultiValuedMap<Suit, Card> cardsBySuit;
public class EclipseCollectionsDeckOfCards {
private ImmutableSortedSet<Card> cards;
private ImmutableSortedSetMultimap<Suit, Card> cardsBySuit;
public class GoogleGuavaDeckOfCards {
private ImmutableSortedSet<Card> cards;
private ImmutableSetMultimap<Suit, Card> cardsBySuit;
public class JavaSlangDeckOfCards {
private SortedSet<Card> cards;
private Map<Suit, ? extends SortedSet<Card>> cardsBySuit;
20. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
public class JDK8DeckOfCards {
private SortedSet<Card> cards;
private Map<Suit, SortedSet<Card>> cardsBySuit;
A Deck of Cards – Only the Types
public class ApacheCommonsDeckOfCards {
private SortedSet<Card> cards;
private MultiValuedMap<Suit, Card> cardsBySuit;
public class EclipseCollectionsDeckOfCards {
private ImmutableSortedSet<Card> cards;
private ImmutableSortedSetMultimap<Suit, Card> cardsBySuit;
public class GoogleGuavaDeckOfCards {
private ImmutableSortedSet<Card> cards;
private ImmutableSetMultimap<Suit, Card> cardsBySuit;
public class JavaSlangDeckOfCards {
private SortedSet<Card> cards;
private Map<Suit, ? extends SortedSet<Card>> cardsBySuit;
21. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
public class JDK8DeckOfCards {
private SortedSet<Card> cards;
private Map<Suit, SortedSet<Card>> cardsBySuit;
A Deck of Cards – Only the Types
public class ApacheCommonsDeckOfCards {
private SortedSet<Card> cards;
private MultiValuedMap<Suit, Card> cardsBySuit;
public class EclipseCollectionsDeckOfCards {
private ImmutableSortedSet<Card> cards;
private ImmutableSortedSetMultimap<Suit, Card> cardsBySuit;
public class GoogleGuavaDeckOfCards {
private ImmutableSortedSet<Card> cards;
private ImmutableSetMultimap<Suit, Card> cardsBySuit;
public class JavaSlangDeckOfCards {
private SortedSet<Card> cards;
private Map<Suit, ? extends SortedSet<Card>> cardsBySuit;
22. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
public class JDK8DeckOfCards {
private SortedSet<Card> cards;
private Map<Suit, SortedSet<Card>> cardsBySuit;
A Deck of Cards – Only the Types
public class ApacheCommonsDeckOfCards {
private SortedSet<Card> cards;
private MultiValuedMap<Suit, Card> cardsBySuit;
public class EclipseCollectionsDeckOfCards {
private ImmutableSortedSet<Card> cards;
private ImmutableSortedSetMultimap<Suit, Card> cardsBySuit;
public class GoogleGuavaDeckOfCards {
private ImmutableSortedSet<Card> cards;
private ImmutableSetMultimap<Suit, Card> cardsBySuit;
public class JavaSlangDeckOfCards {
private SortedSet<Card> cards;
private Map<Suit, ? extends SortedSet<Card>> cardsBySuit;
23. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
Problem Statement – Deck of Cards
1. Create Deck of Cards
• Store Cards in an “Immutable” SortedSet (Cartesian product of Suit x Rank)
• Group the cards by Suit in an “Immutable” SortedSet “Multimap” (Group By)
2. Get the number of cards
• Count By Suit returning “Multiset” or “Bag”
• Count By Rank returning “Multiset” or “Bag”
3. Deal five hands of five cards each
• Return the cards as an “Immutable” List of five Sets of five cards
36. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
Problem Statement – Deck of Cards
1. Create Deck of Cards
• Store Cards in an “Immutable” SortedSet (Cartesian product of Suit x Rank)
• Group the cards by Suit in an “Immutable” SortedSet “Multimap” (Group By)
2. Get the number of cards
• Count By Suit returning “Multiset” or “Bag”
• Count By Rank returning “Multiset” or “Bag”
3. Deal five hands of five cards each
• Return the cards as an “Immutable” List of five Sets of five cards
49. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
Problem Statement – Deck of Cards
1. Create Deck of Cards
• Store Cards in an “Immutable” SortedSet (Cartesian product of Suit x Rank)
• Group the cards by Suit in an “Immutable” SortedSet “Multimap” (Group By)
2. Get the number of cards
• Count By Suit returning “Multiset” or “Bag”
• Count By Rank returning “Multiset” or “Bag”
3. Deal five hands of five cards each
• Return the cards as an “Immutable” List of five Sets of five cards
57. #CollectionsDevoxxUS @TheDonRaab @leomrlima @NikhilNanivade
Problem Statement – Deck of Cards
1. Create Deck of Cards
• Store Cards in an “Immutable” SortedSet (Cartesian product of Suit x Rank)
• Group the cards by Suit in an “Immutable” SortedSet “Multimap” (Group By)
2. Get the number of cards
• Count By Suit returning “Multiset” or “Bag”
• Count By Rank returning “Multiset” or “Bag”
3. Deal five hands of five cards each
• Return the cards as an “Immutable” List of five Sets of five cards
We'd like to have a session for both beginner and seasoned developers that would help them choose which collections framework is better for their projects. While they can look very much alike, there are key differences regarding performance, style of programming and memory impact that are not explicit until you already committed to using one framework over the other. Our goal is to present common use cases for collections, the frameworks available and how we use them. There should be little slides for use case descriptions and comparison, and actual tests will run from our IDEs.
We'd like to have a session for both beginner and seasoned developers that would help them choose which collections framework is better for their projects. While they can look very much alike, there are key differences regarding performance, style of programming and memory impact that are not explicit until you already committed to using one framework over the other. Our goal is to present common use cases for collections, the frameworks available and how we use them. There should be little slides for use case descriptions and comparison, and actual tests will run from our IDEs.