Filtering items using ItemProcessor

In Spring Batch, items are read from the source using reader and written to destination using a writer. Sometimes, we need to add business logic between the reader and writer for the following purpose1) Filtering an item2) Converting an item read from one format to another before written to the destination3) Modify the item read…… Continue reading Filtering items using ItemProcessor

Combining two or more Consumer Functional Interface

In this post I will explain how to combine two or more Consumer Functional interface implementations. Consumer Functional interface has a default method “andThen”, which combines two Consumer Functional interface implementations. The method signature is as shown below default Consumer andThen(Consumer after) The way two Consumer implementations are combined using “andThen” method is as shown…… Continue reading Combining two or more Consumer Functional Interface

Map with Composite key

In Maps we always use one key object to uniquely identify an entry. We never combined a collection of keys to create one composite key and use it to uniquely identify an entry. But with help of MultiKey class available in Apache Common Collections framework, we can create a composite key to uniquely identify an…… Continue reading Map with Composite key

Verifying the exact number of method invocations

This post explains how to verify that a method is executed desired number of times using Mockito framework. Below is the code of the class to be tested. Class1 code package package14; import java.util.List; public class Class1 { private List list; public void method1() { for(int i = 0; i < 10 ;i++) { list.add(i);…… Continue reading Verifying the exact number of method invocations

Sorting arrays using Comparator

This post explains how to sort arrays using comparator with an example. The java jdk provides Arrays class, which has a static method named “sort”. This method takes two arguments 1) the array to be sorted 2) Comparator which contains the logic to sort the array Below is the example which sort cards based on…… Continue reading Sorting arrays using Comparator

MultiValuedMap Collection

This post will introduce you to different version of Map called “MultiValuedMap”. This map was added in Apache Commons Collection framework. This map is similar to java.util.Map and at the same different. The similarities are 1) Both map hold key value pair The differences are 2) In java.util.Map the value is a single value whereas…… Continue reading MultiValuedMap Collection