Skip to main content

Posts

Showing posts from August, 2016

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  java.io.IOException;      /**    * @author ekansh    */    @Component    @Order (Ordered.HIGHEST_PRECEDENCE)   public   c

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 etc. After

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  SearchElement {           private   static   final   int [] arr = { 1 , 2 , 3 , 2 , 3 , 4 , 5 , 6 , 7 , 6 ,