autoGrowCollections example

In this post under Spring SpEL, I will show with example the purpose of “autoGrowCollections” configuration. When evaluating a SpEL expression, containing collections, if we try to access an entry which doesn’t exist in collection. We get an exception. Lets say we have the below pojo class Employee package spel.package22; public class Employee { private…… Continue reading autoGrowCollections example

MappingConstants.ANY_UNMAPPED example

In this post under MapStruct, I will explain with example the purpose of MappingConstants.ANY_UNMAPPED enum. This enum is used when mapping two enums with different constant names. It indicates MapStruct that any unmapped enum constant (i.e., source enum constant without any explicit mapping) must be mapped to a particular target enum constant. The specific target…… Continue reading MappingConstants.ANY_UNMAPPED example

File copy example

In this post under Apache Commons IO, I will explain with example how to copy a file. Apache provides “IOUtils” static class which has static method “copy”. We can use this “copy” method to copy files. Below is the complete main code for your reference. Main class package ioutils; import org.apache.commons.io.IOUtils; import java.io.File; import java.io.FileReader;…… Continue reading File copy example

Checking whether contents of two files are equal or not

In this post under Apache Commons IO, I will show with example the easiest way to compare whether contents of two files are equal or not. Apache Commons “IOUtils” class provide a static method called “contentEquals” which compare contents of two file and return a boolen. Below is the complete main code Main class package…… Continue reading Checking whether contents of two files are equal or not

autoGrowNullReferences example

In this post under Spring SpEL, I will show with example the purpose of “autoGrowNullReferences” configuration. When evaluating a SpEL expression, containing chain of property references, if one of the property in the chain is null we get an exception. To prevent that we use the “autoGrowNullReferences” configuration. It’s data type is boolean. By default…… Continue reading autoGrowNullReferences example

Reading file and ignoring its contents

In this post under Apache Commons IO, I will show with example how to read a file and ignore the contents that we have read. In Apache Commons IO framework, we have static utility class “IOUtils”, which has a method “consume” which reads a file and ignore the contents that it has read. Below is…… Continue reading Reading file and ignoring its contents

Mapping two enums with different constant name

In this post under MapStruct I will show with example how to map two enums having different constant name. For our example lets say you have to map below enum Day package package12; public enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY; } to below enum Week package package12; public enum Week {…… Continue reading Mapping two enums with different constant name

Making Java objects available during sqel expression evaluation

In this post under Spring SpEL, I will explain with example how to make java objects available to SpElExpression during its evaluation. For our example we will use the below pojo class Employee package spel.package20; public class Employee { private int id; private String name; private int salary; public Employee(int id, String name, int salary)…… Continue reading Making Java objects available during sqel expression evaluation

Mapping two enums with same constant name

In this post under MapStruct, I will show with example how to map between two enums both having same constant name. For our example, I will use the below two enums ProcessStatus package package11; public enum ProcessStatus { RUNNING, PAUSE, CANCELLED, SHUTDOWN; } DisplayStatus package package11; public enum DisplayStatus { RUNNING, PAUSE, CANCELLED, SHUTDOWN; }…… Continue reading Mapping two enums with same constant name

Populating the entire array with different elements

In this post under Java Collections, I will show with example an api provided in “Arrays” class that will populate an array with different element. We are talking about “Arrays” class static method “setAll”. It takes two arguments1) the array to be populated2) a function that will generate the elements that are to be inserted…… Continue reading Populating the entire array with different elements