# Google Guava官方教程(中文版)
[原文鏈接](http://code.google.com/p/guava-libraries/wiki/GuavaExplained)? [譯文鏈接](http://ifeve.com/?p=8776)?**譯者:** 沈義揚,**羅立樹,何一昕,****武祖?**?**校對**:方騰飛
**引言**
Guava工程包含了若干被Google的 Java項目廣泛依賴 的核心庫,例如:集合 [collections] 、緩存 [caching] 、原生類型支持 [primitives support] 、并發庫 [concurrency libraries] 、通用注解 [common annotations] 、字符串處理 [string processing] 、I/O 等等。 所有這些工具每天都在被Google的工程師應用在產品服務中。
查閱Javadoc并不一定是學習這些庫最有效的方式。在此,我們希望通過此文檔為Guava中最流行和最強大的功能,提供更具可讀性和解釋性的說明。
_**譯文格式說明**_
* Guava中的類被首次引用時,都會鏈接到Guava的API文檔。如:[Optional<T>](http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/base/Optional.html)。
* Guava和JDK中的方法被引用時,一般都會鏈接到Guava或JDK的API文檔,一些人所共知的JDK方法除外。如:`[Optional.of(T)](http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/base/Optional.html#of%28T%29)`, Map.get(key)。
* 譯者對文檔的額外說明以斜體顯示,并且以“_譯者注__:_”開始。
**目錄**
## 1\. 基本工具 [Basic utilities]
讓使用Java語言變得更舒適
1.1 [使用和避免null](http://ifeve.com/using-and-avoiding-null/):null是模棱兩可的,會引起令人困惑的錯誤,有些時候它讓人很不舒服。很多Guava工具類用快速失敗拒絕null值,而不是盲目地接受
1.2 [前置條件](http://ifeve.com/google-guava-preconditions/ "[Google Guava] 1.2-前置條件"): 讓方法中的條件檢查更簡單
1.3 [常見Object方法](http://ifeve.com/google-guava-commonobjectutilities/ "[Google Guava] 常見對象方法:簡化Object方法實現,如hashCode()和toString()"): 簡化Object方法實現,如hashCode()和toString()
1.4 [排序: Guava強大的”流暢風格比較器”](http://ifeve.com/google-guava-ordering/ "[Google Guava] 排序: Guava強大的”流暢風格比較器”")
1.5 [Throwables](http://ifeve.com/google-guava-throwables/ "[Google Guava] Throwables:簡化異常和錯誤的傳播與檢查"):簡化了異常和錯誤的傳播與檢查
## 2\. 集合[Collections]
Guava對JDK集合的擴展,這是Guava最成熟和為人所知的部分
2.1 [不可變集合](http://ifeve.com/google-guava-immutablecollections/ "[Google Guava] 不可變集合: 防御性編程、常量集合和性能提升"): 用不變的集合進行防御性編程和性能提升。
2.2 [新集合類型](http://ifeve.com/google-guava-newcollectiontypes/): multisets, multimaps, tables, bidirectional maps等
2.3 [強大的集合工具類](http://ifeve.com/google-guava-collectionutilities/ "[Google Guava] 2.3-強大的集合工具類:java.util.Collections中未包含的集合工具"): 提供java.util.Collections中沒有的集合工具
2.4 [擴展工具類](http://ifeve.com/google-guava-collectionhelpersexplained/ "[Google Guava] 2.4-集合擴展工具類"):讓實現和擴展集合類變得更容易,比如創建`Collection`的裝飾器,或實現迭代器
## 3\. [緩存](http://ifeve.com/google-guava-cachesexplained)[Caches]
Guava Cache:本地緩存實現,支持多種緩存過期策略
## 4\. [函數式風格](http://ifeve.com/google-guava-functional/ "[Google Guava] 4-函數式編程")[Functional idioms]
Guava的函數式支持可以顯著簡化代碼,但請謹慎使用它
## 5\. 并發[Concurrency]
強大而簡單的抽象,讓編寫正確的并發代碼更簡單
5.1 [ListenableFuture](http://ifeve.com/google-guava-listenablefuture/ "google Guava包的ListenableFuture解析"):完成后觸發回調的Future
5.2 [Service框架](http://ifeve.com/google-guava-serviceexplained/ "Google-Guava Concurrent包里的Service框架淺析"):抽象可開啟和關閉的服務,幫助你維護服務的狀態邏輯
## 6\. [字符串處理](http://ifeve.com/google-guava-strings/ "[Google Guava] 6-字符串處理:分割,連接,填充")[Strings]
非常有用的字符串工具,包括分割、連接、填充等操作
## 7\. [原生類型](http://ifeve.com/google-guava-primitives/ "[Google Guava] 7-原生類型")[Primitives]
擴展 JDK 未提供的原生類型(如int、char)操作, 包括某些類型的無符號形式
## 8\. [區間](http://ifeve.com/google-guava-ranges/ "[Google Guava] 8-區間")[Ranges]
可比較類型的區間API,包括連續和離散類型
## 9\. [I/O](http://ifeve.com/google-guava-io/ "[Google Guava] 9-I/O")
簡化I/O尤其是I/O流和文件的操作,針對Java5和6版本
## 10\. [散列](http://ifeve.com/google-guava-hashing/ "[Google Guava] 10-散列")[Hash]
提供比`Object.hashCode()`更復雜的散列實現,并提供布魯姆過濾器的實現
## 11\. [事件總線](http://ifeve.com/google-guava-eventbus/ "[Google Guava] 11-事件總線")[EventBus]
發布-訂閱模式的組件通信,但組件不需要顯式地注冊到其他組件中
## 12\. [數學運算](http://ifeve.com/google-guava-math/ "[Google Guava] 12-數學運算")[Math]
優化的、充分測試的數學工具類
## 13\. [反射](http://ifeve.com/guava-reflection/ "google Guava包的reflection解析")[Reflection]
Guava 的 Java 反射機制工具類
- Google Guava官方教程(中文版)
- 1-基本工具
- 1.1-使用和避免null
- 1.2-前置條件
- 1.3-常見Object方法
- 1.4-排序: Guava強大的”流暢風格比較器”
- 1.5-Throwables:簡化異常和錯誤的傳播與檢查
- 2-集合
- 2.1-不可變集合
- 2.2-新集合類型
- 2.3-強大的集合工具類:java.util.Collections中未包含的集合工具
- 2.4-集合擴展工具類
- 3-緩存
- 4-函數式編程
- 5-并發
- 5.1-google Guava包的ListenableFuture解析
- 5.2-Google-Guava Concurrent包里的Service框架淺析
- 6-字符串處理:分割,連接,填充
- 7-原生類型
- 9-I/O
- 10-散列
- 11-事件總線
- 12-數學運算
- 13-反射