Skip to main content

Posts

Groovy : Difference between findAll() and collect() methods

findAll() This method will find all the items in the groovy collection that matches the IDENTITY closure. collect() This method iterates through a collection and transforms each entry element to a new element using IDENTITY closure as a transformer. It returns a new collection of elements copied from the original collection. Difference between finalAll() and collect() methods findAll() collect() findAll() will return the collection or subset of collection that satisfy the Identity closure or a condition collect() will return a new collection or sub set of collection. findAll() will not modify the entry elements of the collection collect() will modify the elements by Identity closure. findAll() will return the elements that matches the condition or Identity closure. collect() will return all the elements of the collection based on the transformation specified by the closure. def list = [ 1 , 2 , 3 , 4 , 5 ]; println list.findAll{it== 3 } // [3] println list.findAll{it> ...

SpringBoot : How to create a Filter in Spring Boot Application

Points To Remember Implement the class Filter . Add @Configuration  annotation to the class to register it as a filter bean. Call method  filterChain.doFilter(resquest,response)  to continue the request flow Call method sendError to send error, ((HttpServletResponse)response).sendError(HttpServletResponse.SC_BAD_REQUEST); Call method sendRedirect to redirect request to error handler ((HttpServletResponse)response).sendRedirect("/errorUrl"); How to create a Filter in Spring Boot Application IN order to make a filter, we have create a class SecurityFilter view plain copy to clipboard print ? package  com.ekiras.filter;      import  org.springframework.core.Ordered;   import  org.springframework.core.annotation.Order;   import  org.springframework.stereotype.Component;      import  javax.servlet.*;   import  javax.servlet.http.HttpServletResponse;   import  ja...

SpringBoot : What is Spring Boot

Spring Boot : Introduction Spring Boot can be referred as Spring on Steroids.  Spring boot is a wrapper written over spring modules to allow users to create fast paced spring applications without doing the redundent configurations needed to setup the application. Features provided by Spring Boot CLI applications  - enables to create a single class application. Embedded Tomcat and Jetty Auto configurations for most of the libraries like mysql, mongo, amqp etc No Xml required for setup or configurations. Ability to package the application as both war and jar. Dependency Management using starter projects and BOM's. For example, When you create a spring application that needs Mysql database. We had to  declare the mysql connector dependency in build file. add the component scan to search the classes for mappings. map each entity/domain in xml files. Read data base configurations and create DataSource bean. add resource handlers to serve static content like css, js, images e...

Ionic : How to get list of all plugins installed

How to get list of all plugins installed for Ionic App You can get a list of all plugins that you have installed on for your ionic app by the following command cordova plugin list Make sure you are in your app directory. Output of the above command will result as follows. cordova-plugin-admob 2.2.0 "AdMob" cordova-plugin-admobpro 2.18.0 "AdMob Plugin Pro" cordova-plugin-device 1.1.2 "Device" cordova-plugin-extension 1.5.1 "Cordova Plugin Extension" cordova-plugin-google-analytics 0.8.1 "Google Universal Analytics Plugin" cordova-plugin-splashscreen 3.2.2 "Splashscreen" cordova-plugin-statusbar 2.1.3 "StatusBar" cordova-plugin-whitelist 1.2.3-dev "Whitelist" cordova-plugin-x-socialsharing 5.1.2 "SocialSharing" cordova-plugin-x-toast 2.5.2 "Toast" cordova-sqlite-storage 1.4.2 "Cordova sqlite storage plugin" ionic-plugin-keyboard 2.2.0 "Keyboard" Also you can view the ...

Arrays : Finding the Element in array where next element is +1, +0 or -1

Problem Statement You are given an array where each element follows the rule that given any index, the number at that index will either be  +1 of the number at that index. +0 of the number at that index. -1 of the number at that index. Suppose the array is  Sample Input arr       = {1,2,3,2,3,4,5,6,7,6,5,4,5,6,4,4,4,4}; search = 5 Sample Output 6  (First occurrence of search ) Sample Input arr       = {1,2,1,2,1,2,1,2,1,2}; search = 5 Sample Output 1  ( Element is not found in the array) Algorithm Star iterating from start of the array. Check if the value at the index is same as the search value if yes, then return the index if no, then increment the index counter by modulus of difference of value to search and value at index return -1 if value to search does not exist in the array. Java Program view plain copy to clipboard print ? package  com.ekiras.arrays;      public   class  SearchEl...

Spring : Difference between @Autowired, @Inject and @Resource

Points To Remember @Inject is not a spring feature you need to include  javax inject dependency  in order to use @Inject. @Autowired is Spring annotation used to inject dependency just like @Inject. It use @Qualifier annotation to differentiate between the beans. @Resource is also Spring annotation, but it uses bean name to inject dependencies and differentiate between beans. Problem Statement :: Structure In order to show how @Autowired @Inject and @Resource annotations work  we will create 3 services Interface PersonService , this is the interface for all person related operations. Class EngineerService , this is the service that will do operations for engineer. Class ManagerService , this is the service that will do operations for manager. Here, both EngineerService and ManagerService implements PersonService.  Now we will try to add the services to a controller by different  ways to test how @Autowire , @Inject and @Resource will work. So the ...

SpringBoot : What are Profiles in Spring Boot Application

What are Profiles in Spring Boot Profiles can be seen as different environments in spring boot application. Suppose you are working on an application where you have different staging environments like Dev, QA, UAT, Production etc. So you will have different configurations for each environment, for this kind of applications what you need is having different values that can be switched depending upon some flags. In early days, people used to write configurations for all environments and comment the unused environments. But with Spring Boot we can do this without commenting any code by use of Profiles . Suppose we have database name configurations for our application as follows Dev     - ekiras_dev QA    - ekiras_qa UAT  - ekiras_uat Prod  - ekiras Now, we can use profiling in this case. How we will do it ? lets see Creating Profiles in Spring Boot  We will create different files for different environments and call then as profile in rest of the blog...