Clone wiki

guava-jdk8 / Home

A library that facilitates the use of the Guava API under JDK 8

Getting Started

You can use the following Maven dependency:

<dependency>
    <groupId>org.bitbucket.cowwoc</groupId>
    <artifactId>guava-jdk8</artifactId>
    <version>2.0.0</version>
</dependency>

Or download the files directly.

The Javadoc is at http://cowwoc.bitbucket.org/guava-jdk8/javadoc/latest/

The changelog is at https://bitbucket.org/cowwoc/guava-jdk8/wiki/Changelog/

Usage

There are two ways to construct Stream collectors:

  1. Using direct constructors (e.g. GuavaCollectors.toImmutableSetMultimap()).
  2. Using Collector builders (e.g. GuavaCollectors.multimapFrom()).

The first approach supports common use-cases using a compact syntax. The second approach is more verbose but supports more advanced use-cases. For example:

public final class Testcase
{
    public static void main(String[] args)
    {
        ImmutableSetMultimap<Integer, String> multimapWithoutSorting = Stream.of(10, 20, 40, 30, 15).
            collect(GuavaCollectors.toImmutableSetMultimap(i -> i / 10, i -> Integer.toString(i)));
        // Prints {1=[15, 10], 2=[20], 3=[30], 4=[40]}
        System.out.println(multimapWithoutSorting);

        ImmutableSetMultimap<Integer, String> sortedMultimap = Stream.of(10, 20, 40, 30, 15).
            collect(GuavaCollectors.multimapFrom(Integer.class).
                               map(i -> i / 10, i -> Integer.toString(i)).
                               asImmutableSetMultimap().
                               sortKeys((a, b) -> b.compareTo(a)).
                               sortValues((a, b) -> b.compareTo(a)).
                               build());
        // Prints {4=[40], 3=[30], 2=[20], 1=[15, 10]}
        System.out.println(sortedMultimap);
    }
}

Versioning scheme

Given a version number MAJOR.MINOR.PATCH, we will increment the:

  • PATCH version when we make backwards-compatible changes.
  • MINOR version when we make binary-incompatible API changes, and
  • MAJOR version when we make source-incompatible API changes

Meaning:

  • Upgrading to a newer PATCH version will not require recompiling or changing user code.
  • Upgrading to a newer MINOR version will require recompiling user code.
  • Upgrading to a newer MAJOR version will require modifying and recompiling user code.

This guarantee does not apply to @Beta classes, methods or fields.

License

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

Updated