You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by Ted Dunning <te...@gmail.com> on 2011/07/04 05:16:42 UTC

guava dependency


At the zookeeper contributor meeting after the Hadoop Summit, the question
came up about whether we should introduce a dependency on the Guava library
from Google.

That led to a question of what Guava really is.

Not that I would like to try to replace the very nice presentations that are
around, but here is a list of some of the constructs that I use from Guava
all the time:


   - splitters and joiners (that work right)

          final static Splitter onWhiteSpace =
Splitter.on(CharMatcher.WHITESPACE);

    - type inferencing factory methods

          Map<String, String> dictionary = Maps.newHashMap();
          Map<String, Integer> table = ImmutableMap.of("abc", 1, "def", 2);

     - orderings that make sense and do cool things

          Ordering.natural().immutableSortedCopy(iterable)

     - reading a resource all in a gulp (note the predefined charset that
never requires a throw):

           Resources.readLines(Resources.getResource("foo.csv"),
Charsets.UTF-8)

It can take a bit of time to realize how useful Guava can be and it is
difficult to understand at first glance how deep the design thinking was
that created it, but after getting used to Guava, programming without it is
painful.