diff --git a/algorithms/README.md b/algorithms/README.md
index 3401b6d935..31cb8076d9 100644
--- a/algorithms/README.md
+++ b/algorithms/README.md
@@ -16,3 +16,4 @@
- [Introduction to Minimax Algorithm](http://www.baeldung.com/java-minimax-algorithm)
- [How to Calculate Levenshtein Distance in Java?](http://www.baeldung.com/java-levenshtein-distance)
- [How to Find the Kth Largest Element in Java](http://www.baeldung.com/java-kth-largest-element)
+- [Multi-Swarm Optimization Algorithm in Java](http://www.baeldung.com/java-multi-swarm-algorithm)
diff --git a/algorithms/pom.xml b/algorithms/pom.xml
index 2eb8cd42b6..8751cf45c0 100644
--- a/algorithms/pom.xml
+++ b/algorithms/pom.xml
@@ -9,6 +9,7 @@
1.5.0
1.16.12
3.6.1
+ 1.0.1
@@ -39,6 +40,11 @@
jgrapht-core
1.0.1
+
+ pl.allegro.finance
+ tradukisto
+ ${tradukisto.version}
+
org.assertj
assertj-core
@@ -46,7 +52,6 @@
test
-
@@ -77,4 +82,4 @@
-
+
\ No newline at end of file
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/numberwordconverter/NumberWordConverter.java b/algorithms/src/main/java/com/baeldung/algorithms/numberwordconverter/NumberWordConverter.java
new file mode 100644
index 0000000000..0fe2960f96
--- /dev/null
+++ b/algorithms/src/main/java/com/baeldung/algorithms/numberwordconverter/NumberWordConverter.java
@@ -0,0 +1,75 @@
+package com.baeldung.algorithms.numberwordconverter;
+
+import java.math.BigDecimal;
+
+import pl.allegro.finance.tradukisto.MoneyConverters;
+
+public class NumberWordConverter {
+
+ public static final String INVALID_INPUT_GIVEN = "Invalid input given";
+
+ public static final String[] ones = { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
+
+ public static final String[] tens = {
+ "", // 0
+ "", // 1
+ "twenty", // 2
+ "thirty", // 3
+ "forty", // 4
+ "fifty", // 5
+ "sixty", // 6
+ "seventy", // 7
+ "eighty", // 8
+ "ninety" // 9
+ };
+
+ public static String getMoneyIntoWords(String input) {
+ MoneyConverters converter = MoneyConverters.ENGLISH_BANKING_MONEY_VALUE;
+ return converter.asWords(new BigDecimal(input));
+ }
+
+ public static String getMoneyIntoWords(final double money) {
+ long dollar = (long) money;
+ long cents = Math.round((money - dollar) * 100);
+ if (money == 0D) {
+ return "";
+ }
+ if (money < 0) {
+ return INVALID_INPUT_GIVEN;
+ }
+ String dollarPart = "";
+ if (dollar > 0) {
+ dollarPart = convert(dollar) + " dollar" + (dollar == 1 ? "" : "s");
+ }
+ String centsPart = "";
+ if (cents > 0) {
+ if (dollarPart.length() > 0) {
+ centsPart = " and ";
+ }
+ centsPart += convert(cents) + " cent" + (cents == 1 ? "" : "s");
+ }
+ return dollarPart + centsPart;
+ }
+
+ private static String convert(final long n) {
+ if (n < 0) {
+ return INVALID_INPUT_GIVEN;
+ }
+ if (n < 20) {
+ return ones[(int) n];
+ }
+ if (n < 100) {
+ return tens[(int) n / 10] + ((n % 10 != 0) ? " " : "") + ones[(int) n % 10];
+ }
+ if (n < 1000) {
+ return ones[(int) n / 100] + " hundred" + ((n % 100 != 0) ? " " : "") + convert(n % 100);
+ }
+ if (n < 1_000_000) {
+ return convert(n / 1000) + " thousand" + ((n % 1000 != 0) ? " " : "") + convert(n % 1000);
+ }
+ if (n < 1_000_000_000) {
+ return convert(n / 1_000_000) + " million" + ((n % 1_000_000 != 0) ? " " : "") + convert(n % 1_000_000);
+ }
+ return convert(n / 1_000_000_000) + " billion" + ((n % 1_000_000_000 != 0) ? " " : "") + convert(n % 1_000_000_000);
+ }
+}
\ No newline at end of file
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/moneywords/NumberWordConverterTest.java b/algorithms/src/test/java/com/baeldung/algorithms/moneywords/NumberWordConverterTest.java
new file mode 100644
index 0000000000..a4a169f158
--- /dev/null
+++ b/algorithms/src/test/java/com/baeldung/algorithms/moneywords/NumberWordConverterTest.java
@@ -0,0 +1,84 @@
+package com.baeldung.algorithms.moneywords;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.baeldung.algorithms.numberwordconverter.NumberWordConverter;
+
+public class NumberWordConverterTest {
+
+ @Test
+ public void whenMoneyNegative_thenReturnInvalidInput() {
+ assertEquals(NumberWordConverter.INVALID_INPUT_GIVEN, NumberWordConverter.getMoneyIntoWords(-13));
+ }
+
+ @Test
+ public void whenZeroDollarsGiven_thenReturnEmptyString() {
+ assertEquals("", NumberWordConverter.getMoneyIntoWords(0));
+ }
+
+ @Test
+ public void whenOnlyDollarsGiven_thenReturnWords() {
+ assertEquals("one dollar", NumberWordConverter.getMoneyIntoWords(1));
+ }
+
+ @Test
+ public void whenOnlyCentsGiven_thenReturnWords() {
+ assertEquals("sixty cents", NumberWordConverter.getMoneyIntoWords(0.6));
+ }
+
+ @Test
+ public void whenAlmostAMillioDollarsGiven_thenReturnWords() {
+ String expectedResult = "nine hundred ninety nine thousand nine hundred ninety nine dollars";
+ assertEquals(expectedResult, NumberWordConverter.getMoneyIntoWords(999_999));
+ }
+
+ @Test
+ public void whenThirtyMillionDollarsGiven_thenReturnWords() {
+ String expectedResult = "thirty three million three hundred forty eight thousand nine hundred seventy eight dollars";
+ assertEquals(expectedResult, NumberWordConverter.getMoneyIntoWords(33_348_978));
+ }
+
+ @Test
+ public void whenTwoBillionDollarsGiven_thenReturnWords() {
+ String expectedResult = "two billion one hundred thirty three million two hundred forty seven thousand eight hundred ten dollars";
+ assertEquals(expectedResult, NumberWordConverter.getMoneyIntoWords(2_133_247_810));
+ }
+
+ @Test
+ public void whenGivenDollarsAndCents_thenReturnWords() {
+ String expectedResult = "nine hundred twenty four dollars and sixty cents";
+ assertEquals(expectedResult, NumberWordConverter.getMoneyIntoWords(924.6));
+ }
+
+ @Test
+ public void whenOneDollarAndNoCents_thenReturnDollarSingular() {
+ assertEquals("one dollar", NumberWordConverter.getMoneyIntoWords(1));
+ }
+
+ @Test
+ public void whenNoDollarsAndOneCent_thenReturnCentSingular() {
+ assertEquals("one cent", NumberWordConverter.getMoneyIntoWords(0.01));
+ }
+
+ @Test
+ public void whenNoDollarsAndTwoCents_thenReturnCentsPlural() {
+ assertEquals("two cents", NumberWordConverter.getMoneyIntoWords(0.02));
+ }
+
+ @Test
+ public void whenNoDollarsAndNinetyNineCents_thenReturnWords() {
+ assertEquals("ninety nine cents", NumberWordConverter.getMoneyIntoWords(0.99));
+ }
+
+ @Test
+ public void whenNoDollarsAndNineFiveNineCents_thenCorrectRounding() {
+ assertEquals("ninety six cents", NumberWordConverter.getMoneyIntoWords(0.959));
+ }
+
+ @Test
+ public void whenGivenDollarsAndCents_thenReturnWordsVersionTwo() {
+ assertEquals("three hundred ten £ 00/100", NumberWordConverter.getMoneyIntoWords("310"));
+ }
+}
diff --git a/apache-curator/pom.xml b/apache-curator/pom.xml
index 36c3949b1a..35549861c8 100644
--- a/apache-curator/pom.xml
+++ b/apache-curator/pom.xml
@@ -18,6 +18,7 @@
3.6.1
+ 1.7.0
@@ -64,5 +65,12 @@
${assertj.version}
test
+
+
+ com.jayway.awaitility
+ awaitility
+ ${avaitility.version}
+ test
+
diff --git a/apache-curator/src/test/java/com/baeldung/apache/curator/configuration/ConfigurationManagementManualTest.java b/apache-curator/src/test/java/com/baeldung/apache/curator/configuration/ConfigurationManagementManualTest.java
index 0475f9c237..d02ef8131d 100644
--- a/apache-curator/src/test/java/com/baeldung/apache/curator/configuration/ConfigurationManagementManualTest.java
+++ b/apache-curator/src/test/java/com/baeldung/apache/curator/configuration/ConfigurationManagementManualTest.java
@@ -1,5 +1,6 @@
package com.baeldung.apache.curator.configuration;
+import static com.jayway.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
@@ -26,30 +27,27 @@ public class ConfigurationManagementManualTest extends BaseTest {
String expected = "my_value";
// Create key nodes structure
- client
- .create()
- .forPath(key);
+ client.create()
+ .forPath(key);
// Set data value for our key
- async
- .setData()
- .forPath(key, expected.getBytes());
+ async.setData()
+ .forPath(key, expected.getBytes());
// Get data value
AtomicBoolean isEquals = new AtomicBoolean();
- async
- .getData()
- .forPath(key)
- .thenAccept(data -> isEquals.set(new String(data).equals(expected)));
+ async.getData()
+ .forPath(key)
+ .thenAccept(
+ data -> isEquals.set(new String(data).equals(expected)));
- Thread.sleep(1000);
-
- assertThat(isEquals.get()).isTrue();
+ await().until(() -> assertThat(isEquals.get()).isTrue());
}
}
@Test
- public void givenPath_whenWatchAKeyAndStoreAValue_thenWatcherIsTriggered() throws Exception {
+ public void givenPath_whenWatchAKeyAndStoreAValue_thenWatcherIsTriggered()
+ throws Exception {
try (CuratorFramework client = newClient()) {
client.start();
AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
@@ -57,42 +55,35 @@ public class ConfigurationManagementManualTest extends BaseTest {
String expected = "my_value";
// Create key structure
- async
- .create()
- .forPath(key);
+ async.create()
+ .forPath(key);
List changes = new ArrayList<>();
// Watch data value
- async
- .watched()
- .getData()
- .forPath(key)
- .event()
- .thenAccept(watchedEvent -> {
- try {
- changes.add(new String(client
- .getData()
- .forPath(watchedEvent.getPath())));
- } catch (Exception e) {
- // fail ...
- }
- });
+ async.watched()
+ .getData()
+ .forPath(key)
+ .event()
+ .thenAccept(watchedEvent -> {
+ try {
+ changes.add(new String(client.getData()
+ .forPath(watchedEvent.getPath())));
+ } catch (Exception e) {
+ // fail ...
+ }
+ });
// Set data value for our key
- async
- .setData()
- .forPath(key, expected.getBytes());
+ async.setData()
+ .forPath(key, expected.getBytes());
- Thread.sleep(1000);
-
- assertThat(changes.size() > 0).isTrue();
+ await().until(() -> assertThat(changes.size() > 0).isTrue());
}
}
private String getKey() {
- return String.format(KEY_FORMAT, UUID
- .randomUUID()
- .toString());
+ return String.format(KEY_FORMAT, UUID.randomUUID()
+ .toString());
}
}
diff --git a/apache-curator/src/test/java/com/baeldung/apache/curator/connection/ConnectionManagementManualTest.java b/apache-curator/src/test/java/com/baeldung/apache/curator/connection/ConnectionManagementManualTest.java
index 931a977900..61fa1c7c2c 100644
--- a/apache-curator/src/test/java/com/baeldung/apache/curator/connection/ConnectionManagementManualTest.java
+++ b/apache-curator/src/test/java/com/baeldung/apache/curator/connection/ConnectionManagementManualTest.java
@@ -1,5 +1,6 @@
package com.baeldung.apache.curator.connection;
+import static com.jayway.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -14,56 +15,65 @@ import org.junit.Test;
public class ConnectionManagementManualTest {
@Test
- public void givenRunningZookeeper_whenOpenConnection_thenClientIsOpened() throws Exception {
+ public void givenRunningZookeeper_whenOpenConnection_thenClientIsOpened()
+ throws Exception {
int sleepMsBetweenRetries = 100;
int maxRetries = 3;
- RetryPolicy retryPolicy = new RetryNTimes(maxRetries, sleepMsBetweenRetries);
+ RetryPolicy retryPolicy = new RetryNTimes(maxRetries,
+ sleepMsBetweenRetries);
- try (CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy)) {
+ try (CuratorFramework client = CuratorFrameworkFactory
+ .newClient("127.0.0.1:2181", retryPolicy)) {
client.start();
- assertThat(client
- .checkExists()
- .forPath("/")).isNotNull();
+
+ assertThat(client.checkExists()
+ .forPath("/")).isNotNull();
}
}
@Test
- public void givenRunningZookeeper_whenOpenConnectionUsingAsyncNotBlocking_thenClientIsOpened() throws InterruptedException {
+ public void givenRunningZookeeper_whenOpenConnectionUsingAsyncNotBlocking_thenClientIsOpened()
+ throws InterruptedException {
int sleepMsBetweenRetries = 100;
int maxRetries = 3;
- RetryPolicy retryPolicy = new RetryNTimes(maxRetries, sleepMsBetweenRetries);
+ RetryPolicy retryPolicy = new RetryNTimes(maxRetries,
+ sleepMsBetweenRetries);
- try (CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy)) {
+ try (CuratorFramework client = CuratorFrameworkFactory
+ .newClient("127.0.0.1:2181", retryPolicy)) {
client.start();
AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
AtomicBoolean exists = new AtomicBoolean(false);
- async
- .checkExists()
- .forPath("/")
- .thenAcceptAsync(s -> exists.set(s != null));
- Thread.sleep(100);
- assertThat(exists.get()).isTrue();
+
+ async.checkExists()
+ .forPath("/")
+ .thenAcceptAsync(s -> exists.set(s != null));
+
+ await().until(() -> assertThat(exists.get()).isTrue());
}
}
@Test
- public void givenRunningZookeeper_whenOpenConnectionUsingAsyncBlocking_thenClientIsOpened() throws InterruptedException {
+ public void givenRunningZookeeper_whenOpenConnectionUsingAsyncBlocking_thenClientIsOpened()
+ throws InterruptedException {
int sleepMsBetweenRetries = 100;
int maxRetries = 3;
- RetryPolicy retryPolicy = new RetryNTimes(maxRetries, sleepMsBetweenRetries);
+ RetryPolicy retryPolicy = new RetryNTimes(maxRetries,
+ sleepMsBetweenRetries);
- try (CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy)) {
+ try (CuratorFramework client = CuratorFrameworkFactory
+ .newClient("127.0.0.1:2181", retryPolicy)) {
client.start();
AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
AtomicBoolean exists = new AtomicBoolean(false);
- async
- .checkExists()
- .forPath("/")
- .thenAccept(s -> exists.set(s != null));
- Thread.sleep(100);
- assertThat(exists.get()).isTrue();
+
+ async.checkExists()
+ .forPath("/")
+ .thenAccept(s -> exists.set(s != null));
+
+ await().until(() -> assertThat(exists.get()).isTrue());
}
}
}
diff --git a/apache-curator/src/test/java/com/baeldung/apache/curator/modeled/ModelTypedExamplesManualTest.java b/apache-curator/src/test/java/com/baeldung/apache/curator/modeled/ModelTypedExamplesManualTest.java
index 9d00c0a4c2..4400c1d1aa 100644
--- a/apache-curator/src/test/java/com/baeldung/apache/curator/modeled/ModelTypedExamplesManualTest.java
+++ b/apache-curator/src/test/java/com/baeldung/apache/curator/modeled/ModelTypedExamplesManualTest.java
@@ -16,31 +16,33 @@ import com.baeldung.apache.curator.BaseTest;
public class ModelTypedExamplesManualTest extends BaseTest {
@Test
- public void givenPath_whenStoreAModel_thenNodesAreCreated() throws InterruptedException {
+ public void givenPath_whenStoreAModel_thenNodesAreCreated()
+ throws InterruptedException {
ModelSpec mySpec = ModelSpec
- .builder(ZPath.parseWithIds("/config/dev"), JacksonModelSerializer.build(HostConfig.class))
- .build();
+ .builder(ZPath.parseWithIds("/config/dev"),
+ JacksonModelSerializer.build(HostConfig.class))
+ .build();
try (CuratorFramework client = newClient()) {
client.start();
AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
- ModeledFramework modeledClient = ModeledFramework.wrap(async, mySpec);
+ ModeledFramework modeledClient = ModeledFramework
+ .wrap(async, mySpec);
modeledClient.set(new HostConfig("host-name", 8080));
- modeledClient
- .read()
- .whenComplete((value, e) -> {
- if (e != null) {
- fail("Cannot read host config", e);
- } else {
- assertThat(value).isNotNull();
- assertThat(value.getHostname()).isEqualTo("host-name");
- assertThat(value.getPort()).isEqualTo(8080);
- }
+ modeledClient.read()
+ .whenComplete((value, e) -> {
+ if (e != null) {
+ fail("Cannot read host config", e);
+ } else {
+ assertThat(value).isNotNull();
+ assertThat(value.getHostname()).isEqualTo("host-name");
+ assertThat(value.getPort()).isEqualTo(8080);
+ }
- });
+ });
}
}
diff --git a/core-java/src/main/java/com/baeldung/array/Find2ndLargestInArray.java b/core-java/src/main/java/com/baeldung/array/Find2ndLargestInArray.java
new file mode 100644
index 0000000000..d424bd429f
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/array/Find2ndLargestInArray.java
@@ -0,0 +1,20 @@
+package com.baeldung.array;
+
+public class Find2ndLargestInArray {
+
+ public static int find2ndLargestElement(int[] array) {
+ int maxElement = array[0];
+ int secondLargestElement = -1;
+
+ for (int index = 0; index < array.length; index++) {
+ if (maxElement <= array[index]) {
+ secondLargestElement = maxElement;
+ maxElement = array[index];
+ } else if (secondLargestElement < array[index]) {
+ secondLargestElement = array[index];
+ }
+ }
+ return secondLargestElement;
+ }
+
+}
diff --git a/core-java/src/main/java/com/baeldung/array/FindElementInArray.java b/core-java/src/main/java/com/baeldung/array/FindElementInArray.java
new file mode 100644
index 0000000000..6da889fe91
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/array/FindElementInArray.java
@@ -0,0 +1,22 @@
+package com.baeldung.array;
+
+import java.util.Arrays;
+
+public class FindElementInArray {
+
+ public static boolean findGivenElementInArrayWithoutUsingStream(int[] array, int element) {
+ boolean actualResult = false;
+
+ for (int index = 0; index < array.length; index++) {
+ if (element == array[index]) {
+ actualResult = true;
+ break;
+ }
+ }
+ return actualResult;
+ }
+
+ public static boolean findGivenElementInArrayUsingStream(int[] array, int element) {
+ return Arrays.stream(array).filter(x -> element == x).findFirst().isPresent();
+ }
+}
diff --git a/core-java/src/main/java/com/baeldung/array/SumAndAverageInArray.java b/core-java/src/main/java/com/baeldung/array/SumAndAverageInArray.java
new file mode 100644
index 0000000000..e7d7172fdb
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/array/SumAndAverageInArray.java
@@ -0,0 +1,27 @@
+package com.baeldung.array;
+
+import java.util.Arrays;
+
+public class SumAndAverageInArray {
+
+ public static int findSumWithoutUsingStream(int[] array) {
+ int sum = 0;
+ for (int index = 0; index < array.length; index++) {
+ sum += array[index];
+ }
+ return sum;
+ }
+
+ public static int findSumUsingStream(int[] array) {
+ return Arrays.stream(array).sum();
+ }
+
+ public static double findAverageWithoutUsingStream(int[] array) {
+ int sum = findSumWithoutUsingStream(array);
+ return (double) sum / array.length;
+ }
+
+ public static double findAverageUsingStream(int[] array) {
+ return Arrays.stream(array).average().getAsDouble();
+ }
+}
diff --git a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/AuthenticationProvider.java b/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/AuthenticationProvider.java
deleted file mode 100644
index 552a7ff6d9..0000000000
--- a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/AuthenticationProvider.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.baeldung.designpatterns.chainofresponsibility;
-
-public interface AuthenticationProvider {
-
-}
diff --git a/core-java/src/test/java/com/baeldung/array/Find2ndLargestInArrayTest.java b/core-java/src/test/java/com/baeldung/array/Find2ndLargestInArrayTest.java
new file mode 100644
index 0000000000..ec916af092
--- /dev/null
+++ b/core-java/src/test/java/com/baeldung/array/Find2ndLargestInArrayTest.java
@@ -0,0 +1,16 @@
+package com.baeldung.array;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class Find2ndLargestInArrayTest {
+ @Test
+ public void givenAnIntArray_thenFind2ndLargestElement() {
+ int[] array = { 1, 3, 24, 16, 87, 20 };
+ int expected2ndLargest = 24;
+
+ int actualSecondLargestElement = Find2ndLargestInArray.find2ndLargestElement(array);
+
+ Assert.assertEquals(expected2ndLargest, actualSecondLargestElement);
+ }
+}
diff --git a/core-java/src/test/java/com/baeldung/array/FindElementInArrayTest.java b/core-java/src/test/java/com/baeldung/array/FindElementInArrayTest.java
new file mode 100644
index 0000000000..ba9188fa7b
--- /dev/null
+++ b/core-java/src/test/java/com/baeldung/array/FindElementInArrayTest.java
@@ -0,0 +1,35 @@
+package com.baeldung.array;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class FindElementInArrayTest {
+ @Test
+ public void givenAnIntArray_whenNotUsingStream_thenFindAnElement() {
+ int[] array = { 1, 3, 4, 8, 19, 20 };
+ int element = 19;
+ boolean expectedResult = true;
+ boolean actualResult = FindElementInArray.findGivenElementInArrayWithoutUsingStream(array, element);
+ Assert.assertEquals(expectedResult, actualResult);
+
+ element = 78;
+ expectedResult = false;
+ actualResult = FindElementInArray.findGivenElementInArrayWithoutUsingStream(array, element);
+ Assert.assertEquals(expectedResult, actualResult);
+ }
+
+ @Test
+ public void givenAnIntArray_whenUsingStream_thenFindAnElement() {
+ int[] array = { 15, 16, 12, 18 };
+ int element = 16;
+ boolean expectedResult = true;
+ boolean actualResult = FindElementInArray.findGivenElementInArrayUsingStream(array, element);
+ Assert.assertEquals(expectedResult, actualResult);
+
+ element = 20;
+ expectedResult = false;
+ actualResult = FindElementInArray.findGivenElementInArrayUsingStream(array, element);
+ Assert.assertEquals(expectedResult, actualResult);
+ }
+
+}
diff --git a/core-java/src/test/java/com/baeldung/array/SumAndAverageInArrayTest.java b/core-java/src/test/java/com/baeldung/array/SumAndAverageInArrayTest.java
new file mode 100644
index 0000000000..3385ed690f
--- /dev/null
+++ b/core-java/src/test/java/com/baeldung/array/SumAndAverageInArrayTest.java
@@ -0,0 +1,41 @@
+package com.baeldung.array;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SumAndAverageInArrayTest {
+ @Test
+ public void givenAnIntArray_whenNotUsingStream_thenFindSum() {
+ int[] array = { 1, 3, 4, 8, 19, 20 };
+ int expectedSumOfArray = 55;
+ int actualSumOfArray = SumAndAverageInArray.findSumWithoutUsingStream(array);
+ Assert.assertEquals(expectedSumOfArray, actualSumOfArray);
+ }
+
+ @Test
+ public void givenAnIntArray_whenUsingStream_thenFindSum() {
+ int[] array = { 1, 3, 4, 8, 19, 20 };
+ int expectedSumOfArray = 55;
+ int actualSumOfArray = SumAndAverageInArray.findSumUsingStream(array);
+
+ Assert.assertEquals(expectedSumOfArray, actualSumOfArray);
+ }
+
+ @Test
+ public void givenAnIntArray_whenNotUsingStream_thenFindAverage() {
+ int[] array = { 1, 3, 4, 8, 19, 20 };
+ double expectedAvgOfArray = 9.17;
+ double actualAvgOfArray = SumAndAverageInArray.findAverageWithoutUsingStream(array);
+
+ Assert.assertEquals(expectedAvgOfArray, actualAvgOfArray, 0.0034);
+ }
+
+ @Test
+ public void givenAnIntArray_whenUsingStream_thenFindAverage() {
+ int[] array = { 1, 3, 4, 8, 19, 20 };
+ double expectedAvgOfArray = 9.17;
+ double actualAvgOfArray = SumAndAverageInArray.findAverageUsingStream(array);
+
+ Assert.assertEquals(expectedAvgOfArray, actualAvgOfArray, 0.0034);
+ }
+}
diff --git a/core-kotlin/README.md b/core-kotlin/README.md
index 7f68648eba..b8cea19c58 100644
--- a/core-kotlin/README.md
+++ b/core-kotlin/README.md
@@ -20,3 +20,4 @@
- [Infix Functions in Kotlin](http://www.baeldung.com/kotlin-infix-functions)
- [Try-with-resources in Kotlin](http://www.baeldung.com/kotlin-try-with-resources)
- [HTTP Requests with Kotlin and khttp](http://www.baeldung.com/kotlin-khttp)
+- [Kotlin Dependency Injection with Kodein](http://www.baeldung.com/kotlin-kodein-dependency-injection)
diff --git a/intelliJ/README.md b/intelliJ/README.md
deleted file mode 100644
index ff12555376..0000000000
--- a/intelliJ/README.md
+++ /dev/null
@@ -1 +0,0 @@
-## Relevant articles:
diff --git a/jsonld/.gitignore b/jsonld/.gitignore
deleted file mode 100644
index 2af7cefb0a..0000000000
--- a/jsonld/.gitignore
+++ /dev/null
@@ -1,24 +0,0 @@
-target/
-!.mvn/wrapper/maven-wrapper.jar
-
-### STS ###
-.apt_generated
-.classpath
-.factorypath
-.project
-.settings
-.springBeans
-
-### IntelliJ IDEA ###
-.idea
-*.iws
-*.iml
-*.ipr
-
-### NetBeans ###
-nbproject/private/
-build/
-nbbuild/
-dist/
-nbdist/
-.nb-gradle/
\ No newline at end of file
diff --git a/jsonld/.mvn/wrapper/maven-wrapper.jar b/jsonld/.mvn/wrapper/maven-wrapper.jar
deleted file mode 100644
index 5fd4d5023f..0000000000
Binary files a/jsonld/.mvn/wrapper/maven-wrapper.jar and /dev/null differ
diff --git a/jsonld/.mvn/wrapper/maven-wrapper.properties b/jsonld/.mvn/wrapper/maven-wrapper.properties
deleted file mode 100644
index c954cec91c..0000000000
--- a/jsonld/.mvn/wrapper/maven-wrapper.properties
+++ /dev/null
@@ -1 +0,0 @@
-distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
diff --git a/jsonld/README.md b/jsonld/README.md
deleted file mode 100644
index 51ca961bea..0000000000
--- a/jsonld/README.md
+++ /dev/null
@@ -1,22 +0,0 @@
-JSON-LD
-=======
-
-Hypermedia serialization with JSON-LD.
-
-### Requirements
-
-- Maven
-- JDK 8
-- JSON-LD
-
-### Running
-To build and start the server simply type
-
-```bash
-$ mvn clean install
-$ mvn spring-boot:run
-```
-
-Now with default configurations it will be available at: [http://localhost:8080](http://localhost:8080)
-
-Enjoy it :)
\ No newline at end of file
diff --git a/jsonld/mvnw b/jsonld/mvnw
deleted file mode 100755
index a1ba1bf554..0000000000
--- a/jsonld/mvnw
+++ /dev/null
@@ -1,233 +0,0 @@
-#!/bin/sh
-# ----------------------------------------------------------------------------
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-# ----------------------------------------------------------------------------
-
-# ----------------------------------------------------------------------------
-# Maven2 Start Up Batch script
-#
-# Required ENV vars:
-# ------------------
-# JAVA_HOME - location of a JDK home dir
-#
-# Optional ENV vars
-# -----------------
-# M2_HOME - location of maven2's installed home dir
-# MAVEN_OPTS - parameters passed to the Java VM when running Maven
-# e.g. to debug Maven itself, use
-# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
-# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
-# ----------------------------------------------------------------------------
-
-if [ -z "$MAVEN_SKIP_RC" ] ; then
-
- if [ -f /etc/mavenrc ] ; then
- . /etc/mavenrc
- fi
-
- if [ -f "$HOME/.mavenrc" ] ; then
- . "$HOME/.mavenrc"
- fi
-
-fi
-
-# OS specific support. $var _must_ be set to either true or false.
-cygwin=false;
-darwin=false;
-mingw=false
-case "`uname`" in
- CYGWIN*) cygwin=true ;;
- MINGW*) mingw=true;;
- Darwin*) darwin=true
- #
- # Look for the Apple JDKs first to preserve the existing behaviour, and then look
- # for the new JDKs provided by Oracle.
- #
- if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
- #
- # Apple JDKs
- #
- export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
- fi
-
- if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
- #
- # Apple JDKs
- #
- export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
- fi
-
- if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
- #
- # Oracle JDKs
- #
- export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
- fi
-
- if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
- #
- # Apple JDKs
- #
- export JAVA_HOME=`/usr/libexec/java_home`
- fi
- ;;
-esac
-
-if [ -z "$JAVA_HOME" ] ; then
- if [ -r /etc/gentoo-release ] ; then
- JAVA_HOME=`java-config --jre-home`
- fi
-fi
-
-if [ -z "$M2_HOME" ] ; then
- ## resolve links - $0 may be a link to maven's home
- PRG="$0"
-
- # need this for relative symlinks
- while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG="`dirname "$PRG"`/$link"
- fi
- done
-
- saveddir=`pwd`
-
- M2_HOME=`dirname "$PRG"`/..
-
- # make it fully qualified
- M2_HOME=`cd "$M2_HOME" && pwd`
-
- cd "$saveddir"
- # echo Using m2 at $M2_HOME
-fi
-
-# For Cygwin, ensure paths are in UNIX format before anything is touched
-if $cygwin ; then
- [ -n "$M2_HOME" ] &&
- M2_HOME=`cygpath --unix "$M2_HOME"`
- [ -n "$JAVA_HOME" ] &&
- JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
- [ -n "$CLASSPATH" ] &&
- CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
-fi
-
-# For Migwn, ensure paths are in UNIX format before anything is touched
-if $mingw ; then
- [ -n "$M2_HOME" ] &&
- M2_HOME="`(cd "$M2_HOME"; pwd)`"
- [ -n "$JAVA_HOME" ] &&
- JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
- # TODO classpath?
-fi
-
-if [ -z "$JAVA_HOME" ]; then
- javaExecutable="`which javac`"
- if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
- # readlink(1) is not available as standard on Solaris 10.
- readLink=`which readlink`
- if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
- if $darwin ; then
- javaHome="`dirname \"$javaExecutable\"`"
- javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
- else
- javaExecutable="`readlink -f \"$javaExecutable\"`"
- fi
- javaHome="`dirname \"$javaExecutable\"`"
- javaHome=`expr "$javaHome" : '\(.*\)/bin'`
- JAVA_HOME="$javaHome"
- export JAVA_HOME
- fi
- fi
-fi
-
-if [ -z "$JAVACMD" ] ; then
- if [ -n "$JAVA_HOME" ] ; then
- if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
- # IBM's JDK on AIX uses strange locations for the executables
- JAVACMD="$JAVA_HOME/jre/sh/java"
- else
- JAVACMD="$JAVA_HOME/bin/java"
- fi
- else
- JAVACMD="`which java`"
- fi
-fi
-
-if [ ! -x "$JAVACMD" ] ; then
- echo "Error: JAVA_HOME is not defined correctly." >&2
- echo " We cannot execute $JAVACMD" >&2
- exit 1
-fi
-
-if [ -z "$JAVA_HOME" ] ; then
- echo "Warning: JAVA_HOME environment variable is not set."
-fi
-
-CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
-
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin; then
- [ -n "$M2_HOME" ] &&
- M2_HOME=`cygpath --path --windows "$M2_HOME"`
- [ -n "$JAVA_HOME" ] &&
- JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
- [ -n "$CLASSPATH" ] &&
- CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
-fi
-
-# traverses directory structure from process work directory to filesystem root
-# first directory with .mvn subdirectory is considered project base directory
-find_maven_basedir() {
- local basedir=$(pwd)
- local wdir=$(pwd)
- while [ "$wdir" != '/' ] ; do
- if [ -d "$wdir"/.mvn ] ; then
- basedir=$wdir
- break
- fi
- wdir=$(cd "$wdir/.."; pwd)
- done
- echo "${basedir}"
-}
-
-# concatenates all lines of a file
-concat_lines() {
- if [ -f "$1" ]; then
- echo "$(tr -s '\n' ' ' < "$1")"
- fi
-}
-
-export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
-MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
-
-# Provide a "standardized" way to retrieve the CLI args that will
-# work with both Windows and non-Windows executions.
-MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
-export MAVEN_CMD_LINE_ARGS
-
-WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
-
-exec "$JAVACMD" \
- $MAVEN_OPTS \
- -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
- "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
- ${WRAPPER_LAUNCHER} "$@"
diff --git a/jsonld/mvnw.cmd b/jsonld/mvnw.cmd
deleted file mode 100644
index 2b934e89dd..0000000000
--- a/jsonld/mvnw.cmd
+++ /dev/null
@@ -1,145 +0,0 @@
-@REM ----------------------------------------------------------------------------
-@REM Licensed to the Apache Software Foundation (ASF) under one
-@REM or more contributor license agreements. See the NOTICE file
-@REM distributed with this work for additional information
-@REM regarding copyright ownership. The ASF licenses this file
-@REM to you under the Apache License, Version 2.0 (the
-@REM "License"); you may not use this file except in compliance
-@REM with the License. You may obtain a copy of the License at
-@REM
-@REM http://www.apache.org/licenses/LICENSE-2.0
-@REM
-@REM Unless required by applicable law or agreed to in writing,
-@REM software distributed under the License is distributed on an
-@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-@REM KIND, either express or implied. See the License for the
-@REM specific language governing permissions and limitations
-@REM under the License.
-@REM ----------------------------------------------------------------------------
-
-@REM ----------------------------------------------------------------------------
-@REM Maven2 Start Up Batch script
-@REM
-@REM Required ENV vars:
-@REM JAVA_HOME - location of a JDK home dir
-@REM
-@REM Optional ENV vars
-@REM M2_HOME - location of maven2's installed home dir
-@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
-@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
-@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
-@REM e.g. to debug Maven itself, use
-@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
-@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
-@REM ----------------------------------------------------------------------------
-
-@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
-@echo off
-@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
-@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
-
-@REM set %HOME% to equivalent of $HOME
-if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
-
-@REM Execute a user defined script before this one
-if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
-@REM check for pre script, once with legacy .bat ending and once with .cmd ending
-if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
-if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
-:skipRcPre
-
-@setlocal
-
-set ERROR_CODE=0
-
-@REM To isolate internal variables from possible post scripts, we use another setlocal
-@setlocal
-
-@REM ==== START VALIDATION ====
-if not "%JAVA_HOME%" == "" goto OkJHome
-
-echo.
-echo Error: JAVA_HOME not found in your environment. >&2
-echo Please set the JAVA_HOME variable in your environment to match the >&2
-echo location of your Java installation. >&2
-echo.
-goto error
-
-:OkJHome
-if exist "%JAVA_HOME%\bin\java.exe" goto init
-
-echo.
-echo Error: JAVA_HOME is set to an invalid directory. >&2
-echo JAVA_HOME = "%JAVA_HOME%" >&2
-echo Please set the JAVA_HOME variable in your environment to match the >&2
-echo location of your Java installation. >&2
-echo.
-goto error
-
-@REM ==== END VALIDATION ====
-
-:init
-
-set MAVEN_CMD_LINE_ARGS=%*
-
-@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
-@REM Fallback to current working directory if not found.
-
-set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
-IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
-
-set EXEC_DIR=%CD%
-set WDIR=%EXEC_DIR%
-:findBaseDir
-IF EXIST "%WDIR%"\.mvn goto baseDirFound
-cd ..
-IF "%WDIR%"=="%CD%" goto baseDirNotFound
-set WDIR=%CD%
-goto findBaseDir
-
-:baseDirFound
-set MAVEN_PROJECTBASEDIR=%WDIR%
-cd "%EXEC_DIR%"
-goto endDetectBaseDir
-
-:baseDirNotFound
-set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
-cd "%EXEC_DIR%"
-
-:endDetectBaseDir
-
-IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
-
-@setlocal EnableExtensions EnableDelayedExpansion
-for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
-@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
-
-:endReadAdditionalConfig
-
-SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
-
-set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar""
-set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
-
-%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
-if ERRORLEVEL 1 goto error
-goto end
-
-:error
-set ERROR_CODE=1
-
-:end
-@endlocal & set ERROR_CODE=%ERROR_CODE%
-
-if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
-@REM check for post script, once with legacy .bat ending and once with .cmd ending
-if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
-if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
-:skipRcPost
-
-@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
-if "%MAVEN_BATCH_PAUSE%" == "on" pause
-
-if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
-
-exit /B %ERROR_CODE%
\ No newline at end of file
diff --git a/jsonld/pom.xml b/jsonld/pom.xml
deleted file mode 100644
index 1574878667..0000000000
--- a/jsonld/pom.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-
-
- 4.0.0
-
- jsonld
- 0.0.1-SNAPSHOT
- jar
-
- jsonld
- Hypermedia serialization with JSON-LD
-
-
- parent-boot-5
- com.baeldung
- 0.0.1-SNAPSHOT
- ../parent-boot-5
-
-
-
- UTF-8
- UTF-8
- 1.8
- 0.11.1
-
-
-
-
- org.springframework.boot
- spring-boot-starter
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
-
- com.github.jsonld-java
- jsonld-java
- ${jsonld.version}
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
-
diff --git a/jsonld/src/main/java/com/baeldung/JsonLdApplication.java b/jsonld/src/main/java/com/baeldung/JsonLdApplication.java
deleted file mode 100644
index 0b8f338127..0000000000
--- a/jsonld/src/main/java/com/baeldung/JsonLdApplication.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.baeldung;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-@SpringBootApplication
-public class JsonLdApplication {
- public static void main(String[] args) {
- SpringApplication.run(JsonLdApplication.class, args);
- }
-}
diff --git a/jsonld/src/main/resources/application.properties b/jsonld/src/main/resources/application.properties
deleted file mode 100644
index b6bfd8f6f3..0000000000
--- a/jsonld/src/main/resources/application.properties
+++ /dev/null
@@ -1,14 +0,0 @@
-# the db host
-spring.data.mongodb.host=localhost
-# the connection port (defaults to 27107)
-spring.data.mongodb.port=27017
-# The database's name
-spring.data.mongodb.database=Jenkins-Pipeline
-
-# Or this
-# spring.data.mongodb.uri=mongodb://localhost/Jenkins-Pipeline
-
-# spring.data.mongodb.username=
-# spring.data.mongodb.password=
-
-spring.data.mongodb.repositories.enabled=true
\ No newline at end of file
diff --git a/jsonld/src/test/java/com/baeldung/JsonLdSerializatorTest.java b/jsonld/src/test/java/com/baeldung/JsonLdSerializatorTest.java
deleted file mode 100644
index 762a4254dc..0000000000
--- a/jsonld/src/test/java/com/baeldung/JsonLdSerializatorTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.baeldung;
-
-import com.github.jsonldjava.core.JsonLdError;
-import com.github.jsonldjava.core.JsonLdOptions;
-import com.github.jsonldjava.core.JsonLdProcessor;
-import com.github.jsonldjava.utils.JsonUtils;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.assertNotEquals;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@SpringBootTest
-public class JsonLdSerializatorTest {
-
- @Test
- public void whenInserting_andCount_thenWeDontGetZero() throws JsonLdError {
- String inputStream = "{name:}";
- Object jsonObject = JsonUtils.fromInputStream(inputStream);
-
- Map context = new HashMap();
- JsonLdOptions options = new JsonLdOptions();
- Object compact = JsonLdProcessor.compact(jsonObject, context, options);
-
- assertNotEquals(0, 0);
- }
-
-}
diff --git a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/AuthenticationProcessor.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/AuthenticationProcessor.java
similarity index 85%
rename from core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/AuthenticationProcessor.java
rename to patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/AuthenticationProcessor.java
index b86a572393..374de31ba9 100644
--- a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/AuthenticationProcessor.java
+++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/AuthenticationProcessor.java
@@ -1,4 +1,4 @@
-package com.baeldung.designpatterns.chainofresponsibility;
+package com.baeldung.pattern.chainofresponsibility;
public abstract class AuthenticationProcessor {
diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/AuthenticationProvider.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/AuthenticationProvider.java
new file mode 100644
index 0000000000..7b8771ca41
--- /dev/null
+++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/AuthenticationProvider.java
@@ -0,0 +1,5 @@
+package com.baeldung.pattern.chainofresponsibility;
+
+public interface AuthenticationProvider {
+
+}
diff --git a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/OAuthAuthenticationProcessor.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/OAuthAuthenticationProcessor.java
similarity index 90%
rename from core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/OAuthAuthenticationProcessor.java
rename to patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/OAuthAuthenticationProcessor.java
index 2e2e51fed2..3bf20cfc85 100644
--- a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/OAuthAuthenticationProcessor.java
+++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/OAuthAuthenticationProcessor.java
@@ -1,4 +1,4 @@
-package com.baeldung.designpatterns.chainofresponsibility;
+package com.baeldung.pattern.chainofresponsibility;
public class OAuthAuthenticationProcessor extends AuthenticationProcessor {
diff --git a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/OAuthTokenProvider.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/OAuthTokenProvider.java
similarity index 54%
rename from core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/OAuthTokenProvider.java
rename to patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/OAuthTokenProvider.java
index d4e516053b..92d5f94245 100644
--- a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/OAuthTokenProvider.java
+++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/OAuthTokenProvider.java
@@ -1,4 +1,4 @@
-package com.baeldung.designpatterns.chainofresponsibility;
+package com.baeldung.pattern.chainofresponsibility;
public class OAuthTokenProvider implements AuthenticationProvider {
diff --git a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/SamlAuthenticationProvider.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/SamlAuthenticationProvider.java
similarity index 57%
rename from core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/SamlAuthenticationProvider.java
rename to patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/SamlAuthenticationProvider.java
index 533b2b4a2d..cd927932ad 100644
--- a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/SamlAuthenticationProvider.java
+++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/SamlAuthenticationProvider.java
@@ -1,4 +1,4 @@
-package com.baeldung.designpatterns.chainofresponsibility;
+package com.baeldung.pattern.chainofresponsibility;
public class SamlAuthenticationProvider implements AuthenticationProvider {
diff --git a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/UsernamePasswordAuthenticationProcessor.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/UsernamePasswordAuthenticationProcessor.java
similarity index 90%
rename from core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/UsernamePasswordAuthenticationProcessor.java
rename to patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/UsernamePasswordAuthenticationProcessor.java
index df600c35db..3885b2b79b 100644
--- a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/UsernamePasswordAuthenticationProcessor.java
+++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/UsernamePasswordAuthenticationProcessor.java
@@ -1,4 +1,4 @@
-package com.baeldung.designpatterns.chainofresponsibility;
+package com.baeldung.pattern.chainofresponsibility;
public class UsernamePasswordAuthenticationProcessor extends AuthenticationProcessor {
diff --git a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/UsernamePasswordProvider.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/UsernamePasswordProvider.java
similarity index 56%
rename from core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/UsernamePasswordProvider.java
rename to patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/UsernamePasswordProvider.java
index 9fbfa7554d..9877039446 100644
--- a/core-java/src/main/java/com/baeldung/designpatterns/chainofresponsibility/UsernamePasswordProvider.java
+++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/UsernamePasswordProvider.java
@@ -1,4 +1,4 @@
-package com.baeldung.designpatterns.chainofresponsibility;
+package com.baeldung.pattern.chainofresponsibility;
public class UsernamePasswordProvider implements AuthenticationProvider {
diff --git a/core-java/src/test/java/com/baeldung/designpatterns/chainofresponsibility/ChainOfResponsibilityTest.java b/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/chainofresponsibility/ChainOfResponsibilityTest.java
similarity index 95%
rename from core-java/src/test/java/com/baeldung/designpatterns/chainofresponsibility/ChainOfResponsibilityTest.java
rename to patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/chainofresponsibility/ChainOfResponsibilityTest.java
index a28577efb1..a84f9dd8e5 100644
--- a/core-java/src/test/java/com/baeldung/designpatterns/chainofresponsibility/ChainOfResponsibilityTest.java
+++ b/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/chainofresponsibility/ChainOfResponsibilityTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.designpatterns.chainofresponsibility;
+package com.baeldung.pattern.chainofresponsibility;
import org.junit.Test;
diff --git a/persistence-modules/java-jdbi/README.md b/persistence-modules/java-jdbi/README.md
new file mode 100644
index 0000000000..3bab6faa29
--- /dev/null
+++ b/persistence-modules/java-jdbi/README.md
@@ -0,0 +1,2 @@
+### Relevant Articles:
+- [Guide to CockroachDB in Java](http://www.baeldung.com/cockroachdb-java)
diff --git a/persistence-modules/java-jdbi/pom.xml b/persistence-modules/java-jdbi/pom.xml
new file mode 100644
index 0000000000..392f0bdcbf
--- /dev/null
+++ b/persistence-modules/java-jdbi/pom.xml
@@ -0,0 +1,40 @@
+
+
+
+
+ parent-modules
+ com.baeldung
+ 1.0.0-SNAPSHOT
+ ../../
+
+
+ 4.0.0
+
+ java-jdbi
+ 1.0-SNAPSHOT
+
+
+
+ org.jdbi
+ jdbi3-core
+ 3.1.0
+
+
+ org.hsqldb
+ hsqldb
+ 2.4.0
+ test
+
+
+
+
+
+ Central
+ Central
+ http://repo1.maven.org/maven2/
+ default
+
+
+
\ No newline at end of file
diff --git a/persistence-modules/java-jdbi/src/test/java/com/baeldung/persistence/jdbi/JdbiTest.java b/persistence-modules/java-jdbi/src/test/java/com/baeldung/persistence/jdbi/JdbiTest.java
new file mode 100644
index 0000000000..503bf90fdb
--- /dev/null
+++ b/persistence-modules/java-jdbi/src/test/java/com/baeldung/persistence/jdbi/JdbiTest.java
@@ -0,0 +1,338 @@
+package com.baeldung.persistence.jdbi;
+
+import org.jdbi.v3.core.Handle;
+import org.jdbi.v3.core.Jdbi;
+import org.jdbi.v3.core.result.ResultBearing;
+import org.jdbi.v3.core.result.ResultProducer;
+import org.jdbi.v3.core.statement.Query;
+import org.jdbi.v3.core.statement.StatementContext;
+import org.jdbi.v3.core.statement.Update;
+import org.junit.Test;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.*;
+import java.util.function.Supplier;
+import java.util.stream.Stream;
+
+import static org.junit.Assert.*;
+
+public class JdbiTest {
+
+ @Test
+ public void whenJdbiCreated_thenSuccess() {
+ Jdbi jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", "sa", "");
+
+ Jdbi.create("WRONG");
+ }
+
+ @Test
+ public void whenJdbiWithProperties_thenSuccess() {
+ Jdbi jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", "sa", "");
+ jdbi.open().close();
+ Properties properties = new Properties();
+ properties.setProperty("username", "sa");
+ properties.setProperty("password", "");
+ jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", properties);
+ jdbi.open().close();
+ }
+
+ @Test
+ public void whenHandle_thenBoh() {
+ Jdbi jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", "sa", "");
+ final Handle[] handleRef = new Handle[1];
+ boolean closed = jdbi.withHandle(handle -> {
+ handleRef[0] = handle;
+ return handle.isClosed();
+ });
+
+ assertFalse(closed);
+ assertTrue(handleRef[0].isClosed());
+ }
+
+ @Test
+ public void whenTableCreated_thenInsertIsPossible() {
+ Jdbi jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", "sa", "");
+ jdbi.useHandle(handle -> {
+ int updateCount = handle.execute("create table PROJECT_1 (id integer identity, name varchar(50), url varchar(100))");
+
+ assertEquals(0, updateCount);
+
+ updateCount = handle.execute("INSERT INTO PROJECT_1 VALUES (1, 'tutorials', 'github.com/eugenp/tutorials')");
+
+ assertEquals(1, updateCount);
+ });
+ }
+
+ @Test
+ public void whenIdentityColumn_thenInsertReturnsNewId() {
+ Jdbi jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", "sa", "");
+ jdbi.useHandle(handle -> {
+ handle.execute("create table PROJECT_2 (ID IDENTITY, NAME VARCHAR (50), URL VARCHAR (100))");
+ Update update = handle.createUpdate(
+ "INSERT INTO PROJECT_2 (NAME, URL) VALUES ('tutorials', 'github.com/eugenp/tutorials')");
+ ResultBearing generatedKeys = update.executeAndReturnGeneratedKeys();
+
+ assertEquals(0, generatedKeys.mapToMap().findOnly().get("id"));
+
+ update = handle.createUpdate(
+ "INSERT INTO PROJECT_2 (NAME, URL) VALUES ('REST with Spring', 'github.com/eugenp/REST-With-Spring')");
+
+ assertEquals(1, generatedKeys.mapToMap().findOnly().get("id"));
+ });
+ }
+
+ @Test
+ public void whenSelectMapToMap_thenResultsAreMapEntries() {
+ Jdbi jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", "sa", "");
+ jdbi.useHandle(handle -> {
+ handle.execute("create table PROJECT_3 (ID IDENTITY, NAME VARCHAR (50), URL VARCHAR (100))");
+ handle.execute("INSERT INTO PROJECT_3 (NAME, URL) VALUES ('tutorials', 'github.com/eugenp/tutorials')");
+ handle.execute("INSERT INTO PROJECT_3 (NAME, URL) VALUES ('REST with Spring', 'github.com/eugenp/REST-With-Spring')");
+ Query query = handle.createQuery("select * from PROJECT_3 order by id");
+ List