Posts

Chain of Command

public interface Command<T>{     boolean execute(T context); } public class FirstCommand implements Command<Map<String, Object>>{     public boolean execute(Map<String, Object> context){         //doing something in here     } } public class SecondCommand implements Command<Map<String, Object>>{     public boolean execute(Map<String, Object> context){         //doing something in here     } } public class Chain {     public List<Command> commands;     public Chain(Command... commands){         this.commands = Arrays.asList(commands);     }     public void start(Object context){         for(Command command : commands){             boolean shouldStop = command.execute(context);             i...

Builder Pattern

public class Product {     private String id;     private Product(Builder builder) {         setId(builder.id);     }     public static Builder newProduct() {         return new Builder();     }     public String getId() {         return id;     }     public void setId(String id) {         this.id = id;     }     public static final class Builder {         private String id;         private Builder() {         }         public Builder id(String id) {             this.id = id;             return this;         }         public Product build() {             return new Produc...

Singleton in Enum

Singleton using Java 8 public enum Singleton {   INSTANCE;      private Singleton(){   }   public Test getObject(){     return new Test();   } } Usage: Singleton.INSTANCE.getObject();

Java 8 Comparing Two object Structure using Streams and lambda

Java 8 Compare Object Parent             -->  Child                               -->  School Try to compare this using Stream 8 Java and Lambda import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.stream.Collector; import java.util.stream.Collectors; public class Test1 { public static void main(String args[]) { P p1 = new P(); p1.setFn("pfn1"); List<C> cobj1 = new ArrayList<C>(); C c1 = new C(); c1.setFn("cfn1"); List<S> sobj1 = new ArrayList<S>(); c1.setObj(sobj1); S s1 = new S(); s1.setN("sn1"); sobj1.add(s1); cobj1.add(c1); p1.setObj(cobj1); P p2 = new P(); p2.setFn("pfn2"); List<C> cobj2 = new ArrayList<C>(); C c2 = new C(); c2.setFn("cfn2"); List<S> sobj2 = new ArrayList<S>(); c2.set...

CSV Parsing in Java8 Streams

Java 8 Stream File Processing import java.io.BufferedReader; import java.io.IOException; import java.io.PrintWriter; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.function.Predicate; public class Test { public static void main(String[] args) throws IOException { BufferedReader br = Files.newBufferedReader(Paths.get("C:\\Users\\anharayanan\\Desktop\\test.csv")); try (PrintWriter pw = new PrintWriter( Files.newBufferedWriter(Paths.get("C:\\Users\\anharayanan\\Desktop\\test2.csv")))) { br.lines().skip(1).parallel().map(x -> x.split("\\s+", 2)).map(x -> x[0].split("\\$")).filter(x->x.length>=6).filter(distinctByKey(x -> x[0]+x[1]+x[2])) .forEach(x -> pw.println(new String(x[0] + "," + x[1] + "," + x[2] + "," + x[3] + "," + x[4] + ...

Swagger User Interface

Image
Swagger UI allows anyone — be it your development team or your end consumers — to visualize and interact with the API’s resources without having any of the implementation logic in place. It’s automatically generated from your Swagger specification, with the visual documentation making it easy for back end implementation and client side consumption. Swagger UI https://github.com/swagger-api/swagger-ui.git XAMPP https://www.apachefriends.org/xampp-files/7.1.7/xampp-win32-7.1.7-0-VC14-installer.exe Copy the Swagger UI master zip into httdocs Click on the XAMPP Control Start the Apache from the XAMPP Control start on port 80 http://localhost/swagger-ui-master/dist/

Swagger Editor

Image
Swagger  is the world's largest framework of API developer tools for the OpenAPI Specification(OAS). It is used for Creating the REST API How to Setup Swagger Editior using XAMPP Swagger Editor  https://github.com/swagger-api/swagger-editor.git XAMPP https://www.apachefriends.org/xampp-files/7.1.7/xampp-win32-7.1.7-0-VC14-installer.exe Copy the Swagger Editor into httdocs Click on the XAMPP Control Start the Apache from the XAMPP Control start on port 80 http://localhost/swagger-editor/#/ We can see REST API Document we can edit our swagger editor.