{"id":13932806,"url":"https://github.com/guobinhit/guava-guide","last_synced_at":"2025-02-28T18:39:01.837Z","repository":{"id":110172691,"uuid":"103467553","full_name":"guobinhit/guava-guide","owner":"guobinhit","description":"🌴A chinese guide of Guava.","archived":false,"fork":false,"pushed_at":"2020-04-08T11:21:37.000Z","size":22,"stargazers_count":108,"open_issues_count":0,"forks_count":28,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-01-11T10:49:05.141Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guobinhit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-09-14T00:56:59.000Z","updated_at":"2024-11-30T13:36:57.000Z","dependencies_parsed_at":"2023-04-22T16:46:19.970Z","dependency_job_id":null,"html_url":"https://github.com/guobinhit/guava-guide","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guobinhit%2Fguava-guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guobinhit%2Fguava-guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guobinhit%2Fguava-guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guobinhit%2Fguava-guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guobinhit","download_url":"https://codeload.github.com/guobinhit/guava-guide/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241202186,"owners_count":19926564,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-07T21:01:14.087Z","updated_at":"2025-02-28T18:39:01.814Z","avatar_url":"https://github.com/guobinhit.png","language":null,"funding_links":[],"categories":["Others"],"sub_categories":[],"readme":"# Guava 中文指南\n\n![author](https://img.shields.io/badge/author-chariesgavin-blueviolet.svg)![last commit](https://img.shields.io/github/last-commit/guobinhit/guava-guide.svg)![issues](https://img.shields.io/github/issues/guobinhit/guava-guide.svg)![stars](https://img.shields.io/github/stars/guobinhit/guava-guide.svg)![forks](https://img.shields.io/github/forks/guobinhit/guava-guide.svg)![license](https://img.shields.io/github/license/guobinhit/guava-guide.svg)\n\n 　　Guava 项目包含若干被 Google 的 Java 项目依赖的核心类库，例如：集合、缓存、原生类型支持、并发库、通用注解、字符串处理、I/O 等等。Google 的开发者们每天都在使用这些工具进行项目的开发。但是查阅 Javadoc 并不总是最有效的学习这些类库的方式。在这里，我们尝试为 Guava 中一些最受欢迎和最有用的功能提供更具可读性的说明。\n\n - **基础工具[Basic utilities]**：让我们更愉快的使用 Java 语言。\n\t - 使用和避免 null[[Using and avoiding null](https://github.com/guobinhit/guava-guide/blob/master/articles/basic-utilities/using-and-avoiding-null.md)]：`null`的定义很模糊，可能导致令人疑惑的错误，有时会让我们很不爽。很多的 Guava 工具类对`null`都是快速失败的，拒绝使用`null`，，而不是盲目的接收它们。\n\t - 前置条件[[Preconditons](https://github.com/guobinhit/guava-guide/blob/master/articles/basic-utilities/preconditions.md)]：让你的方法更容易进行前置条件的检查。\n\t - 通用 object 方法[[Common object methods](https://github.com/guobinhit/guava-guide/blob/master/articles/basic-utilities/common-object-methods.md)]：简化`Object`方法的实现，例如`hashCode()`和`toString()`.\n\t - 排序[[Ordering](https://github.com/google/guava/wiki/OrderingExplained)]：Guava 有强大且流畅的`Comparator`类。\n\t - 可抛的[[Throwable](https://github.com/guobinhit/guava-guide/blob/master/articles/basic-utilities/throwable.md)]：简化了异常和错误的检查及传播机制。\n - **集合[Collections]**：Guava 扩展了 JDK 的集合体系，这是 Guava 最成熟且最受欢迎的部分。\n   - 不可变集合[[Immutable Collections](https://github.com/google/guava/wiki/ImmutableCollectionsExplained)]：为了进行防御性编程、使用常量集合和提高效率。\n   - 新集合类型[[New Collection Types]](https://github.com/google/guava/wiki/NewCollectionTypesExplained)]：提供了多集合、多 Map、多表、双向 Map 等。\n   - 强大的集合工具类[[Powerful Collection Utilities]](https://github.com/google/guava/wiki/CollectionUtilitiesExplained)]：普通的操作并没有在`java.util.Collections`中提供。\n   - 扩展工具类[[Extension Utilities]](https://github.com/google/guava/wiki/CollectionHelpersExplained)]：装饰`Collection`？实现`Iterator`？我们让类似的操作变的更简单。\n\n - **图[[Graphs](https://github.com/google/guava/wiki/GraphsExplained)]**：这是一个图结构数据的模型类库，它展现了实体以及图和实体之间的关系，主要的特点包括：\n   - 图[[Graph](https://github.com/google/guava/wiki/GraphsExplained#graph)]：图的边缘是没有自己标识和信息的匿名实体。\n   - 值图[[ValueGraph](https://github.com/google/guava/wiki/GraphsExplained#valuegraph)]：图的边缘关联着非唯一的值。\n   - 网络[[Network](https://github.com/google/guava/wiki/GraphsExplained#network)]：图的边缘是唯一的对象。\n   - 支持可变的、不可变的、定向的和无向的图以及其他一些属性。\n\n - **缓存[[Caches](https://github.com/google/guava/wiki/CachesExplained)]**：支持本地缓存，也支持多种缓存过期行为。\n\n - **函数风格[[Functional idioms](https://github.com/google/guava/wiki/FunctionalExplained)]**：Guava 的函数风格能够显著的简化代码，但请谨慎使用。\n\n - **并发[Concurrency]**：强大而简单的抽象，让编写正确的并发代码更简单。 \n   - [ListenableFuture](https://github.com/google/guava/wiki/ListenableFutureExplained)： Future，结束时触发回调 。\n   - [Service](https://github.com/google/guava/wiki/ServiceExplained)：开启和关闭服务，帮助我们处理困难的状态逻辑。\n\n - **字符串[[Strings](https://github.com/google/guava/wiki/StringsExplained)]**：非常有用的字符串处理工具，包括分割、拼接等等。\n\n - **原生类型[[Primitives](https://github.com/google/guava/wiki/PrimitivesExplained)]**：扩展了 JDK 没有提供的原生类型（像`int`和`char`）操作，包含了某些类型的无符号变量。\n\n - **区间[[Ranges](https://github.com/google/guava/wiki/RangesExplained)]**：Guava 强大的 API 提供了基于`Comparable`类型区间比较功能，包连续类型和离散类型。\n\n - **输入输出流[[I/O](https://github.com/google/guava/wiki/IOExplained)]**：针对 Java 5 和 Java 6 版本，简化了 I/O 操作，尤其是 I/O 流和文件操作。\n\n - **散列[[Hashing](https://github.com/google/guava/wiki/HashingExplained)]**：提供了比`Object.hashCode()`更负责的哈希实现，包含了 Bloom 过滤器。\n\n - **事件总线[[EventBus](https://github.com/google/guava/wiki/EventBusExplained)]**：在不需要组件之间显示注册的情况下，提供了组件之间的发布-订阅模式的通信。\n\n - **数学运算[[Math](https://github.com/google/guava/wiki/MathExplained)]**：优化了 JDK 已经提供的数学工具类，并彻底的测试了 JDK 没有提供的数学工具类。\n\n - **反射[[Reflection](https://github.com/google/guava/wiki/ReflectionExplained)]**：对应 Java 反射能力的 Guava 工具类。\n\n\n\n\n## Guava 的使用方法：\n\n如果我们使用 Maven 进行项目管理，那么我们只需要在`POM.xml`中添加如下依赖：\n\n```\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.google.guava\u003c/groupId\u003e\n  \u003cartifactId\u003eguava\u003c/artifactId\u003e\n  \u003cversion\u003e28.2-jre\u003c/version\u003e\n  \u003c!-- or, for Android: --\u003e\n  \u003cversion\u003e28.2-android\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n而如果我们使用 Gradle 进行项目管理，那么我们则需要在`config.gradle`中添加如下依赖：\n\n```\ndependencies {\n  // Pick one:\n\n  // 1. Use Guava in your implementation only:\n  implementation(\"com.google.guava:guava:28.2-jre\")\n\n  // 2. Use Guava types in your public API:\n  api(\"com.google.guava:guava:28.2-jre\")\n\n  // 3. Android - Use Guava in your implementation only:\n  implementation(\"com.google.guava:guava:28.2-android\")\n\n  // 4. Android - Use Guava types in your public API:\n  api(\"com.google.guava:guava:28.2-android\")\n}\n```\n\n---------\n\nEnglish Original Editon: [Guava - User Guide](https://github.com/google/guava/wiki)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguobinhit%2Fguava-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguobinhit%2Fguava-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguobinhit%2Fguava-guide/lists"}