发布于 2015-09-18 17:54:26 | 349 次阅读 | 评论: 0 | 来源: 网友投递
Guava Java类库
Google Guava Collections 是一个对 Java Collections Framework 增强和扩展的一个开源项目。由于它高质量 API 的实现和对 JDK5 特性的充分利用,使得其在 Java 社区受到很高评价。笔者主要介绍它的基本用法和功能特性。
Guava 19.0 RC2 发布,此版本值得关注的 API 改进如下:
Added CharMatcher
static factory methods equivalent to the CharMatcher
constants. For example, added CharMatcher.whitespace()
which is equivalent to CharMatcher.WHITESPACE
. Eventually, the constants will be deprecated and removed.
This is being done because using constants requires a large number of classes to be initialized when anything from CharMatcher
is used; switching to static factory methods allows classes to be initialized only as needed for the type of CharMatcher
actually being used.
Added Throwables.lazyStackTrace(Throwable)
- Returns a List<StackTraceElement>
that may load the stack trace elements lazily. Useful if you want to get only the first N elements of the stack trace efficiently.
Added lazyStackTraceIsLazy()
- Returns whether or not the above method is able to use the special implementation that makes it lazy on the current platform.
Added VerifyException
constructor overloads taking a Throwable
cause.
This package has graduated from @Beta
, making it safe to use in library code.
Added visibility of CacheLoader.UnsupportedLoadingOperationException
Added RemovalNotification.create
These should only be needed if creating a custom cache implementation
Added factory and builder methods for various ImmutableMap
s and ImmutableMultimap
s that take Iterable<Map.Entry>
.
Added FluentIterable.toMultiset()
Added RangeSet.asDescendingSetOfRanges()
and RangeMap.asDescendingMapOfRanges()
Added Lists.cartesianProduct(List...)
and Lists.cartesianProduct(List<List>>)
Added Maps.newLinkedHashMapWithExpectedSize(int)
Re-added Multisets.removeOccurrences(Multiset, Multiset)
which was (binary incompatibly) missing in 18.0 because it was replaced with Multisets.removeOccurences(Multiset, Iterable)
Deprecated MapConstraint
and MapConstraints
Deprecated Sets.newSetFromMap(Map)
- Java 6 provides Collections.newSetFromMap(Map)
Removed MapMaker.softValues()
Added EventBus.identifier()
Removed protected method AsyncEventBus.dispatchQueuedEvents()
(made package-private)
Added BloomFilter.create
overloads taking a long
for the expectedInsertions
Added Hashing.sha384()
Added Hashing.concatenating(HashFunction, HashFunction, HashFunction...)
and Hashing.concatenating(Iterable<HashFunction>)
Added ByteSource.sizeIfKnown()
Added CharSource.length()
Added CharSource.lengthIfKnown()
Added a couple new constants to HttpHeaders
and MediaType
Updated public suffix list for InternetDomainName
Added TypeToken.isSubtypeOf(TypeToken)
, TypeToken.isSupertypeOf(TypeToken)
and overloads of both that take a Type
Deprecated TypeToken.isAssignableFrom(TypeToken)
and TypeToken.isAssignableFrom(Type)
- isSupertypeOf
provides equivalent behavior with a less confusing name
Futures.getChecked
, the replacement for Futures.get
(see below), has become stricter. It now rejects calls that pass an unsuitable exception type, even if the input Future
succeeded. Previously, it would reject only calls in which the input Future
had failed.
Added AbstractFuture.newCancellationCause()
Added AbstractFuture.setFuture(ListenableFuture)
Added Futures.getChecked
Added Futures.catching
and Futures.catchingAsync
Added Futures.transformAsync
Added Futures.withTimeout
Deprecated FutureFallback
and Futures.withFallback
methods - these are replaced with Futures.catching
Deprecated Futures.get
methods taking a Class<X extends Exception>
- these are replaced with Futures.getChecked
Deprecated Futures.transform
methods taking an AsyncFunction
- these are replaced with Futures.transformAsync
更多改进请看发行说明。
下载链接:https://github.com/google/guava/archive/v19.0-rc2.zip。
Guava | Guava (GWT) | |
---|---|---|
Maven Identifier | com.google.guava:guava:19.0-rc2 | com.google.guava:guava-gwt:19.0-rc2 |
Jar | guava-19.0-rc2.jar | guava-gwt-19.0-rc2.jar |
Javadoc | guava-19.0-rc2-javadoc.jar | guava-gwt-19.0-rc2-javadoc.jar |
Sources | guava-19.0-rc2-sources.jar | guava-gwt-19.0-rc2-sources.jar |
Google Guava Collections 是一个对 Java Collections Framework 增强和扩展的一个开源项目。由于它高质量 API 的实现和对 JDK5 特性的充分利用,使得其在 Java 社区受到很高评价。笔者主要介绍它的基本用法和功能特性。
目前主要包含:
com.google.common.annotations
com.google.common.base
com.google.common.collect
com.google.common.io
com.google.common.net
com.google.common.primitives
com.google.common.util.concurrent