Merge branch 'master' into BAEL-20886

This commit is contained in:
Krzysiek 2020-02-07 21:43:20 +01:00
commit f77c90f06e
983 changed files with 3332 additions and 2484 deletions

View File

@ -13,4 +13,5 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
- [Create a Sudoku Solver in Java](https://www.baeldung.com/java-sudoku)
- [Displaying Money Amounts in Words](https://www.baeldung.com/java-money-into-words)
- [A Collaborative Filtering Recommendation System in Java](https://www.baeldung.com/java-collaborative-filtering-recommendations)
- [Implementing A* Pathfinding in Java](https://www.baeldung.com/java-a-star-pathfinding)
- More articles: [[<-- prev]](/../algorithms-miscellaneous-1) [[next -->]](/../algorithms-miscellaneous-3)

View File

@ -12,4 +12,5 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
- [How to Determine if a Binary Tree is Balanced](https://www.baeldung.com/java-balanced-binary-tree)
- [The Caesar Cipher in Java](https://www.baeldung.com/java-caesar-cipher)
- [Overview of Combinatorial Problems in Java](https://www.baeldung.com/java-combinatorial-algorithms)
- [Prims Algorithm](https://www.baeldung.com/java-prim-algorithm)
- More articles: [[<-- prev]](/../algorithms-miscellaneous-4)

View File

@ -7,4 +7,4 @@ This module contains articles about Apache Spark
- [Introduction to Apache Spark](https://www.baeldung.com/apache-spark)
- [Building a Data Pipeline with Kafka, Spark Streaming and Cassandra](https://www.baeldung.com/kafka-spark-data-pipeline)
- [Machine Learning with Spark MLlib](https://www.baeldung.com/spark-mlib-machine-learning)
- [Introduction to Spark Graph Processing with GraphFrames](https://www.baeldung.com/spark-graph-graphframes)

View File

@ -0,0 +1,3 @@
### Relevant Articles
- [Intro to Apache Tapestry](https://www.baeldung.com/apache-tapestry)

View File

@ -77,7 +77,7 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>3.3.0-01</version>
<version>${groovy.compiler.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>

View File

@ -28,17 +28,16 @@ class CategoryUnitTest extends GroovyTestCase {
}
}
// http://team.baeldung.com/browse/BAEL-20687
// void test_whenUsingTimeCategory_thenOperationOnNumber() {
// SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy")
// use (TimeCategory) {
// assert sdf.format(5.days.from.now) == sdf.format(new Date() + 5.days)
//
// sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss")
// assert sdf.format(10.minutes.from.now) == sdf.format(new Date() + 10.minutes)
// assert sdf.format(2.hours.ago) == sdf.format(new Date() - 2.hours)
// }
// }
void test_whenUsingTimeCategory_thenOperationOnNumber() {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy")
use (TimeCategory) {
assert sdf.format(5.days.from.now) == sdf.format(new Date() + 5.days)
sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss")
assert sdf.format(10.minutes.from.now) == sdf.format(new Date() + 10.minutes)
assert sdf.format(2.hours.ago) == sdf.format(new Date() - 2.hours)
}
}
void test_whenUsingDOMCategory_thenOperationOnXML() {

View File

@ -75,7 +75,6 @@ class WebserviceManualTest extends GroovyTestCase {
assert stories.size() == 5
}
/* see BAEL-3753
void test_whenConsumingSoap_thenReceiveResponse() {
def url = "http://www.dataaccess.com/webservicesserver/numberconversion.wso"
def soapClient = new SOAPClient(url)
@ -90,7 +89,6 @@ class WebserviceManualTest extends GroovyTestCase {
def words = response.NumberToWordsResponse
assert words == "one thousand two hundred and thirty four "
}
*/
void test_whenConsumingRestGet_thenReceiveResponse() {
def path = "/get"

View File

@ -33,7 +33,6 @@ class ReadFileUnitTest extends Specification {
assert lines.size(), 3
}
@Ignore
def 'Should return file content in string using ReadFile.readFileString given filePath' () {
given:
def filePath = "src/main/resources/fileContent.txt"

View File

@ -65,7 +65,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<version>${shade.plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
@ -109,6 +109,7 @@
<uberjar.name>benchmarks</uberjar.name>
<jmh.version>1.22</jmh.version>
<eclipse.collections.version>10.0.0</eclipse.collections.version>
<shade.plugin.version>10.0.0</shade.plugin.version>
</properties>
</project>

View File

@ -0,0 +1,3 @@
### Relevant articles:
- [Java Switch Statement](https://www.baeldung.com/java-switch)

View File

@ -0,0 +1 @@
--enable-preview

View File

@ -0,0 +1,7 @@
## Core Java 14
This module contains articles about Java 14.
### Relevant articles
- [Guide to the @Serial Annotation in Java 14](https://www.baeldung.com/java-14-serial-annotation)

View File

@ -1,53 +1,66 @@
<?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>
<groupId>com.baeldung</groupId>
<artifactId>core-java-14</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>core-java-14</name>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>
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-14</artifactId>
<name>core-java-14</name>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>${maven.compiler.release}</release>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source.version}</source>
<target>${maven.compiler.target.version}</target>
<compilerArgs>
<compilerArg>
--enable-preview
</compilerArg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source.version>14</maven.compiler.source.version>
<maven.compiler.target.version>14</maven.compiler.target.version>
<properties>
<maven.compiler.release>14</maven.compiler.release>
<assertj.version>3.6.1</assertj.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<surefire.plugin.version>3.0.0-M3</surefire.plugin.version>
</properties>
</properties>
</project>

View File

@ -0,0 +1,46 @@
package com.baeldung.java14.textblocks;
public class TextBlocks13 {
public String getBlockOfHtml() {
return """
<html>
<body>
<span>example text</span>
</body>
</html>""";
}
public String getNonStandardIndent() {
return """
Indent
""";
}
public String getQuery() {
return """
select "id", "user"
from "table"
""";
}
public String getTextWithCarriageReturns() {
return """
separated with\r
carriage returns""";
}
public String getTextWithEscapes() {
return """
fun with\n
whitespace\t\r
and other escapes \"""
""";
}
public String getFormattedText(String parameter) {
return """
Some parameter: %s
""".formatted(parameter);
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.java14.textblocks;
public class TextBlocks14 {
public String getIgnoredNewLines() {
return """
This is a long test which looks to \
have a newline but actually does not""";
}
public String getEscapedSpaces() {
return """
line 1
line 2 \s
""";
}
}

View File

@ -10,41 +10,41 @@ import java.io.Serializable;
/**
* Class showcasing the usage of the Java 14 @Serial annotation.
*
*
* @author Donato Rimenti
*/
public class MySerialClass implements Serializable {
@Serial
private static final ObjectStreamField[] serialPersistentFields = null;
@Serial
private static final long serialVersionUID = 1;
@Serial
private void writeObject(ObjectOutputStream stream) throws IOException {
// ...
}
@Serial
private static final ObjectStreamField[] serialPersistentFields = null;
@Serial
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
// ...
}
@Serial
private static final long serialVersionUID = 1;
@Serial
private void readObjectNoData() throws ObjectStreamException {
// ...
}
@Serial
private void writeObject(ObjectOutputStream stream) throws IOException {
// ...
}
@Serial
private Object writeReplace() throws ObjectStreamException {
// ...
return null;
}
@Serial
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
// ...
}
@Serial
private Object readResolve() throws ObjectStreamException {
// ...
return null;
}
@Serial
private void readObjectNoData() throws ObjectStreamException {
// ...
}
@Serial
private Object writeReplace() throws ObjectStreamException {
// ...
return null;
}
@Serial
private Object readResolve() throws ObjectStreamException {
// ...
return null;
}
}

View File

@ -0,0 +1,58 @@
package com.baeldung.java14.textblocks;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
class TextBlocks13UnitTest {
private TextBlocks13 subject = new TextBlocks13();
@Test
void givenAnOldStyleMultilineString_whenComparing_thenEqualsTextBlock() {
String expected = "<html>\n"
+ "\n"
+ " <body>\n"
+ " <span>example text</span>\n"
+ " </body>\n"
+ "</html>";
assertThat(subject.getBlockOfHtml()).isEqualTo(expected);
}
@Test
void givenAnOldStyleString_whenComparing_thenEqualsTextBlock() {
String expected = "<html>\n\n <body>\n <span>example text</span>\n </body>\n</html>";
assertThat(subject.getBlockOfHtml()).isEqualTo(expected);
}
@Test
void givenAnIndentedString_thenMatchesIndentedOldStyle() {
assertThat(subject.getNonStandardIndent()).isEqualTo(" Indent\n");
}
@Test
void givenAMultilineQuery_thenItCanContainUnescapedQuotes() {
assertThat(subject.getQuery()).contains("select \"id\", \"user\"");
}
@Test
void givenAMultilineQuery_thenItEndWithANewline() {
assertThat(subject.getQuery()).endsWith("\n");
}
@Test
void givenATextWithCarriageReturns_thenItContainsBoth() {
assertThat(subject.getTextWithCarriageReturns()).isEqualTo("separated with\r\ncarriage returns");
}
@Test
void givenAStringWithEscapedWhitespace_thenItAppearsInTheResultingString() {
assertThat(subject.getTextWithEscapes()).contains("fun with\n\n")
.contains("whitespace\t\r\n")
.contains("and other escapes \"\"\"");
}
@Test
void givenAFormattedString_thenTheParameterIsReplaced() {
assertThat(subject.getFormattedText("parameter")).contains("Some parameter: parameter");
}
}

View File

@ -0,0 +1,21 @@
package com.baeldung.java14.textblocks;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
class TextBlocks14UnitTest {
private TextBlocks14 subject = new TextBlocks14();
@Test
void givenAStringWithEscapedNewLines_thenTheResultHasNoNewLines() {
String expected = "This is a long test which looks to have a newline but actually does not";
assertThat(subject.getIgnoredNewLines()).isEqualTo(expected);
}
@Test
void givenAStringWithEscapesSpaces_thenTheResultHasLinesEndingWithSpaces() {
String expected = "line 1\nline 2 \n";
assertThat(subject.getEscapedSpaces()).isEqualTo(expected);
}
}

View File

@ -9,6 +9,7 @@ This module contains articles about Java 9 core features
- [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 Set in Java](https://www.baeldung.com/java-immutable-set)
- [Immutable ArrayList in Java](https://www.baeldung.com/java-immutable-list)
Note: also contains part of the code for the article
[How to Filter a Collection in Java](https://www.baeldung.com/java-collection-filtering).

View File

@ -37,6 +37,11 @@
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>${commons-collections4.version}</version>
</dependency>
</dependencies>
<build>
@ -69,6 +74,7 @@
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
<guava.version>25.1-jre</guava.version>
<commons-collections4.version>4.1</commons-collections4.version>
</properties>
</project>

View File

@ -0,0 +1,48 @@
package com.baeldung.java9.list.immutable;
import com.google.common.collect.ImmutableList;
import org.apache.commons.collections4.ListUtils;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class ImmutableArrayListUnitTest {
@Test(expected = UnsupportedOperationException.class)
public final void givenUsingTheJdk_whenUnmodifiableListIsCreated_thenNotModifiable() {
final List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
final List<String> unmodifiableList = Collections.unmodifiableList(list);
unmodifiableList.add("four");
}
@Test(expected = UnsupportedOperationException.class)
public final void givenUsingTheJava9_whenUnmodifiableListIsCreated_thenNotModifiable() {
final List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
final List<String> unmodifiableList = List.of(list.toArray(new String[]{}));
unmodifiableList.add("four");
}
@Test(expected = UnsupportedOperationException.class)
public final void givenUsingGuava_whenUnmodifiableListIsCreated_thenNotModifiable() {
final List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
final List<String> unmodifiableList = ImmutableList.copyOf(list);
unmodifiableList.add("four");
}
@Test(expected = UnsupportedOperationException.class)
public final void givenUsingGuavaBuilder_whenUnmodifiableListIsCreated_thenNoLongerModifiable() {
final List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
final ImmutableList<String> unmodifiableList = ImmutableList.<String>builder().addAll(list).build();
unmodifiableList.add("four");
}
@Test(expected = UnsupportedOperationException.class)
public final void givenUsingCommonsCollections_whenUnmodifiableListIsCreated_thenNotModifiable() {
final List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
final List<String> unmodifiableList = ListUtils.unmodifiableList(list);
unmodifiableList.add("four");
}
}

View File

@ -3,9 +3,8 @@
This module contains articles about the Java ArrayList collection
### Relevant Articles:
- [Immutable ArrayList in Java](http://www.baeldung.com/java-immutable-list)
- [Guide to the Java ArrayList](http://www.baeldung.com/java-arraylist)
- [Add Multiple Items to an Java ArrayList](http://www.baeldung.com/java-add-items-array-list)
- [Guide to the Java ArrayList](https://www.baeldung.com/java-arraylist)
- [Add Multiple Items to an Java ArrayList](https://www.baeldung.com/java-add-items-array-list)
- [ClassCastException: Arrays$ArrayList cannot be cast to ArrayList](https://www.baeldung.com/java-classcastexception-arrays-arraylist)
- [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist)
- [Removing an Element From an ArrayList](https://www.baeldung.com/java-arraylist-remove-element)

View File

@ -15,42 +15,11 @@ public class CoreJavaCollectionsUnitTest {
private static final Logger LOG = LoggerFactory.getLogger(CoreJavaCollectionsUnitTest.class);
// tests -
@Test
public final void givenUsingTheJdk_whenArrayListIsSynchronized_thenCorrect() {
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
final List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
final List<String> synchronizedList = Collections.synchronizedList(list);
LOG.debug("Synchronized List is: " + synchronizedList);
}
@Test(expected = UnsupportedOperationException.class)
public final void givenUsingTheJdk_whenUnmodifiableListIsCreatedFromOriginal_thenNoLongerModifiable() {
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
final List<String> unmodifiableList = Collections.unmodifiableList(list);
unmodifiableList.add("four");
}
@Test(expected = UnsupportedOperationException.class)
public final void givenUsingGuava_whenUnmodifiableListIsCreatedFromOriginal_thenNoLongerModifiable() {
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
final List<String> unmodifiableList = ImmutableList.copyOf(list);
unmodifiableList.add("four");
}
@Test(expected = UnsupportedOperationException.class)
public final void givenUsingGuavaBuilder_whenUnmodifiableListIsCreatedFromOriginal_thenNoLongerModifiable() {
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
final ImmutableList<String> unmodifiableList = ImmutableList.<String>builder().addAll(list).build();
unmodifiableList.add("four");
}
@Test(expected = UnsupportedOperationException.class)
public final void givenUsingCommonsCollections_whenUnmodifiableListIsCreatedFromOriginal_thenNoLongerModifiable() {
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
final List<String> unmodifiableList = ListUtils.unmodifiableList(list);
unmodifiableList.add("four");
}
}

View File

@ -1,22 +1,27 @@
package com.baeldung.threadlocalrandom;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.ChainedOptionsBuilder;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import com.google.common.collect.ImmutableList;
public class ThreadLocalRandomBenchMarkRunner {
public static void main(String[] args) throws Exception {
Options options = new OptionsBuilder().include(ThreadLocalRandomBenchMarker.class.getSimpleName())
.threads(1)
ChainedOptionsBuilder options = new OptionsBuilder().include(ThreadLocalRandomBenchMarker.class.getSimpleName())
.forks(1)
.shouldFailOnError(true)
.shouldDoGC(true)
.jvmArgs("-server")
.build();
new Runner(options).run();
.jvmArgs("-server");
for (Integer i : ImmutableList.of(1, 2, 8, 32)) {
new Runner(
options
.threads(i)
.build())
.run();
}
}
}

View File

@ -1,64 +1,34 @@
package com.baeldung.threadlocalrandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
@BenchmarkMode(Mode.AverageTime)
@BenchmarkMode(Mode.Throughput)
@Warmup(iterations = 1)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@State(Scope.Benchmark)
public class ThreadLocalRandomBenchMarker {
private final Random random = new Random();
List<Callable<Integer>> randomCallables = new ArrayList<>();
List<Callable<Integer>> threadLocalRandomCallables = new ArrayList<>();
@Setup(Level.Iteration)
public void init() {
Random random = new Random();
randomCallables = new ArrayList<>();
threadLocalRandomCallables = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
randomCallables.add(() -> {
return random.nextInt();
});
}
for (int i = 0; i < 1000; i++) {
threadLocalRandomCallables.add(() -> {
return ThreadLocalRandom.current()
.nextInt();
});
}
@Benchmark
public int randomValuesUsingRandom() {
return random.nextInt();
}
@Benchmark
public void randomValuesUsingRandom() throws InterruptedException {
ExecutorService executor = Executors.newWorkStealingPool();
executor.invokeAll(randomCallables);
executor.shutdown();
}
@Benchmark
public void randomValuesUsingThreadLocalRandom() throws InterruptedException {
ExecutorService executor = Executors.newWorkStealingPool();
executor.invokeAll(threadLocalRandomCallables);
executor.shutdown();
public int randomValuesUsingThreadLocalRandom() {
return ThreadLocalRandom
.current()
.nextInt();
}
}

View File

@ -2,4 +2,6 @@
This module contains articles about core java exceptions
###
### Relevant Articles:
- [Is It a Bad Practice to Catch Throwable?](https://www.baeldung.com/java-catch-throwable-bad-practice)

View File

@ -13,4 +13,5 @@ This module contains articles about core Java input and output (IO)
- [Getting a Files Mime Type in Java](https://www.baeldung.com/java-file-mime-type)
- [How to Write to a CSV File in Java](https://www.baeldung.com/java-csv)
- [How to Avoid the Java FileNotFoundException When Loading Resources](https://www.baeldung.com/java-classpath-resource-cannot-be-opened)
- [Create a Directory in Java](https://www.baeldung.com/java-create-directory)
- [[More -->]](/core-java-modules/core-java-io-2)

View File

@ -10,3 +10,5 @@ This module contains articles about working with the Java Virtual Machine (JVM).
- [Class Loaders in Java](https://www.baeldung.com/java-classloaders)
- [A Guide to System.exit()](https://www.baeldung.com/java-system-exit)
- [Guide to System.gc()](https://www.baeldung.com/java-system-gc)
- [Runtime.getRuntime().halt() vs System.exit() in Java](https://www.baeldung.com/java-runtime-halt-vs-system-exit)
- [Adding Shutdown Hooks for JVM Applications](https://www.baeldung.com/jvm-shutdown-hooks)

View File

@ -15,6 +15,11 @@
</parent>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>

View File

@ -0,0 +1,20 @@
package com.baeldung.methodmultiplereturnvalues;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Comparator;
import java.util.List;
class MultipleReturnValuesUsingApacheCommonsPair {
static ImmutablePair<Coordinates, Double> getMostDistantPoint(
List<Coordinates> coordinatesList,
Coordinates target) {
return coordinatesList.stream()
.map(coordinates -> ImmutablePair.of(coordinates, coordinates.calculateDistance(target)))
.max(Comparator.comparingDouble(Pair::getRight))
.get();
}
}

View File

@ -0,0 +1,23 @@
package com.baeldung.methodmultiplereturnvalues;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import java.util.List;
import java.util.stream.Collectors;
class MultipleReturnValuesUsingApacheCommonsTriple {
static ImmutableTriple<Double, Double, Double> getMinAvgMaxTriple(
List<Coordinates> coordinatesList,
Coordinates target) {
List<Double> distanceList = coordinatesList.stream()
.map(coordinates -> coordinates.calculateDistance(target))
.collect(Collectors.toList());
Double minDistance = distanceList.stream().mapToDouble(Double::doubleValue).min().getAsDouble();
Double avgDistance = distanceList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0D);
Double maxDistance = distanceList.stream().mapToDouble(Double::doubleValue).max().getAsDouble();
return ImmutableTriple.of(minDistance, avgDistance, maxDistance);
}
}

View File

@ -0,0 +1,34 @@
package com.baeldung.methodmultiplereturnvalues;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
class MultipleReturnValuesUsingApacheCommonsPairUnitTest {
@Test
void whenUsingPair_thenMultipleFieldsAreReturned() {
List<Coordinates> coordinatesList = new ArrayList<>();
coordinatesList.add(new Coordinates(1, 1, "home"));
coordinatesList.add(new Coordinates(2, 2, "school"));
coordinatesList.add(new Coordinates(3, 3, "hotel"));
Coordinates target = new Coordinates(5, 5, "gym");
ImmutablePair<Coordinates, Double> mostDistantPoint = MultipleReturnValuesUsingApacheCommonsPair.getMostDistantPoint(coordinatesList, target);
assertEquals(1, mostDistantPoint.getLeft().getLongitude());
assertEquals(1, mostDistantPoint.getLeft().getLatitude());
assertEquals("home", mostDistantPoint.getLeft().getPlaceName());
assertEquals(5.66, BigDecimal.valueOf(mostDistantPoint.getRight()).setScale(2, RoundingMode.HALF_UP).doubleValue());
}
}

View File

@ -0,0 +1,35 @@
package com.baeldung.methodmultiplereturnvalues;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
class MultipleReturnValuesUsingApacheCommonsTripleUnitTest {
@Test
void whenUsingTriple_thenMultipleFieldsAreReturned() {
List<Coordinates> coordinatesList = new ArrayList<>();
coordinatesList.add(new Coordinates(1, 1, "home"));
coordinatesList.add(new Coordinates(2, 2, "school"));
coordinatesList.add(new Coordinates(3, 3, "hotel"));
Coordinates target = new Coordinates(5, 5, "gym");
ImmutableTriple<Double, Double, Double> minAvgMax = MultipleReturnValuesUsingApacheCommonsTriple.getMinAvgMaxTriple(coordinatesList, target);
assertEquals(2.83, scaleDouble(minAvgMax.left)); //min
assertEquals(4.24, scaleDouble(minAvgMax.middle)); //avg
assertEquals(5.66, scaleDouble(minAvgMax.right)); //max
}
private double scaleDouble(Double d) {
return BigDecimal.valueOf(d).setScale(2, RoundingMode.HALF_UP).doubleValue();
}
}

View File

@ -8,9 +8,9 @@ This module contains articles about Object-oriented programming (OOP) in Java
- [Guide to the super Java Keyword](https://www.baeldung.com/java-super)
- [Guide to the this Java Keyword](https://www.baeldung.com/java-this)
- [Java public Access Modifier](https://www.baeldung.com/java-public-keyword)
- [Composition, Aggregation and Association in Java](https://www.baeldung.com/java-composition-aggregation-association)
- [Composition, Aggregation, and Association in Java](https://www.baeldung.com/java-composition-aggregation-association)
- [Nested Classes in Java](https://www.baeldung.com/java-nested-classes)
- [A Guide to Inner Interfaces in Java](https://www.baeldung.com/java-inner-interfaces)
- [Java Classes and Objects](https://www.baeldung.com/java-classes-objects)
- [Java Interfaces](https://www.baeldung.com/java-interfaces)
- [[<-- Prev]](/core-java-modules/core-java-lang-oop-2)[[More -->]](/core-java-modules/core-java-lang-oop-4)
- [[<-- Prev]](/core-java-modules/core-java-lang-oop-2)[[More -->]](/core-java-modules/core-java-lang-oop-4)

View File

@ -9,3 +9,4 @@ This module contains articles about performance of Java applications
- [OutOfMemoryError: GC Overhead Limit Exceeded](http://www.baeldung.com/java-gc-overhead-limit-exceeded)
- [Basic Introduction to JMX](http://www.baeldung.com/java-management-extensions)
- [Monitoring Java Applications with Flight Recorder](https://www.baeldung.com/java-flight-recorder-monitoring)
- [Branch Prediction in Java](https://www.baeldung.com/java-branch-prediction)

View File

@ -3,3 +3,5 @@
This module contains articles about string-related algorithms.
### Relevant Articles:
- [Check if Two Strings are Anagrams in Java](https://www.baeldung.com/java-strings-anagrams)

View File

@ -8,4 +8,5 @@ This module contains articles about string operations.
- [String Initialization in Java](https://www.baeldung.com/java-string-initialization)
- [String toLowerCase and toUpperCase Methods in Java](https://www.baeldung.com/java-string-convert-case)
- [Java String equalsIgnoreCase()](https://www.baeldung.com/java-string-equalsignorecase)
- [How to avoid String contains() Case Insensitive in Java](https://www.baeldung.com/how-to-avoid-string-contains-case-insensitive-in-java)
- More articles: [[<-- prev]](../core-java-string-operations)

View File

@ -1,6 +1,7 @@
<?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">
<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-string-operations-2</artifactId>
<version>0.1.0-SNAPSHOT</version>
@ -51,6 +52,18 @@
<version>${org.hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh-core.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh-generator.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
@ -61,6 +74,29 @@
<build>
<finalName>core-java-string-operations-2</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>

View File

@ -0,0 +1,78 @@
package com.baeldung.contains;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
/**
* Based on https://github.com/tedyoung/indexof-contains-benchmark
*/
@Fork(5)
@State(Scope.Benchmark)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public class CaseInsensitiveWorkarounds {
private String src;
private String dest;
private Pattern pattern;
public static void main(String[] args) throws Exception {
org.openjdk.jmh.Main.main(args);
}
@Setup
public void setup() {
src = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum";
dest = "eiusmod";
pattern = Pattern.compile(Pattern.quote(dest), Pattern.CASE_INSENSITIVE);
}
// toLowerCase() and contains()
@Benchmark
public boolean lowerCaseContains() {
return src.toLowerCase()
.contains(dest.toLowerCase());
}
// matches() with Regular Expressions
@Benchmark
public boolean matchesRegularExpression() {
return src.matches("(?i).*" + dest + ".*");
}
public boolean processRegionMatches(String localSrc, String localDest) {
for (int i = localSrc.length() - localDest.length(); i >= 0; i--)
if (localSrc.regionMatches(true, i, localDest, 0, localDest.length()))
return true;
return false;
}
// String regionMatches()
@Benchmark
public boolean regionMatches() {
return processRegionMatches(src, dest);
}
// Pattern CASE_INSENSITIVE with regexp
@Benchmark
public boolean patternCaseInsensitiveRegexp() {
return pattern.matcher(src)
.find();
}
// Apache Commons StringUtils containsIgnoreCase
@Benchmark
public boolean apacheCommonsStringUtils() {
return org.apache.commons.lang3.StringUtils.containsIgnoreCase(src, dest);
}
}

View File

@ -0,0 +1,53 @@
package com.baeldung.contains;
import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import org.junit.Test;
import java.util.regex.Pattern;
/**
* BAEL-3739: Different ways to solve the contains() case insensitive behavior.
*/
public class CaseInsensitiveWorkaroundsUnitTest {
private String src = "Lorem ipsum dolor sit amet";
private String dest = "lorem";
@Test
public void givenString_whenCallingContainsWithToLowerOrUpperCase_shouldReturnTrue() {
// Use toLowerCase to avoid case insensitive issues
Assert.assertTrue(src.toLowerCase().contains(dest.toLowerCase()));
// Use toUpperCase to avoid case insensitive issues
Assert.assertTrue(src.toUpperCase().contains(dest.toUpperCase()));
}
@Test
public void givenString_whenCallingStringMatches_thenReturnsTrue() {
// Use String Matches to avoid case insensitive issues
Assert.assertTrue(src.matches("(?i).*" + dest + ".*"));
}
@Test
public void givenString_whenCallingStringRegionMatches_thenReturnsTrue() {
// Use String Region Matches to avoid case insensitive issues
CaseInsensitiveWorkarounds comparator = new CaseInsensitiveWorkarounds();
Assert.assertTrue(comparator.processRegionMatches(src, dest));
}
@Test
public void givenString_whenCallingPaternCompileMatcherFind_thenReturnsTrue() {
// Use Pattern Compile Matcher and Find to avoid case insensitive issues
Assert.assertTrue(Pattern.compile(Pattern.quote(dest),
Pattern.CASE_INSENSITIVE) .matcher(src) .find());
}
@Test
public void givenString_whenCallingStringUtilsContainsIgnoreCase_thenReturnsTrue() {
// Use StringUtils containsIgnoreCase to avoid case insensitive issues
Assert.assertTrue(StringUtils.containsIgnoreCase(src, dest));
}
}

View File

@ -6,3 +6,4 @@ This module contains articles about data structures in Java
- [The Trie Data Structure in Java](https://www.baeldung.com/trie-java)
- [Implementing a Binary Tree in Java](https://www.baeldung.com/java-binary-tree)
- [Circular Linked List Java Implementation](https://www.baeldung.com/java-circular-linked-list)

View File

@ -23,7 +23,7 @@
<dependency>
<groupId>com.leansoft</groupId>
<artifactId>bigqueue</artifactId>
<version>0.7.0</version>
<version>${bigqueue.version}</version>
</dependency>
</dependencies>
@ -39,4 +39,8 @@
</pluginManagement>
</build>
<properties>
<bigqueue.version>0.7.0</bigqueue.version>
</properties>
</project>

View File

@ -177,8 +177,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler.plugin.version}</version>
<configuration>
<source>${source.version}</source>
<target>${target.version}</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
@ -189,7 +189,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<version>${maven-war-plugin.version}</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
@ -216,7 +216,5 @@
<slf4j.version>1.7.25</slf4j.version>
<spring-boot-maven-plugin.version>2.0.4.RELEASE</spring-boot-maven-plugin.version>
<compiler.plugin.version>3.1</compiler.plugin.version>
<source.version>1.8</source.version>
<target.version>1.8</target.version>
</properties>
</project>

View File

@ -1,85 +0,0 @@
:toc:
:spring_version: current
:icons: font
:source-highlighter: prettify
:project_id: gs-scheduling-tasks
This guide walks you through the steps for scheduling tasks with Spring.
== What you'll build
You'll build an application that prints out the current time every five seconds using Spring's `@Scheduled` annotation.
== What you'll need
:java_version: 1.8
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/prereq_editor_jdk_buildtools.adoc[]
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/how_to_complete_this_guide.adoc[]
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/hide-show-gradle.adoc[]
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/hide-show-maven.adoc[]
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/hide-show-sts.adoc[]
[[initial]]
== Create a scheduled task
Now that you've set up your project, you can create a scheduled task.
`src/main/java/hello/ScheduledTasks.java`
[source,java]
----
include::complete/src/main/java/hello/ScheduledTasks.java[]
----
The `Scheduled` annotation defines when a particular method runs.
NOTE: This example uses `fixedRate`, which specifies the interval between method invocations measured from the start time of each invocation. There are https://docs.spring.io/spring/docs/{spring_version}/spring-framework-reference/html/scheduling.html#scheduling-annotation-support-scheduled[other options], like `fixedDelay`, which specifies the interval between invocations measured from the completion of the task. You can also https://docs.spring.io/spring/docs/{spring_version}/javadoc-api/org/springframework/scheduling/support/CronSequenceGenerator.html[use `@Scheduled(cron=". . .")` expressions for more sophisticated task scheduling].
== Enable Scheduling
Although scheduled tasks can be embedded in web apps and WAR files, the simpler approach demonstrated below creates a standalone application. You package everything in a single, executable JAR file, driven by a good old Java `main()` method.
`src/main/java/hello/Application.java`
[source,java]
----
include::complete/src/main/java/hello/Application.java[]
----
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/spring-boot-application.adoc[]
https://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#scheduling-enable-annotation-support[`@EnableScheduling`] ensures that a background task executor is created. Without it, nothing gets scheduled.
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/build_an_executable_jar_subhead.adoc[]
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/build_an_executable_jar_with_both.adoc[]
Logging output is displayed and you can see from the logs that it is on a background thread. You should see your scheduled task fire every 5 seconds:
....
[...]
2016-08-25 13:10:00.143 INFO 31565 --- [pool-1-thread-1] hello.ScheduledTasks : The time is now 13:10:00
2016-08-25 13:10:05.143 INFO 31565 --- [pool-1-thread-1] hello.ScheduledTasks : The time is now 13:10:05
2016-08-25 13:10:10.143 INFO 31565 --- [pool-1-thread-1] hello.ScheduledTasks : The time is now 13:10:10
2016-08-25 13:10:15.143 INFO 31565 --- [pool-1-thread-1] hello.ScheduledTasks : The time is now 13:10:15
....
== Summary
Congratulations! You created an application with a scheduled task. Heck, the actual code was shorter than the build file! This technique works in any type of application.
== See Also
The following guides may also be helpful:
* https://spring.io/guides/gs/spring-boot/[Building an Application with Spring Boot]
* https://spring.io/guides/gs/batch-processing/[Creating a Batch Service]
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/footer.adoc[]

View File

@ -0,0 +1,3 @@
### Relevant Articles:
- [Remote Debugging with IntelliJ IDEA](https://www.baeldung.com/intellij-remote-debugging)

View File

@ -4,4 +4,4 @@ This module contains articles about the Security API in Java EE 8.
### Relevant articles
- [Java EE 8 Security API](https://www.baeldung.com/java-ee-8-security)
- [Jakarta EE 8 Security API](https://www.baeldung.com/java-ee-8-security)

View File

@ -15,4 +15,5 @@ This module contains articles about numbers in Java.
- [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers)
- [Generating Random Numbers in a Range in Java](https://www.baeldung.com/java-generating-random-numbers)
- [Listing Numbers Within a Range in Java](https://www.baeldung.com/java-listing-numbers-within-a-range)
- [Fibonacci Series in Java](https://www.baeldung.com/java-fibonacci)
- More articles: [[<-- prev]](/../java-numbers)

View File

@ -17,7 +17,7 @@
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>dsiutils</artifactId>
<version>2.6.0</version>
<version>${dsiutils.version}</version>
</dependency>
</dependencies>
@ -31,4 +31,8 @@
</resources>
</build>
<properties>
<dsiutils.version>2.6.0</dsiutils.version>
</properties>
</project>

View File

@ -9,6 +9,6 @@ This module contains articles about Servlets.
- [Uploading Files with Servlets and JSP](https://www.baeldung.com/upload-file-servlet)
- [Example of Downloading File in a Servlet](https://www.baeldung.com/servlet-download-file)
- [Returning a JSON Response from a Servlet](https://www.baeldung.com/servlet-json-response)
- [Java EE Servlet Exception Handling](https://www.baeldung.com/servlet-exceptions)
- [Jakarta EE Servlet Exception Handling](https://www.baeldung.com/servlet-exceptions)
- [Context and Servlet Initialization Parameters](https://www.baeldung.com/context-servlet-initialization-param)
- [The Difference between getRequestURI and getPathInfo in HttpServletRequest](https://www.baeldung.com/http-servlet-request-requesturi-pathinfo)

View File

@ -3,4 +3,4 @@
This module contains articles about security in JEE 7.
### Relevant Articles:
- [Securing Java EE with Spring Security](https://www.baeldung.com/java-ee-spring-security)
- [Securing Jakarta EE with Spring Security](https://www.baeldung.com/java-ee-spring-security)

View File

@ -3,7 +3,7 @@
This module contains articles about JEE 7.
### Relevant Articles:
- [Scheduling in Java EE](https://www.baeldung.com/scheduling-in-java-enterprise-edition)
- [Scheduling in Jakarta EE](https://www.baeldung.com/scheduling-in-java-enterprise-edition)
- [JSON Processing in Java EE 7](https://www.baeldung.com/jee7-json)
- [Converters, Listeners and Validators in Java EE 7](https://www.baeldung.com/java-ee7-converter-listener-validator)
- [Introduction to JAX-WS](https://www.baeldung.com/jax-ws)

View File

@ -3,4 +3,4 @@
This module contains articles about Java EE with Kotlin.
### Relevant Articles:
- [Java EE Application with Kotlin](https://www.baeldung.com/java-ee-kotlin-app)
- [Jakarta EE Application with Kotlin](https://www.baeldung.com/java-ee-kotlin-app)

View File

@ -232,7 +232,7 @@
<dependency>
<groupId>org.zalando</groupId>
<artifactId>problem-spring-web</artifactId>
<version>0.24.0-RC.0</version>
<version>${zalando.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
@ -910,5 +910,6 @@
<sonar.tests>${project.basedir}/src/test/</sonar.tests>
<!-- jhipster-needle-maven-property -->
<zalando.version>0.24.0-RC.0</zalando.version>
</properties>
</project>

View File

@ -3,4 +3,4 @@
This module contains articles about the Java Transaction API (JTA).
### Relevant Articles:
- [Guide to Java EE JTA](https://www.baeldung.com/jee-jta)
- [Guide to Jakarta EE JTA](https://www.baeldung.com/jee-jta)

View File

@ -21,7 +21,7 @@
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxkotlin</artifactId>
<version>2.3.0</version>
<version>${rxkotlin.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@ -86,6 +86,7 @@
<guava.version>27.1-jre</guava.version>
<mockk.version>1.9.3</mockk.version>
<kotlinx-collections-immutable.version>0.1</kotlinx-collections-immutable.version>
<rxkotlin.version>2.3.0</rxkotlin.version>
</properties>
</project>

View File

@ -48,7 +48,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${junit.version}</version>
</dependency>
<!-- logging -->
<dependency>
@ -148,6 +148,7 @@
<dependency.plugin.version>3.1.1</dependency.plugin.version>
<surefire.plugin.version>2.22.1</surefire.plugin.version>
<exec.plugin.version>1.3.2</exec.plugin.version>
<junit.version>4.12</junit.version>
</properties>
</project>

View File

@ -67,7 +67,12 @@
<groupId>org.cactoos</groupId>
<artifactId>cactoos</artifactId>
<version>${cactoos.version}</version>
</dependency>
<dependency>
<groupId>org.cache2k</groupId>
<artifactId>cache2k-base-bom</artifactId>
<version>${cache2k.version}</version>
<type>pom</type>
</dependency>
</dependencies>
@ -88,5 +93,6 @@
<cactoos.version>0.43</cactoos.version>
<airline.version>2.7.2</airline.version>
<cache2k.version>1.2.3.Final</cache2k.version>
</properties>
</project>

View File

@ -0,0 +1,41 @@
package com.baeldung.cache2k;
import java.util.Objects;
import org.cache2k.Cache;
import org.cache2k.Cache2kBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProductHelper {
final Logger LOGGER = LoggerFactory.getLogger(ProductHelper.class);
private Cache<String, Integer> cachedDiscounts;
public ProductHelper() {
cachedDiscounts = Cache2kBuilder.of(String.class, Integer.class)
.name("discount")
.eternal(true)
.entryCapacity(100)
.build();
initDiscountCache("Sports", 20);
}
public void initDiscountCache(String productType, Integer value) {
cachedDiscounts.put(productType, value);
}
public Integer getDiscount(String productType) {
Integer discount = cachedDiscounts.get(productType);
if (Objects.isNull(discount)) {
LOGGER.info("Discount for {} not found.", productType);
discount = 0;
} else {
LOGGER.info("Discount for {} found.", productType);
}
return discount;
}
}

View File

@ -0,0 +1,41 @@
package com.baeldung.cache2k;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.cache2k.Cache;
import org.cache2k.Cache2kBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProductHelperUsingLoader {
final Logger LOGGER = LoggerFactory.getLogger(ProductHelperUsingLoader.class);
private Cache<String, Integer> cachedDiscounts;
public ProductHelperUsingLoader() {
cachedDiscounts = Cache2kBuilder.of(String.class, Integer.class)
.name("discount-loader")
.eternal(false)
.expireAfterWrite(10, TimeUnit.MILLISECONDS)
.entryCapacity(100)
.loader((key) -> {
LOGGER.info("Calculating discount for {}.", key);
return "Sports".equalsIgnoreCase(key) ? 20 : 10;
})
.build();
}
public Integer getDiscount(String productType) {
Integer discount = cachedDiscounts.get(productType);
if (Objects.isNull(discount)) {
LOGGER.info("Discount for {} not found.", productType);
discount = 0;
} else {
LOGGER.info("Discount for {} found.", productType);
}
return discount;
}
}

View File

@ -0,0 +1,49 @@
package com.baeldung.cache2k;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.cache2k.Cache;
import org.cache2k.Cache2kBuilder;
import org.cache2k.CacheEntry;
import org.cache2k.event.CacheEntryCreatedListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProductHelperWithEventListener {
final Logger LOGGER = LoggerFactory.getLogger(ProductHelperWithEventListener.class);
private Cache<String, Integer> cachedDiscounts;
public ProductHelperWithEventListener() {
cachedDiscounts = Cache2kBuilder.of(String.class, Integer.class)
.name("discount-listener")
.eternal(false)
.expireAfterWrite(10, TimeUnit.MILLISECONDS)
.entryCapacity(100)
.loader((key) -> {
LOGGER.info("Calculating discount for {}.", key);
return "Sports".equalsIgnoreCase(key) ? 20 : 10;
})
.addListener(new CacheEntryCreatedListener<String, Integer>() {
@Override
public void onEntryCreated(Cache<String, Integer> cache, CacheEntry<String, Integer> entry) {
LOGGER.info("Entry created: [{}, {}].", entry.getKey(), entry.getValue());
}
})
.build();
}
public Integer getDiscount(String productType) {
Integer discount = cachedDiscounts.get(productType);
if (Objects.isNull(discount)) {
LOGGER.info("Discount for {} not found.", productType);
discount = 0;
} else {
LOGGER.info("Discount for {} found.", productType);
}
return discount;
}
}

View File

@ -0,0 +1,43 @@
package com.baeldung.cache2k;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.cache2k.Cache;
import org.cache2k.Cache2kBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProductHelperWithExpiry {
final Logger LOGGER = LoggerFactory.getLogger(ProductHelperWithExpiry.class);
private Cache<String, Integer> cachedDiscounts;
public ProductHelperWithExpiry() {
cachedDiscounts = Cache2kBuilder.of(String.class, Integer.class)
.name("discount-expiry")
.eternal(false)
.expireAfterWrite(5, TimeUnit.MILLISECONDS)
.entryCapacity(100)
.build();
initDiscountCache("Sports", 20);
}
public void initDiscountCache(String productType, Integer value) {
cachedDiscounts.put(productType, value);
}
public Integer getDiscount(String productType) {
Integer discount = cachedDiscounts.get(productType);
if (Objects.isNull(discount)) {
LOGGER.info("Discount for {} not found.", productType);
discount = 0;
} else {
LOGGER.info("Discount for {} found.", productType);
}
return discount;
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.cache2k;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class ProductHelperUnitTest {
ProductHelper productHelper = new ProductHelper();
@Test
public void whenInvokedGetDiscount_thenGetItFromCache() {
assertTrue(productHelper.getDiscount("Sports") == 20);
assertTrue(productHelper.getDiscount("Electronics") == 0);
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.cache2k;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class ProductHelperUsingLoaderUnitTest {
ProductHelperUsingLoader productHelper = new ProductHelperUsingLoader();
@Test
public void whenInvokedGetDiscount_thenPopulateCache() {
assertTrue(productHelper.getDiscount("Sports") == 20);
assertTrue(productHelper.getDiscount("Electronics") == 10);
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.cache2k;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class ProductHelperWithEventListenerUnitTest {
ProductHelperWithEventListener productHelper = new ProductHelperWithEventListener();
@Test
public void whenEntryAddedInCache_thenEventListenerCalled() {
assertTrue(productHelper.getDiscount("Sports") == 20);
}
}

View File

@ -0,0 +1,18 @@
package com.baeldung.cache2k;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class ProductHelperWithExpiryUnitTest {
ProductHelperWithExpiry productHelper = new ProductHelperWithExpiry();
@Test
public void whenInvokedGetDiscountForExpiredProduct_thenNoDiscount() throws InterruptedException {
assertTrue(productHelper.getDiscount("Sports") == 20);
Thread.sleep(20);
assertTrue(productHelper.getDiscount("Sports") == 0);
}
}

View File

@ -12,3 +12,4 @@ This module contains articles about HTTP libraries.
- [Introduction to Retrofit](https://www.baeldung.com/retrofit)
- [A Guide to Unirest](https://www.baeldung.com/unirest)
- [Creating REST Microservices with Javalin](https://www.baeldung.com/javalin-rest-microservices)
- [A Quick Guide to Timeouts in OkHttp](https://www.baeldung.com/okhttp-timeouts)

View File

@ -9,4 +9,4 @@ This module contains articles about security libraries.
- [Guide to Google Tink](https://www.baeldung.com/google-tink)
- [Introduction to BouncyCastle with Java](https://www.baeldung.com/java-bouncy-castle)
- [Intro to Jasypt](https://www.baeldung.com/jasypt)
- [Digital Signature in Java](https://www.baeldung.com/java-digital-signature)
- [Digital Signatures in Java](https://www.baeldung.com/java-digital-signature)

View File

@ -0,0 +1,3 @@
### Relevant Articles:
- [How to Create a Maven Plugin](https://www.baeldung.com/maven-plugin)

View File

@ -73,7 +73,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>3.2.0</version>
<version>${help.plugin.version}</version>
<executions>
<execution>
<id>show-profiles</id>
@ -87,4 +87,8 @@
</plugins>
</build>
<properties>
<help.plugin.version>3.2.0</help.plugin.version>
</properties>
</project>

View File

@ -46,7 +46,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<version>${versions.plugin.version}</version>
<configuration>
<excludes>
<exclude>org.apache.commons:commons-collections4</exclude>
@ -76,6 +76,7 @@
<commons-collections4.version>4.0</commons-collections4.version>
<commons-lang3.version>3.0</commons-lang3.version>
<commons-beanutils.version>1.9.1</commons-beanutils.version>
<versions.plugin.version>2.7</versions.plugin.version>
</properties>
</project>

View File

@ -16,6 +16,12 @@
<bootstrap.version>3.3.4</bootstrap.version>
<jquery.version>2.1.3</jquery.version>
<h2.version>1.4.186</h2.version>
<compiler.plugin.version>3.2</compiler.plugin.version>
<source.version>1.8</source.version>
<target.version>1.8</target.version>
<enforcer.plugin.version>1.3.1</enforcer.plugin.version>
<deploy.plugin.version>2.8.2</deploy.plugin.version>
<shade.plugin.version>2.2</shade.plugin.version>
</properties>
<build>
@ -23,16 +29,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<version>${compiler.plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>${source.version}</source>
<target>${target.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<version>${enforcer.plugin.version}</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
@ -95,7 +101,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<version>${deploy.plugin.version}</version>
<configuration>
<skip>true</skip>
</configuration>
@ -103,7 +109,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<version>${shade.plugin.version}</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>

View File

@ -4,4 +4,4 @@ This module contains articles about the implementation of OAuth2 with Java EE.
### Relevant Articles
- [Implementing The OAuth 2.0 Authorization Framework Using Java EE](https://www.baeldung.com/java-ee-oauth2-implementation)
- [Implementing The OAuth 2.0 Authorization Framework Using Jakarta EE](https://www.baeldung.com/java-ee-oauth2-implementation)

130
open-liberty/pom.xml Normal file
View File

@ -0,0 +1,130 @@
<?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>
<groupId>com.baeldung</groupId>
<artifactId>open-liberty</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>${version.jakarta.jakartaee-web-api}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>${version.microprofile}</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>${version.derby}</version>
</dependency>
<!-- For tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>yasson</artifactId>
<version>${version.yasson}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>${version.cxf-rt-rs-client}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>${version.javax.json}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-mp-client</artifactId>
<version>${version.cxf-rt-rs-mp-client}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- Enable liberty-maven plugin -->
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>${version.liberty-maven-plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${version.maven-dependency-plugin}</version>
<executions>
<execution>
<id>copy-derby-dependency</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>derby</includeArtifactIds>
<outputDirectory>${project.build.directory}/liberty/wlp/usr/shared/resources/</outputDirectory>
<systemPropertyVariables>
<liberty.test.port>${testServerHttpPort}</liberty.test.port>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${version.maven-war-plugin}</version>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!-- versions -->
<version.jakarta.jakartaee-web-api>8.0.0</version.jakarta.jakartaee-web-api>
<version.microprofile>3.2</version.microprofile>
<version.derby>10.14.2.0</version.derby>
<version.liberty-maven-plugin>3.1</version.liberty-maven-plugin>
<version.maven-dependency-plugin>2.10</version.maven-dependency-plugin>
<version.maven-war-plugin>3.2.3</version.maven-war-plugin>
<version.junit>4.12</version.junit>
<version.yasson>1.0.5</version.yasson>
<version.cxf-rt-rs-client>3.2.6</version.cxf-rt-rs-client>
<version.javax.json>1.0.4</version.javax.json>
<version.cxf-rt-rs-mp-client>3.3.1</version.cxf-rt-rs-mp-client>
<!-- Liberty configuration -->
<liberty.var.app.context.root>openliberty</liberty.var.app.context.root>
<liberty.var.default.http.port>9080</liberty.var.default.http.port>
<liberty.var.default.https.port>9443</liberty.var.default.https.port>
<testServerHttpPort>7070</testServerHttpPort>
</properties>
</project>

View File

@ -0,0 +1,24 @@
package com.baeldung.openliberty.person.dao;
import javax.enterprise.context.RequestScoped;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import com.baeldung.openliberty.person.model.Person;
@RequestScoped
public class PersonDao {
@PersistenceContext(name = "jpa-unit")
private EntityManager em;
public Person createPerson(Person person) {
em.persist(person);
return person;
}
public Person readPerson(int personId) {
return em.find(Person.class, personId);
}
}

View File

@ -0,0 +1,58 @@
package com.baeldung.openliberty.person.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
@Entity
public class Person {
@GeneratedValue(strategy = GenerationType.AUTO)
@Id
private int id;
private String username;
private String email;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Person(int id, @NotBlank String username, @Email String email) {
super();
this.id = id;
this.username = username;
this.email = email;
}
public Person() {
super();
}
public String toString() {
return this.id + ":" +this.username;
}
}

View File

@ -0,0 +1,52 @@
package com.baeldung.openliberty.person.resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
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 com.baeldung.openliberty.person.dao.PersonDao;
import com.baeldung.openliberty.person.model.Person;
@RequestScoped
@Path("persons")
public class PersonResource {
@Inject
private PersonDao personDao;
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Person> getAllPersons() {
return Arrays.asList(new Person(1, "normanlewis", "normanlewis@email.com"));
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Transactional
public Response addPerson(Person person) {
personDao.createPerson(person);
String respMessage = "Person #" + person.getId() + " created successfully.";
return Response.status(Response.Status.CREATED).entity(respMessage).build();
}
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public Person getPerson(@PathParam("id") int id) {
Person person = personDao.readPerson(id);
return person;
}
}

View File

@ -0,0 +1,9 @@
package com.baeldung.openliberty.rest;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/api")
public class ApiApplication extends Application {
}

View File

@ -0,0 +1,18 @@
package com.baeldung.openliberty.rest.consumes;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
public class RestConsumer {
public static String consumeWithJsonb(String targetUrl) {
Client client = ClientBuilder.newClient();
Response response = client.target(targetUrl).request().get();
String result = response.readEntity(String.class);
response.close();
client.close();
return result;
}
}

View File

@ -0,0 +1,27 @@
package com.baeldung.openliberty.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns="/app")
public class AppServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String htmlOutput = "<html><h2>Hello! Welcome to Open Liberty</h2></html>";
response.getWriter().append(htmlOutput);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}

View File

@ -0,0 +1,28 @@
<server description="Baeldung Open Liberty server">
<featureManager>
<feature>mpHealth-2.0</feature>
<feature>servlet-4.0</feature>
<feature>jaxrs-2.1</feature>
<feature>jsonp-1.1</feature>
<feature>jsonb-1.0</feature>
<feature>cdi-2.0</feature>
<feature>jpa-2.2</feature>
</featureManager>
<webApplication location="open-liberty.war" contextRoot="/" />
<logging traceSpecification="com.ibm.ws.microprofile.health.*=all" hideMessage="SRVE9967W" />
<httpEndpoint host="*" httpPort="${default.http.port}" httpsPort="${default.https.port}" id="defaultHttpEndpoint" />
<library id="derbyJDBCLib">
<fileset dir="${shared.resource.dir}" includes="derby*.jar"/>
</library>
<!-- Datasource Configuration -->
<dataSource id="jpadatasource" jndiName="jdbc/jpadatasource">
<jdbcDriver libraryRef="derbyJDBCLib" />
<properties.derby.embedded databaseName="libertyDB" createDatabase="create" />
</dataSource>
</server>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name="jpa-unit" transaction-type="JTA">
<jta-data-source>jdbc/jpadatasource</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="both" />
</properties>
</persistence-unit>
</persistence>

View File

@ -0,0 +1,40 @@
package com.baeldung.openliberty;
import static org.junit.Assert.assertEquals;
import javax.json.bind.JsonbBuilder;
import org.junit.BeforeClass;
import org.junit.Test;
import com.baeldung.openliberty.person.model.Person;
import com.baeldung.openliberty.rest.consumes.RestConsumer;
public class RestClientTest {
private static String BASE_URL;
private final String API_PERSON = "api/persons";
@BeforeClass
public static void oneTimeSetup() {
BASE_URL = "http://localhost:9080/";
}
@Test
public void testSuite() {
//run the test only when liberty server is started
//this.whenConsumeWithJsonb_thenGetPerson();
}
public void whenConsumeWithJsonb_thenGetPerson() {
String url = BASE_URL + API_PERSON + "/1";
String result = RestConsumer.consumeWithJsonb(url);
Person person = JsonbBuilder.create().fromJson(result, Person.class);
assertEquals(1, person.getId());
assertEquals("normanlewis", person.getUsername());
assertEquals("normanlewis@email.com", person.getEmail());
}
}

View File

@ -16,7 +16,7 @@
<repositories>
<repository>
<id>jcenter</id>
<url>http://jcenter.bintray.com</url>
<url>https://jcenter.bintray.com</url>
</repository>
<repository>
<id>kotlin-ktor</id>
@ -45,7 +45,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.0.M4</version>
<version>${boot.dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -215,6 +215,7 @@
<ktor.io.version>0.9.5</ktor.io.version>
<assertj.version>3.12.0</assertj.version>
<junit.platform.version>1.3.2</junit.platform.version>
<boot.dependencies.version>2.2.0.M4</boot.dependencies.version>
</properties>
</project>

View File

@ -51,7 +51,7 @@
</build>
<properties>
<spring.version>4.3.25.RELEASE</spring.version>
<spring.version>4.3.26.RELEASE</spring.version>
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
</properties>

View File

@ -38,7 +38,7 @@
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.2.0.Final</version>
<version>${mapstruct-jdk8.version}</version>
<scope>provided</scope>
</dependency>
@ -93,6 +93,15 @@
Name of the benchmark Uber-JAR to generate.
-->
<uberjar.name>benchmarks</uberjar.name>
<compiler.plugin.version>3.1</compiler.plugin.version>
<shade.plugin.version>2.2</shade.plugin.version>
<install.version>2.5.1</install.version>
<jar.plugin.version>2.4</jar.plugin.version>
<javadoc.plugin.version>2.9.1</javadoc.plugin.version>
<resources.plugin.version>2.6</resources.plugin.version>
<site.plugin.version>3.3</site.plugin.version>
<source.plugin.version>2.2.1</source.plugin.version>
<surefire.plugin.version>2.17</surefire.plugin.version>
</properties>
<build>
@ -100,7 +109,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>${compiler.plugin.version}</version>
<configuration>
<compilerVersion>${javac.target}</compilerVersion>
<source>${javac.target}</source>
@ -117,7 +126,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<version>${shade.plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
@ -162,31 +171,31 @@
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
<version>${install.version}</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<version>${jar.plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<version>${javadoc.plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<version>${resources.plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<version>${site.plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<version>${source.plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<version>${surefire.plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>

View File

@ -6,4 +6,5 @@ This module contains articles about Hibernate 5.
- [Hibernate Error “Not all named parameters have been set”](https://www.baeldung.com/hibernate-error-named-parameters-not-set)
- [FetchMode in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-fetchmode)
- [JPA/Hibernate Persistence Context](https://www.baeldung.com/jpa-hibernate-persistence-context)
- [FetchMode in Hibernate](https://www.baeldung.com/hibernate-fetchmode)
- [[<-- Prev]](/hibernate5)

View File

@ -54,9 +54,9 @@
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang3.version}</version>
</dependency>
</dependencies>
@ -66,6 +66,9 @@
<commons-lang3.version>3.8.1</commons-lang3.version>
<maven.deploy.skip>true</maven.deploy.skip>
<spring-boot.version>2.1.7.RELEASE</spring-boot.version>
<hibernate.core.version>5.4.7.Final</hibernate.core.version>
<h2.version>1.4.200</h2.version>
<commons.lang3.version>3.8.1</commons.lang3.version>
</properties>
</project>

View File

@ -55,7 +55,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<id>document</id>

View File

@ -1,4 +1,3 @@
## Relevant articles:
- [Introduction to Sirix](https://www.baeldung.com/introduction-to-sirix)
- [A Guide to SirixDB](https://www.baeldung.com/sirix)

View File

@ -30,7 +30,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<version>${compiler.plugin.version}</version>
<configuration>
<release>${maven.release.version}</release>
<encoding>${project.build.sourceEncoding}</encoding>
@ -39,7 +39,7 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.1</version> <!-- Use newer version of ASM -->
<version>${asm.version}</version> <!-- Use newer version of ASM -->
</dependency>
</dependencies>
</plugin>
@ -50,6 +50,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.release.version>11</maven.release.version>
<sirix-core.version>0.9.3</sirix-core.version>
<compiler.plugin.version>3.8.0</compiler.plugin.version>
<asm.version>6.1</asm.version>
</properties>
</project>

View File

@ -20,7 +20,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.8.RELEASE</version>
<version>${spring.boot.dependencies}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -95,6 +95,7 @@
<properties>
<jdbi.version>3.9.1</jdbi.version>
<spring.boot.dependencies>2.1.8.RELEASE</spring.boot.dependencies>
</properties>
</project>

View File

@ -17,7 +17,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot-version}</version>
<version>${spring.boot.starter.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
@ -88,6 +88,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.baeldung.springdatageode.app.ClientCacheApp</start-class>
<spring-geode-starter-version>1.1.1.RELEASE</spring-geode-starter-version>
<spring.boot.starter.version>2.1.9.RELEASE</spring.boot.starter.version>
</properties>
</project>

63
pom.xml
View File

@ -538,6 +538,7 @@
<module>netflix-modules</module>
<module>ninja</module>
<module>open-liberty</module>
<module>oauth2-framework-impl</module>
<module>optaplanner</module>
@ -637,38 +638,8 @@
<module>spring-batch</module>
<module>spring-bom</module>
<module>spring-boot</module>
<module>spring-boot-modules</module>
<module>spring-boot-angular</module>
<module>spring-boot-autoconfiguration</module>
<module>spring-boot-bootstrap</module>
<module>spring-boot-camel</module>
<!-- <module>spring-boot-cli</module> --> <!-- Not a maven project -->
<module>spring-boot-client</module>
<module>spring-boot-config-jpa-error</module>
<module>spring-boot-crud</module>
<module>spring-boot-ctx-fluent</module>
<module>spring-boot-custom-starter</module>
<module>spring-boot-deployment</module>
<module>spring-boot-di</module>
<module>spring-boot-environment</module>
<module>spring-boot-flowable</module>
<!-- <module>spring-boot-gradle</module> --> <!-- Not a maven project -->
<module>spring-boot-jasypt</module>
<module>spring-boot-kotlin</module>
<module>spring-boot-libraries</module>
<module>spring-boot-logging-log4j2</module>
<module>spring-boot-mvc-2</module>
<module>spring-boot-nashorn</module>
<module>spring-boot-parent</module>
<module>spring-boot-property-exp</module>
<module>spring-boot-rest</module>
<module>spring-boot-runtime</module>
<module>spring-boot-runtime/disabling-console-jul</module>
<module>spring-boot-runtime/disabling-console-log4j2</module>
<module>spring-boot-runtime/disabling-console-logback</module>
<module>spring-caching</module>
@ -1075,6 +1046,7 @@
<module>netflix-modules</module>
<module>ninja</module>
<module>open-liberty</module>
<module>oauth2-framework-impl</module>
<module>optaplanner</module>
@ -1166,39 +1138,8 @@
<module>spring-batch</module>
<module>spring-bom</module>
<module>spring-boot</module>
<module>spring-boot-modules</module>
<module>spring-boot-angular</module>
<module>spring-boot-autoconfiguration</module>
<module>spring-boot-bootstrap</module>
<module>spring-boot-camel</module>
<!-- <module>spring-boot-cli</module> --> <!-- Not a maven project -->
<module>spring-boot-client</module>
<module>spring-boot-config-jpa-error</module>
<module>spring-boot-crud</module>
<module>spring-boot-ctx-fluent</module>
<module>spring-boot-custom-starter</module>
<module>spring-boot-deployment</module>
<module>spring-boot-di</module>
<module>spring-boot-environment</module>
<module>spring-boot-flowable</module>
<!-- <module>spring-boot-gradle</module> --> <!-- Not a maven project -->
<module>spring-boot-jasypt</module>
<module>spring-boot-kotlin</module>
<module>spring-boot-libraries</module>
<module>spring-boot-logging-log4j2</module>
<module>spring-boot-mvc</module>
<module>spring-boot-mvc-2</module>
<module>spring-boot-nashorn</module>
<module>spring-boot-parent</module>
<module>spring-boot-property-exp</module>
<module>spring-boot-rest</module>
<module>spring-boot-runtime</module>
<module>spring-boot-runtime/disabling-console-jul</module>
<module>spring-boot-runtime/disabling-console-log4j2</module>
<module>spring-boot-runtime/disabling-console-logback</module>
<module>spring-caching</module>

View File

@ -0,0 +1,3 @@
### Relevant Articles:
- [How to Implement a Quarkus Extension](https://www.baeldung.com/quarkus-extension-java)

View File

@ -40,7 +40,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>${compiler.plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<path>
@ -54,4 +54,8 @@
</plugins>
</build>
<properties>
<compiler.plugin.version>3.8.1</compiler.plugin.version>
</properties>
</project>

View File

@ -50,7 +50,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>${compiler.plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<path>
@ -66,6 +66,8 @@
<properties>
<liquibase-core.version>3.8.1</liquibase-core.version>
<compiler.plugin.version>3.8.1</compiler.plugin.version>
<liquibase.version>3.8.1</liquibase.version>
</properties>
</project>

View File

@ -13,4 +13,5 @@ This module contains articles about RxJava.
- [RxJava Maybe](https://www.baeldung.com/rxjava-maybe)
- [Combining RxJava Completables](https://www.baeldung.com/rxjava-completable)
- [RxJava Hooks](https://www.baeldung.com/rxjava-hooks)
- [Introduction to rxjava-jdbc](https://www.baeldung.com/rxjava-jdbc)
- More articles: [[next -->]](/rxjava-2)

View File

@ -39,16 +39,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<version>${compiler.plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<version>${dependency.plugin.version}</version>
<executions>
<execution>
<id>copy-dependencies</id>
@ -84,6 +84,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spf4j.version>8.6.10</spf4j.version>
<org.slf4j.version>1.7.21</org.slf4j.version>
<compiler.plugin.version>3.8.0</compiler.plugin.version>
<dependency.plugin.version>3.1.1</dependency.plugin.version>
</properties>
</project>

View File

@ -39,16 +39,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<version>${compiler.plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<version>${dependency.plugin.version}</version>
<executions>
<execution>
<id>copy-dependencies</id>
@ -84,6 +84,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spf4j.version>8.6.10</spf4j.version>
<org.slf4j.version>1.7.21</org.slf4j.version>
<compiler.plugin.version>3.8.0</compiler.plugin.version>
<dependency.plugin.version>3.1.1</dependency.plugin.version>
</properties>
</project>

View File

@ -5,4 +5,5 @@ This module contains articles about Spring with the AMQP messaging system
## Relevant articles:
- [Messaging With Spring AMQP](https://www.baeldung.com/spring-amqp)
- [RabbitMQ Message Dispatching with Spring AMQP](https://www.baeldung.com/rabbitmq-spring-amqp)
- [RabbitMQ Message Dispatching with Spring AMQP](https://www.baeldung.com/rabbitmq-spring-amqp)
- [Error Handling with Spring AMQP](https://www.baeldung.com/spring-amqp-error-handling)

Some files were not shown because too many files have changed in this diff Show More