[Guava] Guava: Google Core Libraries for Java easy-to-use tools

Guava Preface

Guava is Google's set of core Java libraries that includes 新的集合类型 (如multimap和multiset), 不可变集合, 图库, and 并发、I/O、哈希、缓存、基元、字符串utilities for and more! It is widely used in most Java projects within Google and is widely used by many people.

Guava是一种基于开源的Java库, Google Guava originated from the "Google Collections Library" in 2007. This library is to facilitate coding and reduce coding errors. This library is used to provide utility methods for collections, caching, support for primitives, concurrency, common annotations, string handling, I/O, and validation.

com.google.common.annotations:普通注解类型。
com.google.common.base:基本工具类库和接口。
com.google.common.cache:缓存工具包,非常简单易用且功能强大的JVM内缓存。
com.google.common.collect:带泛型的集合接口扩展和实现,以及工具类,这里你会发现很多好玩的集合。
com.google.common.eventbus:发布订阅风格的事件总线。
com.google.common.hash: 哈希工具包。
com.google.common.io:I/O工具包。
com.google.common.math:原始算术类型和超大数的运算工具包。
com.google.common.net:网络工具包。
com.google.common.primitives:八种原始类型和无符号类型的静态工具包。
com.google.common.reflect:反射工具包。
com.google.common.util.concurrent:多线程工具包。

Advantages of Guava

Standardization - Guava library is hosted by Google.
Efficient - Reliable, fast and efficient extension of the JAVA standard library.
Optimization - The Guava library is highly optimized.
Functional Programming: Adds Java functionality and processing power
Utilities: Provides many utility classes that often need to be developed in applications
Validation: Provides standard fail-safe validation mechanisms.
Best Practices: Emphasizes best practices.

它是一个提高代码质量、简化工作,促使代码更有弹性、更加简洁的工具

Guava official website

https://gitcode.net/mirrors/google/guava

<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <version>32.0.1-jre</version>
  <!-- or, for Android: -->
  <version>32.0.1-android</version>
</dependency>

Guava class library use

https://github.com/google/guava/wiki

Basic Utilities: Make working with the Java language more enjoyable.

1. Use and avoid null: null has language ambiguity, which will cause puzzling errors, and it is always annoying anyway. Many of Guava's utility classes simply reject or error out when nulls are encountered, rather than silently accepting them.
2. Preconditions: It is easier to test the preconditions of your method.
3. Common object methods: Simplify the implementation of Object common methods, such as hashCode() and toString().
4. Sorting: Guava's powerful "fluent Comparator" comparator provides multi-keyword sorting.
5. Throwable class: Simplifies exception checking and error propagation.

Collection classes: The collection class library is Guava's extension to the JDK collection classes.

1. Immutable collections: Defensive programming, unmodifiable collections, and improved efficiency.
2. New collection types (new collection types): some collection types that JDK collections do not have, mainly: multisets, multimaps, tables, bidirectional maps, etc. 3.
Powerful collection utilities (powerful collection tools): java.util.Collections Commonly used operation tool classes not included in
4. Extension utilities (extended tool class): Add a decorator to the Collection object? Implement an iterator? We can use these methods more easily.

Guava cache: local cache, which can easily manipulate cache objects and supports various cache invalidation behavior modes.

Functional idioms (functional): Concise, Guava implements Java's functional programming, which can significantly simplify the code.

Concurrency: Powerful, simple abstraction that makes it easier for us to implement simple and correct concurrency code.

1. ListenableFuture (listenable Future): Futures, callbacks for asynchronous completion.
2. Service: Control the startup and shutdown of events, and manage complex state logic for you.

Strings: A very, very useful string tool class: providing splitting, joining, padding and other operations.

Primitives: Extend operations on native types (such as int, char, etc.) that are not provided in the JDK, including some types of unsigned variables.

Ranges: Guava is a powerful API that provides range processing of Comparable types, including continuous and discrete cases.

I/O: Simplifies I/O operations, especially on I/O streams and files, for Java 5 and 6.

Hashing: Provides a more complex hash method than Object.hashCode(), and provides Bloom filters.

EventBus: Component communication based on the publish-subscribe pattern, but does not need to be explicitly registered in the delegate object.

Math: Optimized math tools, fully tested.

Reflection: Guava's Java reflection mechanism tool class.

Code combat

Guess you like

Origin blog.csdn.net/qq_39900031/article/details/131407011