Merge branch 'eugenp:master' into master
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-10</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-10</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-11-2</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-11-2</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-11-3</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-11-3</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -14,7 +13,7 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
|
||||
@@ -4,10 +4,8 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-11</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-11</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -4,10 +4,8 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-12</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-12</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -3,12 +3,9 @@
|
||||
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>core-java-13</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-13</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
<artifactId>core-java-14</artifactId>
|
||||
<name>core-java-14</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
<artifactId>core-java-15</artifactId>
|
||||
<name>core-java-15</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -4,10 +4,8 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-16</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-16</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -4,10 +4,8 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-17</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-17</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project 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">
|
||||
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-19</artifactId>
|
||||
<name>core-java-19</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>core-java-19</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>19</maven.compiler.source>
|
||||
<maven.compiler.target>19</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@@ -30,4 +26,10 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>19</maven.compiler.source>
|
||||
<maven.compiler.target>19</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.highcpu;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.IntUnaryOperator;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Application {
|
||||
|
||||
static List<Integer> generateList() {
|
||||
return IntStream.range(0, 10000000).parallel().map(IntUnaryOperator.identity()).collect(LinkedList::new, List::add, List::addAll);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Integer> list = generateList();
|
||||
long start = System.nanoTime();
|
||||
int value = list.get(9500000);
|
||||
System.out.printf("Found value %d in %d nanos\n", value, (System.nanoTime() - start));
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-8-2</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-8-2</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.baeldung.helpervsutilityclasses;
|
||||
|
||||
class MyHelperClass {
|
||||
public double discount;
|
||||
public MyHelperClass(double discount) {
|
||||
if (discount > 0 && discount < 1) {
|
||||
this.discount = discount;
|
||||
}
|
||||
}
|
||||
public double discountedPrice(double price) {
|
||||
return price - (price * discount);
|
||||
}
|
||||
|
||||
public static int getMaxNumber(int[] numbers) {
|
||||
if (numbers.length == 0) {
|
||||
throw new IllegalArgumentException("Ensure array is not empty");
|
||||
}
|
||||
int max = numbers[0];
|
||||
for (int i = 1; i < numbers.length; i++) {
|
||||
if (numbers[i] > max) {
|
||||
max = numbers[i];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
public static int getMinNumber(int[] numbers) {
|
||||
if (numbers.length == 0) {
|
||||
throw new IllegalArgumentException("Ensure array is not empty");
|
||||
}
|
||||
int min = numbers[0];
|
||||
for (int i = 1; i < numbers.length; i++) {
|
||||
if (numbers[i] < min) {
|
||||
min = numbers[i];
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.helpervsutilityclasses;
|
||||
|
||||
public final class MyUtilityClass {
|
||||
|
||||
private MyUtilityClass(){}
|
||||
|
||||
public static String returnUpperCase(String stringInput) {
|
||||
return stringInput.toUpperCase();
|
||||
}
|
||||
|
||||
public static String returnLowerCase(String stringInput) {
|
||||
return stringInput.toLowerCase();
|
||||
}
|
||||
|
||||
public static String[] splitStringInput(String stringInput, String delimiter) {
|
||||
return stringInput.split(delimiter);
|
||||
}
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.helpervsutilityclasses;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class MyHelperClassUnitTest {
|
||||
|
||||
@Test
|
||||
void whenCreatingHelperObject_thenHelperObjectShouldBeCreated() {
|
||||
MyHelperClass myHelperClassObject = new MyHelperClass(0.10);
|
||||
int[] numberArray = {15, 23, 66, 3, 51, 79};
|
||||
|
||||
assertNotNull(myHelperClassObject);
|
||||
|
||||
assertEquals(90, myHelperClassObject.discountedPrice(100.00));
|
||||
assertEquals( 79, MyHelperClass.getMaxNumber(numberArray));
|
||||
assertEquals(3, MyHelperClass.getMinNumber(numberArray));
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.helpervsutilityclasses;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class MyUtilityClassUnitTest {
|
||||
|
||||
@Test
|
||||
void whenUsingUtilityMethods_thenAccessMethodsViaClassName(){
|
||||
assertEquals( "INIUBONG", MyUtilityClass.returnUpperCase("iniubong"));
|
||||
assertEquals("accra", MyUtilityClass.returnLowerCase("AcCrA"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-8-datetime-2</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<name>core-java-8-datetime-2</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-8-datetime</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<name>core-java-8-datetime</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-8</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-8</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-9-improvements</artifactId>
|
||||
<version>0.2-SNAPSHOT</version>
|
||||
<name>core-java-9-improvements</name>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-9-jigsaw</artifactId>
|
||||
<version>0.2-SNAPSHOT</version>
|
||||
<name>core-java-9-jigsaw</name>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-9-new-features</artifactId>
|
||||
<version>0.2-SNAPSHOT</version>
|
||||
<name>core-java-9-new-features</name>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-9-streams</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-9-streams</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ This module contains articles about Java 9 core features
|
||||
### Relevant Articles:
|
||||
|
||||
- [Method Handles in Java](https://www.baeldung.com/java-method-handles)
|
||||
- [Introduction to Chronicle Queue](https://www.baeldung.com/java-chronicle-queue)
|
||||
- [Iterate Through a Range of Dates in Java](https://www.baeldung.com/java-iterate-date-range)
|
||||
- [Initialize a HashMap in Java](https://www.baeldung.com/java-initialize-hashmap)
|
||||
- [Immutable ArrayList in Java](https://www.baeldung.com/java-immutable-list)
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-9</artifactId>
|
||||
<version>0.2-SNAPSHOT</version>
|
||||
<name>core-java-9</name>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-annotations</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-annotations</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -24,4 +23,12 @@
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>javax.annotation-api</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,6 @@
|
||||
## Core Java Booleans
|
||||
|
||||
This module contains articles about Java Booleans.
|
||||
|
||||
### Relevant Articles:
|
||||
- [Convert Boolean to String in Java](https://www.baeldung.com/java-convert-boolean-to-string)
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project 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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-booleans</artifactId>
|
||||
<name>core-java-booleans</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
</project>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.baeldung.booleans;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class BooleanToStringUnitTest {
|
||||
String optionToString(String optionName, boolean optionValue) {
|
||||
return String.format("The option '%s' is %s.", optionName, optionValue ? "Enabled" : "Disabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenPrimitiveBoolean_whenConvertingUsingTernaryOperator_thenSuccess() {
|
||||
boolean primitiveBoolean = true;
|
||||
assertEquals("true", primitiveBoolean ? "true" : "false");
|
||||
|
||||
primitiveBoolean = false;
|
||||
assertEquals("false", primitiveBoolean ? "true" : "false");
|
||||
|
||||
assertEquals("The option 'IgnoreWarnings' is Enabled.", optionToString("IgnoreWarnings", true));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void givenBooleanObject_whenConvertingUsingBooleanToString_thenSuccess() {
|
||||
Boolean myBoolean = Boolean.TRUE;
|
||||
assertEquals("true", myBoolean.toString());
|
||||
|
||||
myBoolean = Boolean.FALSE;
|
||||
assertEquals("false", myBoolean.toString());
|
||||
|
||||
Boolean nullBoolean = null;
|
||||
assertThrows(NullPointerException.class, () -> nullBoolean.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenBooleanObject_whenConvertingUsingStringValueOf_thenSuccess() {
|
||||
Boolean myBoolean = Boolean.TRUE;
|
||||
assertEquals("true", String.valueOf(myBoolean));
|
||||
|
||||
myBoolean = Boolean.FALSE;
|
||||
assertEquals("false", String.valueOf(myBoolean));
|
||||
|
||||
Boolean nullBoolean = null;
|
||||
assertEquals("null", String.valueOf(nullBoolean));
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user