Guava database introduction, guava Database

Source: Internet
Author: User
Tags google guava

Guava database introduction, guava Database
1. What is Guava?

1) The Guava library is a common tool library suitable for many Java projects.
2) The Guava tool library contains: collection, concurrent Concurrency, Primitive, Reflection, Comparison of Comparison, I/O operations, Hash, network Networking, String, Math mathematical function, cache Caching, In-memory release/ subscribe ...... And various data types
3) JDK 6 or a later version is required.

Ii. Function Interfaces

Before going deep into the Guava library, we should first understand its function interfaces and understand these function interfaces to help us better understand the Guava library.

Function interface:

1) function interfaces are interfaces that define a single method.
2) The function interface contains a well-known Single Abstract Method (SAM, Single Abstract Method)
3) function interfaces provide the basis for Java 8 Lambda expressions
Function interfaces are cool: You can specify any interface as a method parameter, or pass a Lambda expression in Java 8.
4) function interfaces can be used as Callback objects.

Iii. Examples of function Interfaces

The following example shows the function interfaces of Java 8.

1. Function interfaces contain a single method parameter

@FunctionalInterface{    public boolean check(Order o);}

Then we can create a Lambda expression and use the above function interface.

IOrder newOrder = (Order o) -> o.getStatus().equals("NEW");

Or

IOrder newOrder = (o) ->o.getStatus().equals("NEW");
Note:

1) the right side of the expression is the content of a simple check method-checking the status passed to the Order object.
2) When a large number of Lambda expressions can express the demand behavior or function, the power of Lambda expressions can be reflected.

2. Let's take another example. Next to the above example, find a large order.

// Find the IOrder bigOrderLambda = (Order o)-> o. getQuantity ()> 10000000;
// Lambda expression to find the new large order ITrade issuerbignewtradelam.pdf = (o)-> {return o. getIssuer (). equals ("Honda") & o. getQuantity ()> 10000000 & o. getStatus (). equals ("NEW ");}
Iv. Summary

The Google Guava Library provides several useful SAM in "com. google. common. base", including:
1) Function
Specifies a method to receive "T" type instances and return "R" type instances.
2) Predicate
Specifies a method that passes the "T" type instance and returns a Boolean value.
3) Supplier
Specifies a method that can return values.

You also need to know that although these SAM were born in the Guava library, they are also added to Java 8.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.