From 88b8eec8e283049e358115cb28c2ebf8bcb25ccc Mon Sep 17 00:00:00 2001 From: "Hani M. K" Date: Sun, 12 Aug 2018 22:08:03 +0300 Subject: [PATCH 01/13] updated Servlet & pom.xml - updated JSONServlet, used @WevServlet - updated pom.xml , newer version of javax.servlet-api, jackson and jetty plugin --- java-servlet-json/.classpath | 7 +++---- java-servlet-json/pom.xml | 21 +++++++++++-------- .../main/java/com/hmkcode/JSONServlet.java | 3 +++ .../src/main/webapp/WEB-INF/web.xml | 20 ------------------ 4 files changed, 18 insertions(+), 33 deletions(-) delete mode 100644 java-servlet-json/src/main/webapp/WEB-INF/web.xml diff --git a/java-servlet-json/.classpath b/java-servlet-json/.classpath index fd0d555d..3579da99 100644 --- a/java-servlet-json/.classpath +++ b/java-servlet-json/.classpath @@ -1,11 +1,10 @@ - - - - + + + \ No newline at end of file diff --git a/java-servlet-json/pom.xml b/java-servlet-json/pom.xml index dd7dc447..f37f61f0 100644 --- a/java-servlet-json/pom.xml +++ b/java-servlet-json/pom.xml @@ -5,7 +5,7 @@ com.hmkcode java-servlet-json 1.0-SNAPSHOT - jar + war java-servlet-json http://maven.apache.org @@ -15,36 +15,39 @@ - + javax.servlet javax.servlet-api 3.1.0 + provided + + com.fasterxml.jackson.core jackson-core - 2.2.2 + 2.9.6 com.fasterxml.jackson.core jackson-databind - 2.2.2 + 2.9.6 com.fasterxml.jackson.core jackson-annotations - 2.2.2 + 2.9.6 java-servlet-json - - org.eclipse.jetty + + org.eclipse.jetty jetty-maven-plugin - 9.0.4.v20130625 - + 9.4.11.v20180605 + diff --git a/java-servlet-json/src/main/java/com/hmkcode/JSONServlet.java b/java-servlet-json/src/main/java/com/hmkcode/JSONServlet.java index afccf9b4..3f881427 100644 --- a/java-servlet-json/src/main/java/com/hmkcode/JSONServlet.java +++ b/java-servlet-json/src/main/java/com/hmkcode/JSONServlet.java @@ -6,6 +6,7 @@ import java.util.LinkedList; import java.util.List; import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -13,6 +14,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.hmkcode.vo.Article; +@WebServlet("/jsonservlet") public class JSONServlet extends HttpServlet { private static final long serialVersionUID = 1L; @@ -32,6 +34,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) String json = ""; if(br != null){ json = br.readLine(); + System.out.println(json); } // 2. initiate jackson mapper diff --git a/java-servlet-json/src/main/webapp/WEB-INF/web.xml b/java-servlet-json/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index ac732e11..00000000 --- a/java-servlet-json/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - Java Servlet JSON - - index.html - - - - jsonservlet - com.hmkcode.JSONServlet - - - jsonservlet - /jsonservlet - - \ No newline at end of file From 2641b4a2874d5ee11e7bd67c31916e6e98e3e35b Mon Sep 17 00:00:00 2001 From: "Hani M. K" Date: Sun, 12 Aug 2018 22:11:04 +0300 Subject: [PATCH 02/13] updated 2018! updated spaces --- .../src/main/java/com/hmkcode/JSONServlet.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/java-servlet-json/src/main/java/com/hmkcode/JSONServlet.java b/java-servlet-json/src/main/java/com/hmkcode/JSONServlet.java index 3f881427..67415b87 100644 --- a/java-servlet-json/src/main/java/com/hmkcode/JSONServlet.java +++ b/java-servlet-json/src/main/java/com/hmkcode/JSONServlet.java @@ -38,18 +38,18 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) } // 2. initiate jackson mapper - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper(); - // 3. Convert received JSON to Article - Article article = mapper.readValue(json, Article.class); + // 3. Convert received JSON to Article + Article article = mapper.readValue(json, Article.class); // 4. Set response type to JSON response.setContentType("application/json"); - // 5. Add article to List
+ // 5. Add article to List
articles.add(article); // 6. Send List
as JSON to client - mapper.writeValue(response.getOutputStream(), articles); + mapper.writeValue(response.getOutputStream(), articles); } } From 3f36d4f47a85892efaad292029ea79d01bdf5806 Mon Sep 17 00:00:00 2001 From: "Hani M. K" Date: Sat, 25 Aug 2018 00:10:52 +0300 Subject: [PATCH 03/13] java lambda 08.25.18 java lambda 08.25.18 --- java-lambda/README.md | 36 ++++++++++++++++ java-lambda/pom.xml | 34 +++++++++++++++ .../src/main/java/com/hmkcode/App.java | 42 +++++++++++++++++++ .../src/main/java/com/hmkcode/Button.java | 31 ++++++++++++++ .../java/com/hmkcode/OnClickListener.java | 7 ++++ 5 files changed, 150 insertions(+) create mode 100644 java-lambda/README.md create mode 100644 java-lambda/pom.xml create mode 100644 java-lambda/src/main/java/com/hmkcode/App.java create mode 100644 java-lambda/src/main/java/com/hmkcode/Button.java create mode 100644 java-lambda/src/main/java/com/hmkcode/OnClickListener.java diff --git a/java-lambda/README.md b/java-lambda/README.md new file mode 100644 index 00000000..4fd9a0e7 --- /dev/null +++ b/java-lambda/README.md @@ -0,0 +1,36 @@ +Using Lambda to Implement Funtional Interface Method +==================================================== + +- We have a *virtual* `Button` that when clicked will call an abstract method **onClick()** of a listener interface `OnClickListener`. +- We need to implement the **onClick()** so that it prints the `Button` name. + + +`OnClickListener.java` + +```java +package com.hmkcode; + +public interface OnClickListener { + void onClick(Button button); +} +``` + +`Button.java` + +```java +package com.hmkcode; + +public class Button { + + private OnClickListener onClickListener; + private String name; + + // click the button + public void click(){ + this.onClickListener.onClick(this); + } + + // getters & setters +} +``` + diff --git a/java-lambda/pom.xml b/java-lambda/pom.xml new file mode 100644 index 00000000..8240ec70 --- /dev/null +++ b/java-lambda/pom.xml @@ -0,0 +1,34 @@ + + + + 4.0.0 + + com.hmkcode + java-lambda + 1.0-SNAPSHOT + + java-lambda + + + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + com.hmkcode.App + + + + + + diff --git a/java-lambda/src/main/java/com/hmkcode/App.java b/java-lambda/src/main/java/com/hmkcode/App.java new file mode 100644 index 00000000..c1cdd001 --- /dev/null +++ b/java-lambda/src/main/java/com/hmkcode/App.java @@ -0,0 +1,42 @@ +package com.hmkcode; + + +public class App implements OnClickListener +{ + public static void main( String[] args ){ + System.out.println( "Running App..." ); + new App().run(); + } + + public void run(){ + + Button myButton = new Button(); + myButton.setName("MyButton"); + + // 1. implements onClickListener + //myButton.setOnClickListener(this); + + // 2. anonymous class + /*myButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(Button button) { + System.out.println(button.getName() +" Clicked! - anonymous class"); + } + }); */ + + // 3. lambda + OnClickListener lambda = button -> { System.out.println(button.getName()+" Clicked! - lambda"); } ; + myButton.setOnClickListener(lambda); + + + // click the button + myButton.click(); + } + + + @Override + public void onClick(Button button) { + System.out.println(button.getName() +" Clicked! - implements interface"); + + } +} diff --git a/java-lambda/src/main/java/com/hmkcode/Button.java b/java-lambda/src/main/java/com/hmkcode/Button.java new file mode 100644 index 00000000..adc65baf --- /dev/null +++ b/java-lambda/src/main/java/com/hmkcode/Button.java @@ -0,0 +1,31 @@ +package com.hmkcode; + +public class Button { + + private OnClickListener onClickListener; + private String name; + + public void click(){ + this.onClickListener.onClick(this); + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public OnClickListener getOnClickListener() { + return onClickListener; + } + + public void setOnClickListener(OnClickListener onClickListener) { + this.onClickListener = onClickListener; + } + + + +} diff --git a/java-lambda/src/main/java/com/hmkcode/OnClickListener.java b/java-lambda/src/main/java/com/hmkcode/OnClickListener.java new file mode 100644 index 00000000..662f65c7 --- /dev/null +++ b/java-lambda/src/main/java/com/hmkcode/OnClickListener.java @@ -0,0 +1,7 @@ +package com.hmkcode; + + +public interface OnClickListener { + void onClick(Button button); + +} From c15471e07602d5827f65a97523bbfcf9cb5fe615 Mon Sep 17 00:00:00 2001 From: "Hani M. K" Date: Sat, 25 Aug 2018 00:28:44 +0300 Subject: [PATCH 04/13] update README.md update README.md --- java-lambda/README.md | 117 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/java-lambda/README.md b/java-lambda/README.md index 4fd9a0e7..fe41c829 100644 --- a/java-lambda/README.md +++ b/java-lambda/README.md @@ -4,7 +4,6 @@ Using Lambda to Implement Funtional Interface Method - We have a *virtual* `Button` that when clicked will call an abstract method **onClick()** of a listener interface `OnClickListener`. - We need to implement the **onClick()** so that it prints the `Button` name. - `OnClickListener.java` ```java @@ -34,3 +33,119 @@ public class Button { } ``` +- We have three ways to achieve that: + 1. **Implement** `OnClickListener` and override **onClick()** method. + 2. Use `OnClickListener` as an anonymous class. + 3. Use Lambda. + +- Our main class is `App.java` + +```java +package com.hmkcode; + +public class App +{ + public static void main( String[] args ){ + System.out.println( "Running App..." ); + new App().run(); + } + + public void run(){ + + Button myButton = new Button(); + myButton.setName("MyButton"); + + // 1. implements onClickListener + + // 2. anonymous class + + // 3. lambda + + + // click the button + myButton.click(); + } +} +``` + +### 1. **Implement** `OnClickListener` and override **onClick()** method + +```java +public class App implements OnClickListener +{ + public static void main( String[] args ){...} + + public void run(){ + + Button myButton = new Button(); + myButton.setName("MyButton"); + + // 1. implements onClickListener + myButton.setOnClickListener(this); + + // click the button + myButton.click(); + } + + @Override + public void onClick(Button button) { + System.out.println(button.getName() +" Clicked! - implements interface"); + + } +} +``` + +### 2. Use `OnClickListener` as an anonymous class + +```java +public class App +{ + public static void main( String[] args ){...} + + public void run(){ + + Button myButton = new Button(); + myButton.setName("MyButton"); + + // 2. anonymous class + myButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(Button button) { + System.out.println(button.getName() +" Clicked! - anonymous class"); + } + }); + + // click the button + myButton.click(); + } +} +``` + +### 3. Use Lambda + +```java +public class App +{ + public static void main( String[] args ){...} + + public void run(){ + + Button myButton = new Button(); + myButton.setName("MyButton"); + + // 3. lambda + OnClickListener lambda = button -> { System.out.println(button.getName()+" Clicked! - lambda"); } ; + myButton.setOnClickListener(lambda); + + // click the button + myButton.click(); + } +} +``` + +*To run the code use* + +``` +java-lambda>mvn exec:java +``` + From bc62846b13436d9ebf83f0ed1206f9b02a9c7833 Mon Sep 17 00:00:00 2001 From: "Hani M. K" Date: Sat, 25 Aug 2018 00:33:56 +0300 Subject: [PATCH 05/13] typo type --- java-lambda/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-lambda/README.md b/java-lambda/README.md index fe41c829..8213fe8e 100644 --- a/java-lambda/README.md +++ b/java-lambda/README.md @@ -1,4 +1,4 @@ -Using Lambda to Implement Funtional Interface Method +Using Lambda to Implement Functional Interface Method ==================================================== - We have a *virtual* `Button` that when clicked will call an abstract method **onClick()** of a listener interface `OnClickListener`. From 19f096b17dd68c0e059722610cb885d4c7cf0dd2 Mon Sep 17 00:00:00 2001 From: "Hani M. K" Date: Mon, 27 Aug 2018 21:40:04 +0300 Subject: [PATCH 06/13] java stream examples java stream examples --- .../src/main/java/com/hmkcode/App.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 java-stream/src/main/java/com/hmkcode/App.java diff --git a/java-stream/src/main/java/com/hmkcode/App.java b/java-stream/src/main/java/com/hmkcode/App.java new file mode 100644 index 00000000..b97bbd63 --- /dev/null +++ b/java-stream/src/main/java/com/hmkcode/App.java @@ -0,0 +1,87 @@ +package com.hmkcode; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class App +{ + public static void main( String[] args ) + { + String[] arr = new String[]{"a", "b", "c", "d"}; + Stream stream = Arrays.stream(arr); + + stream = Stream.of("a", "b", "c", "d"); + + List list = new LinkedList(); + list.add("a"); + list.add("b"); + stream = list.stream(); + + // forEach() + stream = Stream.of("a", "b", "c", "d"); + stream.forEach(e -> System.out.println(e)); + + // distinct() | count() + stream = Stream.of("a", "b", "c", "d"); + System.out.println(stream.distinct().count()); + + // anyMatch() + stream = Stream.of("a", "b", "c", "d"); + System.out.println(stream.anyMatch(e -> e.contains("a"))); + + // filter() + stream = Stream.of("a", "b", "c", "d"); + stream.filter(e -> e.contains("b")).forEach(e -> System.out.println(e)); + + // map() + stream = Stream.of("a", "b", "c", "d"); + stream.map(e -> e.toUpperCase()).forEach(e -> System.out.println(e)); + + // flatMap() + stream = getBigList().stream().flatMap(lst -> lst.stream()); + stream.forEach(e -> System.out.println(e)); + + //[any|all|none]Match() + System.out.println(Stream.of("a", "b", "c", "d").allMatch( e -> (e.length() == 1))); + System.out.println(Stream.of("a", "b", "c", "d").noneMatch(e -> (e.length() == 2))); + System.out.println(Stream.of("a", "b", "c", "d").anyMatch( e -> e.equals("a") )); + + //reduce() + stream = Stream.of("a", "b", "c", "d"); + System.out.println(stream.reduce("", (x,y) -> apply(x,y))); + + //collect(Collectors) + stream = Stream.of("a", "b", "c", "d"); + System.out.println(stream.collect(Collectors.toList())); + + + } + + private static String apply(String a, String b){ + System.out.println(a+"->"+b); + return a+b; + } + + private static List> getBigList(){ + + List> bigList = new LinkedList>(); + + List list1 = new LinkedList(); + list1.add("a"); + list1.add("b"); + + List list2 = new LinkedList(); + list2.add("c"); + list2.add("d"); + + bigList.add(list1); + bigList.add(list2); + + return bigList; + } + + +} From 4661432aebf0d0576d84616949cfb007a042268d Mon Sep 17 00:00:00 2001 From: "Hani M. K" Date: Wed, 29 Aug 2018 22:07:53 +0300 Subject: [PATCH 07/13] updated algorithm updated algorithm --- java-combinations/Combination.java | 57 +++++++++++++----------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/java-combinations/Combination.java b/java-combinations/Combination.java index 12accc05..ebe54224 100644 --- a/java-combinations/Combination.java +++ b/java-combinations/Combination.java @@ -1,4 +1,4 @@ -package com.hmkcode.baloot; +package com.hmkcode; @@ -6,9 +6,8 @@ public class Combination { public static void main(String[] args){ - Object[] elements = new Object[] {'A','B','C','D','E', 'F', 'G', 'H'}; - - combination(elements,7); + Object[] elements = new Object[] {'A','B','C','D','E'}; + combination(elements,3); } @@ -22,55 +21,49 @@ public static void combination(Object[] elements, int K){ System.out.println("Invalid input, K > N"); return; } + // calculate the possible combinations - // e.g. c(4,2) c(N,K); - // get the combination by index - // e.g. 01 --> AB , 23 --> CD + // init combination index array int combination[] = new int[K]; - // position of current index - // if (r = 1) r* - // index ==> 0 | 1 | 2 - // element ==> A | B | C - int r = 0; - int index = 0; + + int r = 0; // index for combination array + int i = 0; // index for elements array while(r >= 0){ - // possible indexes for 1st position "r=0" are "0,1,2" --> "A,B,C" - // possible indexes for 2nd position "r=1" are "1,2,3" --> "B,C,D" - - // for r = 0 ==> index < (4+ (0 - 2)) = 2 - if(index <= (N + (r - K))){ - combination[r] = index; + + // forward step if i < (N + (r-K)) + if(i <= (N + (r - K))){ + combination[r] = i; - // if we are at the last position print and increase the index + // if combination array is full print and increment i; if(r == K-1){ - - //do something with the combination e.g. add to list or print print(combination, elements); - index++; + i++; } else{ - // select index for next position - index = combination[r]+1; + // if combination is not full yet, select next element + i = combination[r]+1; r++; } + } + + // backward step else{ r--; - if(r > 0) - index = combination[r]+1; - else - index = combination[0]+1; + if(r >= 0) + i = combination[r]+1; + } } } - public static int c(int n, int r){ + private static int c(int n, int r){ int nf=fact(n); int rf=fact(r); int nrf=fact(n-r); @@ -82,7 +75,7 @@ public static int c(int n, int r){ return ncr; } - public static int fact(int n) + private static int fact(int n) { if(n == 0) return 1; @@ -91,7 +84,7 @@ public static int fact(int n) } - public static void print(int[] combination, Object[] elements){ + private static void print(int[] combination, Object[] elements){ String output = ""; for(int z = 0 ; z < combination.length;z++){ From 7b30dc2209bff6a6448933603181e03668ef6f72 Mon Sep 17 00:00:00 2001 From: "Hani M. K" Date: Wed, 29 Aug 2018 22:31:29 +0300 Subject: [PATCH 08/13] combinations readme combinations readme --- java-combinations/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 java-combinations/README.md diff --git a/java-combinations/README.md b/java-combinations/README.md new file mode 100644 index 00000000..31c34299 --- /dev/null +++ b/java-combinations/README.md @@ -0,0 +1,12 @@ +Non-Recursive Algorithm for Finding Combination +=============================================== + +Here is a generic non-recursive algorithm for finding all possible combination for an array of objects. + +For example, if we have an Array of elements=`{"A","B","C","D","E"}` and we want to find the combination of these elements taken 3 at a time. +Using math we can find the number of possible combination using a known [formula](https://en.wikipedia.org/wiki/Combination). + +However, to find those combinations we need an algorithm to do so. +Below image explains the steps taken by the algorithm to find the results. + +![combinations](http://hmkcode.github.io/images/java/combinations.png) From 5eced3577fd622c573b9c9d6ca3957cfe343af4e Mon Sep 17 00:00:00 2001 From: "Hani M. K" Date: Thu, 30 Aug 2018 21:32:33 +0300 Subject: [PATCH 09/13] new algorithms new algorithms --- java-combinations/README.md | 14 +-- .../java/com/hmkcode/ForwardBackward.java | 94 +++++++++++++++++++ .../src/main/java/com/hmkcode/Recursive.java | 38 ++++++++ .../src/main/java/com/hmkcode/Shifting.java | 59 ++++++++++++ 4 files changed, 196 insertions(+), 9 deletions(-) create mode 100644 java-combinations/src/main/java/com/hmkcode/ForwardBackward.java create mode 100644 java-combinations/src/main/java/com/hmkcode/Recursive.java create mode 100644 java-combinations/src/main/java/com/hmkcode/Shifting.java diff --git a/java-combinations/README.md b/java-combinations/README.md index 31c34299..402992b5 100644 --- a/java-combinations/README.md +++ b/java-combinations/README.md @@ -1,12 +1,8 @@ -Non-Recursive Algorithm for Finding Combination -=============================================== +Algorithms for Finding all Possible Combinations of k Elements in an Array with Java Implementation +=================================================================================================== -Here is a generic non-recursive algorithm for finding all possible combination for an array of objects. +Refer to the [http://hmkcode.github.io/calculate-find-all-possible-combinations-of-an-array-using-java/](http://hmkcode.github.io/calculate-find-all-possible-combinations-of-an-array-using-java/) for more info. -For example, if we have an Array of elements=`{"A","B","C","D","E"}` and we want to find the combination of these elements taken 3 at a time. -Using math we can find the number of possible combination using a known [formula](https://en.wikipedia.org/wiki/Combination). +Given an array of size N e.g. `e={'A','B','C','D','E'}` **N=5**, we want to find all possible combinations of K elements in that array. For example, if K=3 then one possible combination is of array **e** is `{'A','B','C'}. Here we have three different algorithms for finding *k*-combinations of an array. -However, to find those combinations we need an algorithm to do so. -Below image explains the steps taken by the algorithm to find the results. - -![combinations](http://hmkcode.github.io/images/java/combinations.png) +![combinations](http://hmkcode.github.io/images/java/combinations_forwardbackward.png) diff --git a/java-combinations/src/main/java/com/hmkcode/ForwardBackward.java b/java-combinations/src/main/java/com/hmkcode/ForwardBackward.java new file mode 100644 index 00000000..ac3a48be --- /dev/null +++ b/java-combinations/src/main/java/com/hmkcode/ForwardBackward.java @@ -0,0 +1,94 @@ +package com.hmkcode; + + + +public class ForwardBackward { + + + public static void main(String[] args){ + Object[] elements = new Object[] {'A','B','C','D','E'}; + combination(elements,3); + } + + + public static void combination(Object[] elements, int K){ + + // get the length of the array + // e.g. for {'A','B','C','D'} => N = 4 + int N = elements.length; + + if(K > N){ + System.out.println("Invalid input, K > N"); + return; + } + + // calculate the possible combinations + c(N,K); + + // init combination index array + int pointers[] = new int[K]; + + + int r = 0; // index for combination array + int i = 0; // index for elements array + + while(r >= 0){ + + // forward step if i < (N + (r-K)) + if(i <= (N + (r - K))){ + pointers[r] = i; + + // if combination array is full print and increment i; + if(r == K-1){ + print(pointers, elements); + i++; + } + else{ + // if combination is not full yet, select next element + i = pointers[r]+1; + r++; + } + } + + // backward step + else{ + r--; + if(r >= 0) + i = pointers[r]+1; + + } + } + } + + + + private static int c(int n, int r){ + int nf=fact(n); + int rf=fact(r); + int nrf=fact(n-r); + int npr=nf/nrf; + int ncr=npr/rf; + + System.out.println("C("+n+","+r+") = "+ ncr); + + return ncr; + } + + private static int fact(int n) + { + if(n == 0) + return 1; + else + return n * fact(n-1); + } + + + private static void print(int[] combination, Object[] elements){ + + String output = ""; + for(int z = 0 ; z < combination.length;z++){ + output += elements[combination[z]]; + } + System.out.println(output); + } +} diff --git a/java-combinations/src/main/java/com/hmkcode/Recursive.java b/java-combinations/src/main/java/com/hmkcode/Recursive.java new file mode 100644 index 00000000..7d74192a --- /dev/null +++ b/java-combinations/src/main/java/com/hmkcode/Recursive.java @@ -0,0 +1,38 @@ +package com.hmkcode; + +import java.util.Arrays; +import java.util.List; + +public class Recursive { + + public static void main(String[] args) { + + List e = Arrays.asList("A", "B", "C", "D", "E"); + combination(e, 3, ""); + + } + static int counter = 0; + public static void combination(List e, int K, String c){ + + if(e.size() < K) + return; + + if(K == 1) + for(String s:e) + print(c+s); + else if(e.size() == K){ + for(String s:e) + c+=s; + print(c); + } + else if(e.size() > K) + for(int i = 0 ; i < e.size() ; i++) + combination(e.subList(i+1, e.size()), K-1, c+e.get(i)); + + } + + public static void print(String c){ + counter++; + System.out.println(counter+"\t"+c); + } +} diff --git a/java-combinations/src/main/java/com/hmkcode/Shifting.java b/java-combinations/src/main/java/com/hmkcode/Shifting.java new file mode 100644 index 00000000..bdf86e57 --- /dev/null +++ b/java-combinations/src/main/java/com/hmkcode/Shifting.java @@ -0,0 +1,59 @@ +package com.hmkcode; + +public class Shifting +{ + public static void main( String[] args ) + { + String[] e = {"A","B","C","D","E"}; + int K = 3; + } + public static void combination(Object[] e, int K){ + + int[] ignore = new int[e.length-K]; // --> [0][0] + int[] combination = new int[K]; // --> [][][] + + for(int w = 0; w < ignore.length; w++){ // --> [3][4] + ignore[w] = e.length - K +(w+1); + //System.out.println(ignore[w]); + } + + int i = 0; + int r = 0; + int g = 0; + boolean terminate = false; + while(!terminate){ + while(i < e.length && r < K){ + + if(i != ignore[g]){ + combination[r] = i; + System.out.print(e[combination[r]]+" "); + r++; + i++; + } + else{ + g++; + + if(g == ignore.length) + g--; + + i++; + } + } + i = 0; r=0; g =0; + System.out.println(""); + + terminate = true; + + for(int w = 0 ; w < ignore.length; w++){ + if(ignore[w] > w){ + ignore[w]--; + + if(w > 0) + ignore[w-1] = ignore[w]-1; + terminate = false; + break; + } + } + } + } +} \ No newline at end of file From ad0be342995cf8d256b64a98fc677880e4491dd6 Mon Sep 17 00:00:00 2001 From: "Hani M. K" Date: Fri, 31 Aug 2018 09:40:25 +0300 Subject: [PATCH 10/13] updated updated --- .../java/com/hmkcode/ForwardBackward.java | 17 +++--- .../src/main/java/com/hmkcode/Recursive.java | 31 +++++++---- .../src/main/java/com/hmkcode/Shifting.java | 55 +++++++++++-------- 3 files changed, 59 insertions(+), 44 deletions(-) diff --git a/java-combinations/src/main/java/com/hmkcode/ForwardBackward.java b/java-combinations/src/main/java/com/hmkcode/ForwardBackward.java index ac3a48be..42f94932 100644 --- a/java-combinations/src/main/java/com/hmkcode/ForwardBackward.java +++ b/java-combinations/src/main/java/com/hmkcode/ForwardBackward.java @@ -6,27 +6,28 @@ public class ForwardBackward { public static void main(String[] args){ - Object[] elements = new Object[] {'A','B','C','D','E'}; - combination(elements,3); + Object[] e = new Object[] {'A','B','C','D','E'}; + int k = 3; + combination(e,k); } - public static void combination(Object[] elements, int K){ + public static void combination(Object[] elements, int k){ // get the length of the array // e.g. for {'A','B','C','D'} => N = 4 int N = elements.length; - if(K > N){ + if(k > N){ System.out.println("Invalid input, K > N"); return; } // calculate the possible combinations - c(N,K); + c(N,k); // init combination index array - int pointers[] = new int[K]; + int pointers[] = new int[k]; int r = 0; // index for combination array @@ -35,11 +36,11 @@ public static void combination(Object[] elements, int K){ while(r >= 0){ // forward step if i < (N + (r-K)) - if(i <= (N + (r - K))){ + if(i <= (N + (r - k))){ pointers[r] = i; // if combination array is full print and increment i; - if(r == K-1){ + if(r == k-1){ print(pointers, elements); i++; } diff --git a/java-combinations/src/main/java/com/hmkcode/Recursive.java b/java-combinations/src/main/java/com/hmkcode/Recursive.java index 7d74192a..a4acc9ac 100644 --- a/java-combinations/src/main/java/com/hmkcode/Recursive.java +++ b/java-combinations/src/main/java/com/hmkcode/Recursive.java @@ -7,27 +7,34 @@ public class Recursive { public static void main(String[] args) { - List e = Arrays.asList("A", "B", "C", "D", "E"); - combination(e, 3, ""); + List e = Arrays.asList("A", "B", "C", "D", "E"); + int k = 3; + combination(e, k, ""); } static int counter = 0; - public static void combination(List e, int K, String c){ + public static void combination(List e, int k, String accumulated){ - if(e.size() < K) + // 1. stop + if(e.size() < k) return; - - if(K == 1) + + // 2. add each element in e to accumulated + if(k == 1) for(String s:e) - print(c+s); - else if(e.size() == K){ + print(accumulated+s); + + // 3. add all elements in e to accumulated + else if(e.size() == k){ for(String s:e) - c+=s; - print(c); + accumulated+=s; + print(accumulated); } - else if(e.size() > K) + + // 4. for each element, call combination + else if(e.size() > k) for(int i = 0 ; i < e.size() ; i++) - combination(e.subList(i+1, e.size()), K-1, c+e.get(i)); + combination(e.subList(i+1, e.size()), k-1, accumulated+e.get(i)); } diff --git a/java-combinations/src/main/java/com/hmkcode/Shifting.java b/java-combinations/src/main/java/com/hmkcode/Shifting.java index bdf86e57..d81ce2b5 100644 --- a/java-combinations/src/main/java/com/hmkcode/Shifting.java +++ b/java-combinations/src/main/java/com/hmkcode/Shifting.java @@ -5,45 +5,43 @@ public class Shifting public static void main( String[] args ) { String[] e = {"A","B","C","D","E"}; - int K = 3; + int k = 3; + combination(e,k); } - public static void combination(Object[] e, int K){ + public static void combination(Object[] e, int k){ - int[] ignore = new int[e.length-K]; // --> [0][0] - int[] combination = new int[K]; // --> [][][] + int[] ignore = new int[e.length-k]; // --> [0][0] + int[] combination = new int[k]; // --> [][][] - for(int w = 0; w < ignore.length; w++){ // --> [3][4] - ignore[w] = e.length - K +(w+1); - //System.out.println(ignore[w]); - } + // set initial ignored elements + //(last k elements will be ignored) + for(int w = 0; w < ignore.length; w++) + ignore[w] = e.length - k +(w+1); + + int i = 0, r = 0, g = 0; - int i = 0; - int r = 0; - int g = 0; boolean terminate = false; - while(!terminate){ - while(i < e.length && r < K){ + while(!terminate){ + + // selecting N-k non-ignored elements + while(i < e.length && r < k){ if(i != ignore[g]){ combination[r] = i; - System.out.print(e[combination[r]]+" "); - r++; - i++; + r++; i++; } - else{ - g++; - - if(g == ignore.length) - g--; - + else{ + if(g != ignore.length-1) + g++; i++; } } - i = 0; r=0; g =0; - System.out.println(""); + print(combination, e); + i = 0; r = 0; g = 0; terminate = true; + // shifting ignored indices for(int w = 0 ; w < ignore.length; w++){ if(ignore[w] > w){ ignore[w]--; @@ -56,4 +54,13 @@ public static void combination(Object[] e, int K){ } } } + + private static void print(int[] combination, Object[] elements){ + + String output = ""; + for(int z = 0 ; z < combination.length;z++){ + output += elements[combination[z]]; + } + System.out.println(output); + } } \ No newline at end of file From 9224b6e55d7089dc632ff61262045cf8ca06399d Mon Sep 17 00:00:00 2001 From: "Hani M. K" Date: Fri, 6 Dec 2019 21:40:20 +0300 Subject: [PATCH 11/13] updated iText to version 7.1.9 updated iText to version 7.1.9 --- itext-java-html-pdf/.classpath | 15 +++++++- itext-java-html-pdf/index.html | 4 +- itext-java-html-pdf/java.png | Bin 0 -> 9053 bytes itext-java-html-pdf/pdf.pdf | Bin 1712 -> 0 bytes itext-java-html-pdf/pom.xml | 18 +++++---- .../src/main/java/com/hmkcode/App.java | 36 +++++++++--------- 6 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 itext-java-html-pdf/java.png delete mode 100644 itext-java-html-pdf/pdf.pdf diff --git a/itext-java-html-pdf/.classpath b/itext-java-html-pdf/.classpath index 33a301cc..8d216a15 100644 --- a/itext-java-html-pdf/.classpath +++ b/itext-java-html-pdf/.classpath @@ -3,6 +3,17 @@ - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/itext-java-html-pdf/index.html b/itext-java-html-pdf/index.html index db6616a9..054b0e51 100644 --- a/itext-java-html-pdf/index.html +++ b/itext-java-html-pdf/index.html @@ -7,8 +7,10 @@

HTML to PDF

- itext 5.4.2 converting HTML to PDF + itext 7.1.9 + converting HTML to PDF

+ java-logo diff --git a/itext-java-html-pdf/java.png b/itext-java-html-pdf/java.png new file mode 100644 index 0000000000000000000000000000000000000000..c1e3d02305b471cccf8c752da84d363fb9f1b478 GIT binary patch literal 9053 zcmZ{~cQ_o*^EiIzaLQ?isL{I!qW8|776cK!M2p@#cRGpQdyf*)f)MQl(K}JYk?8%U z_pkTwzt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6*v**Wd=rA>HK-b|XhCC16GIweVp6i5hQ9&RUPCMZ diff --git a/itext-java-html-pdf/pom.xml b/itext-java-html-pdf/pom.xml index d764eeb2..f7910a6b 100644 --- a/itext-java-html-pdf/pom.xml +++ b/itext-java-html-pdf/pom.xml @@ -12,18 +12,20 @@ UTF-8 + RELEASE - com.itextpdf - itextpdf - 5.4.2 - - - com.itextpdf.tool - xmlworker - 5.4.1 + com.itextpdf + itext7-core + 7.1.9 + pom + + + com.itextpdf + html2pdf + 2.1.6 diff --git a/itext-java-html-pdf/src/main/java/com/hmkcode/App.java b/itext-java-html-pdf/src/main/java/com/hmkcode/App.java index 0e6c9723..0be911e5 100644 --- a/itext-java-html-pdf/src/main/java/com/hmkcode/App.java +++ b/itext-java-html-pdf/src/main/java/com/hmkcode/App.java @@ -1,29 +1,31 @@ package com.hmkcode; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import com.itextpdf.text.Document; -import com.itextpdf.text.DocumentException; -import com.itextpdf.text.pdf.PdfWriter; -import com.itextpdf.tool.xml.XMLWorkerHelper; + +import com.itextpdf.html2pdf.HtmlConverter; public class App { - public static void main( String[] args ) throws DocumentException, IOException + public static final String HTML = "

Hello

" + + "

This was created using iText

" + + "hmkcode.com"; + + + public static void main( String[] args ) throws FileNotFoundException, IOException { - // step 1 - Document document = new Document(); - // step 2 - PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf.pdf")); - // step 3 - document.open(); - // step 4 - XMLWorkerHelper.getInstance().parseXHtml(writer, document, - new FileInputStream("index.html")); - //step 5 - document.close(); - + + // String to PDF + HtmlConverter.convertToPdf(HTML, new FileOutputStream("string-to-pdf.pdf")); + + + // HTML file to PDF + HtmlConverter.convertToPdf(new FileInputStream("index.html"), + new FileOutputStream("index-to-pdf.pdf")); + + System.out.println( "PDF Created!" ); } } From dc0b1bcee3fa23428898b96fec7ee945ae040e16 Mon Sep 17 00:00:00 2001 From: "Hani M. K" Date: Sat, 25 Apr 2020 22:27:14 +0300 Subject: [PATCH 12/13] java jasper example java jasper example --- java-jasper/pom.xml | 36 +++++++++++ .../src/main/java/com/hmkcode/App.java | 61 +++++++++++++++++++ .../src/main/java/com/hmkcode/Country.java | 47 ++++++++++++++ java-jasper/src/main/resources/report.jrxml | 37 +++++++++++ 4 files changed, 181 insertions(+) create mode 100644 java-jasper/pom.xml create mode 100644 java-jasper/src/main/java/com/hmkcode/App.java create mode 100644 java-jasper/src/main/java/com/hmkcode/Country.java create mode 100644 java-jasper/src/main/resources/report.jrxml diff --git a/java-jasper/pom.xml b/java-jasper/pom.xml new file mode 100644 index 00000000..37666f32 --- /dev/null +++ b/java-jasper/pom.xml @@ -0,0 +1,36 @@ + + + + 4.0.0 + + com.hmkcode + java-jasper + 1.0-SNAPSHOT + + java-jasper + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + net.sf.jasperreports + jasperreports + 6.10.0 + + + + + org.springframework + spring-core + 5.2.3.RELEASE + + + + diff --git a/java-jasper/src/main/java/com/hmkcode/App.java b/java-jasper/src/main/java/com/hmkcode/App.java new file mode 100644 index 00000000..72853237 --- /dev/null +++ b/java-jasper/src/main/java/com/hmkcode/App.java @@ -0,0 +1,61 @@ +package com.hmkcode; + +import net.sf.jasperreports.engine.*; +import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; +import org.springframework.util.ResourceUtils; + +import java.io.*; +import java.util.*; + +public class App +{ + // name and destination of output file e.g. "report.pdf" + private static String destFileName = "report.pdf"; + public static void main( String[] args ) throws FileNotFoundException, JRException { + + System.out.println( "generating jasper report..." ); + + // 1. compile template ".jrxml" file + JasperReport jasperReport = getJasperReport(); + + // 2. parameters "empty" + Map parameters = getParameters(); + + // 3. datasource "java object" + JRDataSource dataSource = getDataSource(); + + JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource); + JasperExportManager.exportReportToPdfFile(jasperPrint, destFileName); + + } + + private static JasperReport getJasperReport() throws FileNotFoundException, JRException { + File template = ResourceUtils.getFile("classpath:report.jrxml"); + return JasperCompileManager.compileReport(template.getAbsolutePath()); + } + private static Map getParameters(){ + Map parameters = new HashMap<>(); + parameters.put("createdBy", "hmkcode"); + return parameters; + } + + private static JRDataSource getDataSource(){ + + List countries = new LinkedList<>(); + + countries.add(new Country("IS", "Iceland", "https://i.pinimg.com/originals/72/b4/49/72b44927f220151547493e528a332173.png")); + countries.add(new Country("TR", "Turkey", "https://i.pinimg.com/originals/82/63/23/826323bba32e6e5a5996062c3a3c662f.png")); + countries.add(new Country("ZA", "South Africa", "https://i.pinimg.com/originals/f5/c7/8d/f5c78da001b46e26481c04fb93473454.png")); + countries.add(new Country("PL", "Poland", "https://i.pinimg.com/originals/7f/ae/21/7fae21c4854010b11127218ead743863.png")); + countries.add(new Country("CA", "Canada", "https://i.pinimg.com/originals/4d/d4/01/4dd401733ba25e6442fc8696e04e5846.png")); + + countries.add(new Country("PA", "Panama", "https://i.pinimg.com/originals/84/dc/e4/84dce49e52ebfb5b3814393069807e0a.png")); + countries.add(new Country("HR", "Croatia", "https://i.pinimg.com/originals/f5/8c/94/f58c94a2a2b3221328fc1e2b7acfa656.png")); + countries.add(new Country("JP", "Japan", "https://i.pinimg.com/originals/a5/d6/88/a5d688289cd6850016f14fe93b17da01.png")); + countries.add(new Country("DE", "Germany", "https://i.pinimg.com/originals/af/c9/b2/afc9b2592a9f1cf591e8a52256ae1e9f.png")); + countries.add(new Country("BR", "Brazil", "https://i.pinimg.com/originals/e4/03/c4/e403c4447a3bd8940459ae4f50856bed.png")); + + + return new JRBeanCollectionDataSource(countries); + } +} diff --git a/java-jasper/src/main/java/com/hmkcode/Country.java b/java-jasper/src/main/java/com/hmkcode/Country.java new file mode 100644 index 00000000..ecbc501d --- /dev/null +++ b/java-jasper/src/main/java/com/hmkcode/Country.java @@ -0,0 +1,47 @@ +package com.hmkcode; + +public class Country { + + private String code; + private String name; + private String url; + + public Country(String code, String name, String url) { + this.code = code; + this.name = name; + this.url = url; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + @Override + public String toString() { + return "Country{" + + "code='" + code + '\'' + + ", name='" + name + '\'' + + ", url='" + url + '\'' + + '}'; + } +} diff --git a/java-jasper/src/main/resources/report.jrxml b/java-jasper/src/main/resources/report.jrxml new file mode 100644 index 00000000..113a787a --- /dev/null +++ b/java-jasper/src/main/resources/report.jrxml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 6c5c149014c5686b3abb51c9f0e0c0165740d793 Mon Sep 17 00:00:00 2001 From: "Hani M. K" Date: Sun, 22 May 2022 18:15:52 +0300 Subject: [PATCH 13/13] java-spi java service provider interface --- java-spi/java-spi-api/pom.xml | 27 ++++++++++++ .../main/java/com/hmkcode/api/MyService.java | 6 +++ .../api/MyServiceProviderInterface.java | 6 +++ .../lib/java-spi-api-1.0-SNAPSHOT.jar | Bin 0 -> 2492 bytes .../lib/java-spi-impl1-1.0-SNAPSHOT.jar | Bin 0 -> 3328 bytes java-spi/java-spi-app/pom.xml | 40 ++++++++++++++++++ .../src/main/java/com/hmkcode/app/App.java | 9 ++++ .../java/com/hmkcode/app/MyServiceLoader.java | 31 ++++++++++++++ .../lib/java-spi-api-1.0-SNAPSHOT.jar | Bin 0 -> 2492 bytes java-spi/java-spi-impl1/pom.xml | 31 ++++++++++++++ .../java/com/hmkcode/impl/MyServiceImpl1.java | 12 ++++++ .../hmkcode/impl/MyServiceProviderImpl1.java | 13 ++++++ ...com.hmkcode.api.MyServiceProviderInterface | 1 + 13 files changed, 176 insertions(+) create mode 100644 java-spi/java-spi-api/pom.xml create mode 100644 java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyService.java create mode 100644 java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyServiceProviderInterface.java create mode 100644 java-spi/java-spi-app/lib/java-spi-api-1.0-SNAPSHOT.jar create mode 100644 java-spi/java-spi-app/lib/java-spi-impl1-1.0-SNAPSHOT.jar create mode 100644 java-spi/java-spi-app/pom.xml create mode 100644 java-spi/java-spi-app/src/main/java/com/hmkcode/app/App.java create mode 100644 java-spi/java-spi-app/src/main/java/com/hmkcode/app/MyServiceLoader.java create mode 100644 java-spi/java-spi-impl1/lib/java-spi-api-1.0-SNAPSHOT.jar create mode 100644 java-spi/java-spi-impl1/pom.xml create mode 100644 java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceImpl1.java create mode 100644 java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceProviderImpl1.java create mode 100644 java-spi/java-spi-impl1/src/main/resources/META-INF/services/com.hmkcode.api.MyServiceProviderInterface diff --git a/java-spi/java-spi-api/pom.xml b/java-spi/java-spi-api/pom.xml new file mode 100644 index 00000000..e7c1e87d --- /dev/null +++ b/java-spi/java-spi-api/pom.xml @@ -0,0 +1,27 @@ + + + + 4.0.0 + + com.hmkcode.api + java-spi-api + 1.0-SNAPSHOT + + java-spi-api + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + + + + + diff --git a/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyService.java b/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyService.java new file mode 100644 index 00000000..4928f453 --- /dev/null +++ b/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyService.java @@ -0,0 +1,6 @@ +package com.hmkcode.api; + +public interface MyService { + + void doSomething(); +} diff --git a/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyServiceProviderInterface.java b/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyServiceProviderInterface.java new file mode 100644 index 00000000..8e166424 --- /dev/null +++ b/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyServiceProviderInterface.java @@ -0,0 +1,6 @@ +package com.hmkcode.api; + +public interface MyServiceProviderInterface { + + MyService getService(); +} diff --git a/java-spi/java-spi-app/lib/java-spi-api-1.0-SNAPSHOT.jar b/java-spi/java-spi-app/lib/java-spi-api-1.0-SNAPSHOT.jar new file mode 100644 index 0000000000000000000000000000000000000000..23a1c6be1ad6136d8b3ee9fc32a69c57cddfaf5f GIT binary patch literal 2492 zcmWIWW@h1H0D+^;TSLGMD8UJ&eO*Hwbv^yu^aG&EI2euqm1Rf-e98byHvq8+vNB&s zKTkK;;1E4ux6i(3PWyQ4>RsgZ*3~+9=KSU$gDb`lo)+nNojal9t?R_W{$xqm6fx}s zDiu5DbO#B02L+eR)mkee!!0z~I7qZc_;k=`k)E$QUwVM@UdF{<2R2DMSQ{xYY3_>C zyy;+l<|~gwR>e*Rn9CR#wxD@{1?aNm{9L%(F;(zDRb=F5C+DZ6BB?xpW|jb&%EW?9 zxN1n4h|Oc3)c{o055)3VRQpy2rxulECa3Bp=Oh*vTYt^JZpX&Pmdxf?#-`@RcJj%e zn7=)D-aPp;CFJjsCZF2-ryg8cwCT)~kTNzgH@3z#M>e_qopWSQN$vk7Ypy&Ia$|cp z<jE4b9#6jQh5{(aF|S- z+Q@q(DS>^G504By*dUI#2;`LL13LN?5F6lgd_YltS!POVk!M~>YEfDuF5j%h<(n%F zi~ejnGv$iX`8|`aEZTAexA)e4xgxYe&W$aS*H?ayTNJY>`}65ys>^q!K4TC){dk)X ze+s{}GP5$XF*An&)7!Mv1m=wrHyTxhnc3lf!%WlsK)=D$bZ%lRAYpi@{+Z0tflUWTD8rrg7_U*oUcUva+>GRuf$976wN#1|l zXaCH^$+fWyWh2zLN~w#h_zGw&EMD1F_-Rwsf$b+%r1{#I)7I3nKMXX`F!%F%f41Y& ztoIIrc{?;3GomjXt#MoLc}uM8)Wv%zn|EbOU5atNn>s7*!q=Q#JjZ4wublJT%fU!S zK}1Jc{NqZoJIB}mz0Lo3*^S+Mm)+q;;o;wN>EoKCFW&7~ z{>b#t3gLww^AdaH=3U!dt>U$g%i)sp`ic6CU$d>sS2XrcmJ>KOH#2+no7-{;=d*(u z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..74906a4f --- /dev/null +++ b/java-spi/java-spi-app/pom.xml @@ -0,0 +1,40 @@ + + + + 4.0.0 + + com.hmkcode.app + java-spi-app + 1.0-SNAPSHOT + + java-spi-app + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + + com.hmkcode.api + java-spi-api + 1.0-SNAPSHOT + system + ${project.basedir}/lib/java-spi-api-1.0-SNAPSHOT.jar + + + com.hmkcode.impl + java-spi-impl1 + 1.0-SNAPSHOT + system + ${project.basedir}/lib/java-spi-impl1-1.0-SNAPSHOT.jar + + + + + diff --git a/java-spi/java-spi-app/src/main/java/com/hmkcode/app/App.java b/java-spi/java-spi-app/src/main/java/com/hmkcode/app/App.java new file mode 100644 index 00000000..8e46d684 --- /dev/null +++ b/java-spi/java-spi-app/src/main/java/com/hmkcode/app/App.java @@ -0,0 +1,9 @@ +package com.hmkcode.app; + +public class App +{ + public static void main( String[] args ) + { + MyServiceLoader.defaultProvider().getService().doSomething(); + } +} diff --git a/java-spi/java-spi-app/src/main/java/com/hmkcode/app/MyServiceLoader.java b/java-spi/java-spi-app/src/main/java/com/hmkcode/app/MyServiceLoader.java new file mode 100644 index 00000000..2efc5d74 --- /dev/null +++ b/java-spi/java-spi-app/src/main/java/com/hmkcode/app/MyServiceLoader.java @@ -0,0 +1,31 @@ +package com.hmkcode.app; + +import java.nio.file.ProviderNotFoundException; +import java.util.Iterator; +import java.util.ServiceLoader; + +import com.hmkcode.api.MyServiceProviderInterface; + + +public class MyServiceLoader { + + private static final String DEFAULT_PROVIDER = "com.hmkcode.impl.MyServiceProviderImpl1"; + + public static MyServiceProviderInterface defaultProvider() { + return provider(DEFAULT_PROVIDER); + } + + public static MyServiceProviderInterface provider(String providerName) { + ServiceLoader loader = ServiceLoader.load(MyServiceProviderInterface.class); + + Iterator it = loader.iterator(); + while (it.hasNext()) { + MyServiceProviderInterface provider = it.next(); + if (providerName.equals(provider.getClass().getName())) { + return provider; + } + } + throw new ProviderNotFoundException("provider " + providerName + " not found"); + } + +} diff --git a/java-spi/java-spi-impl1/lib/java-spi-api-1.0-SNAPSHOT.jar b/java-spi/java-spi-impl1/lib/java-spi-api-1.0-SNAPSHOT.jar new file mode 100644 index 0000000000000000000000000000000000000000..23a1c6be1ad6136d8b3ee9fc32a69c57cddfaf5f GIT binary patch literal 2492 zcmWIWW@h1H0D+^;TSLGMD8UJ&eO*Hwbv^yu^aG&EI2euqm1Rf-e98byHvq8+vNB&s zKTkK;;1E4ux6i(3PWyQ4>RsgZ*3~+9=KSU$gDb`lo)+nNojal9t?R_W{$xqm6fx}s zDiu5DbO#B02L+eR)mkee!!0z~I7qZc_;k=`k)E$QUwVM@UdF{<2R2DMSQ{xYY3_>C zyy;+l<|~gwR>e*Rn9CR#wxD@{1?aNm{9L%(F;(zDRb=F5C+DZ6BB?xpW|jb&%EW?9 zxN1n4h|Oc3)c{o055)3VRQpy2rxulECa3Bp=Oh*vTYt^JZpX&Pmdxf?#-`@RcJj%e zn7=)D-aPp;CFJjsCZF2-ryg8cwCT)~kTNzgH@3z#M>e_qopWSQN$vk7Ypy&Ia$|cp z<jE4b9#6jQh5{(aF|S- z+Q@q(DS>^G504By*dUI#2;`LL13LN?5F6lgd_YltS!POVk!M~>YEfDuF5j%h<(n%F zi~ejnGv$iX`8|`aEZTAexA)e4xgxYe&W$aS*H?ayTNJY>`}65ys>^q!K4TC){dk)X ze+s{}GP5$XF*An&)7!Mv1m=wrHyTxhnc3lf!%WlsK)=D$bZ%lRAYpi@{+Z0tflUWTD8rrg7_U*oUcUva+>GRuf$976wN#1|l zXaCH^$+fWyWh2zLN~w#h_zGw&EMD1F_-Rwsf$b+%r1{#I)7I3nKMXX`F!%F%f41Y& ztoIIrc{?;3GomjXt#MoLc}uM8)Wv%zn|EbOU5atNn>s7*!q=Q#JjZ4wublJT%fU!S zK}1Jc{NqZoJIB}mz0Lo3*^S+Mm)+q;;o;wN>EoKCFW&7~ z{>b#t3gLww^AdaH=3U!dt>U$g%i)sp`ic6CU$d>sS2XrcmJ>KOH#2+no7-{;=d*(u zITuRg?%Y?Xk)ZHLB4$geNA#qeZJSPYUXIp&u+M&y&OMIB^;y5H?xs1}D{F7qtKsvo z?c(Jtne(4-W2nD$J=l=lmg`dc>4OcY4!71HeZ9o~L7znn*9mo4p~S&(9T=O!fosKT zfw9;G#8za)WS8ng3aDT`wI^-$0L5As>8oyw5&<8pP+P!?;OXw1-EO zr*|#SnKeE>qIYVYx9~Q|FtY-)h;rPzFN^+MVmdE!8<;KkLJOI_z(OW&-H}C;&H!_v z(1Mt-q{u~ig^tVgA{OavU14EtfBss)c?a_w=M5EZ9JX(n&JD~~j7%cTxGM{w&wxOH z;jJTxhUXlFHtdxLNHGX3X;cT2aBWCc3Bm--A{ + + + 4.0.0 + + com.hmkcode.impl + java-spi-impl1 + 1.0-SNAPSHOT + + java-spi-impl1 + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + com.hmkcode.api + java-spi-api + 1.0-SNAPSHOT + system + ${project.basedir}/lib/java-spi-api-1.0-SNAPSHOT.jar + + + + diff --git a/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceImpl1.java b/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceImpl1.java new file mode 100644 index 00000000..24afcfa4 --- /dev/null +++ b/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceImpl1.java @@ -0,0 +1,12 @@ +package com.hmkcode.impl; + +import com.hmkcode.api.MyService; + +public class MyServiceImpl1 implements MyService{ + + @Override + public void doSomething() { + System.out.println("MyServiceImpl1"); + + } +} diff --git a/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceProviderImpl1.java b/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceProviderImpl1.java new file mode 100644 index 00000000..252b7a3e --- /dev/null +++ b/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceProviderImpl1.java @@ -0,0 +1,13 @@ +package com.hmkcode.impl; + +import com.hmkcode.api.MyService; +import com.hmkcode.api.MyServiceProviderInterface; + +public class MyServiceProviderImpl1 implements MyServiceProviderInterface { + + @Override + public MyService getService() { + return new MyServiceImpl1(); + } + +} diff --git a/java-spi/java-spi-impl1/src/main/resources/META-INF/services/com.hmkcode.api.MyServiceProviderInterface b/java-spi/java-spi-impl1/src/main/resources/META-INF/services/com.hmkcode.api.MyServiceProviderInterface new file mode 100644 index 00000000..008c8c11 --- /dev/null +++ b/java-spi/java-spi-impl1/src/main/resources/META-INF/services/com.hmkcode.api.MyServiceProviderInterface @@ -0,0 +1 @@ +com.hmkcode.impl.MyServiceProviderImpl1 \ No newline at end of file
Title