ted@tedneward.com | Blog: http://blogs.tedneward.com | Twitter: tedneward | Github: tedneward | LinkedIn: tedneward
Let's take a look at Guava
most commonly used parts
rationale for its existence
additional resources for its use
https://github.com/google/guava
Guava is a set of Google's extensions to Java
not extensions in the language sense, but the library sense
provides a number of interesting libraries
caching
collections
concurrent utilities
and more
as such, there's a fair amount of ground to cover
com.google.common.base
com.google.common.cache
com.google.common.collect
com.google.common.eventbus
com.google.common.io
com.google.common.net
com.google.common.primitives
com.google.common.util.concurrent
... is a matter of getting the JAR file in your build
either directly
http://search.maven.org/remotecontent?filepath=com/google/guava/guava/19.0/guava-19.0.jar
or through a build tool
or build it yourself
Guava via Maven
<dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>19.0</version> </dependency>
Guava via Gradle
dependencies { compile 'com.google.guava:guava:19.0' }
Guava via source
git clone https://github.com/google/guava
Extension methods
Objects: common Object operations
equal, hashCode, firstNonNull
toStringHelper – fluent interface for implementing toString()
Equivalences: equals-vs-identity distinction factory
Defaults: provide default values for JLS types
Splitter/Joiner: extension methods to split/join collections
Preconditions: series of assertion-like check methods
useful for ensuring preconditions/postconditions/etc
Throwables: extension methods making Throwable easier
String support
Strings: another extension class for Strings
CaseFormat: enum (with methods) to convert between different upper/lower case formats
LOWER_CAMEL, LOWER_HYPHEN, etc
Ascii: methods pertaining to the ASCII character set
Charsets: six common Charset objects
CharMatcher: Fluent interface for matching/parsing character strings
this is a wonderful (yet not 100%) replacement for regex
Object factory support
Supplier: interface describing the production of T
Suppliers: useful methods around Suppliers
most of these are to compose Suppliers in interesting ways
Functional (lite) programming support
Function
Function is a wrapper around T apply(F in);
Predicate is a wrapper around bool apply(T in);
Functions: series of extension methods around Function
NOT a full functional library
very incomplete (see FJ for full functional support)
Predicates: ditto for Predicate
more extensive than Functions, but still incomplete
NOTE: these may go away when Java8 ships
Services
code performing operations on behalf of clients
RPC, web servers, chat servers, etc
Service: interface defining basic Service operations
start(), stop(), startAndWait(), stopAndWait(), state()
Two base classes commonly used for default behavior
AbstractExecutionThreadService: uses a single thread
AbstractService: manage threading manually (harder)
(both are in com.google.common.concurrent.util)
Reference type support
FinalizableReferenceQueue
FinalizableSoftReference
FinalizableWeakReference
FinalizablePhantomReference
these only matter if you use Soft/Weak/Phantom already
Guava's a good base of functionality to consider
it's just a jar file, so most of its features are "opt-in"
most developers will see best results from starting with .base
and .collect
packages and working from there
it's a huge pile of functionality, well-tested
Google promises continued enhancements and fixes
Who is this guy?
Architect, Engineering Manager/Leader, "force multiplier"
Co-founder, Solidify US
http://www.solidify.dev
Principal -- Neward & Associates
Author
Professional F# 2.0 (w/Erickson, et al; Wrox, 2010)
Effective Enterprise Java (Addison-Wesley, 2004)
SSCLI Essentials (w/Stutz, et al; OReilly, 2003)
Server-Based Java Programming (Manning, 2000)
See http://www.newardassociates.com