Die News unter https://github.com/google/guava/wiki/Release21:
Significant API additions and changes
common.base
Function
,Predicate
andSupplier
: changed to extend the newjava.util.function
interfaces with the same names.Optional
: addedtoJavaUtil
andfromJavaUtil
methods for easy conversion between Guava’sOptional
andjava.util.Optional
.Objects
: removed deprecatedfirstNonNull
andtoStringHelper
methods (both found onMoreObjects
since Guava 18.0).
common.cache
New default methods on ConcurrentMap
that were added in Java 8 are now implemented and safe to use for Cache.asMap()
views.
common.collect
Many APIs in collect now have better implementations of many of the default
methods added to Collection
and Map
types in Java 8.
New classes
Comparators
: With the addition of many useful methods to theComparator
type in Java 8,Ordering
now provides little benefit.Comparators
is a new location for methods onOrdering
that still don’t have a good equivalent in the JDK.Streams
: Utility class for working withjava.util.stream.Stream
. Includes methods for creating streams (such asstream(Iterable)
,stream(Optional)
andconcat(Stream...)
) and methods that do things with streams (such asfindLast(Stream)
).MoreCollectors
: Factories forjava.util.stream.Collector
objects; note thatCollector
s for Guava’s collection types are generally found on those types themselves rather than here.Interners.InternerBuilder
: Builder forInterner
instances, with options similar to those found onMapMaker
. Created withInterners.newBuilder()
.
Removed classes
MapConstraint
andMapConstraints
: deprecated since 19.0.
Changes
FluentIterable
: addedstream()
method.ForwardingBlockingDeque
: deprecated; moved toutil.concurrent
.Immutable*
types: added methods to all namedtoImmutable[Type]()
(e.g.ImmutableList.toImmutableList()
) which return aCollector
for collecting aStream
into an immutable collection/map object. As with most methods that createCollector
s, these are generally intended to be used as static imports.Multimap
: addedforEach(BiConsumer)
method.Multimaps
: addedtoMultimap
andflatteningToMultimap
methods returningCollector
objects that collect to aMultimap
.Multiset
: addedforEachEntry(ObjIntConsumer)
method.Maps
: addedtoImmutableEnumMap
methods returningCollector
objects that collect to anImmutableMap
withenum
keys.Sets
: addedtoImmutableEnumSet
method returning aCollector
that collects to anImmutableSet
ofenum
s.Tables
: addedtoTable
methods returningCollector
objects that collect to aTable
.RangeSet
: added defaultaddAll(Iterable<Range>)
,removeAll(Iterable<Range>)
andenclosesAll(Iterable<Range>)
methods.ImmutableRangeSet
: addedcopyOf(Iterable<Range>)
,unionOf(Iterable<Range>)
,union(RangeSet)
,intersection(RangeSet)
anddifference(RangeSet)
methods.TreeRangeSet
: addedcreate(Iterable<Range>)
method.- A number of rarely-used methods on concrete implementations of Guava collection types that aren’t present on the interface they implement have been deprecated. These include:
ArrayListMultimap.trimToSize()
,TreeMultimap.keyComparator()
, andTreeBasedTable.row/columnComparator()
.
common.io
MoreFiles
: New class which contains methods similar to those inFiles
, but for use withjava.nio.file.Path
objects.- This includes
deleteRecursively
anddeleteDirectoryContents
methods which are secure against race conditions that Java previously had no way of dealing with provided that theFileSystem
supportsSecureDirectoryStream
(modern Linux versions do; Windows [NTFS at least] does not). For security, these will throw an exception ifSecureDirectoryStream
is not supported unlessRecursiveDeleteOption.ALLOW_INSECURE
is passed when calling the method.
common.primitives
- Most classes: added
constrainToRange([type] value, [type] min, [type] max)
methods which constrain the given value to the closed range defined by themin
andmax
values. They return the value itself if it’s within the range, themin
if it’s below the range and themax
if it’s above the range.
common.util.concurrent
ForwardingBlockingDeque
: added; moved fromcommon.collect
becauseBlockingDeque
is a concurrent type rather than a standard collection (it’s defined injava.util.concurrent
).AtomicLongMap
: added a number of methods such asaccumulateAndGet(K, LongBinaryOperator)
that take advantage of new Java functional types.Monitor
: addednewGuard(BooleanSupplier)
.MoreExecutors
: removedsameThreadExecutor()
; deprecated since 18.0 in favor ofdirectExecutor()
(preferable) ornewDirectExecutorService()
.