diff --git a/cdi/pom.xml b/cdi/pom.xml
index fec12a9b16..226ca529e1 100644
--- a/cdi/pom.xml
+++ b/cdi/pom.xml
@@ -1,8 +1,8 @@
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
cdi
1.0-SNAPSHOT
@@ -10,9 +10,9 @@
com.baeldung
- parent-spring-4
+ parent-spring-5
0.0.1-SNAPSHOT
- ../parent-spring-4
+ ../parent-spring-5
@@ -26,28 +26,22 @@
weld-se-core
${weld-se-core.version}
-
- org.hamcrest
- hamcrest
- ${hamcrest.version}
- test
-
org.assertj
assertj-core
${assertj-core.version}
test
-
- org.springframework
- spring-context
- ${spring.version}
-
org.aspectj
aspectjweaver
${aspectjweaver.version}
+
+ org.springframework
+ spring-context
+ ${spring.version}
+
org.springframework
spring-test
@@ -61,7 +55,6 @@
3.0.5.Final
1.9.2
3.10.0
- 5.1.2.RELEASE
diff --git a/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java
index f529e219a6..0b70516146 100644
--- a/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java
+++ b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java
@@ -10,5 +10,6 @@ public class CopyListServiceUnitTest {
@Test(expected = UnsupportedOperationException.class)
public void whenModifyCopyOfList_thenThrowsException() {
List copyList = List.copyOf(Arrays.asList(1, 2, 3, 4));
+ copyList.add(4);
}
}
diff --git a/core-java-modules/core-java-exceptions-3/pom.xml b/core-java-modules/core-java-exceptions-3/pom.xml
index 32c522dab5..b909572afe 100644
--- a/core-java-modules/core-java-exceptions-3/pom.xml
+++ b/core-java-modules/core-java-exceptions-3/pom.xml
@@ -30,5 +30,4 @@
3.10.0
-
-
\ No newline at end of file
+
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/nullmethodparameter/NullParameterExample.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/nullmethodparameter/NullParameterExample.java
new file mode 100644
index 0000000000..c2c76bdc46
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/nullmethodparameter/NullParameterExample.java
@@ -0,0 +1,17 @@
+package com.baeldung.nullmethodparameter;
+
+public class NullParameterExample {
+ public void processSomethingNotNull(Object myParameter) {
+ if (myParameter == null) {
+ throw new IllegalArgumentException("Parameter 'myParameter' cannot be null");
+ }
+ //Do something with the parameter
+ }
+
+ public void processSomethingElseNotNull(Object myParameter) {
+ if (myParameter == null) {
+ throw new NullPointerException("Parameter 'myParameter' cannot be null");
+ }
+ //Do something with the parameter
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/nullmethodparameter/NullParameterExampleUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/nullmethodparameter/NullParameterExampleUnitTest.java
new file mode 100644
index 0000000000..aa4b332e52
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/nullmethodparameter/NullParameterExampleUnitTest.java
@@ -0,0 +1,17 @@
+package com.baeldung.nullmethodparameter;
+
+import org.junit.Test;
+
+public class NullParameterExampleUnitTest {
+ @Test(expected = IllegalArgumentException.class)
+ public void givenNullParameter_whenProcessSomethingNotNull_thenIllegalArgumentException() {
+ NullParameterExample example = new NullParameterExample();
+ example.processSomethingNotNull(null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void givenNullParameter_whenProcessSomethingElseNotNull_thenNullPointerException() {
+ NullParameterExample example = new NullParameterExample();
+ example.processSomethingElseNotNull(null);
+ }
+}
diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2.java
new file mode 100644
index 0000000000..ca6b25b3e7
--- /dev/null
+++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2.java
@@ -0,0 +1,60 @@
+package com.baeldung.algorithms.largestpowerof2;
+
+import org.nd4j.linalg.io.Assert;
+
+public class LargestPowerOf2 {
+ public long findLargestPowerOf2LessThanTheGivenNumber(long input) {
+ Assert.isTrue(input > 1, "Invalid input");
+
+ long firstPowerOf2 = 1;
+ long nextPowerOf2 = 2;
+
+ while (nextPowerOf2 < input) {
+ firstPowerOf2 = nextPowerOf2;
+ nextPowerOf2 = nextPowerOf2 * 2;
+ }
+ return firstPowerOf2;
+ }
+
+ public long findLargestPowerOf2LessThanTheGivenNumberUsingLogBase2(long input) {
+ Assert.isTrue(input > 1, "Invalid input");
+
+ long temp = input;
+ if (input % 2 == 0) {
+ temp = input - 1;
+ }
+
+ // Find log base 2 of a given number
+ long power = (long) (Math.log(temp) / Math.log(2));
+ long result = (long) Math.pow(2, power);
+
+ return result;
+ }
+
+ public long findLargestPowerOf2LessThanTheGivenNumberUsingBitwiseAnd(long input) {
+ Assert.isTrue(input > 1, "Invalid input");
+ long result = 1;
+ for (long i = input - 1; i > 1; i--) {
+ if ((i & (i - 1)) == 0) {
+ result = i;
+ break;
+ }
+ }
+ return result;
+ }
+
+ public long findLargestPowerOf2LessThanTheGivenNumberUsingBitShiftApproach(long input) {
+ Assert.isTrue(input > 1, "Invalid input");
+ long result = 1;
+ long powerOf2;
+
+ for (long i = 0; i < Long.BYTES * 8; i++) {
+ powerOf2 = 1 << i;
+ if (powerOf2 >= input) {
+ break;
+ }
+ result = powerOf2;
+ }
+ return result;
+ }
+}
diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2UnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2UnitTest.java
new file mode 100644
index 0000000000..63f7b03cf7
--- /dev/null
+++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2UnitTest.java
@@ -0,0 +1,67 @@
+package com.baeldung.algorithms.largestpowerof2;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class LargestPowerOf2UnitTest {
+ private long input;
+ private long expectedResult;
+
+ public LargestPowerOf2UnitTest(long input, long expectedResult) {
+ this.input = input;
+ this.expectedResult = expectedResult;
+ }
+
+ @Parameterized.Parameters(name = "{index}: verifyLargestPowerOf2LessThanTheGivenNumber({0}) = {1}")
+ public static Collection