Skip to main content

Posts

Showing posts with the label guava

Finally a Book on Google Guava

Well, this was about time: Google Guava at PacktPub TL;DR: There's a little book about Guava out. I've had a quick look through it and it looks mighty fine. Earlier this week I got an offer to review this new book on Google Guava. For those of you who don't know Guava, I dare say it is the finest utility tool-belt library available for Java development. The author, Bill Bejeck , hasn't been involved with the development of Guava, but he has blogged some articles on the subject in the past . What I've read so far in the book speaks that he knows what he's talking about. Why do you need a book about Guava? Now, Guava is a library where you can only fully immerse yourself by reading through all of the JavaDoc, and in the first few rounds of doing so you probably won't understand half of it. What you can do instead, for starters, is to read through the GuavaExplained wiki pages , which offer a much nicer reading experience, but go into very littl...

Filtering out illegal characters using Guava

The other day, I needed to validate a text-field against a whitelist of characters. Actually, lots of text-fields needed lots of different sets of whitelists, but let's just stick to one for the sake of example. The text field "First name" is only allowed to contain any of these characters:   ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz°Žµ·žŒœŸÀÁÂÃÄÅÆ ÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ Þßàáâãäåæçèéêëìíîï     ðñòóôõöøùúûüýþÿ .. and the user should be notified with which illegal characters she has entered in the field, if any. The knee-jerk reaction to this kind of logic is regular expressions, but my knee-jerk reaction to regexp is  to avoid it. The above character set probably doesn't fit with any of the predefined regexp notations, so it would probably be nasty anyway. Some  Guava fruits for coloring up this blog post ( image source ) So, let's put Google Guava to some use. It has some nifty utilities for working with sets   and other collect...

Google Guava's Predicates

So the other day I was working away on some rather tricky rules for validating an incoming identifier code. Like 999392304II+TJAJEIAJTI901119 or EPFOOMNNVLLALOWEIITOE Now, the system where this code is going is rather picky about what these codes should look like. (For the sake of this blog-post, I'll invent some business rules here on the fly, in reality they are a bit different, but the nature of them are the same): A code cannot be null, or an empty string (of course) If there are only letters (A-Z) in the code, it must be longer than 10 characters, but fewer than 20 On the other hand, if there are letters mixed with numbers, it must be exactly 10 or 15 characters Numbers only are not allowed No other symbols are allowed, but + signs are allowed, if the code starts with 999. In this case, the max length is 10. Instead of just going straight for the if-else'ing my way through these rules, I implemented it using Predicates from Google Guava . I was pretty hap...

Google Guava r08 is released

A few days ago, Google Guava r08 was released . "This project contains several of Google's core libraries that we rely on in our Java-based projects: collections, caching, primitives support, concurrency libraries, common annotations, basic string processing, I/O, etc." I had a little look through the API changes to find some neat new details, and put together a couple of JUnit tests that show them by example here . That whole GitHub project is a Guava showcase, so if you can think of some more examples that should be in there, please fork ! Especially the IO, Net,  and Concurrency bits could need some examples. I've also taken my old blogposts about Google Guava and ported them to tfnico.com/presentations/guava . After noting this, the Guava guys honored the effort by linking the page from the Guava homepage , which gave me quite the traffic bump! Luckily, my pages are all hosted on Google servers, so it's their own bandwidth bill ;)

Made a Google Guava page

Just a quick post to announce my new Google Guava page. My Guava blog post has gotten a relatively large amount of traffic, but the list of resources have gone a bit stale. In order to make the resources a bit more "time-agnostic", I've cleaned it up a little, and made it into it's own page: http://www.tfnico.com/presentations/google-guava

Some Google Guava Resources

Update: I've moved the list of Google Guava resources to  http://www.tfnico.com/presentations/google-guava . This page won't be updated any more, but I'll leave it the way it was. I recently blogged about the Guava Libraries taking over for Google Collections . I figured I'd add a few more pointers to documentation, as the Guava wiki seem to be a bit empty (feel free to copy in these links). Update: More resources (I think if there are any more updates, I'll move this into an editable page on tfnico.com). A four part quite extensive tutorial from Sezin Karli: http://scaramoche.blogspot.com/search/label/guava Google Guava, the easy parts. A basic tutorial that recently surfaced on DZone: http://www.copperykeenclaws.com/googles-guava-java-the-easy-parts/ Old entries: A collection of short snippets (great mini reference for Google Collections): http://blog.publicobject.com/2007/09/series-recap-coding-in-small-with.html Codemunchies' 4 part series o...

Google Guava taking over for Google Collections

Update: There's a full list of Google Guava resources on  http://www.tfnico.com/presentations/google-guava . I recently spent some time gathering documentation for our internal use of Google Collections . No more than a few days after quickly presenting Collections at work last week, Kevin Bourrillion announced Guava Release 05 , urging all users of google-collect to replace it with Guava  ASAP, and spread the news (so here we go). If you don't know Guava or Google Collections, they're basically a nice set of Java util classes that you always wanted. I figured I'd have a look through the library's docs, and as I went along, I coded a few easy examples (mostly from the base package). The code is available as a Maven project on github , and I also made a presentation (PDF) with roughly the same examples, seen here: Google guava presentation on slideshare Feel free to extend the examples by forking them on GitHub!