Google Collections

An overview of google collections and how to levergae it for fun and profit. »
James Carr

Google Collections
What!?
Open Source Compliment to JDK Collections API
Now part of Google Guava
http://code.google.com/p/google-collections/
http://code.google.com/p/guava-libraries/
or
Thank You!
This presentation was 
brought to you in part by:
Gradle
Questions?
PeekingIterator
ForwardingCollection
Specific Implementations
A few minor details



Some Things I Didn't Cover...
Benefits from 500 Feet

easy immutibility
literal collection creation
new collection types
Utilities
caching on the cheap
Creating a Immutable Map Old School
ImmutableMap
ImmutableMapBuilder
Immutable Everything :)
ImmutableList.of(T...)
ImmutableSet.of(T...)
ImmutableSortedSet
ImmutableMap
ImmutableBiMap
Joiner
MultiSet
BiMap
Simplifies joining
elements from a collection
Why Not Just Use Collections.unmodifiableX?
unModifiableX is a VIEW of a collection that can change elsewhere




ImmutableX contains private collection that will NEVER CHANGE 
Creating a Copy
ImmutableSet.copyOf(Iterable)
creates an immutable copy that will never change 
(even if the backing Iterable changes)
If collection is already an immutable copy it just returns it
Sometimes you want to 
"just create a collection of elements"
List<Integer> numbers = Arrays.asList(1,2,3,4,5)
Cleaner Creation
"unordered equality, can have duplicates."
When to use?
Want a list where we don't care about order
Histograms


MultiMap
Unique keys + unique values
Assign Multiple Values to a Single Key
Functions
Predicates
Ordering
All Collections Can Be 
Created via static
factory methods
All Google Collections specific
Collections can ONLY be created 
via static factory methods
"Comparators made easy"
Functional Programming
Transformations
Iterable Utilities
filter(Iterable<T>, Class<T>)
filter(Iterable<T>, Predicate<T>)
cycle(Iterable<T>)
elementsEqual(Iterable<T>, Iterable<T>)
size
and many more... check the API!
With MapMaker
A nice caveat: if you try to get an entry that doesn't exist it will just return an empty collection, they're not going to trick you and make you check for null
before you look try to look a key up! :)
All of these examples are available at 

http://github.com/jamescarr/google-collections-presentation
Google Collections
Rock!
Joshua Bloch
HECK YEAH!!!
Random Dude
Why?
Why Not Use Apache Commons Collections?
It's no longer maintained,  1.4 support only.
But there's a project on source forge with generics support!
Hasn't been updated in 4 years, not maintained. 
PLUS...
Google Collections adhers to existing JDK conventions
Very well rounded and designed
And more reasons as we will see! :)
http://gradle.org/
@jamescarr
Object Computing, Inc

Loading comments...

Please log in to add your comment.

Report abuse

More presentations by James Carr

More prezis by author