diff --git a/README.md b/README.md
index 6dff78aa7a..62d2d5b55e 100644
--- a/README.md
+++ b/README.md
@@ -39,6 +39,3 @@ This tutorials project is being built **[>> HERE](https://rest-security.ci.cloud
- [Apache Maven Standard Directory Layout](http://www.baeldung.com/maven-directory-structure)
- [Apache Maven Tutorial](http://www.baeldung.com/maven)
-- [Designing a User Friendly Java Library](http://www.baeldung.com/design-a-user-friendly-java-library)
-- [Java Service Provider Interface](http://www.baeldung.com/java-spi)
-- [Java Streams vs Vavr Streams](http://www.baeldung.com/vavr-java-streams)
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java b/algorithms/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java
index 8b47fa0fdf..5ca2d626f1 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java
+++ b/algorithms/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java
@@ -148,7 +148,7 @@ public class Board {
System.out.println("Game Draw");
break;
case IN_PROGRESS:
- System.out.println("Game In rogress");
+ System.out.println("Game In Progress");
break;
}
}
diff --git a/animal-sniffer-mvn-plugin/pom.xml b/animal-sniffer-mvn-plugin/pom.xml
index ab7b38f6e0..9ccc7354af 100644
--- a/animal-sniffer-mvn-plugin/pom.xml
+++ b/animal-sniffer-mvn-plugin/pom.xml
@@ -5,7 +5,7 @@
animal-sniffer-mvn-plugin
jar
1.0-SNAPSHOT
- example-animal-sniffer-mvn-plugin
+ animal-sniffer-mvn-plugin
http://maven.apache.org
diff --git a/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneAdvancedOperationIntegrationTest.java b/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneAdvancedOperationLiveTest.java
similarity index 99%
rename from apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneAdvancedOperationIntegrationTest.java
rename to apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneAdvancedOperationLiveTest.java
index 546b8fe45c..b54b62ca02 100644
--- a/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneAdvancedOperationIntegrationTest.java
+++ b/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneAdvancedOperationLiveTest.java
@@ -19,7 +19,7 @@ import java.util.List;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-public class CayenneAdvancedOperationIntegrationTest {
+public class CayenneAdvancedOperationLiveTest {
private static ObjectContext context = null;
@BeforeClass
diff --git a/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationIntegrationTest.java b/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationLiveTest.java
similarity index 98%
rename from apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationIntegrationTest.java
rename to apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationLiveTest.java
index 85f06d5538..e6ca4a3634 100644
--- a/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationIntegrationTest.java
+++ b/apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationLiveTest.java
@@ -16,7 +16,7 @@ import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-public class CayenneOperationIntegrationTest {
+public class CayenneOperationLiveTest {
private static ObjectContext context = null;
@BeforeClass
diff --git a/azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationTests.java b/azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationIntegrationTest.java
similarity index 86%
rename from azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationTests.java
rename to azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationIntegrationTest.java
index 91632be11a..7c3084446f 100644
--- a/azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationTests.java
+++ b/azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationIntegrationTest.java
@@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
-public class AzureApplicationTests {
+public class AzureApplicationIntegrationTest {
@Test
public void contextLoads() {
diff --git a/camel-api/pom.xml b/camel-api/pom.xml
index 86f6713cd6..4e50828b96 100644
--- a/camel-api/pom.xml
+++ b/camel-api/pom.xml
@@ -5,7 +5,6 @@
com.example
spring-boot-camel
0.0.1-SNAPSHOT
- Spring-Boot - Camel API
com.baeldung
diff --git a/core-java-8/pom.xml b/core-java-8/pom.xml
index aab349781a..20db1e1146 100644
--- a/core-java-8/pom.xml
+++ b/core-java-8/pom.xml
@@ -195,6 +195,16 @@
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.1
+
+ 1.8
+ 1.8
+ -parameters
+
+
org.springframework.boot
spring-boot-maven-plugin
diff --git a/core-java-8/src/main/java/com/baeldung/reflect/Person.java b/core-java-8/src/main/java/com/baeldung/reflect/Person.java
new file mode 100644
index 0000000000..fba25aca8b
--- /dev/null
+++ b/core-java-8/src/main/java/com/baeldung/reflect/Person.java
@@ -0,0 +1,18 @@
+package com.baeldung.reflect;
+
+public class Person {
+
+ private String fullName;
+
+ public Person(String fullName) {
+ this.fullName = fullName;
+ }
+
+ public void setFullName(String fullName) {
+ this.fullName = fullName;
+ }
+
+ public String getFullName() {
+ return fullName;
+ }
+}
diff --git a/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameUnitTest.java b/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameUnitTest.java
new file mode 100644
index 0000000000..b191c94826
--- /dev/null
+++ b/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameUnitTest.java
@@ -0,0 +1,34 @@
+package com.baeldung.reflect;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.lang.reflect.Parameter;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+
+import org.junit.Test;
+
+public class MethodParamNameUnitTest {
+
+ @Test
+ public void whenGetConstructorParams_thenOk()
+ throws NoSuchMethodException, SecurityException {
+ List parameters
+ = Arrays.asList(Person.class.getConstructor(String.class).getParameters());
+ Optional parameter
+ = parameters.stream().filter(Parameter::isNamePresent).findFirst();
+ assertThat(parameter.get().getName()).isEqualTo("fullName");
+ }
+
+ @Test
+ public void whenGetMethodParams_thenOk()
+ throws NoSuchMethodException, SecurityException {
+ List parameters
+ = Arrays.asList(
+ Person.class.getMethod("setFullName", String.class).getParameters());
+ Optional parameter
+ = parameters.stream().filter(Parameter::isNamePresent).findFirst();
+ assertThat(parameter.get().getName()).isEqualTo("fullName");
+ }
+}
diff --git a/core-java-io/src/test/java/com/baeldung/file/FilesManualTest.java b/core-java-io/src/test/java/com/baeldung/file/FilesManualTest.java
index 8322106c24..f5c5c3dd3a 100644
--- a/core-java-io/src/test/java/com/baeldung/file/FilesManualTest.java
+++ b/core-java-io/src/test/java/com/baeldung/file/FilesManualTest.java
@@ -77,6 +77,6 @@ public class FilesManualTest {
bw.newLine();
bw.close();
- assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\n");
+ assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
}
}
\ No newline at end of file
diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java b/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java
index b56841117e..a96232d66c 100644
--- a/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java
+++ b/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java
@@ -1,6 +1,7 @@
package org.baeldung.java.io;
import org.junit.Test;
+import org.junit.Ignore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -105,8 +106,9 @@ public class JavaReadFromFileUnitTest {
}
@Test
+ @Ignore // TODO
public void whenReadUTFEncodedFile_thenCorrect() throws IOException {
- final String expected_value = "�空";
+ final String expected_value = "青空";
final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("src/test/resources/test_read7.in"), "UTF-8"));
final String currentLine = reader.readLine();
reader.close();
diff --git a/core-java/README.md b/core-java/README.md
index 9bc7d9f7ee..484b788974 100644
--- a/core-java/README.md
+++ b/core-java/README.md
@@ -141,6 +141,7 @@
- [Java KeyStore API](http://www.baeldung.com/java-keystore)
- [Double-Checked Locking with Singleton](http://www.baeldung.com/java-singleton-double-checked-locking)
- [Guide to Java Clock Class](http://www.baeldung.com/java-clock)
+- [Infinite Loops in Java](http://www.baeldung.com/infinite-loops-java)
- [Using Java Assertions](http://www.baeldung.com/java-assert)
- [Pass-By-Value as a Parameter Passing Mechanism in Java](http://www.baeldung.com/java-pass-by-value-or-pass-by-reference)
- [Check If a String Is Numeric in Java](http://www.baeldung.com/java-check-string-number)
@@ -149,5 +150,3 @@
- [NaN in Java](http://www.baeldung.com/java-not-a-number)
- [Infinite Loops in Java](http://www.baeldung.com/infinite-loops-java)
- [Why Use char[] Array Over a String for Storing Passwords in Java?](http://www.baeldung.com/java-storing-passwords)
-
-
diff --git a/core-java/src/main/java/com/baeldung/array/JaggedArray.java b/core-java/src/main/java/com/baeldung/array/JaggedArray.java
new file mode 100644
index 0000000000..36cfc88b95
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/array/JaggedArray.java
@@ -0,0 +1,49 @@
+package com.baeldung.array;
+
+import java.util.Arrays;
+import java.util.Scanner;
+
+public class JaggedArray {
+
+ int[][] shortHandFormInitialization() {
+ int[][] jaggedArr = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } };
+ return jaggedArr;
+ }
+
+ int[][] declarationAndThenInitialization() {
+ int[][] jaggedArr = new int[3][];
+ jaggedArr[0] = new int[] { 1, 2 };
+ jaggedArr[1] = new int[] { 3, 4, 5 };
+ jaggedArr[2] = new int[] { 6, 7, 8, 9 };
+ return jaggedArr;
+ }
+
+ int[][] declarationAndThenInitializationUsingUserInputs() {
+ int[][] jaggedArr = new int[3][];
+ jaggedArr[0] = new int[2];
+ jaggedArr[1] = new int[3];
+ jaggedArr[2] = new int[4];
+ initializeElements(jaggedArr);
+ return jaggedArr;
+ }
+
+ void initializeElements(int[][] jaggedArr) {
+ Scanner sc = new Scanner(System.in);
+ for (int outer = 0; outer < jaggedArr.length; outer++) {
+ for (int inner = 0; inner < jaggedArr[outer].length; inner++) {
+ jaggedArr[outer][inner] = sc.nextInt();
+ }
+ }
+ }
+
+ void printElements(int[][] jaggedArr) {
+ for (int index = 0; index < jaggedArr.length; index++) {
+ System.out.println(Arrays.toString(jaggedArr[index]));
+ }
+ }
+
+ int[] getElementAtGivenIndex(int[][] jaggedArr, int index) {
+ return jaggedArr[index];
+ }
+
+}
diff --git a/core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java b/core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java
index 27684c93d2..2caf17fd0c 100644
--- a/core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java
+++ b/core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java
@@ -1,10 +1,20 @@
package com.baeldung.linkedlist;
-import com.baeldung.linkedlist.LinkedList.Node;
+import java.util.LinkedList;
+
+import com.baeldung.linkedlist.Node;
public class MiddleElementLookup {
- public static String findMiddleElement(Node head) {
+ public static String findMiddleElementLinkedList(LinkedList linkedList) {
+ if (linkedList == null || linkedList.isEmpty()) {
+ return null;
+ }
+
+ return linkedList.get((linkedList.size() - 1) / 2);
+ }
+
+ public static String findMiddleElementFromHead(Node head) {
if (head == null) {
return null;
}
@@ -26,7 +36,7 @@ public class MiddleElementLookup {
return current.data();
}
- public static String findMiddleElement1PassRecursively(Node head) {
+ public static String findMiddleElementFromHead1PassRecursively(Node head) {
if (head == null) {
return null;
}
@@ -53,7 +63,7 @@ public class MiddleElementLookup {
middleAux.length--;
}
- public static String findMiddleElement1PassIteratively(Node head) {
+ public static String findMiddleElementFromHead1PassIteratively(Node head) {
if (head == null) {
return null;
}
diff --git a/core-java/src/main/java/com/baeldung/linkedlist/Node.java b/core-java/src/main/java/com/baeldung/linkedlist/Node.java
new file mode 100644
index 0000000000..daceaffdcd
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/linkedlist/Node.java
@@ -0,0 +1,34 @@
+package com.baeldung.linkedlist;
+
+public class Node {
+ private Node next;
+ private String data;
+
+ public Node(String data) {
+ this.data = data;
+ }
+
+ public String data() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public boolean hasNext() {
+ return next != null;
+ }
+
+ public Node next() {
+ return next;
+ }
+
+ public void setNext(Node next) {
+ this.next = next;
+ }
+
+ public String toString() {
+ return this.data;
+ }
+}
diff --git a/core-java/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java b/core-java/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java
new file mode 100644
index 0000000000..f432436190
--- /dev/null
+++ b/core-java/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java
@@ -0,0 +1,53 @@
+package com.baeldung.array;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.PrintStream;
+
+import org.junit.Test;
+
+public class JaggedArrayUnitTest {
+
+ private JaggedArray obj = new JaggedArray();
+
+ @Test
+ public void whenInitializedUsingShortHandForm_thenCorrect() {
+ assertArrayEquals(new int[][] { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } }, obj.shortHandFormInitialization());
+ }
+
+ @Test
+ public void whenInitializedWithDeclarationAndThenInitalization_thenCorrect() {
+ assertArrayEquals(new int[][] { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } }, obj.declarationAndThenInitialization());
+ }
+
+ @Test
+ public void whenInitializedWithDeclarationAndThenInitalizationUsingUserInputs_thenCorrect() {
+ InputStream is = new ByteArrayInputStream("1 2 3 4 5 6 7 8 9".getBytes());
+ System.setIn(is);
+ assertArrayEquals(new int[][] { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } }, obj.declarationAndThenInitializationUsingUserInputs());
+ System.setIn(System.in);
+ }
+
+ @Test
+ public void givenJaggedArrayAndAnIndex_thenReturnArrayAtGivenIndex() {
+ int[][] jaggedArr = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } };
+ assertArrayEquals(new int[] { 1, 2 }, obj.getElementAtGivenIndex(jaggedArr, 0));
+ assertArrayEquals(new int[] { 3, 4, 5 }, obj.getElementAtGivenIndex(jaggedArr, 1));
+ assertArrayEquals(new int[] { 6, 7, 8, 9 }, obj.getElementAtGivenIndex(jaggedArr, 2));
+ }
+
+ @Test
+ public void givenJaggedArray_whenUsingArraysAPI_thenVerifyPrintedElements() {
+ int[][] jaggedArr = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } };
+ ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outContent));
+ obj.printElements(jaggedArr);
+ assertEquals("[1, 2]\n[3, 4, 5]\n[6, 7, 8, 9]\n", outContent.toString());
+ System.setOut(System.out);
+ }
+
+}
diff --git a/core-java/src/test/java/com/baeldung/linkedlist/MiddleElementLookupUnitTest.java b/core-java/src/test/java/com/baeldung/linkedlist/MiddleElementLookupUnitTest.java
index d456259612..08a4e52ff9 100644
--- a/core-java/src/test/java/com/baeldung/linkedlist/MiddleElementLookupUnitTest.java
+++ b/core-java/src/test/java/com/baeldung/linkedlist/MiddleElementLookupUnitTest.java
@@ -2,51 +2,46 @@ package com.baeldung.linkedlist;
import static org.junit.Assert.assertEquals;
+import java.util.LinkedList;
+
import org.junit.Test;
public class MiddleElementLookupUnitTest {
@Test
- public void whenFindingMiddle_thenMiddleFound() {
- String middle = MiddleElementLookup.findMiddleElement(createList(5).head());
- assertEquals("3", middle);
-
- middle = MiddleElementLookup.findMiddleElement(createList(4).head());
- assertEquals("2", middle);
+ public void whenFindingMiddleLinkedList_thenMiddleFound() {
+ assertEquals("3", MiddleElementLookup.findMiddleElementLinkedList(createLinkedList(5)));
+ assertEquals("2", MiddleElementLookup.findMiddleElementLinkedList(createLinkedList(4)));
}
@Test
- public void whenFindingMiddle1PassRecursively_thenMiddleFound() {
- String middle = MiddleElementLookup.findMiddleElement1PassRecursively(createList(5).head());
- assertEquals("3", middle);
-
- middle = MiddleElementLookup.findMiddleElement1PassRecursively(createList(4).head());
- assertEquals("2", middle);
+ public void whenFindingMiddleFromHead_thenMiddleFound() {
+ assertEquals("3", MiddleElementLookup.findMiddleElementFromHead(createNodesList(5)));
+ assertEquals("2", MiddleElementLookup.findMiddleElementFromHead(createNodesList(4)));
}
@Test
- public void whenFindingMiddle1PassIteratively_thenMiddleFound() {
- String middle = MiddleElementLookup.findMiddleElement1PassIteratively(createList(5).head());
- assertEquals("3", middle);
+ public void whenFindingMiddleFromHead1PassRecursively_thenMiddleFound() {
+ assertEquals("3", MiddleElementLookup.findMiddleElementFromHead1PassRecursively(createNodesList(5)));
+ assertEquals("2", MiddleElementLookup.findMiddleElementFromHead1PassRecursively(createNodesList(4)));
+ }
- middle = MiddleElementLookup.findMiddleElement1PassIteratively(createList(4).head());
- assertEquals("2", middle);
+ @Test
+ public void whenFindingMiddleFromHead1PassIteratively_thenMiddleFound() {
+ assertEquals("3", MiddleElementLookup.findMiddleElementFromHead1PassIteratively(createNodesList(5)));
+ assertEquals("2", MiddleElementLookup.findMiddleElementFromHead1PassIteratively(createNodesList(4)));
}
@Test
public void whenListEmptyOrNull_thenMiddleNull() {
- String middle = MiddleElementLookup.findMiddleElement(null);
- assertEquals(null, middle);
-
- middle = MiddleElementLookup.findMiddleElement1PassIteratively(null);
- assertEquals(null, middle);
-
- middle = MiddleElementLookup.findMiddleElement1PassRecursively(null);
- assertEquals(null, middle);
+ assertEquals(null, MiddleElementLookup.findMiddleElementLinkedList(null));
+ assertEquals(null, MiddleElementLookup.findMiddleElementFromHead(null));
+ assertEquals(null, MiddleElementLookup.findMiddleElementFromHead1PassIteratively(null));
+ assertEquals(null, MiddleElementLookup.findMiddleElementFromHead1PassRecursively(null));
}
- private static LinkedList createList(int n) {
- LinkedList list = new LinkedList();
+ private static LinkedList createLinkedList(int n) {
+ LinkedList list = new LinkedList<>();
for (int i = 1; i <= n; i++) {
list.add(String.valueOf(i));
@@ -55,4 +50,17 @@ public class MiddleElementLookupUnitTest {
return list;
}
+ private static Node createNodesList(int n) {
+ Node head = new Node("1");
+ Node current = head;
+
+ for (int i = 2; i <= n; i++) {
+ Node newNode = new Node(String.valueOf(i));
+ current.setNext(newNode);
+ current = newNode;
+ }
+
+ return head;
+ }
+
}
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/enums/CardType.kt b/core-kotlin/src/main/kotlin/com/baeldung/enums/CardType.kt
new file mode 100644
index 0000000000..013c8070bf
--- /dev/null
+++ b/core-kotlin/src/main/kotlin/com/baeldung/enums/CardType.kt
@@ -0,0 +1,48 @@
+package com.baeldung.enums
+
+enum class CardType(val color: String) : ICardLimit {
+ SILVER("gray") {
+ override fun getCreditLimit(): Int {
+ return 100000
+ }
+
+ override fun calculateCashbackPercent(): Float {
+ return 0.25f
+ }
+ },
+ GOLD("yellow") {
+ override fun getCreditLimit(): Int {
+ return 200000
+ }
+
+ override fun calculateCashbackPercent(): Float {
+ return 0.5f
+ }
+ },
+ PLATINUM("black") {
+ override fun getCreditLimit(): Int {
+ return 300000
+ }
+
+ override fun calculateCashbackPercent(): Float {
+ return 0.75f
+ }
+ };
+
+ companion object {
+ fun getCardTypeByColor(color: String): CardType? {
+ for (cardType in CardType.values()) {
+ if (cardType.color.equals(color)) {
+ return cardType;
+ }
+ }
+ return null
+ }
+
+ fun getCardTypeByName(name: String): CardType {
+ return CardType.valueOf(name.toUpperCase())
+ }
+ }
+
+ abstract fun calculateCashbackPercent(): Float
+}
\ No newline at end of file
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/enums/ICardLimit.kt b/core-kotlin/src/main/kotlin/com/baeldung/enums/ICardLimit.kt
new file mode 100644
index 0000000000..7994822a52
--- /dev/null
+++ b/core-kotlin/src/main/kotlin/com/baeldung/enums/ICardLimit.kt
@@ -0,0 +1,5 @@
+package com.baeldung.enums
+
+interface ICardLimit {
+ fun getCreditLimit(): Int
+}
\ No newline at end of file
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt
new file mode 100644
index 0000000000..525faebd55
--- /dev/null
+++ b/core-kotlin/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt
@@ -0,0 +1,84 @@
+package com.baeldung.enums
+
+import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Test
+
+internal class CardTypeUnitTest {
+
+ @Test
+ fun givenSilverCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() {
+ assertEquals(0.25f, CardType.SILVER.calculateCashbackPercent())
+ }
+
+ @Test
+ fun givenGoldCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() {
+ assertEquals(0.5f, CardType.GOLD.calculateCashbackPercent())
+ }
+
+ @Test
+ fun givenPlatinumCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() {
+ assertEquals(0.75f, CardType.PLATINUM.calculateCashbackPercent())
+ }
+
+ @Test
+ fun givenSilverCardType_whenGetCreditLimit_thenReturnCreditLimit() {
+ assertEquals(100000, CardType.SILVER.getCreditLimit())
+ }
+
+ @Test
+ fun givenGoldCardType_whenGetCreditLimit_thenReturnCreditLimit() {
+ assertEquals(200000, CardType.GOLD.getCreditLimit())
+ }
+
+ @Test
+ fun givenPlatinumCardType_whenGetCreditLimit_thenReturnCreditLimit() {
+ assertEquals(300000, CardType.PLATINUM.getCreditLimit())
+ }
+
+ @Test
+ fun givenSilverCardType_whenCheckColor_thenReturnColor() {
+ assertEquals("gray", CardType.SILVER.color)
+ }
+
+ @Test
+ fun givenGoldCardType_whenCheckColor_thenReturnColor() {
+ assertEquals("yellow", CardType.GOLD.color)
+ }
+
+ @Test
+ fun givenPlatinumCardType_whenCheckColor_thenReturnColor() {
+ assertEquals("black", CardType.PLATINUM.color)
+ }
+
+ @Test
+ fun whenGetCardTypeByColor_thenSilverCardType() {
+ Assertions.assertEquals(CardType.SILVER, CardType.getCardTypeByColor("gray"))
+ }
+
+ @Test
+ fun whenGetCardTypeByColor_thenGoldCardType() {
+ Assertions.assertEquals(CardType.GOLD, CardType.getCardTypeByColor("yellow"))
+ }
+
+ @Test
+ fun whenGetCardTypeByColor_thenPlatinumCardType() {
+ Assertions.assertEquals(CardType.PLATINUM, CardType.getCardTypeByColor("black"))
+ }
+
+ @Test
+ fun whenGetCardTypeByName_thenSilverCardType() {
+ Assertions.assertEquals(CardType.SILVER, CardType.getCardTypeByName("silver"))
+ }
+
+ @Test
+ fun whenGetCardTypeByName_thenGoldCardType() {
+ Assertions.assertEquals(CardType.GOLD, CardType.getCardTypeByName("gold"))
+ }
+
+ @Test
+ fun whenGetCardTypeByName_thenPlatinumCardType() {
+ Assertions.assertEquals(CardType.PLATINUM, CardType.getCardTypeByName("platinum"))
+ }
+
+}
diff --git a/custom-pmd-0.0.1.jar b/custom-pmd-0.0.1.jar
index 4ad6933865..5038a70475 100644
Binary files a/custom-pmd-0.0.1.jar and b/custom-pmd-0.0.1.jar differ
diff --git a/custom-pmd/src/main/java/org/baeldung/pmd/UnitTestNamingConventionRule.java b/custom-pmd/src/main/java/org/baeldung/pmd/UnitTestNamingConventionRule.java
index 4136165b6f..9a2795b581 100644
--- a/custom-pmd/src/main/java/org/baeldung/pmd/UnitTestNamingConventionRule.java
+++ b/custom-pmd/src/main/java/org/baeldung/pmd/UnitTestNamingConventionRule.java
@@ -14,17 +14,16 @@ public class UnitTestNamingConventionRule extends AbstractJavaRule {
"ManualTest",
"JdbcTest",
"LiveTest",
- "UnitTest");
+ "UnitTest",
+ "jmhTest");
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
String className = node.getImage();
Objects.requireNonNull(className);
- if (className.endsWith("Test") || className.endsWith("Tests")) {
- if (allowedEndings.stream()
- .noneMatch(className::endsWith)) {
- addViolation(data, node);
- }
+ if (className.endsWith("Tests")
+ || (className.endsWith("Test") && allowedEndings.stream().noneMatch(className::endsWith))) {
+ addViolation(data, node);
}
return data;
diff --git a/ejb/ejb-client/pom.xml b/ejb/ejb-client/pom.xml
index 83dd0aef30..88116f8003 100755
--- a/ejb/ejb-client/pom.xml
+++ b/ejb/ejb-client/pom.xml
@@ -3,7 +3,6 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
ejb-client
- EJB3 Client Maven
EJB3 Client Maven
diff --git a/ethereumj/pom.xml b/ethereumj/pom.xml
index 611b7b09eb..6917505f1b 100644
--- a/ethereumj/pom.xml
+++ b/ethereumj/pom.xml
@@ -10,10 +10,10 @@
ethereumj
- parent-boot-5
+ parent-boot-1
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-5
+ ../parent-boot-1
diff --git a/flips/pom.xml b/flips/pom.xml
index be9f584114..34cbab7035 100644
--- a/flips/pom.xml
+++ b/flips/pom.xml
@@ -8,10 +8,10 @@
flips
- parent-boot-5
+ parent-boot-1
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-5
+ ../parent-boot-1
diff --git a/spring-4/src/test/java/com/baeldung/flips/controller/FlipControllerTest.java b/flips/src/test/java/com/baeldung/flips/controller/FlipControllerIntegrationTest.java
similarity index 98%
rename from spring-4/src/test/java/com/baeldung/flips/controller/FlipControllerTest.java
rename to flips/src/test/java/com/baeldung/flips/controller/FlipControllerIntegrationTest.java
index 8fd9c4e340..9dd4ef064a 100644
--- a/spring-4/src/test/java/com/baeldung/flips/controller/FlipControllerTest.java
+++ b/flips/src/test/java/com/baeldung/flips/controller/FlipControllerIntegrationTest.java
@@ -23,7 +23,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
}, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureMockMvc
@ActiveProfiles("dev")
-public class FlipControllerTest {
+public class FlipControllerIntegrationTest {
@Autowired private MockMvc mvc;
diff --git a/flyway/pom.xml b/flyway/pom.xml
index 3637f1de28..018f9b7f86 100644
--- a/flyway/pom.xml
+++ b/flyway/pom.xml
@@ -8,10 +8,10 @@
Flyway Callbacks Demo
- parent-boot-5
+ parent-boot-1
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-5
+ ../parent-boot-1
diff --git a/grpc/pom.xml b/grpc/pom.xml
index ad563f16fd..fb8312e8df 100644
--- a/grpc/pom.xml
+++ b/grpc/pom.xml
@@ -5,8 +5,6 @@
grpc-demo
0.0.1-SNAPSHOT
jar
- grpc-demo
- http://maven.apache.org
com.baeldung
diff --git a/guest/spring-mvc/pom.xml b/guest/spring-mvc/pom.xml
index 169b216ff9..da4d27b14d 100644
--- a/guest/spring-mvc/pom.xml
+++ b/guest/spring-mvc/pom.xml
@@ -27,28 +27,6 @@
-
-
- spring-milestones
- Spring Milestones
- https://repo.spring.io/milestone
-
- false
-
-
-
-
-
-
- spring-milestones
- Spring Milestones
- https://repo.spring.io/milestone
-
- false
-
-
-
-
UTF-8
UTF-8
diff --git a/guest/spring-security/pom.xml b/guest/spring-security/pom.xml
index 16e946d108..793df750de 100644
--- a/guest/spring-security/pom.xml
+++ b/guest/spring-security/pom.xml
@@ -45,28 +45,6 @@
-
-
- spring-milestones
- Spring Milestones
- https://repo.spring.io/milestone
-
- false
-
-
-
-
-
-
- spring-milestones
- Spring Milestones
- https://repo.spring.io/milestone
-
- false
-
-
-
-
UTF-8
UTF-8
diff --git a/hystrix/pom.xml b/hystrix/pom.xml
index 8e4a9b28b7..b17ca2bfd9 100644
--- a/hystrix/pom.xml
+++ b/hystrix/pom.xml
@@ -6,10 +6,10 @@
hystrix
- parent-boot-5
+ parent-boot-1
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-5
+ ../parent-boot-1
diff --git a/java-websocket/pom.xml b/java-websocket/pom.xml
index 461182e504..85078bd696 100644
--- a/java-websocket/pom.xml
+++ b/java-websocket/pom.xml
@@ -5,8 +5,6 @@
java-websocket
war
0.0.1-SNAPSHOT
- java-websocket Maven Webapp
- http://maven.apache.org
com.baeldung
diff --git a/jhipster/jhipster-microservice/car-app/pom.xml b/jhipster/jhipster-microservice/car-app/pom.xml
index 77e214234e..e5593bdbb9 100644
--- a/jhipster/jhipster-microservice/car-app/pom.xml
+++ b/jhipster/jhipster-microservice/car-app/pom.xml
@@ -3,10 +3,10 @@
4.0.0
- parent-boot-5
+ parent-boot-1
com.baeldung
0.0.1-SNAPSHOT
- ../../../parent-boot-5
+ ../../../parent-boot-1
com.car.app
diff --git a/jhipster/jhipster-microservice/dealer-app/pom.xml b/jhipster/jhipster-microservice/dealer-app/pom.xml
index beada8f064..3c21e0042f 100644
--- a/jhipster/jhipster-microservice/dealer-app/pom.xml
+++ b/jhipster/jhipster-microservice/dealer-app/pom.xml
@@ -3,10 +3,10 @@
4.0.0
- parent-boot-5
+ parent-boot-1
com.baeldung
0.0.1-SNAPSHOT
- ../../../parent-boot-5
+ ../../../parent-boot-1
com.dealer.app
diff --git a/jhipster/jhipster-microservice/gateway-app/pom.xml b/jhipster/jhipster-microservice/gateway-app/pom.xml
index d90addf51b..42808e26ce 100644
--- a/jhipster/jhipster-microservice/gateway-app/pom.xml
+++ b/jhipster/jhipster-microservice/gateway-app/pom.xml
@@ -3,10 +3,10 @@
4.0.0
- parent-boot-5
+ parent-boot-1
com.baeldung
0.0.1-SNAPSHOT
- ../../../parent-boot-5
+ ../../../parent-boot-1
com.gateway
diff --git a/jhipster/jhipster-monolithic/pom.xml b/jhipster/jhipster-monolithic/pom.xml
index fc8e8353b4..c8c9578fd6 100644
--- a/jhipster/jhipster-monolithic/pom.xml
+++ b/jhipster/jhipster-monolithic/pom.xml
@@ -3,10 +3,10 @@
4.0.0
- parent-boot-5
+ parent-boot-1
com.baeldung
0.0.1-SNAPSHOT
- ../../parent-boot-5
+ ../../parent-boot-1
com.baeldung
diff --git a/jjwt/pom.xml b/jjwt/pom.xml
index 51d4dcf1c0..2aa52b8818 100644
--- a/jjwt/pom.xml
+++ b/jjwt/pom.xml
@@ -10,10 +10,10 @@
Exercising the JJWT
- parent-boot-5
+ parent-boot-1
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-5
+ ../parent-boot-1
diff --git a/jmeter/pom.xml b/jmeter/pom.xml
index bb5769ef57..5f9509f0be 100644
--- a/jmeter/pom.xml
+++ b/jmeter/pom.xml
@@ -9,10 +9,10 @@
Intro to Performance testing using JMeter
- parent-boot-5
+ parent-boot-1
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-5
+ ../parent-boot-1
diff --git a/kotlin-js/README.md b/kotlin-js/README.md
new file mode 100644
index 0000000000..9ef8a999b4
--- /dev/null
+++ b/kotlin-js/README.md
@@ -0,0 +1,3 @@
+### Relevant articles
+
+- [Kotlin and Javascript](http://www.baeldung.com/kotlin-javascript)
diff --git a/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java b/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java
index 63cc4514c0..a8c15887be 100644
--- a/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java
+++ b/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java
@@ -10,8 +10,13 @@ import java.util.*;
public class Histogram {
+ private Map distributionMap;
+ private int classWidth;
+
public Histogram() {
+ distributionMap = new TreeMap();
+ classWidth = 10;
Map distributionMap = processRawData();
List yData = new ArrayList();
yData.addAll(distributionMap.values());
@@ -42,47 +47,49 @@ public class Histogram {
private Map processRawData() {
- List datasetList = Arrays.asList(36, 25, 38, 46, 55, 68, 72, 55, 36, 38, 67, 45, 22, 48, 91, 46, 52, 61, 58, 55);
+ List datasetList = Arrays.asList(
+ 36, 25, 38, 46, 55, 68, 72,
+ 55, 36, 38, 67, 45, 22, 48,
+ 91, 46, 52, 61, 58, 55);
Frequency frequency = new Frequency();
datasetList.forEach(d -> frequency.addValue(Double.parseDouble(d.toString())));
- int classWidth = 10;
+ datasetList.stream()
+ .map(d -> Double.parseDouble(d.toString()))
+ .distinct()
+ .forEach(observation -> {
+ long observationFrequency = frequency.getCount(observation);
+ int upperBoundary = (observation > classWidth)
+ ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth)
+ : classWidth;
+ int lowerBoundary = (upperBoundary > classWidth)
+ ? Math.subtractExact(upperBoundary, classWidth)
+ : 0;
+ String bin = lowerBoundary + "-" + upperBoundary;
- Map distributionMap = new TreeMap();
- List processed = new ArrayList();
- datasetList.forEach(d -> {
+ updateDistributionMap(lowerBoundary, bin, observationFrequency);
- double observation = Double.parseDouble(d.toString());
-
- if(processed.contains(observation))
- return;
-
- long observationFrequency = frequency.getCount(observation);
- int upperBoundary = (observation > classWidth) ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth) : classWidth;
- int lowerBoundary = (upperBoundary > classWidth) ? Math.subtractExact(upperBoundary, classWidth) : 0;
- String bin = lowerBoundary + "-" + upperBoundary;
-
- int prevUpperBoundary = lowerBoundary;
- int prevLowerBoundary = (lowerBoundary > classWidth) ? lowerBoundary - classWidth : 0;
- String prevBin = prevLowerBoundary + "-" + prevUpperBoundary;
- if(!distributionMap.containsKey(prevBin))
- distributionMap.put(prevBin, 0);
-
- if(!distributionMap.containsKey(bin)) {
- distributionMap.put(bin, observationFrequency);
- }
- else {
- long oldFrequency = Long.parseLong(distributionMap.get(bin).toString());
- distributionMap.replace(bin, oldFrequency + observationFrequency);
- }
-
- processed.add(observation);
-
- });
+ });
return distributionMap;
}
+ private void updateDistributionMap(int lowerBoundary, String bin, long observationFrequency) {
+
+ int prevLowerBoundary = (lowerBoundary > classWidth) ? lowerBoundary - classWidth : 0;
+ String prevBin = prevLowerBoundary + "-" + lowerBoundary;
+ if(!distributionMap.containsKey(prevBin))
+ distributionMap.put(prevBin, 0);
+
+ if(!distributionMap.containsKey(bin)) {
+ distributionMap.put(bin, observationFrequency);
+ }
+ else {
+ long oldFrequency = Long.parseLong(distributionMap.get(bin).toString());
+ distributionMap.replace(bin, oldFrequency + observationFrequency);
+ }
+ }
+
public static void main(String[] args) {
new Histogram();
}
diff --git a/mesos-marathon/pom.xml b/mesos-marathon/pom.xml
index 2b7a238ee8..77d13cd5c6 100644
--- a/mesos-marathon/pom.xml
+++ b/mesos-marathon/pom.xml
@@ -7,10 +7,10 @@
0.0.1-SNAPSHOT
- parent-boot-5
+ parent-boot-1
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-5
+ ../parent-boot-1
diff --git a/msf4j/pom.xml b/msf4j/pom.xml
new file mode 100644
index 0000000000..f691d746b7
--- /dev/null
+++ b/msf4j/pom.xml
@@ -0,0 +1,32 @@
+
+
+
+ org.wso2.msf4j
+ msf4j-service
+ 2.6.0
+
+ 4.0.0
+
+ com.baeldung.msf4j
+ msf4j
+ 0.0.1-SNAPSHOT
+ WSO2 MSF4J Microservice
+
+
+ com.baeldung.msf4j.msf4jintro.Application
+
+
+
+ org.wso2.msf4j
+ msf4j-spring
+ 2.6.1
+
+
+ org.wso2.msf4j
+ msf4j-mustache-template
+ 2.6.1
+
+
+
+
\ No newline at end of file
diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Application.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Application.java
new file mode 100644
index 0000000000..c4cf136536
--- /dev/null
+++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Application.java
@@ -0,0 +1,11 @@
+package com.baeldung.msf4j.msf4japi;
+
+import org.wso2.msf4j.MicroservicesRunner;
+
+public class Application {
+ public static void main(String[] args) {
+ new MicroservicesRunner()
+ .deploy(new MenuService())
+ .start();
+ }
+}
\ No newline at end of file
diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Meal.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Meal.java
new file mode 100644
index 0000000000..d17a7a1034
--- /dev/null
+++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Meal.java
@@ -0,0 +1,20 @@
+package com.baeldung.msf4j.msf4japi;
+
+public class Meal {
+ private String name;
+ private Float price;
+
+ public Meal(String name, Float price) {
+ this.name = name;
+ this.price = price;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Float getPrice() {
+ return price;
+ }
+
+}
diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/MenuService.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/MenuService.java
new file mode 100644
index 0000000000..4f880a1393
--- /dev/null
+++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/MenuService.java
@@ -0,0 +1,78 @@
+package com.baeldung.msf4j.msf4japi;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import com.google.gson.Gson;
+
+@Path("/menu")
+public class MenuService {
+
+ private List meals = new ArrayList();
+
+ public MenuService() {
+ meals.add(new Meal("Java beans",42.0f));
+ }
+
+ @GET
+ @Path("/")
+ @Produces({ "application/json" })
+ public Response index() {
+ return Response.ok()
+ .entity(meals)
+ .build();
+ }
+
+ @GET
+ @Path("/{id}")
+ @Produces({ "application/json" })
+ public Response meal(@PathParam("id") int id) {
+ return Response.ok()
+ .entity(meals.get(id))
+ .build();
+ }
+
+
+ @POST
+ @Path("/")
+ @Consumes("application/json")
+ @Produces({ "application/json" })
+ public Response create(Meal meal) {
+ meals.add(meal);
+ return Response.ok()
+ .entity(meal)
+ .build();
+ }
+
+ @PUT
+ @Path("/{id}")
+ @Consumes("application/json")
+ @Produces({ "application/json" })
+ public Response update(@PathParam("id") int id, Meal meal) {
+ meals.set(id, meal);
+ return Response.ok()
+ .entity(meal)
+ .build();
+ }
+
+ @DELETE
+ @Path("/{id}")
+ @Produces({ "application/json" })
+ public Response delete(@PathParam("id") int id) {
+ Meal meal = meals.get(id);
+ meals.remove(id);
+ return Response.ok()
+ .entity(meal)
+ .build();
+ }
+}
diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/Application.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/Application.java
new file mode 100644
index 0000000000..dc4a060056
--- /dev/null
+++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/Application.java
@@ -0,0 +1,11 @@
+package com.baeldung.msf4j.msf4jintro;
+
+import org.wso2.msf4j.MicroservicesRunner;
+
+public class Application {
+ public static void main(String[] args) {
+ new MicroservicesRunner()
+ .deploy(new SimpleService())
+ .start();
+ }
+}
\ No newline at end of file
diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/SimpleService.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/SimpleService.java
new file mode 100644
index 0000000000..bcb52859b5
--- /dev/null
+++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/SimpleService.java
@@ -0,0 +1,21 @@
+package com.baeldung.msf4j.msf4jintro;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+@Path("/")
+public class SimpleService {
+
+ @GET
+ public String index() {
+ return "Default content";
+ }
+
+ @GET
+ @Path("/say/{name}")
+ public String say(@PathParam("name") String name) {
+ return "Hello " + name;
+ }
+
+}
diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/Application.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/Application.java
new file mode 100644
index 0000000000..2a5232a7e6
--- /dev/null
+++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/Application.java
@@ -0,0 +1,10 @@
+package com.baeldung.msf4j.msf4jspring;
+
+import org.wso2.msf4j.spring.MSF4JSpringApplication;
+
+public class Application {
+
+ public static void main(String[] args) {
+ MSF4JSpringApplication.run(Application.class, args);
+ }
+}
\ No newline at end of file
diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/configuration/PortConfiguration.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/configuration/PortConfiguration.java
new file mode 100644
index 0000000000..c3313fc3b1
--- /dev/null
+++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/configuration/PortConfiguration.java
@@ -0,0 +1,15 @@
+package com.baeldung.msf4j.msf4jspring.configuration;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.wso2.msf4j.spring.transport.HTTPTransportConfig;
+
+@Configuration
+public class PortConfiguration {
+
+ @Bean
+ public HTTPTransportConfig http() {
+ return new HTTPTransportConfig(9090);
+ }
+
+}
\ No newline at end of file
diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/domain/Meal.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/domain/Meal.java
new file mode 100644
index 0000000000..99de0abc4c
--- /dev/null
+++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/domain/Meal.java
@@ -0,0 +1,20 @@
+package com.baeldung.msf4j.msf4jspring.domain;
+
+public class Meal {
+ private String name;
+ private Float price;
+
+ public Meal(String name, Float price) {
+ this.name = name;
+ this.price = price;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Float getPrice() {
+ return price;
+ }
+
+}
diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/repositories/MealRepository.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/repositories/MealRepository.java
new file mode 100644
index 0000000000..4d9e54348e
--- /dev/null
+++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/repositories/MealRepository.java
@@ -0,0 +1,37 @@
+package com.baeldung.msf4j.msf4jspring.repositories;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.springframework.stereotype.Component;
+import com.baeldung.msf4j.msf4jspring.domain.Meal;
+
+@Component
+public class MealRepository {
+
+ private List meals = new ArrayList();
+
+ public MealRepository() {
+ meals.add(new Meal("Salad", 4.2f));
+ meals.add(new Meal("Litre of cola", 2.99f));
+ }
+
+ public void create(Meal meal) {
+ meals.add(meal);
+ }
+
+ public void remove(Meal meal) {
+ meals.remove(meal);
+ }
+
+ public Meal find(int id) {
+ return meals.get(id);
+ }
+
+ public List findAll() {
+ return meals;
+ }
+
+ public void update(int id, Meal meal) {
+ meals.set(id, meal);
+ }
+}
\ No newline at end of file
diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/resources/MealResource.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/resources/MealResource.java
new file mode 100644
index 0000000000..9c617257cb
--- /dev/null
+++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/resources/MealResource.java
@@ -0,0 +1,47 @@
+package com.baeldung.msf4j.msf4jspring.resources;
+
+import java.util.Collections;
+import java.util.Map;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.wso2.msf4j.template.MustacheTemplateEngine;
+
+import com.baeldung.msf4j.msf4jspring.services.MealService;
+
+@Component
+@Path("/meal")
+public class MealResource {
+
+ @Autowired
+ private MealService mealService;
+
+ @GET
+ @Path("/")
+ public Response all() {
+ Map map = Collections.singletonMap("meals", mealService.findAll());
+ String html = MustacheTemplateEngine.instance()
+ .render("meals.mustache", map);
+ return Response.ok()
+ .type(MediaType.TEXT_HTML)
+ .entity(html)
+ .build();
+ }
+
+ @GET
+ @Path("/{id}")
+ @Produces({ "text/xml" })
+ public Response meal(@PathParam("id") int id) {
+ return Response.ok()
+ .entity(mealService.find(id))
+ .build();
+ }
+
+}
diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/services/MealService.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/services/MealService.java
new file mode 100644
index 0000000000..fd6a519999
--- /dev/null
+++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/services/MealService.java
@@ -0,0 +1,27 @@
+package com.baeldung.msf4j.msf4jspring.services;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.baeldung.msf4j.msf4jspring.domain.Meal;
+import com.baeldung.msf4j.msf4jspring.repositories.MealRepository;
+
+@Service
+public class MealService {
+ @Autowired
+ private MealRepository mealRepository;
+
+ public Meal find(int id) {
+ return mealRepository.find(id);
+ }
+
+ public List findAll() {
+ return mealRepository.findAll();
+ }
+
+ public void create(Meal meal) {
+ mealRepository.create(meal);
+ }
+}
diff --git a/msf4j/src/main/resources/application.properties b/msf4j/src/main/resources/application.properties
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/msf4j/src/main/resources/templates/meals.mustache b/msf4j/src/main/resources/templates/meals.mustache
new file mode 100644
index 0000000000..f4bdfaccf9
--- /dev/null
+++ b/msf4j/src/main/resources/templates/meals.mustache
@@ -0,0 +1,13 @@
+
+
+ Meals
+
+
+
+
Today's Meals
+ {{#meals}}
+
{{name}}: {{price}}$
+ {{/meals}}
+
+
+