Templates by BIGtheme NET

Guava

Guava’s String Helpers – Joiner, Splitter, CharMatcher and Charsets

This article help to understand and best use of Guava’s string helper classes, Joiner, Splitter, CharMatcher and Charsets. Joiner and Splitter helper classes configuration methods will always return a new instance. This makes these classes as thread safe and can be usable as a static final constant. Joiner : Joining together a sequence of strings with a separator. To deal ...

Read More »

Google Guava Collections – Table

Continue to my tour with Guava Collections, Table is one of the use full Guava collection, First question is First. When should we use Table Collection? Suppose in some project, we are trying to index on more than one key at a time. Let me explain this, Suppose relation between Bank – Customer is many to many(M-M). 1) Bank can ...

Read More »

Google Guava Collections – BiMap

Continue to my tour with Guava Collections, one collection that Enforcing uniqueness in Map values is BiMap( Bidirectional Map). Basic questions here, Is Bimap holds duplicate keys? – answer is No Is Bimap holds duplicate values? – answer is No Nice, key is unique and value is also unique. obviously is is 1-1 Mapping. More over, this help to handle ...

Read More »

Google Guava Collections – MultiMap

Most of the time we are crazy about Map in java collections, In many projects extensively use lists & maps. Continue to my tour with Guava collections, MultiMap is one we should know. So let us starts with, What is MultiMap? A collection to map single key to either single or multiple values. Multimap addresses = ArrayListMultimap.create(); let me give ...

Read More »

Google Guava Collections – MultiSets

Continuing this tour with Guava, MultiSets is a new collection class provided. So we start with What is a MultiSet? As it holds multiple instances of same type, then how union, intersection operations will work? Elements are Ordered or not? Allows duplicates or not? – Very straightforward answers is Yes What is a MultiSet? This is often called a bag. ...

Read More »

Guave Collections

Some important collections in Guava, 1) Immutable collections 2) New collection types (Multiset, Multimap, BiMap, Table, ClassToInstanceMap and RangeSet) 3) Utility Classes (Iterables, Lists, Sets, Maps, Multisets, Multimaps and Tables) 4) Extension Utilities (Forwarding Decorators, PeekingIterator and AbstractIterator) 1) Immutable collections : Immutable objects have many advantages, 1) Safe for use by untrusted libraries. 2) Thread-safe: can be used by ...

Read More »

Cleaner Code with Guava’s Preconditions

Description : There are more simpler and cleaner ways to avoid asserts and handling null checks. Guava’s Preconditions are used for checking method arguments, states, etc. When a condition is false the Precondition will throw the expected exception. The class Preconditions may throw IllegalArgumentException, NullPointerException, IllegalStateException and IndexOutOfBoundsException. Here are some examples that I took that can be shortened to ...

Read More »

An Overview of Guava

What’s Guava : 1) Extensive suite of common libraries that is used in many Java projects. 2) These utilities relate to: collections, concurrency, primitives, reflection, comparison, I/O, hashing, networking, strings, math, in-memory caching, in-memory publish/subscribe… and various basic data types. 3) JDK required is Java 6+. Before jumping to Guava, we will have brief about Functional Interfaces. These Functional Interfaces ...

Read More »

Predicate and Function most useful guavas’ single abstract method Classes

This article explains, how these Predicate and Function classes can be used. Predicate can be used to provide conditions while transforming collection of objects to another collection. We can use Iterables.any() to find object is exist in collection or not?. To extend this example, we can provide condition with help of Predicate class. boolean isHdfcBankIsExist = Iterables.any(banks, new Predicate() { ...

Read More »