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
Sorting a section of an array
In this post I will explain how to sort a section of an array. The java Arrays class provides a static method named “sort” which takes the below three arguments 1) the array 2) fromIndex 3) toIndex This method sorts a section of the array. The section to be sorted is indicated by fromIndex (position…… Continue reading Sorting a section of an array
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
Parsing xml document with SAX API
In this post I will explain how to parse an xml document in java using the SAX API. SAX api is event based java api. The SAX compliant parser which reads the xml document sequentially, generates events whenever the parser encounters an xml element. The parser reads the document sequentially and doesn’t load the entire…… Continue reading Parsing xml document with SAX API
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
JCache EntryProcessor Example
This post introduces you to JCache EntryProcessor interface. This interface is used to create concrete classes, whose purpose is to modify a cache entry. This is useful when multiple thread are accessing the cache and trying to modify a cache entry at the same time. To avoid threading issues like race condition etc, the thread…… Continue reading JCache EntryProcessor Example
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
Creating array dynamically
In this post I will explain how to create array dynamically with an example. This is useful when we don’t know the type of array until runtime. Main code 1 package reflection; 2 3 import java.lang.reflect.Array; 4 5 public class ArraysDemo { 6 public static void main(String[] args) { 7 //Creating single dimension array 8…… Continue reading Creating array dynamically