Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Google Collections now part of Guava -- and then some!

17 views
Skip to first unread message

Kevin Bourrillion

unread,
Jan 5, 2010, 12:03:31 AM1/5/10
to Google Collections Library - users list, Google Collections Library - developer list
I've incorporated all of Google Collections into Guava (http://guava-libraries.googlecode.com) and marked these APIs "stable" (as opposed to the rest of the APIs of Guava which are marked "tentative").  I've also integrated further improvements to these APIs ... and added a bunch of new stuff!

Don't be too tempted by the new stuff, as it is marked "tentative" and is still subject to change.  You may prefer to still stick with the "stable" APIs (currently, just those that used to be part of google collections).

Confused yet?  Please ask any questions.

Here's what's new:

------------------------------------------

com.google.common.base:

* Objects.toStringHelper() - an easy way to implement toString().

    @Override public String toString() {
      return Objects.toStringHelper(this)
          .add("someField", someField)
          .add("someOtherField", someOtherField)
          .toString();
    }

* CharMatcher.BREAKING_WHITESPACE - matches whitespace that isn't
  "non-breaking" whitespace; useful for, well, breaking lines

* Suppliers.memoizeWithExpiration() - like memoize, but expires after a given
  amount of time.
 
------------------------------------------

com.google.common.collect:

* ComparisonChain - the best way to implement a lazy chained comparison
  statement ever!

    public int compareTo(Foo that) {
      return ComparisonChain.start()
          .compare(this.aString, that.aString)
          .compare(this.anInt, that.anInt)
          .compare(this.anEnum, that.anEnum, Ordering.nullsLast())
          .result();
    }

  See javadoc for more explanation.

* ImmutableCollection.asList() - every ImmutableCollection can be viewed as a
  List now, cheaply! In fact, it's a *magical* List, because its contains()
  method is as fast as the contains() method of the immutable collection that
  spawned it - etc.

* Itera*s.consumingItera*(Itera*) - an iterator/iterable which automatically
  removes elements as they are returned.

* Itera*s.indexOf(Itera*, Predicate) - returns the index of the first element
  satisfying a predicate.

* Itera*s.removeIf(Itera*, Predicate) - removes each element that satisfies a
  predicate.

* Multisets.intersection() - a multiplicity-aware intersection view of two
  multisets; for example [a x 2, b x 3] intersected with [b x 2, c x 4] is
  [b x 2]. The count of every element is the smaller of its count in each of
  the given multisets.
 
* Ordering.arbitrary() - an Ordering (Comparator) for those cases where you
  have no logical way to order the items at all -- see javadoc for details.
 
* Ordering.lexicographical() - an Ordering (Comparator) for iterables, which
  compares elements pairwise until the first nonzero result is found
  ("dictionary order").

* Sets.cartesianProduct() - returns the cartesian product of the given sets, in
  a very memory-friendly way.

------------------------------------------

com.google.common.io:

* Files.map() - conveniences to create MappedByteBuffers.

------------------------------------------

com.google.common.primitives:

* Ints.lexicographicalComparator() et al - like Ordering.lexicographical() for primitive arrays.

------------------------------------------

com.google.common.util.concurrent:

* New Futures.compose() overload that accepts an Executor.



--
Kevin Bourrillion @ Google
internal:  http://go/javalibraries
external: guava-libraries.googlecode.com


Kevin Bourrillion

unread,
Jan 5, 2010, 12:10:51 AM1/5/10
to Google Collections Library - users list, Google Collections Library - developer list
To clarify: if you want to stick to only the stable APIs that are part of the Google Collections Library, you can simply keep using the 1.0 release of that library that we put out last week, and all will be well.  If you ever want to upgrade, that's when you'll start using Guava instead.  Got it?

Thanks for putting up with the craziness :-)

Gary Pampara

unread,
Jan 5, 2010, 12:11:53 AM1/5/10
to Kevin Bourrillion, Google Collections Library - users list, Google Collections Library - developer list
Awesome! This is fantastic news. Thanks Kevin and the team :)

> --
> Google Collections Library - users list
> http://groups.google.com/group/google-collections-dev?hl=en
>
> To unsubscribe, send email to:
> google-collections...@googlegroups.com

fishtoprecords

unread,
Jan 5, 2010, 3:08:52 AM1/5/10
to Google Collections Library - users list
> On Tue, Jan 5, 2010 at 7:03 AM, Kevin Bourrillion <kev...@google.com> wrote:
> > I've incorporated all of Google Collections into Guava
> > (http://guava-libraries.googlecode.com)


Is there, or will there be a parallel Guava-users group in google
groups?

Robert Konigsberg

unread,
Jan 5, 2010, 6:13:19 AM1/5/10
to fishtoprecords, Google Collections Library - users list
I'm pretty sure if there is, you'll be in the know, even if you hadn't
asked. These guys are pretty clever.

> --
> Google Collections Library - users list
> http://groups.google.com/group/google-collections-dev?hl=en
>
> To unsubscribe, send email to:
> google-collections...@googlegroups.com

--
Robert Konigsberg
konig...@gmail.com

Tim Harsch

unread,
Jan 5, 2010, 12:45:03 PM1/5/10
to Kevin Bourrillion, Google Collections Library - users list, Google Collections Library - developer list
Hi Kevin,
What value do the helper methods in Objects class and ComparisonChain offer over their commons-lang counterparts?

On Mon, Jan 4, 2010 at 9:03 PM, Kevin Bourrillion <kev...@google.com> wrote:

Kevin Bourrillion

unread,
Jan 5, 2010, 1:05:51 PM1/5/10
to Tim Harsch, Google Collections Library - users list, Google Collections Library - developer list
I prefer to let neutral parties (i.e., our users) offer their own perspectives comparing and contrasting our library with others.  

One suggestion though: take a close look at how many object instantiations are performed when using those.  Especially for compareTo(), these instantiations can really add up when you're sorting a large list!  (And don't forget to include any boxing of primitives that has to happen.)
Reply all
Reply to author
Forward
0 new messages