1. Predicate Basic usageGuava provides many tools to manipulate collections using functions and predicates, typically in Iterables, Lists, sets, Maps, and Multimaps.The most basic use of predicate is to filter the collection, and many of the filter methods in guava are filtered using predicate.
Collection type
Filter method
Iterable
Iterables.filter (iterable, predicate)
Fluentiterable.filter (predicate)
Next to the guava joiner and splitter, this article will introduce another useful guava object optional, which in Java Google Guava first presented us with a nullable object model. In other languages such as C # This is a pattern that has existed for a long time and is included in the. NET class Library Nullable (Int? is also a nullable type).Null sucksReturn to
Overview
Caching is one of the most frequently used techniques in daily development, and reasonable utilization of cache can greatly improve the performance of the application.
Guava official description of the cache
Caches is tremendously useful in a wide variety of use cases. For example, should consider using caches if a value is expensive to compute or retrieve, and you'll need its valu E on a certain input more than once.
A Cache is similar to
Before learning and using guava optional, let's take a look at null in Java. Because, only by having a deep understanding of null, can we gain a deeper understanding of guava's optional design and usage in elegance and simplicity.
Null indicates an uncertain object:
In Java, null is a keyword used to identify an uncertain object. Therefore, null can be assigned to a reference type variable, but null cannot be assigned to a basic type variabl
object (another guava class, described in this chapter) to split a string. You can create a splitter object and then use it given a specific delimiter. Once you have a splitter instance, you can call the Split method and return an iterator object that contains the split string.Splitter.on (' | '). Split ("Foo|bar|baz"); Splitter Splitter = Splitter.on ("\\d+");In the example above, we see a splitter instance using the ' | ' Character segmentation, an
Java people should all know the Java Common Class library of Apache Commons, which, like the Guava and Commons, encapsulates a set of common libraries that are more powerful than those provided by the JDK itself. Now that we have such a powerful library, we have no need to reinvent the wheel. How to use this thing, look at the official website of the document and API. English is not good, there is also online translation to share. Start
Background
For high-frequency access but low-frequency updated data we generally do cache, especially in the high concurrency of the business, the original means we can use HashMap or Concurrenthashmap to store.
There is nothing wrong with this, but there is a problem, for the data in the cache only when we show the call to remove method, will remove an element, even if the high-frequency data, there will be access hit rate of the points, memory is always limited, we can not infinitely increase
redis to find the longest free time, which I think I have 1 million records, it casually find three and began to delete.
Good, clean up the mood again to see the 3.0 version of the improvement: now every random five records, inserted into a length of 16 in the queue of idle time, and then delete the line of the Pai, and then find five out, continue to try to insert the queue ... Well, a little bit, at least two times at random, at least not only in a random five to find the longest in the artic
Guava CacheGuava caches are similar to concurrentmap based on segmented locks and thread safety, but they are not exactly the same. The basic difference is that CONCURRENTMAP will keep all the added elements until explicitly removed. In contrast, the guava cache is usually set to automatically reclaim elements in order to limit memory consumption. In some scenarios, although Loadingcache does not reclaim el
tostring method. Using objects. tostringhelper, you can easily write useful tostring methods. For example:
// Returns "ClassName{x=1}"Objects.toStringHelper(this).add("x", 1).toString();// Returns "MyObject{x=1}"Objects.toStringHelper("MyObject").add("x", 1).toString();
Compare/compareto
Implementing a comparator [comparator], or directly implementing the comparable interface sometimes cannot afford to hurt. Consider this situation:
class Person implements Comparable
This part of the code i
Description of listenablefuture
Concurrent Programming is a difficult problem, but a powerful and simple abstraction can significantly simplify concurrent writing. For this reason, guava defines the listenablefuture interface and inherits the future interface under the JDK concurrent package, listenablefutureAllow you to register the callback method (Callbacks), called when the operation (multi-threaded execution) is completed, or immediately after th
ExampleList scores;iterable Belowmedian =iterables.filter (Scores,range.lessthan (median)); .... Range validgrades = range.closed (1, N); for (int grade:ContiguousSet.create (validgrades, Discretedomain.integers ())) { ...}Brief introductionAn interval, sometimes referred to as a range, is a section of convexity in a particular domain (the informal term is continuous or uninterrupted). In form, convexity indicates to AThe interval can extend to infinity-for example, the range "X>3″" includes
Introduction
The Ratelimiter class is available in the Google Guava library, which is often used to limit the rate of access to some physical or logical resources. Compared to Semaphore, Semaphore limits the number of concurrent accesses rather than the usage rate.
The Ratelimiter class is defined as follows:
Com.google.common.util.concurrent.RateLimiter
@ThreadSafe
@Beta public
abstract class Ratelimiter
extends Object
"); System.out.println ("Adding an element to the list:" +list); System.out.println ("Unmodifiablelist after adding elements through list:" +unmodifiablelist); //adding elements through UnmodifiablelistUnmodifiablelist.add ("Eee"); System.out.println ("Add an element to Unmodifiablelist:" +unmodifiablelist); }}Operation Result:By running the result we can see: Although unmodifiablelist can not add elements directly, but my list can add elements, and list changes will also make unmodifiablelist c
Original: http://www. Zuidaima.com/blog/3182745969511424.htmI've only heard of this toolkit before, but the real thing is in D75 demand. I'm going to implement the list set that the foreground passes in to the database with a semicolon-separated concatenation of a stringAt the beginning I used the code logic as follows:StringBuffer interfacelist=New stringbuffer (); // determines whether the collection in the foreground binding is empty if (interfaces!=null) { for(String str:interfaces) {
Eventbus is the guava event handling mechanism, an elegant implementation of the Observer pattern (production/consumer programming model) in design patterns. For the event listener and publish subscription patterns, Eventbus is a very elegant and simple solution, and we don't have to create complex classes and interface hierarchies. Observer mode is one of the most common design patterns, although sometimes in specific code, it is not necessarily call
control the access frequency of a resource, but not precise control.
@Test
Fun semaphoretest () {
val semaphore = semaphore (2)
(1..10). Map {
thread (true) {
Semaphore.acquire ()
println ("$it \t${date ()}")
Thread.Sleep (1000)
semaphore.release ()
}
. ForEach {it.join ()}
}
The above example creates a semaphore, specifies a concurrency number of 2, and its output is as follows
1 Wed, 10:31:49 CST 2018
2 Wed of t
Example 3 jar package connection sqlserver2000-msbase. jar; MSSQLServer. jar; msutil. Jar
1. Ensure that the environment is OK. 1. Install JDK. 2. Download The JDBC driver.
Here msbase. jar; MSSQLServer. jar; download msutil.
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.