From 1b359b0e48933a8304a23d79bd3a7fa199a037aa Mon Sep 17 00:00:00 2001 From: joe zhang Date: Fri, 19 Jun 2020 11:06:53 +0800 Subject: [PATCH 001/102] Leasy Zhang/shiwangzhihe@gmail.com --- .../convertlisttomap/ListToMapUnitTest.java | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java diff --git a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java new file mode 100644 index 0000000000..e2340a5a9a --- /dev/null +++ b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java @@ -0,0 +1,102 @@ +package com.baeldung.convertlisttomap; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +import org.junit.Test; + +public class ListToMapUnitTest { + + @Test + public void givenAList_whenConvertWithJava8GroupBy_thenReturnMap() { + List strings = Arrays.asList("List", "Map", "Set", "Tree"); + + Map> convertedMap = new HashMap<>(); + + Supplier> listSupplier = () -> { + return new ArrayList<>(); + }; + + Supplier>> mapFactory = () -> { + return new HashMap<>(); + }; + convertedMap = strings.stream() + .collect(Collectors.groupingBy(String::length, mapFactory, Collectors.toCollection(listSupplier))); + + assertEquals(2, convertedMap.size()); + assertTrue(convertedMap.get(3) + .contains("Map")); + } + + @Test + public void givenAList_whenConvertWithJava8Collect_thenReturnMap() { + List strings = Arrays.asList("List", "Map", "Set", "Tree"); + + Map> convertedMap = new HashMap<>(); + + Supplier>> mapFactory = () -> { + return new HashMap<>(); + }; + + Supplier> listSupplier = () -> { + return new ArrayList<>(); + }; + + BiConsumer>, String> accumulator = (response, element) -> { + Integer key = element.length(); + List values = response.getOrDefault(key, listSupplier.get()); + values.add(element); + response.put(key, values); + }; + + BiConsumer>, Map>> combiner = (res1, res2) -> { + res1.putAll(res2); + }; + + convertedMap = strings.stream() + .collect(mapFactory, accumulator, combiner); + + assertEquals(2, convertedMap.size()); + assertTrue(convertedMap.get(3) + .contains("Map")); + } + + @Test + public void givenAList_whenConvertWithCollectorToMap_thenReturnMap() { + List strings = Arrays.asList("List", "Map", "Set", "Tree"); + + Map> convertedMap = new HashMap<>(); + + Supplier>> mapFactory = () -> { + return new HashMap<>(); + }; + + Supplier> listSupplier = () -> { + return new ArrayList<>(); + }; + + convertedMap = strings.stream() + .collect(Collectors.toMap(String::length, (p) -> { + List strs = listSupplier.get(); + strs.add(p); + return strs; + }, (existing, replacement) -> { + existing.addAll(replacement); + return existing; + }, mapFactory)); + + assertEquals(2, convertedMap.size()); + assertTrue(convertedMap.get(3) + .contains("Map")); + } + +} From 4ea247893a965bbca952c16823dcc3c904116c9c Mon Sep 17 00:00:00 2001 From: joe zhang Date: Mon, 29 Jun 2020 22:34:19 +0800 Subject: [PATCH 002/102] update unit test for collectors.toMap method --- .../convertlisttomap/ListToMapUnitTest.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java index e2340a5a9a..5a875a904e 100644 --- a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java +++ b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java @@ -9,6 +9,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.BiConsumer; +import java.util.function.BinaryOperator; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -84,15 +86,23 @@ public class ListToMapUnitTest { return new ArrayList<>(); }; + Function keyMapper = (element) -> { + return element.length(); + }; + + Function> valueMapper = (element) -> { + List collection = listSupplier.get(); + collection.add(element); + return collection; + }; + + BinaryOperator> mergeFunction = (existing, replacement) -> { + existing.addAll(replacement); + return existing; + }; + convertedMap = strings.stream() - .collect(Collectors.toMap(String::length, (p) -> { - List strs = listSupplier.get(); - strs.add(p); - return strs; - }, (existing, replacement) -> { - existing.addAll(replacement); - return existing; - }, mapFactory)); + .collect(Collectors.toMap(keyMapper, valueMapper, mergeFunction, mapFactory)); assertEquals(2, convertedMap.size()); assertTrue(convertedMap.get(3) From a4f1defb280c0d313f504c1a3eba5068bfdd61a5 Mon Sep 17 00:00:00 2001 From: Donato Rimenti Date: Thu, 2 Jul 2020 20:21:57 +0200 Subject: [PATCH 003/102] [BAEL-4074] Accessing Maven properties in Java --- maven-all/maven-2/.gitignore | 2 + maven-all/maven-2/README.md | 6 +++ maven-all/maven-2/pom.xml | 51 +++++++++++++++++++ .../maven/properties/PropertiesReader.java | 41 +++++++++++++++ .../properties/PropertiesReaderUnitTest.java | 27 ++++++++++ 5 files changed, 127 insertions(+) create mode 100644 maven-all/maven-2/.gitignore create mode 100644 maven-all/maven-2/README.md create mode 100644 maven-all/maven-2/pom.xml create mode 100644 maven-all/maven-2/src/main/java/com/baeldung/maven/properties/PropertiesReader.java create mode 100644 maven-all/maven-2/src/test/java/com/baeldung/maven/properties/PropertiesReaderUnitTest.java diff --git a/maven-all/maven-2/.gitignore b/maven-all/maven-2/.gitignore new file mode 100644 index 0000000000..bae0b0d7ce --- /dev/null +++ b/maven-all/maven-2/.gitignore @@ -0,0 +1,2 @@ +/output-resources +/.idea/ diff --git a/maven-all/maven-2/README.md b/maven-all/maven-2/README.md new file mode 100644 index 0000000000..5878a4f732 --- /dev/null +++ b/maven-all/maven-2/README.md @@ -0,0 +1,6 @@ +## Apache Maven + +This module contains articles about core Apache Maven. Articles about other Maven plugins (such as the Maven WAR Plugin) +have their own dedicated modules. + +### Relevant Articles diff --git a/maven-all/maven-2/pom.xml b/maven-all/maven-2/pom.xml new file mode 100644 index 0000000000..629da573b5 --- /dev/null +++ b/maven-all/maven-2/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + maven-2 + 0.0.1-SNAPSHOT + maven-2 + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../.. + + + + + junit + junit + 4.13 + + + + + + + org.codehaus.mojo + properties-maven-plugin + 1.0.0 + + + generate-resources + + write-project-properties + + + ${project.build.outputDirectory}/properties-from-pom.properties + + + + + + + + + ${project.name} + property-from-pom + + + \ No newline at end of file diff --git a/maven-all/maven-2/src/main/java/com/baeldung/maven/properties/PropertiesReader.java b/maven-all/maven-2/src/main/java/com/baeldung/maven/properties/PropertiesReader.java new file mode 100644 index 0000000000..e7000ec2ce --- /dev/null +++ b/maven-all/maven-2/src/main/java/com/baeldung/maven/properties/PropertiesReader.java @@ -0,0 +1,41 @@ +package com.baeldung.maven.properties; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +/** + * Reads properties from one file. + * + * @author Donato Rimenti + */ +public class PropertiesReader { + + /** + * Properties managed by this reader. + */ + private Properties properties; + + /** + * Reads the property file with the given name. + * + * @param propertyFileName the name of the property file to read + * @throws IOException if the file is not found or there's a problem reading it + */ + public PropertiesReader(String propertyFileName) throws IOException { + InputStream is = getClass().getClassLoader() + .getResourceAsStream(propertyFileName); + this.properties = new Properties(); + this.properties.load(is); + } + + /** + * Gets the property with the given name from the property file. + * @param propertyName the name of the property to read + * @return the property with the given name + */ + public String getProperty(String propertyName) { + return this.properties.getProperty(propertyName); + } + +} \ No newline at end of file diff --git a/maven-all/maven-2/src/test/java/com/baeldung/maven/properties/PropertiesReaderUnitTest.java b/maven-all/maven-2/src/test/java/com/baeldung/maven/properties/PropertiesReaderUnitTest.java new file mode 100644 index 0000000000..a1d6e66047 --- /dev/null +++ b/maven-all/maven-2/src/test/java/com/baeldung/maven/properties/PropertiesReaderUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.maven.properties; + +import java.io.IOException; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test for {@link PropertiesReader}. + * + * @author Donato Rimenti + */ +public class PropertiesReaderUnitTest { + + /** + * Reads a property and checks that's the one expected. + * + * @throws IOException if anything goes wrong + */ + @Test + public void givenPomProperties_whenPropertyRead_thenPropertyReturned() throws IOException { + PropertiesReader reader = new PropertiesReader("properties-from-pom.properties"); + String property = reader.getProperty("my.awesome.property"); + Assert.assertEquals("property-from-pom", property); + } + +} \ No newline at end of file From de057dc286243b075193730b3adfa2e5c33a9eb8 Mon Sep 17 00:00:00 2001 From: joe zhang Date: Tue, 7 Jul 2020 13:20:06 +0800 Subject: [PATCH 004/102] update labmda function --- .../convertlisttomap/ListToMapUnitTest.java | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java index 5a875a904e..4ca5671e29 100644 --- a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java +++ b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java @@ -24,13 +24,9 @@ public class ListToMapUnitTest { Map> convertedMap = new HashMap<>(); - Supplier> listSupplier = () -> { - return new ArrayList<>(); - }; + Supplier> listSupplier = ArrayList::new; - Supplier>> mapFactory = () -> { - return new HashMap<>(); - }; + Supplier>> mapFactory = HashMap::new; convertedMap = strings.stream() .collect(Collectors.groupingBy(String::length, mapFactory, Collectors.toCollection(listSupplier))); @@ -45,13 +41,9 @@ public class ListToMapUnitTest { Map> convertedMap = new HashMap<>(); - Supplier>> mapFactory = () -> { - return new HashMap<>(); - }; + Supplier>> mapFactory = HashMap::new; - Supplier> listSupplier = () -> { - return new ArrayList<>(); - }; + Supplier> listSupplier = ArrayList::new; BiConsumer>, String> accumulator = (response, element) -> { Integer key = element.length(); @@ -78,17 +70,11 @@ public class ListToMapUnitTest { Map> convertedMap = new HashMap<>(); - Supplier>> mapFactory = () -> { - return new HashMap<>(); - }; + Supplier>> mapFactory = HashMap::new; - Supplier> listSupplier = () -> { - return new ArrayList<>(); - }; + Supplier> listSupplier = ArrayList::new; - Function keyMapper = (element) -> { - return element.length(); - }; + Function keyMapper = String::length; Function> valueMapper = (element) -> { List collection = listSupplier.get(); From 7f71c4242f7c897c00038d90b1c035d0d2250b0c Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Sat, 11 Jul 2020 20:34:36 -0600 Subject: [PATCH 005/102] BAEL-4148: Demo app for spring boot and Docker --- docker/docker-spring-boot/mvnw | 310 ++++++++++++++++++ docker/docker-spring-boot/mvnw.cmd | 182 ++++++++++ docker/docker-spring-boot/pom.xml | 54 +++ .../src/main/docker/Dockerfile | 15 + .../com/baeldung/docker/DemoApplication.java | 13 + .../com/baeldung/docker/HelloController.java | 16 + .../src/main/resources/application.properties | 1 + 7 files changed, 591 insertions(+) create mode 100755 docker/docker-spring-boot/mvnw create mode 100644 docker/docker-spring-boot/mvnw.cmd create mode 100644 docker/docker-spring-boot/pom.xml create mode 100644 docker/docker-spring-boot/src/main/docker/Dockerfile create mode 100644 docker/docker-spring-boot/src/main/java/com/baeldung/docker/DemoApplication.java create mode 100644 docker/docker-spring-boot/src/main/java/com/baeldung/docker/HelloController.java create mode 100644 docker/docker-spring-boot/src/main/resources/application.properties diff --git a/docker/docker-spring-boot/mvnw b/docker/docker-spring-boot/mvnw new file mode 100755 index 0000000000..a16b5431b4 --- /dev/null +++ b/docker/docker-spring-boot/mvnw @@ -0,0 +1,310 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/docker/docker-spring-boot/mvnw.cmd b/docker/docker-spring-boot/mvnw.cmd new file mode 100644 index 0000000000..c8d43372c9 --- /dev/null +++ b/docker/docker-spring-boot/mvnw.cmd @@ -0,0 +1,182 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/docker/docker-spring-boot/pom.xml b/docker/docker-spring-boot/pom.xml new file mode 100644 index 0000000000..b9c80bc43a --- /dev/null +++ b/docker/docker-spring-boot/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.1.RELEASE + + + com.baeldung.docker + spring-boot-docker + 0.0.1-SNAPSHOT + spring-boot-docker + Demo project showing Spring Boot and Docker + + + 8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + true + + + + + + + diff --git a/docker/docker-spring-boot/src/main/docker/Dockerfile b/docker/docker-spring-boot/src/main/docker/Dockerfile new file mode 100644 index 0000000000..fa147dd69b --- /dev/null +++ b/docker/docker-spring-boot/src/main/docker/Dockerfile @@ -0,0 +1,15 @@ +# To build, run the following command from the top level project directory: +# +# docker build -f src/main/docker/Dockerfile . + +FROM adoptopenjdk:11-jre-hotspot as builder +ARG JAR_FILE=target/*.jar +COPY ${JAR_FILE} application.jar +RUN java -Djarmode=layertools -jar application.jar extract + +FROM adoptopenjdk:11-jre-hotspot +COPY --from=builder dependencies/ ./ +COPY --from=builder snapshot-dependencies/ ./ +COPY --from=builder spring-boot-loader/ ./ +COPY --from=builder application/ ./ +ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"] \ No newline at end of file diff --git a/docker/docker-spring-boot/src/main/java/com/baeldung/docker/DemoApplication.java b/docker/docker-spring-boot/src/main/java/com/baeldung/docker/DemoApplication.java new file mode 100644 index 0000000000..e0c1d57e89 --- /dev/null +++ b/docker/docker-spring-boot/src/main/java/com/baeldung/docker/DemoApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.docker; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + +} diff --git a/docker/docker-spring-boot/src/main/java/com/baeldung/docker/HelloController.java b/docker/docker-spring-boot/src/main/java/com/baeldung/docker/HelloController.java new file mode 100644 index 0000000000..b463bb557f --- /dev/null +++ b/docker/docker-spring-boot/src/main/java/com/baeldung/docker/HelloController.java @@ -0,0 +1,16 @@ +package com.baeldung.docker; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloController { + + @GetMapping("/hello") + public ResponseEntity hello() + { + return ResponseEntity.ok("hello2 "); + } + +} diff --git a/docker/docker-spring-boot/src/main/resources/application.properties b/docker/docker-spring-boot/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/docker/docker-spring-boot/src/main/resources/application.properties @@ -0,0 +1 @@ + From 8a3eac686cbdaf14f467d2c6204fde50b9689018 Mon Sep 17 00:00:00 2001 From: joe zhang Date: Sun, 12 Jul 2020 16:19:08 +0800 Subject: [PATCH 006/102] refactor unit test into utility class --- .../convertlisttomap/ListToMapConverter.java | 70 +++++++++++++++++ .../convertlisttomap/ListToMapUnitTest.java | 78 ++++--------------- 2 files changed, 83 insertions(+), 65 deletions(-) create mode 100644 java-collections-conversions-2/src/main/java/com/baeldung/convertlisttomap/ListToMapConverter.java diff --git a/java-collections-conversions-2/src/main/java/com/baeldung/convertlisttomap/ListToMapConverter.java b/java-collections-conversions-2/src/main/java/com/baeldung/convertlisttomap/ListToMapConverter.java new file mode 100644 index 0000000000..8450f54f9d --- /dev/null +++ b/java-collections-conversions-2/src/main/java/com/baeldung/convertlisttomap/ListToMapConverter.java @@ -0,0 +1,70 @@ +package com.baeldung.convertlisttomap; + +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.BinaryOperator; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +/** + * Convert a string list to a map whose key is the string's length and value is the collection with same length. + * Give a list {"Baeldung", "is", "very", "cool"}. + * After conversion we'll get a map like: + * {8 : ["Baeldung"], 2 : ["is"], 4 : ["very", "cool"]}. + * + * @author leasy.zhang + * + */ +public class ListToMapConverter { + + public Map> groupingByStringLength(List source, + Supplier>> mapSupplier, + Supplier> listSupplier) { + + return source.stream() + .collect(Collectors.groupingBy(String::length, mapSupplier, Collectors.toCollection(listSupplier))); + } + + public Map> streamCollectByStringLength(List source, + Supplier>> mapSupplier, + Supplier> listSupplier) { + + BiConsumer>, String> accumulator = (response, element) -> { + Integer key = element.length(); + List values = response.getOrDefault(key, listSupplier.get()); + values.add(element); + response.put(key, values); + }; + + BiConsumer>, Map>> combiner = (res1, res2) -> { + res1.putAll(res2); + }; + + return source.stream() + .collect(mapSupplier, accumulator, combiner); + } + + public Map> collectorToMapByStringLength(List source, + Supplier>> mapSupplier, + Supplier> listSupplier) { + + Function keyMapper = String::length; + + Function> valueMapper = (element) -> { + List collection = listSupplier.get(); + collection.add(element); + return collection; + }; + + BinaryOperator> mergeFunction = (existing, replacement) -> { + existing.addAll(replacement); + return existing; + }; + + return source.stream() + .collect(Collectors.toMap(keyMapper, valueMapper, mergeFunction, mapSupplier)); + } + +} diff --git a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java index 4ca5671e29..2b43813822 100644 --- a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java +++ b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java @@ -1,6 +1,5 @@ package com.baeldung.convertlisttomap; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.ArrayList; @@ -8,89 +7,38 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.BiConsumer; -import java.util.function.BinaryOperator; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.Collectors; +import org.junit.Before; import org.junit.Test; public class ListToMapUnitTest { + private ListToMapConverter converter; + private List source; + + @Before + public void setUp() { + converter = new ListToMapConverter(); + source = Arrays.asList("List", "Map", "Set", "Tree"); + } + @Test public void givenAList_whenConvertWithJava8GroupBy_thenReturnMap() { - List strings = Arrays.asList("List", "Map", "Set", "Tree"); - - Map> convertedMap = new HashMap<>(); - - Supplier> listSupplier = ArrayList::new; - - Supplier>> mapFactory = HashMap::new; - convertedMap = strings.stream() - .collect(Collectors.groupingBy(String::length, mapFactory, Collectors.toCollection(listSupplier))); - - assertEquals(2, convertedMap.size()); + Map> convertedMap = converter.groupingByStringLength(source, HashMap::new, ArrayList::new); assertTrue(convertedMap.get(3) .contains("Map")); } @Test public void givenAList_whenConvertWithJava8Collect_thenReturnMap() { - List strings = Arrays.asList("List", "Map", "Set", "Tree"); - - Map> convertedMap = new HashMap<>(); - - Supplier>> mapFactory = HashMap::new; - - Supplier> listSupplier = ArrayList::new; - - BiConsumer>, String> accumulator = (response, element) -> { - Integer key = element.length(); - List values = response.getOrDefault(key, listSupplier.get()); - values.add(element); - response.put(key, values); - }; - - BiConsumer>, Map>> combiner = (res1, res2) -> { - res1.putAll(res2); - }; - - convertedMap = strings.stream() - .collect(mapFactory, accumulator, combiner); - - assertEquals(2, convertedMap.size()); + Map> convertedMap = converter.streamCollectByStringLength(source, HashMap::new, ArrayList::new); assertTrue(convertedMap.get(3) .contains("Map")); } @Test public void givenAList_whenConvertWithCollectorToMap_thenReturnMap() { - List strings = Arrays.asList("List", "Map", "Set", "Tree"); - - Map> convertedMap = new HashMap<>(); - - Supplier>> mapFactory = HashMap::new; - - Supplier> listSupplier = ArrayList::new; - - Function keyMapper = String::length; - - Function> valueMapper = (element) -> { - List collection = listSupplier.get(); - collection.add(element); - return collection; - }; - - BinaryOperator> mergeFunction = (existing, replacement) -> { - existing.addAll(replacement); - return existing; - }; - - convertedMap = strings.stream() - .collect(Collectors.toMap(keyMapper, valueMapper, mergeFunction, mapFactory)); - - assertEquals(2, convertedMap.size()); + Map> convertedMap = converter.collectorToMapByStringLength(source, HashMap::new, ArrayList::new); assertTrue(convertedMap.get(3) .contains("Map")); } From f7739a26b8dbfb624f14b1977c3303d396e32802 Mon Sep 17 00:00:00 2001 From: Donato Rimenti Date: Sun, 12 Jul 2020 11:38:22 +0200 Subject: [PATCH 007/102] Fixed formatting. --- maven-all/maven-2/pom.xml | 86 +++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/maven-all/maven-2/pom.xml b/maven-all/maven-2/pom.xml index 629da573b5..74bae61f03 100644 --- a/maven-all/maven-2/pom.xml +++ b/maven-all/maven-2/pom.xml @@ -1,51 +1,51 @@ - 4.0.0 - maven-2 - 0.0.1-SNAPSHOT - maven-2 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + maven-2 + 0.0.1-SNAPSHOT + maven-2 - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../.. - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../.. + - - - junit - junit - 4.13 - - + + + junit + junit + 4.13 + + - - - - org.codehaus.mojo - properties-maven-plugin - 1.0.0 - - - generate-resources - - write-project-properties - - - ${project.build.outputDirectory}/properties-from-pom.properties - - - - - - + + + + org.codehaus.mojo + properties-maven-plugin + 1.0.0 + + + generate-resources + + write-project-properties + + + ${project.build.outputDirectory}/properties-from-pom.properties + + + + + + - - ${project.name} - property-from-pom - + + ${project.name} + property-from-pom + \ No newline at end of file From 192b067e96a2559ebd6034c4d08953d9dede89cc Mon Sep 17 00:00:00 2001 From: Donato Rimenti Date: Sun, 12 Jul 2020 11:45:26 +0200 Subject: [PATCH 008/102] Moved and renamed maven-all/maven-2 to maven-modules/maven-properties --- maven-modules/maven-properties/.gitignore | 2 + maven-modules/maven-properties/README.md | 8 +++ maven-modules/maven-properties/pom.xml | 51 +++++++++++++++++++ .../maven/properties/PropertiesReader.java | 41 +++++++++++++++ .../properties/PropertiesReaderUnitTest.java | 27 ++++++++++ maven-modules/pom.xml | 1 + 6 files changed, 130 insertions(+) create mode 100644 maven-modules/maven-properties/.gitignore create mode 100644 maven-modules/maven-properties/README.md create mode 100644 maven-modules/maven-properties/pom.xml create mode 100644 maven-modules/maven-properties/src/main/java/com/baeldung/maven/properties/PropertiesReader.java create mode 100644 maven-modules/maven-properties/src/test/java/com/baeldung/maven/properties/PropertiesReaderUnitTest.java diff --git a/maven-modules/maven-properties/.gitignore b/maven-modules/maven-properties/.gitignore new file mode 100644 index 0000000000..bae0b0d7ce --- /dev/null +++ b/maven-modules/maven-properties/.gitignore @@ -0,0 +1,2 @@ +/output-resources +/.idea/ diff --git a/maven-modules/maven-properties/README.md b/maven-modules/maven-properties/README.md new file mode 100644 index 0000000000..65d976189c --- /dev/null +++ b/maven-modules/maven-properties/README.md @@ -0,0 +1,8 @@ +## Apache Maven + +This module contains articles about core Apache Maven. Articles about other Maven plugins (such as the Maven WAR Plugin) +have their own dedicated modules. + +### Relevant Articles + +- [Accessing Maven Properties in Java] \ No newline at end of file diff --git a/maven-modules/maven-properties/pom.xml b/maven-modules/maven-properties/pom.xml new file mode 100644 index 0000000000..2cd92da42f --- /dev/null +++ b/maven-modules/maven-properties/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + maven-properties + 0.0.1-SNAPSHOT + maven-properties + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../.. + + + + + junit + junit + 4.13 + + + + + + + org.codehaus.mojo + properties-maven-plugin + 1.0.0 + + + generate-resources + + write-project-properties + + + ${project.build.outputDirectory}/properties-from-pom.properties + + + + + + + + + ${project.name} + property-from-pom + + + \ No newline at end of file diff --git a/maven-modules/maven-properties/src/main/java/com/baeldung/maven/properties/PropertiesReader.java b/maven-modules/maven-properties/src/main/java/com/baeldung/maven/properties/PropertiesReader.java new file mode 100644 index 0000000000..e7000ec2ce --- /dev/null +++ b/maven-modules/maven-properties/src/main/java/com/baeldung/maven/properties/PropertiesReader.java @@ -0,0 +1,41 @@ +package com.baeldung.maven.properties; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +/** + * Reads properties from one file. + * + * @author Donato Rimenti + */ +public class PropertiesReader { + + /** + * Properties managed by this reader. + */ + private Properties properties; + + /** + * Reads the property file with the given name. + * + * @param propertyFileName the name of the property file to read + * @throws IOException if the file is not found or there's a problem reading it + */ + public PropertiesReader(String propertyFileName) throws IOException { + InputStream is = getClass().getClassLoader() + .getResourceAsStream(propertyFileName); + this.properties = new Properties(); + this.properties.load(is); + } + + /** + * Gets the property with the given name from the property file. + * @param propertyName the name of the property to read + * @return the property with the given name + */ + public String getProperty(String propertyName) { + return this.properties.getProperty(propertyName); + } + +} \ No newline at end of file diff --git a/maven-modules/maven-properties/src/test/java/com/baeldung/maven/properties/PropertiesReaderUnitTest.java b/maven-modules/maven-properties/src/test/java/com/baeldung/maven/properties/PropertiesReaderUnitTest.java new file mode 100644 index 0000000000..a1d6e66047 --- /dev/null +++ b/maven-modules/maven-properties/src/test/java/com/baeldung/maven/properties/PropertiesReaderUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.maven.properties; + +import java.io.IOException; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test for {@link PropertiesReader}. + * + * @author Donato Rimenti + */ +public class PropertiesReaderUnitTest { + + /** + * Reads a property and checks that's the one expected. + * + * @throws IOException if anything goes wrong + */ + @Test + public void givenPomProperties_whenPropertyRead_thenPropertyReturned() throws IOException { + PropertiesReader reader = new PropertiesReader("properties-from-pom.properties"); + String property = reader.getProperty("my.awesome.property"); + Assert.assertEquals("property-from-pom", property); + } + +} \ No newline at end of file diff --git a/maven-modules/pom.xml b/maven-modules/pom.xml index c4d8c253df..2de8560244 100644 --- a/maven-modules/pom.xml +++ b/maven-modules/pom.xml @@ -24,6 +24,7 @@ maven-profiles versions-maven-plugin version-collision + maven-properties From 0d5a288fec717c62e42b728fcef83a13288b2514 Mon Sep 17 00:00:00 2001 From: Donato Rimenti Date: Sun, 12 Jul 2020 11:47:27 +0200 Subject: [PATCH 009/102] Fixed pom formatting. --- maven-modules/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-modules/pom.xml b/maven-modules/pom.xml index 2de8560244..d990ed16c1 100644 --- a/maven-modules/pom.xml +++ b/maven-modules/pom.xml @@ -24,7 +24,7 @@ maven-profiles versions-maven-plugin version-collision - maven-properties + maven-properties From 973e78dc4c17a874ce300db1cbcf3c6375bcc3d3 Mon Sep 17 00:00:00 2001 From: Donato Rimenti Date: Sun, 12 Jul 2020 18:01:22 +0200 Subject: [PATCH 010/102] Removed maven-all project since it was moved to maven-modules. --- maven-all/maven-2/.gitignore | 2 - maven-all/maven-2/README.md | 6 --- maven-all/maven-2/pom.xml | 51 ------------------- .../maven/properties/PropertiesReader.java | 41 --------------- .../properties/PropertiesReaderUnitTest.java | 27 ---------- 5 files changed, 127 deletions(-) delete mode 100644 maven-all/maven-2/.gitignore delete mode 100644 maven-all/maven-2/README.md delete mode 100644 maven-all/maven-2/pom.xml delete mode 100644 maven-all/maven-2/src/main/java/com/baeldung/maven/properties/PropertiesReader.java delete mode 100644 maven-all/maven-2/src/test/java/com/baeldung/maven/properties/PropertiesReaderUnitTest.java diff --git a/maven-all/maven-2/.gitignore b/maven-all/maven-2/.gitignore deleted file mode 100644 index bae0b0d7ce..0000000000 --- a/maven-all/maven-2/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/output-resources -/.idea/ diff --git a/maven-all/maven-2/README.md b/maven-all/maven-2/README.md deleted file mode 100644 index 5878a4f732..0000000000 --- a/maven-all/maven-2/README.md +++ /dev/null @@ -1,6 +0,0 @@ -## Apache Maven - -This module contains articles about core Apache Maven. Articles about other Maven plugins (such as the Maven WAR Plugin) -have their own dedicated modules. - -### Relevant Articles diff --git a/maven-all/maven-2/pom.xml b/maven-all/maven-2/pom.xml deleted file mode 100644 index 74bae61f03..0000000000 --- a/maven-all/maven-2/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - 4.0.0 - maven-2 - 0.0.1-SNAPSHOT - maven-2 - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../.. - - - - - junit - junit - 4.13 - - - - - - - org.codehaus.mojo - properties-maven-plugin - 1.0.0 - - - generate-resources - - write-project-properties - - - ${project.build.outputDirectory}/properties-from-pom.properties - - - - - - - - - ${project.name} - property-from-pom - - - \ No newline at end of file diff --git a/maven-all/maven-2/src/main/java/com/baeldung/maven/properties/PropertiesReader.java b/maven-all/maven-2/src/main/java/com/baeldung/maven/properties/PropertiesReader.java deleted file mode 100644 index e7000ec2ce..0000000000 --- a/maven-all/maven-2/src/main/java/com/baeldung/maven/properties/PropertiesReader.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.maven.properties; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -/** - * Reads properties from one file. - * - * @author Donato Rimenti - */ -public class PropertiesReader { - - /** - * Properties managed by this reader. - */ - private Properties properties; - - /** - * Reads the property file with the given name. - * - * @param propertyFileName the name of the property file to read - * @throws IOException if the file is not found or there's a problem reading it - */ - public PropertiesReader(String propertyFileName) throws IOException { - InputStream is = getClass().getClassLoader() - .getResourceAsStream(propertyFileName); - this.properties = new Properties(); - this.properties.load(is); - } - - /** - * Gets the property with the given name from the property file. - * @param propertyName the name of the property to read - * @return the property with the given name - */ - public String getProperty(String propertyName) { - return this.properties.getProperty(propertyName); - } - -} \ No newline at end of file diff --git a/maven-all/maven-2/src/test/java/com/baeldung/maven/properties/PropertiesReaderUnitTest.java b/maven-all/maven-2/src/test/java/com/baeldung/maven/properties/PropertiesReaderUnitTest.java deleted file mode 100644 index a1d6e66047..0000000000 --- a/maven-all/maven-2/src/test/java/com/baeldung/maven/properties/PropertiesReaderUnitTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.maven.properties; - -import java.io.IOException; - -import org.junit.Assert; -import org.junit.Test; - -/** - * Test for {@link PropertiesReader}. - * - * @author Donato Rimenti - */ -public class PropertiesReaderUnitTest { - - /** - * Reads a property and checks that's the one expected. - * - * @throws IOException if anything goes wrong - */ - @Test - public void givenPomProperties_whenPropertyRead_thenPropertyReturned() throws IOException { - PropertiesReader reader = new PropertiesReader("properties-from-pom.properties"); - String property = reader.getProperty("my.awesome.property"); - Assert.assertEquals("property-from-pom", property); - } - -} \ No newline at end of file From 7af5d25d0ed25cb7b624606ffdba17e2568c17ce Mon Sep 17 00:00:00 2001 From: Loredana Date: Fri, 17 Jul 2020 09:33:34 +0300 Subject: [PATCH 011/102] JAVA-2096 remove unused dependencies --- core-java-modules/core-java-io-3/pom.xml | 27 ------------------------ 1 file changed, 27 deletions(-) diff --git a/core-java-modules/core-java-io-3/pom.xml b/core-java-modules/core-java-io-3/pom.xml index cb341ca2ae..cc4dca5fa5 100644 --- a/core-java-modules/core-java-io-3/pom.xml +++ b/core-java-modules/core-java-io-3/pom.xml @@ -46,41 +46,14 @@ ${assertj.version} test - - - com.github.tomakehurst - wiremock - ${wiremock.version} - test - - core-java-io-3 - - - src/main/resources - true - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - ${maven.compiler.source} - ${maven.compiler.target} - - - 3.6.1 - 3.0.0-M1 - 2.26.3 \ No newline at end of file From 635846ffccf1b6d1ecbe949d3f87bc72ba3297c1 Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Fri, 17 Jul 2020 10:54:38 +0200 Subject: [PATCH 012/102] [BAEL4288] initial commit --- persistence-modules/flyway-repair/README.MD | 3 + .../flyway-repair/docker-compose/.env | 2 + .../docker-compose/docker-compose.yaml | 23 ++++ .../flyway-repair/docker-compose/mysql.env | 5 + .../flyway-repair/docker-compose/postgres.env | 3 + persistence-modules/flyway-repair/pom.xml | 105 ++++++++++++++++++ .../flywaycallbacks/FlywayApplication.java | 13 +++ .../application-callbacks.properties | 1 + .../main/resources/application-h2.properties | 3 + .../resources/application-mysql.properties | 3 + .../resources/application-postgres.properties | 3 + .../src/main/resources/application.properties | 6 + .../db/callbacks/afterMigrateError.sql | 1 + .../db/migration/V1_0__add_table_one.sql | 3 + .../db/migration/V1_1__add_table_two.sql | 3 + .../db/migration/V1_2__add_table_three.sql | 3 + .../db/migration/V1_3__add_table.sql | 3 + .../src/main/resources/logback.xml | 19 ++++ 18 files changed, 202 insertions(+) create mode 100644 persistence-modules/flyway-repair/README.MD create mode 100644 persistence-modules/flyway-repair/docker-compose/.env create mode 100644 persistence-modules/flyway-repair/docker-compose/docker-compose.yaml create mode 100644 persistence-modules/flyway-repair/docker-compose/mysql.env create mode 100644 persistence-modules/flyway-repair/docker-compose/postgres.env create mode 100644 persistence-modules/flyway-repair/pom.xml create mode 100644 persistence-modules/flyway-repair/src/main/java/com/baeldung/flywaycallbacks/FlywayApplication.java create mode 100644 persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties create mode 100644 persistence-modules/flyway-repair/src/main/resources/application-h2.properties create mode 100644 persistence-modules/flyway-repair/src/main/resources/application-mysql.properties create mode 100644 persistence-modules/flyway-repair/src/main/resources/application-postgres.properties create mode 100644 persistence-modules/flyway-repair/src/main/resources/application.properties create mode 100644 persistence-modules/flyway-repair/src/main/resources/db/callbacks/afterMigrateError.sql create mode 100644 persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table_one.sql create mode 100644 persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table_two.sql create mode 100644 persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table_three.sql create mode 100644 persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql create mode 100644 persistence-modules/flyway-repair/src/main/resources/logback.xml diff --git a/persistence-modules/flyway-repair/README.MD b/persistence-modules/flyway-repair/README.MD new file mode 100644 index 0000000000..daeb9012b5 --- /dev/null +++ b/persistence-modules/flyway-repair/README.MD @@ -0,0 +1,3 @@ +### Relevant Articles: +- [Database Migrations with Flyway](http://www.baeldung.com/database-migrations-with-flyway) +- [A Guide to Flyway Callbacks](http://www.baeldung.com/flyway-callbacks) diff --git a/persistence-modules/flyway-repair/docker-compose/.env b/persistence-modules/flyway-repair/docker-compose/.env new file mode 100644 index 0000000000..52bd0d6510 --- /dev/null +++ b/persistence-modules/flyway-repair/docker-compose/.env @@ -0,0 +1,2 @@ +MYSQL_PORT=3316 +POSTGRES_PORT=5431 \ No newline at end of file diff --git a/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml b/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml new file mode 100644 index 0000000000..23270c043d --- /dev/null +++ b/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml @@ -0,0 +1,23 @@ +version: '3.0' + +services: + mysql-test: + image: mysql:8.0.17 + ports: + - ${MYSQL_PORT}:3306 + env_file: + - mysql.env + networks: + - baeldung + + postgres-test: + image: postgres:11.5 + ports: + - ${POSTGRES_PORT}:5432 + env_file: postgres.env + networks: + - baeldung + +networks: + baeldung: + driver: bridge \ No newline at end of file diff --git a/persistence-modules/flyway-repair/docker-compose/mysql.env b/persistence-modules/flyway-repair/docker-compose/mysql.env new file mode 100644 index 0000000000..597344d88c --- /dev/null +++ b/persistence-modules/flyway-repair/docker-compose/mysql.env @@ -0,0 +1,5 @@ +MYSQL_ROOT_PASSWORD=password +MYSQL_RANDOM_ROOT_PASSWORD=yes +MYSQL_USER=testuser +MYSQL_PASSWORD=password +MYSQL_DATABASE=testdb \ No newline at end of file diff --git a/persistence-modules/flyway-repair/docker-compose/postgres.env b/persistence-modules/flyway-repair/docker-compose/postgres.env new file mode 100644 index 0000000000..1e7373fdf0 --- /dev/null +++ b/persistence-modules/flyway-repair/docker-compose/postgres.env @@ -0,0 +1,3 @@ +POSTGRES_USER=testuser +POSTGRES_PASSWORD=password +POSTGRES_DB=testdb diff --git a/persistence-modules/flyway-repair/pom.xml b/persistence-modules/flyway-repair/pom.xml new file mode 100644 index 0000000000..f9d62d5dad --- /dev/null +++ b/persistence-modules/flyway-repair/pom.xml @@ -0,0 +1,105 @@ + + + 4.0.0 + flyway + flyway-repair + jar + Flyway Repair Demo + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.flywaydb + flyway-core + ${flyway-core.version} + + + org.springframework.boot + spring-boot-starter-jdbc + + + + + + + org.flywaydb + flyway-maven-plugin + ${flyway-maven-plugin.version} + + + org.springframework.boot + spring-boot-maven-plugin + + + + + true + src/main/resources + + *.properties + db/**/*.sql + + + + + + + 6.5.0 + 6.5.0 + src/main/resources/application-${db.engine}.properties + + + + + + h2 + + h2 + + + + com.h2database + h2 + runtime + + + + + + mysql + + mysql + + + + mysql + mysql-connector-java + runtime + + + + + + postgres + + postgres + + + + org.postgresql + postgresql + runtime + + + + + + + diff --git a/persistence-modules/flyway-repair/src/main/java/com/baeldung/flywaycallbacks/FlywayApplication.java b/persistence-modules/flyway-repair/src/main/java/com/baeldung/flywaycallbacks/FlywayApplication.java new file mode 100644 index 0000000000..34d794f7d1 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/java/com/baeldung/flywaycallbacks/FlywayApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.flywaycallbacks; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class FlywayApplication { + + public static void main(String[] args) { + SpringApplication.run(FlywayApplication.class, args); + } + +} diff --git a/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties b/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties new file mode 100644 index 0000000000..2c10fc711f --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties @@ -0,0 +1 @@ +flyway.locations=db/migration,db/callbacks \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/application-h2.properties b/persistence-modules/flyway-repair/src/main/resources/application-h2.properties new file mode 100644 index 0000000000..15bd482adf --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/application-h2.properties @@ -0,0 +1,3 @@ +flyway.url=jdbc:h2:file:./testdb;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE;MODE=MySQL;DATABASE_TO_UPPER=false; +flyway.user=testuser +flyway.password=password \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/application-mysql.properties b/persistence-modules/flyway-repair/src/main/resources/application-mysql.properties new file mode 100644 index 0000000000..341f978068 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/application-mysql.properties @@ -0,0 +1,3 @@ +flyway.url=jdbc:mysql://127.0.0.1:3316/testdb +flyway.user=testuser +flyway.password=password \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties b/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties new file mode 100644 index 0000000000..5afaca96b5 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties @@ -0,0 +1,3 @@ +flyway.url=jdbc:postgresql://127.0.0.1:5431/testdb +flyway.user=testuser +flyway.password=password \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/application.properties b/persistence-modules/flyway-repair/src/main/resources/application.properties new file mode 100644 index 0000000000..3fae835eb1 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/application.properties @@ -0,0 +1,6 @@ +spring.profiles.include=@db.engine@ + +spring.datasource.url=${flyway.url} +spring.datasource.username=${flyway.user} +spring.datasource.password=${flyway.password} +spring.flyway.locations=${flyway.locations:db/migration} \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/db/callbacks/afterMigrateError.sql b/persistence-modules/flyway-repair/src/main/resources/db/callbacks/afterMigrateError.sql new file mode 100644 index 0000000000..c975e85056 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/db/callbacks/afterMigrateError.sql @@ -0,0 +1 @@ +DELETE FROM flyway_schema_history WHERE success=false; \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table_one.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table_one.sql new file mode 100644 index 0000000000..ec434dd5b2 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table_one.sql @@ -0,0 +1,3 @@ +create table table_one ( + id numeric primary key +); \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table_two.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table_two.sql new file mode 100644 index 0000000000..48720d59d6 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table_two.sql @@ -0,0 +1,3 @@ +create table table_two ( + id numeric primary key +); \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table_three.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table_three.sql new file mode 100644 index 0000000000..1917c88b9b --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table_three.sql @@ -0,0 +1,3 @@ +create table table_three ( + id numeric primary key +); \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql new file mode 100644 index 0000000000..ec434dd5b2 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql @@ -0,0 +1,3 @@ +create table table_one ( + id numeric primary key +); \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/logback.xml b/persistence-modules/flyway-repair/src/main/resources/logback.xml new file mode 100644 index 0000000000..56af2d397e --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + \ No newline at end of file From 46654b61acf7eeb372a4d632f363f7c859964935 Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Fri, 17 Jul 2020 15:13:57 +0200 Subject: [PATCH 013/102] [BAEL4288] remove mysql flow --- .../flyway-repair/docker-compose/.env | 1 - .../docker-compose/docker-compose.yaml | 8 ---- .../flyway-repair/docker-compose/mysql.env | 5 --- persistence-modules/flyway-repair/pom.xml | 43 ++++--------------- .../application-callbacks.properties | 2 +- .../resources/application-mysql.properties | 3 -- .../src/main/resources/application.properties | 3 -- .../afterMigrateError__repair.sql} | 0 ..._add_table_one.sql => V1_0__add_table.sql} | 0 ..._add_table_two.sql => V1_1__add_table.sql} | 0 ...dd_table_three.sql => V1_2__add_table.sql} | 0 .../db/migration/V1_3__add_table.sql | 2 +- 12 files changed, 11 insertions(+), 56 deletions(-) delete mode 100644 persistence-modules/flyway-repair/docker-compose/mysql.env delete mode 100644 persistence-modules/flyway-repair/src/main/resources/application-mysql.properties rename persistence-modules/flyway-repair/src/main/resources/db/{callbacks/afterMigrateError.sql => callback/afterMigrateError__repair.sql} (100%) rename persistence-modules/flyway-repair/src/main/resources/db/migration/{V1_0__add_table_one.sql => V1_0__add_table.sql} (100%) rename persistence-modules/flyway-repair/src/main/resources/db/migration/{V1_1__add_table_two.sql => V1_1__add_table.sql} (100%) rename persistence-modules/flyway-repair/src/main/resources/db/migration/{V1_2__add_table_three.sql => V1_2__add_table.sql} (100%) diff --git a/persistence-modules/flyway-repair/docker-compose/.env b/persistence-modules/flyway-repair/docker-compose/.env index 52bd0d6510..69785c6e5c 100644 --- a/persistence-modules/flyway-repair/docker-compose/.env +++ b/persistence-modules/flyway-repair/docker-compose/.env @@ -1,2 +1 @@ -MYSQL_PORT=3316 POSTGRES_PORT=5431 \ No newline at end of file diff --git a/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml b/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml index 23270c043d..b3502f8775 100644 --- a/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml +++ b/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml @@ -1,14 +1,6 @@ version: '3.0' services: - mysql-test: - image: mysql:8.0.17 - ports: - - ${MYSQL_PORT}:3306 - env_file: - - mysql.env - networks: - - baeldung postgres-test: image: postgres:11.5 diff --git a/persistence-modules/flyway-repair/docker-compose/mysql.env b/persistence-modules/flyway-repair/docker-compose/mysql.env deleted file mode 100644 index 597344d88c..0000000000 --- a/persistence-modules/flyway-repair/docker-compose/mysql.env +++ /dev/null @@ -1,5 +0,0 @@ -MYSQL_ROOT_PASSWORD=password -MYSQL_RANDOM_ROOT_PASSWORD=yes -MYSQL_USER=testuser -MYSQL_PASSWORD=password -MYSQL_DATABASE=testdb \ No newline at end of file diff --git a/persistence-modules/flyway-repair/pom.xml b/persistence-modules/flyway-repair/pom.xml index f9d62d5dad..4d61bd5c0e 100644 --- a/persistence-modules/flyway-repair/pom.xml +++ b/persistence-modules/flyway-repair/pom.xml @@ -18,7 +18,6 @@ org.flywaydb flyway-core - ${flyway-core.version} org.springframework.boot @@ -31,37 +30,23 @@ org.flywaydb flyway-maven-plugin - ${flyway-maven-plugin.version} org.springframework.boot spring-boot-maven-plugin - - - true - src/main/resources - - *.properties - db/**/*.sql - - - - - 6.5.0 - 6.5.0 - src/main/resources/application-${db.engine}.properties - - h2 + + true + - h2 + h2 @@ -72,24 +57,10 @@ - - mysql - - mysql - - - - mysql - mysql-connector-java - runtime - - - - postgres - postgres + postgres @@ -102,4 +73,8 @@ + + src/main/resources/application-${spring-boot.run.profiles}.properties + + diff --git a/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties b/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties index 2c10fc711f..7fb3124764 100644 --- a/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties +++ b/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties @@ -1 +1 @@ -flyway.locations=db/migration,db/callbacks \ No newline at end of file +spring.flyway.locations=classpath:db/migration,classpath:db/callback \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/application-mysql.properties b/persistence-modules/flyway-repair/src/main/resources/application-mysql.properties deleted file mode 100644 index 341f978068..0000000000 --- a/persistence-modules/flyway-repair/src/main/resources/application-mysql.properties +++ /dev/null @@ -1,3 +0,0 @@ -flyway.url=jdbc:mysql://127.0.0.1:3316/testdb -flyway.user=testuser -flyway.password=password \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/application.properties b/persistence-modules/flyway-repair/src/main/resources/application.properties index 3fae835eb1..da666d3cc2 100644 --- a/persistence-modules/flyway-repair/src/main/resources/application.properties +++ b/persistence-modules/flyway-repair/src/main/resources/application.properties @@ -1,6 +1,3 @@ -spring.profiles.include=@db.engine@ - spring.datasource.url=${flyway.url} spring.datasource.username=${flyway.user} spring.datasource.password=${flyway.password} -spring.flyway.locations=${flyway.locations:db/migration} \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/db/callbacks/afterMigrateError.sql b/persistence-modules/flyway-repair/src/main/resources/db/callback/afterMigrateError__repair.sql similarity index 100% rename from persistence-modules/flyway-repair/src/main/resources/db/callbacks/afterMigrateError.sql rename to persistence-modules/flyway-repair/src/main/resources/db/callback/afterMigrateError__repair.sql diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table_one.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table.sql similarity index 100% rename from persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table_one.sql rename to persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table.sql diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table_two.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table.sql similarity index 100% rename from persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table_two.sql rename to persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table.sql diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table_three.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table.sql similarity index 100% rename from persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table_three.sql rename to persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table.sql diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql index ec434dd5b2..cf89d5f308 100644 --- a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql @@ -1,3 +1,3 @@ -create table table_one ( +create table table_four ( id numeric primary key ); \ No newline at end of file From 89c430a16720351dcdac60da6d4039dd40f3d565 Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Fri, 17 Jul 2020 15:32:41 +0200 Subject: [PATCH 014/102] [BAEL4288] small fixes --- persistence-modules/flyway-repair/README.MD | 3 +-- persistence-modules/flyway-repair/docker-compose/.env | 2 +- .../flyway-repair/docker-compose/docker-compose.yaml | 2 +- .../src/main/resources/application-callbacks.properties | 2 +- .../flyway-repair/src/main/resources/application-h2.properties | 2 +- .../src/main/resources/application-postgres.properties | 2 +- .../main/resources/db/callback/afterMigrateError__repair.sql | 2 +- .../src/main/resources/db/migration/V1_0__add_table.sql | 2 +- .../src/main/resources/db/migration/V1_1__add_table.sql | 2 +- .../src/main/resources/db/migration/V1_2__add_table.sql | 2 +- .../src/main/resources/db/migration/V1_3__add_table.sql | 2 +- 11 files changed, 11 insertions(+), 12 deletions(-) diff --git a/persistence-modules/flyway-repair/README.MD b/persistence-modules/flyway-repair/README.MD index daeb9012b5..ca029e8299 100644 --- a/persistence-modules/flyway-repair/README.MD +++ b/persistence-modules/flyway-repair/README.MD @@ -1,3 +1,2 @@ ### Relevant Articles: -- [Database Migrations with Flyway](http://www.baeldung.com/database-migrations-with-flyway) -- [A Guide to Flyway Callbacks](http://www.baeldung.com/flyway-callbacks) +- [Flyway Repair With Spring Boot](http://www.baeldung.com/flyway-repair-with-spring-boot) diff --git a/persistence-modules/flyway-repair/docker-compose/.env b/persistence-modules/flyway-repair/docker-compose/.env index 69785c6e5c..8a9d0e7954 100644 --- a/persistence-modules/flyway-repair/docker-compose/.env +++ b/persistence-modules/flyway-repair/docker-compose/.env @@ -1 +1 @@ -POSTGRES_PORT=5431 \ No newline at end of file +POSTGRES_PORT=5431 diff --git a/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml b/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml index b3502f8775..b32b48d1cf 100644 --- a/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml +++ b/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml @@ -12,4 +12,4 @@ services: networks: baeldung: - driver: bridge \ No newline at end of file + driver: bridge diff --git a/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties b/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties index 7fb3124764..46ad86afee 100644 --- a/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties +++ b/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties @@ -1 +1 @@ -spring.flyway.locations=classpath:db/migration,classpath:db/callback \ No newline at end of file +spring.flyway.locations=classpath:db/migration,classpath:db/callback diff --git a/persistence-modules/flyway-repair/src/main/resources/application-h2.properties b/persistence-modules/flyway-repair/src/main/resources/application-h2.properties index 15bd482adf..64e485244e 100644 --- a/persistence-modules/flyway-repair/src/main/resources/application-h2.properties +++ b/persistence-modules/flyway-repair/src/main/resources/application-h2.properties @@ -1,3 +1,3 @@ flyway.url=jdbc:h2:file:./testdb;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE;MODE=MySQL;DATABASE_TO_UPPER=false; flyway.user=testuser -flyway.password=password \ No newline at end of file +flyway.password=password diff --git a/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties b/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties index 5afaca96b5..951f8f583d 100644 --- a/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties +++ b/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties @@ -1,3 +1,3 @@ flyway.url=jdbc:postgresql://127.0.0.1:5431/testdb flyway.user=testuser -flyway.password=password \ No newline at end of file +flyway.password=password diff --git a/persistence-modules/flyway-repair/src/main/resources/db/callback/afterMigrateError__repair.sql b/persistence-modules/flyway-repair/src/main/resources/db/callback/afterMigrateError__repair.sql index c975e85056..ee0cbb6cee 100644 --- a/persistence-modules/flyway-repair/src/main/resources/db/callback/afterMigrateError__repair.sql +++ b/persistence-modules/flyway-repair/src/main/resources/db/callback/afterMigrateError__repair.sql @@ -1 +1 @@ -DELETE FROM flyway_schema_history WHERE success=false; \ No newline at end of file +DELETE FROM flyway_schema_history WHERE success=false; diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table.sql index ec434dd5b2..1774e837b7 100644 --- a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table.sql +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table.sql @@ -1,3 +1,3 @@ create table table_one ( id numeric primary key -); \ No newline at end of file +); diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table.sql index 48720d59d6..76f2ee7ba1 100644 --- a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table.sql +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table.sql @@ -1,3 +1,3 @@ create table table_two ( id numeric primary key -); \ No newline at end of file +); diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table.sql index 1917c88b9b..dd5cf34059 100644 --- a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table.sql +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table.sql @@ -1,3 +1,3 @@ create table table_three ( id numeric primary key -); \ No newline at end of file +); diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql index cf89d5f308..4a126ffe33 100644 --- a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql @@ -1,3 +1,3 @@ create table table_four ( id numeric primary key -); \ No newline at end of file +); From 1619eee7ef3b775c7cd4b9f6a69ab9625ed12a38 Mon Sep 17 00:00:00 2001 From: Nguyen Nam Thai Date: Sat, 18 Jul 2020 21:56:20 +0700 Subject: [PATCH 015/102] BAEL-4113 Measure exception performance --- .../java/com/baeldung/ExceptionBenchmark.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 jmh/src/main/java/com/baeldung/ExceptionBenchmark.java diff --git a/jmh/src/main/java/com/baeldung/ExceptionBenchmark.java b/jmh/src/main/java/com/baeldung/ExceptionBenchmark.java new file mode 100644 index 0000000000..9a166fe2ce --- /dev/null +++ b/jmh/src/main/java/com/baeldung/ExceptionBenchmark.java @@ -0,0 +1,69 @@ +package com.baeldung; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.infra.Blackhole; + +import java.util.concurrent.TimeUnit; + +@Fork(1) +@Warmup(iterations = 2) +@Measurement(iterations = 10) +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +public class ExceptionBenchmark { + private static final int LIMIT = 10_000; + + @Benchmark + public void doNotThrowException(Blackhole blackhole) { + for (int i = 0; i < LIMIT; i++) { + blackhole.consume(new Object()); + } + } + + @Benchmark + public void throwAndCatchException(Blackhole blackhole) { + for (int i = 0; i < LIMIT; i++) { + try { + throw new Exception(); + } catch (Exception e) { + blackhole.consume(e); + } + } + } + + @Benchmark + public void createExceptionWithoutThrowingIt(Blackhole blackhole) { + for (int i = 0; i < LIMIT; i++) { + blackhole.consume(new Exception()); + } + } + + @Benchmark + @Fork(value = 1, jvmArgs = "-XX:-StackTraceInThrowable") + public void throwExceptionWithoutAddingStackTrace(Blackhole blackhole) { + for (int i = 0; i < LIMIT; i++) { + try { + throw new Exception(); + } catch (Exception e) { + blackhole.consume(e); + } + } + } + + @Benchmark + public void throwExceptionAndUnwindStackTrace(Blackhole blackhole) { + for (int i = 0; i < LIMIT; i++) { + try { + throw new Exception(); + } catch (Exception e) { + blackhole.consume(e.getStackTrace()); + } + } + } +} From 796e474f6028c0b5ff027c28d5c2658f4c060806 Mon Sep 17 00:00:00 2001 From: Nguyen Nam Thai Date: Sun, 19 Jul 2020 22:07:57 +0700 Subject: [PATCH 016/102] BAEL-4113 Relocate the ExceptionBenchmark class --- performance-tests/pom.xml | 13 +++++++++++++ .../exception}/ExceptionBenchmark.java | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) rename {jmh/src/main/java/com/baeldung => performance-tests/src/main/java/com/baeldung/performancetests/exception}/ExceptionBenchmark.java (97%) diff --git a/performance-tests/pom.xml b/performance-tests/pom.xml index 0dc38e56a4..c790dbbb16 100644 --- a/performance-tests/pom.xml +++ b/performance-tests/pom.xml @@ -120,6 +120,18 @@ + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + + com.baeldung.performancetests.MappingFrameworksPerformance + + + + @@ -178,6 +190,7 @@ 1.21 1.21 3.7.0 + 3.2.0 ]](/core-groovy-2) From b85bf56975968829bc4eebc8648e1fc0bc516246 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 21 Jul 2020 21:54:23 +0800 Subject: [PATCH 057/102] Update README.md --- algorithms-miscellaneous-6/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/algorithms-miscellaneous-6/README.md b/algorithms-miscellaneous-6/README.md index 22ee51530f..6e435e3741 100644 --- a/algorithms-miscellaneous-6/README.md +++ b/algorithms-miscellaneous-6/README.md @@ -7,4 +7,5 @@ - [Efficiently Merge Sorted Java Sequences](https://www.baeldung.com/java-merge-sorted-sequences) - [Introduction to Greedy Algorithms with Java](https://www.baeldung.com/java-greedy-algorithms) - [The Caesar Cipher in Java](https://www.baeldung.com/java-caesar-cipher) +- [Implementing a 2048 Solver in Java](https://www.baeldung.com/2048-java-solver) - More articles: [[<-- prev]](/../algorithms-miscellaneous-5) From fcb5fe6e028faa9bfdf9915b3f8f10578f096a18 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 21 Jul 2020 21:55:39 +0800 Subject: [PATCH 058/102] Update README.md --- spring-thymeleaf-3/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-thymeleaf-3/README.md b/spring-thymeleaf-3/README.md index 66e64e7094..34bd1b4b35 100644 --- a/spring-thymeleaf-3/README.md +++ b/spring-thymeleaf-3/README.md @@ -3,6 +3,8 @@ This module contains articles about Spring with Thymeleaf ## Relevant Articles: + - [Add CSS and JS to Thymeleaf](https://www.baeldung.com/spring-thymeleaf-css-js) - [Formatting Currencies in Spring Using Thymeleaf](https://www.baeldung.com/spring-thymeleaf-currencies) - [Working with Select and Option in Thymeleaf](https://www.baeldung.com/thymeleaf-select-option) +- [Conditional CSS Classes in Thymeleaf](https://www.baeldung.com/spring-mvc-thymeleaf-conditional-css-classes) From c579678f13625440a1bbd7d4464b154b69709a05 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 21 Jul 2020 21:57:20 +0800 Subject: [PATCH 059/102] Update README.md --- linux-bash/text/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-bash/text/README.md b/linux-bash/text/README.md index 20df2a33ec..1c27abc8c6 100644 --- a/linux-bash/text/README.md +++ b/linux-bash/text/README.md @@ -1,4 +1,4 @@ ### Relevant Articles: -- [Linux Commands – Remove All Text After X](https://www.baeldung.com/linux/tr-manipulate-strings) +- [Linux Commands – Remove All Text After X](https://www.baeldung.com/linux/remove-text-after-x-in-file) - [Linux Commands for Appending Multiple Lines to a File](https://www.baeldung.com/linux/appending-multiple-lines-to-file2) From 2bb9438beda7f68d1f4ed20abdd9c1fd047d5c02 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 21 Jul 2020 22:15:03 +0800 Subject: [PATCH 060/102] Update README.md --- maven-modules/maven-exec-plugin/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/maven-modules/maven-exec-plugin/README.md b/maven-modules/maven-exec-plugin/README.md index 411639aae1..60035b27c4 100644 --- a/maven-modules/maven-exec-plugin/README.md +++ b/maven-modules/maven-exec-plugin/README.md @@ -3,3 +3,5 @@ This module contains articles about the Maven Exec Plugin. ### Relevant Articles + +- [Run a Java Main Method in Maven](https://www.baeldung.com/maven-java-main-method) From 03264f1c12f04e429c548f7736686b6c4c9a3e17 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 21 Jul 2020 22:16:18 +0800 Subject: [PATCH 061/102] Create README.md --- core-java-modules/core-java-string-operations-3/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 core-java-modules/core-java-string-operations-3/README.md diff --git a/core-java-modules/core-java-string-operations-3/README.md b/core-java-modules/core-java-string-operations-3/README.md new file mode 100644 index 0000000000..4e46849c11 --- /dev/null +++ b/core-java-modules/core-java-string-operations-3/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Version Comparison in Java](https://www.baeldung.com/java-comparing-versions) From 0a75e0c908c906883b96085be4287f29ac68928f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 21 Jul 2020 22:19:17 +0800 Subject: [PATCH 062/102] Update README.md --- core-java-modules/core-java-lang-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-lang-3/README.md b/core-java-modules/core-java-lang-3/README.md index f496b74bfb..d735937a02 100644 --- a/core-java-modules/core-java-lang-3/README.md +++ b/core-java-modules/core-java-lang-3/README.md @@ -2,4 +2,5 @@ This module contains articles about core features in the Java language +- [Class.isInstance vs Class.isAssignableFrom](https://www.baeldung.com/java-isinstance-isassignablefrom) - [[<-- Prev]](/core-java-modules/core-java-lang-2) From fdca5ce14c7998d3222c0b72ca2769ea1609c08c Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 21 Jul 2020 22:21:37 +0800 Subject: [PATCH 063/102] Create README.md --- core-java-modules/core-java-reflection-2/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 core-java-modules/core-java-reflection-2/README.md diff --git a/core-java-modules/core-java-reflection-2/README.md b/core-java-modules/core-java-reflection-2/README.md new file mode 100644 index 0000000000..342fbd73bd --- /dev/null +++ b/core-java-modules/core-java-reflection-2/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Reading the Value of ‘private’ Fields from a Different Class in Java](https://www.baeldung.com/java-reflection-read-private-field-value) From 1272feb3ec628ddad41f880f3bc4cfe7ddfb9760 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 21 Jul 2020 22:25:59 +0800 Subject: [PATCH 064/102] Create README.md --- maven-modules/maven-plugins/maven-enforcer/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 maven-modules/maven-plugins/maven-enforcer/README.md diff --git a/maven-modules/maven-plugins/maven-enforcer/README.md b/maven-modules/maven-plugins/maven-enforcer/README.md new file mode 100644 index 0000000000..44d43050e7 --- /dev/null +++ b/maven-modules/maven-plugins/maven-enforcer/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Maven Enforcer Plugin](https://www.baeldung.com/maven-enforcer-plugin) From 6b16b729018ab040ba703c65b80874e65de281a6 Mon Sep 17 00:00:00 2001 From: Mona Mohamadinia Date: Tue, 21 Jul 2020 19:24:20 +0430 Subject: [PATCH 065/102] How to get the current index in for each Kotlin (#9710) --- .../com/baeldung/index/IndexedIteration.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/index/IndexedIteration.kt diff --git a/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/index/IndexedIteration.kt b/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/index/IndexedIteration.kt new file mode 100644 index 0000000000..07fb595ede --- /dev/null +++ b/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/index/IndexedIteration.kt @@ -0,0 +1,33 @@ +package com.baeldung.index + +fun main() { + + // Index only + val colors = listOf("Red", "Green", "Blue") + for (i in colors.indices) { + println(colors[i]) + } + + val colorArray = arrayOf("Red", "Green", "Blue") + for (i in colorArray.indices) { + println(colorArray[i]) + } + + (0 until colors.size).forEach { println(colors[it]) } + for (i in 0 until colors.size) { + println(colors[i]) + } + + // Index and Value + colors.forEachIndexed { i, v -> println("The value for index $i is $v") } + for (indexedValue in colors.withIndex()) { + println("The value for index ${indexedValue.index} is ${indexedValue.value}") + } + + for ((i, v) in colors.withIndex()) { + println("The value for index $i is $v") + } + + colors.filterIndexed { i, _ -> i % 2 == 0 } + colors.filterIndexed { _, v -> v == "RED" } +} From 11e8755339baa026182cddeca9b33f9c051ec2b0 Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Tue, 21 Jul 2020 17:08:30 +0200 Subject: [PATCH 066/102] [BAEL-4288] address comments after review --- persistence-modules/flyway-repair/README.MD | 1 - 1 file changed, 1 deletion(-) diff --git a/persistence-modules/flyway-repair/README.MD b/persistence-modules/flyway-repair/README.MD index ca029e8299..7d843af9ea 100644 --- a/persistence-modules/flyway-repair/README.MD +++ b/persistence-modules/flyway-repair/README.MD @@ -1,2 +1 @@ ### Relevant Articles: -- [Flyway Repair With Spring Boot](http://www.baeldung.com/flyway-repair-with-spring-boot) From 6bdafc535e4426cc6341fa34ece91038d7d43670 Mon Sep 17 00:00:00 2001 From: Maciej Glowka Date: Tue, 21 Jul 2020 20:46:44 +0200 Subject: [PATCH 067/102] BAEL-3347: moved version collision submodule from maven-all to maven-modules --- maven-all/version-collision/pom.xml | 54 ---------------- .../version-collision/child-module/pom.xml | 21 ------ maven-modules/version-collision/pom.xml | 64 +++++++++++-------- .../version-collision/project-a/pom.xml | 0 .../version-collision/project-b/pom.xml | 0 .../project-collision/pom.xml | 0 .../collision/VersionCollisionUnitTest.java | 0 7 files changed, 37 insertions(+), 102 deletions(-) delete mode 100644 maven-all/version-collision/pom.xml delete mode 100644 maven-modules/version-collision/child-module/pom.xml rename {maven-all => maven-modules}/version-collision/project-a/pom.xml (100%) rename {maven-all => maven-modules}/version-collision/project-b/pom.xml (100%) rename {maven-all => maven-modules}/version-collision/project-collision/pom.xml (100%) rename {maven-all => maven-modules}/version-collision/project-collision/src/test/java/com/baeldung/version/collision/VersionCollisionUnitTest.java (100%) diff --git a/maven-all/version-collision/pom.xml b/maven-all/version-collision/pom.xml deleted file mode 100644 index 7bbd17a789..0000000000 --- a/maven-all/version-collision/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - maven-all - com.baeldung - 0.0.1-SNAPSHOT - - 4.0.0 - - version-collision - pom - - project-a - project-b - project-collision - - - - - - - com.google.guava - guava - 29.0-jre - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/maven-modules/version-collision/child-module/pom.xml b/maven-modules/version-collision/child-module/pom.xml deleted file mode 100644 index 7784bc5953..0000000000 --- a/maven-modules/version-collision/child-module/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - version-collision - com.baeldung - 0.0.1-SNAPSHOT - - 4.0.0 - - child-module - - - - org.apache.maven - maven-core - 3.3.9 - - - \ No newline at end of file diff --git a/maven-modules/version-collision/pom.xml b/maven-modules/version-collision/pom.xml index 9a38fd0edb..6d8441aa7b 100644 --- a/maven-modules/version-collision/pom.xml +++ b/maven-modules/version-collision/pom.xml @@ -3,7 +3,7 @@ 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"> - maven-all + maven-modules com.baeldung 0.0.1-SNAPSHOT @@ -11,34 +11,44 @@ version-collision pom - - child-module + project-a + project-b + project-collision - - - org.apache.commons - commons-configuration2 - 2.7 - - - - - - - - - + + + + + com.google.guava + guava + 29.0-jre + + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/maven-all/version-collision/project-a/pom.xml b/maven-modules/version-collision/project-a/pom.xml similarity index 100% rename from maven-all/version-collision/project-a/pom.xml rename to maven-modules/version-collision/project-a/pom.xml diff --git a/maven-all/version-collision/project-b/pom.xml b/maven-modules/version-collision/project-b/pom.xml similarity index 100% rename from maven-all/version-collision/project-b/pom.xml rename to maven-modules/version-collision/project-b/pom.xml diff --git a/maven-all/version-collision/project-collision/pom.xml b/maven-modules/version-collision/project-collision/pom.xml similarity index 100% rename from maven-all/version-collision/project-collision/pom.xml rename to maven-modules/version-collision/project-collision/pom.xml diff --git a/maven-all/version-collision/project-collision/src/test/java/com/baeldung/version/collision/VersionCollisionUnitTest.java b/maven-modules/version-collision/project-collision/src/test/java/com/baeldung/version/collision/VersionCollisionUnitTest.java similarity index 100% rename from maven-all/version-collision/project-collision/src/test/java/com/baeldung/version/collision/VersionCollisionUnitTest.java rename to maven-modules/version-collision/project-collision/src/test/java/com/baeldung/version/collision/VersionCollisionUnitTest.java From 32f03351e312b1ca567ed8960b8a85dd45c1285a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 22 Jul 2020 14:44:35 +0800 Subject: [PATCH 068/102] Update README.md --- core-java-modules/core-java-arrays-guides/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-arrays-guides/README.md b/core-java-modules/core-java-arrays-guides/README.md index 56c0c716d8..621443e4a9 100644 --- a/core-java-modules/core-java-arrays-guides/README.md +++ b/core-java-modules/core-java-arrays-guides/README.md @@ -5,4 +5,4 @@ This module contains complete guides about arrays in Java ### Relevant Articles: - [Arrays in Java: A Reference Guide](https://www.baeldung.com/java-arrays-guide) - [Guide to the java.util.Arrays Class](https://www.baeldung.com/java-util-arrays) -- [What is [Ljava.lang.Object;?]](https://www.baeldung.com/java-tostring-array) +- [What is \[Ljava.lang.Object;?](https://www.baeldung.com/java-tostring-array) From 058310d873cb0992bf66c3fe1d5ea7fdb0699080 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 22 Jul 2020 15:21:43 +0530 Subject: [PATCH 069/102] JAVA-2155: Updated keycloak version to 10.0.2, and changed parent to parent-boot-2 --- .../spring-boot-keycloak/pom.xml | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/spring-boot-modules/spring-boot-keycloak/pom.xml b/spring-boot-modules/spring-boot-keycloak/pom.xml index 6208fbe305..5049cc3651 100644 --- a/spring-boot-modules/spring-boot-keycloak/pom.xml +++ b/spring-boot-modules/spring-boot-keycloak/pom.xml @@ -2,22 +2,20 @@ 4.0.0 - - - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT - ../ - - com.baeldung.keycloak spring-boot-keycloak 0.0.1 - jar - spring-boot-keycloak + jar This is a simple application demonstrating integration between Keycloak and Spring Boot. + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + @@ -78,7 +76,7 @@ - 10.0.1 + 10.0.2 From c38d485950c53bdb56e97e0e3f5188c461d5da2a Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 22 Jul 2020 15:22:26 +0530 Subject: [PATCH 070/102] JAVA-2155: added properties alternative to spring security --- .../src/main/resources/application.properties | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-boot-modules/spring-boot-keycloak/src/main/resources/application.properties b/spring-boot-modules/spring-boot-keycloak/src/main/resources/application.properties index 6e7da2cb90..9dfd3ea720 100644 --- a/spring-boot-modules/spring-boot-keycloak/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-keycloak/src/main/resources/application.properties @@ -6,4 +6,6 @@ keycloak.auth-server-url=http://localhost:8180/auth keycloak.realm=SpringBootKeycloak keycloak.resource=login-app keycloak.public-client=true +#keycloak.security-constraints[0].authRoles[0]=user +#keycloak.security-constraints[0].securityCollections[0].patterns[0]=/customers/* keycloak.principal-attribute=preferred_username \ No newline at end of file From 461099927f541ffea043a5eab2ed936f4dd0fdb5 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 22 Jul 2020 15:23:01 +0530 Subject: [PATCH 071/102] JAVA-2155: changed package from org.baledung to com.baeldung --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spring-boot-modules/spring-boot-keycloak/src/test/java/{org => com}/baeldung/SpringContextTest.java (100%) diff --git a/spring-boot-modules/spring-boot-keycloak/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-keycloak/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-boot-modules/spring-boot-keycloak/src/test/java/org/baeldung/SpringContextTest.java rename to spring-boot-modules/spring-boot-keycloak/src/test/java/com/baeldung/SpringContextTest.java From a074061cd8635fb420ebfb97f4f2a49f1bc397da Mon Sep 17 00:00:00 2001 From: Mona Mohamadinia Date: Wed, 22 Jul 2020 19:07:29 +0430 Subject: [PATCH 072/102] KTLN-162: Create anonymous inner class in Kotlin (#9718) * Create anonymous inner class in Kotlin * Moved to the New Module --- .../com/baeldung/anonymous/Anonymous.kt | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/anonymous/Anonymous.kt diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/anonymous/Anonymous.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/anonymous/Anonymous.kt new file mode 100644 index 0000000000..ea471f5d00 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/anonymous/Anonymous.kt @@ -0,0 +1,41 @@ +package com.baeldung.anonymous + +import java.io.Serializable +import java.nio.channels.Channel + +fun main() { + val channel = object : Channel { + override fun isOpen() = false + + override fun close() { + } + } + + val maxEntries = 10 + val lruCache = object : LinkedHashMap(10, 0.75f) { + + override fun removeEldestEntry(eldest: MutableMap.MutableEntry?): Boolean { + return size > maxEntries + } + } + + val map = object : LinkedHashMap() { + // omitted + } + + val serializableChannel = object : Channel, Serializable { + override fun isOpen(): Boolean { + TODO("Not yet implemented") + } + + override fun close() { + TODO("Not yet implemented") + } + } + + val obj = object { + val question = "answer" + val answer = 42 + } + println("The ${obj.question} is ${obj.answer}") +} \ No newline at end of file From 8a5bb329b9f5c04472368173fd8dfb8eb46849d6 Mon Sep 17 00:00:00 2001 From: Mona Mohamadinia Date: Wed, 22 Jul 2020 19:11:08 +0430 Subject: [PATCH 073/102] Moving to a new module (#9681) --- .../emptiness/DirectoryEmptinessUnitTest.java | 63 +++++++++++++++++++ .../src/test/resources/notDir.txt | 0 2 files changed, 63 insertions(+) create mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java create mode 100644 core-java-modules/core-java-io-3/src/test/resources/notDir.txt diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java new file mode 100644 index 0000000000..a44aea1383 --- /dev/null +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.emptiness; + +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DirectoryEmptinessUnitTest { + + @Test + public void givenPath_whenInvalid_thenReturnsFalse() throws IOException { + assertThat(isEmpty(Paths.get("invalid-addr"))).isFalse(); + } + + @Test + public void givenPath_whenNotDirectory_thenReturnsFalse() throws IOException { + Path aFile = Paths.get(getClass().getResource("/notDir.txt").getPath()); + assertThat(isEmpty(aFile)).isFalse(); + } + + @Test + public void givenPath_whenNotEmptyDir_thenReturnsFalse() throws IOException { + Path currentDir = new File("").toPath().toAbsolutePath(); + assertThat(isEmpty(currentDir)).isFalse(); + } + + @Test + public void givenPath_whenIsEmpty_thenReturnsTrue() throws Exception { + Path path = Files.createTempDirectory("baeldung-empty"); + assertThat(isEmpty(path)).isTrue(); + } + + private static boolean isEmpty(Path path) throws IOException { + if (Files.isDirectory(path)) { + try (DirectoryStream directory = Files.newDirectoryStream(path)) { + return !directory.iterator().hasNext(); + } + } + + return false; + } + + private static boolean isEmpty2(Path path) throws IOException { + if (Files.isDirectory(path)) { + try (Stream entries = Files.list(path)) { + return !entries.findFirst().isPresent(); + } + } + + return false; + } + + private static boolean isEmptyInefficient(Path path) { + return path.toFile().listFiles().length == 0; + } +} diff --git a/core-java-modules/core-java-io-3/src/test/resources/notDir.txt b/core-java-modules/core-java-io-3/src/test/resources/notDir.txt new file mode 100644 index 0000000000..e69de29bb2 From b4ddf4be8e7e036e770741ef013ce0262e0e87c4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:03:11 +0800 Subject: [PATCH 074/102] Update README.md --- core-java-modules/core-java-exceptions-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-exceptions-2/README.md b/core-java-modules/core-java-exceptions-2/README.md index 7c5db06a55..e6441c2c12 100644 --- a/core-java-modules/core-java-exceptions-2/README.md +++ b/core-java-modules/core-java-exceptions-2/README.md @@ -13,3 +13,4 @@ This module contains articles about core java exceptions - [Java Global Exception Handler](https://www.baeldung.com/java-global-exception-handler) - [How to Find an Exception’s Root Cause in Java](https://www.baeldung.com/java-exception-root-cause) - [Java IOException “Too many open files”](https://www.baeldung.com/java-too-many-open-files) +- [When Does Java Throw the ExceptionInInitializerError?](https://www.baeldung.com/java-exceptionininitializererror) From e9960f2846e49bca5655b17ef9057d893d3251f6 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:06:51 +0800 Subject: [PATCH 075/102] Update README.md --- testing-modules/selenium-junit-testng/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/selenium-junit-testng/README.md b/testing-modules/selenium-junit-testng/README.md index 8baddd3449..aa3f0e8005 100644 --- a/testing-modules/selenium-junit-testng/README.md +++ b/testing-modules/selenium-junit-testng/README.md @@ -4,3 +4,4 @@ - [Testing with Selenium/WebDriver and the Page Object Pattern](http://www.baeldung.com/selenium-webdriver-page-object) - [Using Cookies With Selenium WebDriver in Java](https://www.baeldung.com/java-selenium-webdriver-cookies) - [Clicking Elements in Selenium using JavaScript](https://www.baeldung.com/java-selenium-javascript) +- [Taking Screenshots With Selenium WebDriver](https://www.baeldung.com/java-selenium-screenshots) From 5183318ebd72d59532b5b924ddf982e520db54c4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:09:08 +0800 Subject: [PATCH 076/102] Update README.md --- java-numbers-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-numbers-3/README.md b/java-numbers-3/README.md index 9c323a6c6a..ab0bbd995d 100644 --- a/java-numbers-3/README.md +++ b/java-numbers-3/README.md @@ -13,4 +13,5 @@ This module contains articles about numbers in Java. - [Guide to the Number Class in Java](https://www.baeldung.com/java-number-class) - [Print an Integer in Binary Format in Java](https://www.baeldung.com/java-print-integer-binary) - [Number Formatting in Java](https://www.baeldung.com/java-number-formatting) +- [Division by Zero in Java: Exception, Infinity, or Not a Number](https://www.baeldung.com/java-division-by-zero) - More articles: [[<-- prev]](/java-numbers-2) From f8b0deba6ee0b52205e64b63efb2210beb2b527d Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:12:46 +0800 Subject: [PATCH 077/102] Update README.md --- image-processing/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/image-processing/README.md b/image-processing/README.md index 50129bb994..afe92466c1 100644 --- a/image-processing/README.md +++ b/image-processing/README.md @@ -6,3 +6,4 @@ This module contains articles about image processing. - [Working with Images in Java](https://www.baeldung.com/java-images) - [Intro to OpenCV with Java](https://www.baeldung.com/java-opencv) - [Optical Character Recognition with Tesseract](https://www.baeldung.com/java-ocr-tesseract) +- [How Can I Resize an Image Using Java?](https://www.baeldung.com/java-resize-image) From 22e7999ed85e6723c4e619aa8235067012ee9621 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:18:07 +0800 Subject: [PATCH 078/102] Create README.md --- maven-modules/version-collision/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 maven-modules/version-collision/README.md diff --git a/maven-modules/version-collision/README.md b/maven-modules/version-collision/README.md new file mode 100644 index 0000000000..a71cfdb0b4 --- /dev/null +++ b/maven-modules/version-collision/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [How to Resolve a Version Collision of Artifacts in Maven](https://www.baeldung.com/maven-version-collision) From e7da08b91e64beb5c99b1b57719823d90c3fd86b Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:21:28 +0800 Subject: [PATCH 079/102] Update README.md --- core-java-modules/core-java-lang-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-lang-3/README.md b/core-java-modules/core-java-lang-3/README.md index d735937a02..9ce49da868 100644 --- a/core-java-modules/core-java-lang-3/README.md +++ b/core-java-modules/core-java-lang-3/README.md @@ -3,4 +3,5 @@ This module contains articles about core features in the Java language - [Class.isInstance vs Class.isAssignableFrom](https://www.baeldung.com/java-isinstance-isassignablefrom) +- [Converting a Java String Into a Boolean](https://www.baeldung.com/java-string-to-boolean) - [[<-- Prev]](/core-java-modules/core-java-lang-2) From ac10150a07009d348b28079b413aecfac4041792 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:24:48 +0800 Subject: [PATCH 080/102] Update README.md --- core-java-modules/core-java-concurrency-basic-2/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-java-modules/core-java-concurrency-basic-2/README.md b/core-java-modules/core-java-concurrency-basic-2/README.md index c7143baf36..a8daf14ea9 100644 --- a/core-java-modules/core-java-concurrency-basic-2/README.md +++ b/core-java-modules/core-java-concurrency-basic-2/README.md @@ -3,10 +3,12 @@ This module contains articles about basic Java concurrency ### Relevant Articles: + - [How to Delay Code Execution in Java](https://www.baeldung.com/java-delay-code-execution) - [wait and notify() Methods in Java](https://www.baeldung.com/java-wait-notify) - [Difference Between Wait and Sleep in Java](https://www.baeldung.com/java-wait-and-sleep) - [Guide to the Synchronized Keyword in Java](https://www.baeldung.com/java-synchronized) - [Life Cycle of a Thread in Java](https://www.baeldung.com/java-thread-lifecycle) - [Guide to AtomicMarkableReference](https://www.baeldung.com/java-atomicmarkablereference) +- [Why are Local Variables Thread-Safe in Java](https://www.baeldung.com/java-local-variables-thread-safe) - [[<-- Prev]](/core-java-modules/core-java-concurrency-basic) From fb454518abb797e27fce5a0466860fa1abeaffd4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:28:59 +0800 Subject: [PATCH 081/102] Update README.md --- image-processing/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/image-processing/README.md b/image-processing/README.md index afe92466c1..eba23f83eb 100644 --- a/image-processing/README.md +++ b/image-processing/README.md @@ -7,3 +7,4 @@ This module contains articles about image processing. - [Intro to OpenCV with Java](https://www.baeldung.com/java-opencv) - [Optical Character Recognition with Tesseract](https://www.baeldung.com/java-ocr-tesseract) - [How Can I Resize an Image Using Java?](https://www.baeldung.com/java-resize-image) +- [Adding Text to an Image in Java](https://www.baeldung.com/java-add-text-to-image) From b50e4149703bf20e8a428e47d68f8b1f1e166912 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:31:26 +0800 Subject: [PATCH 082/102] Update README.md --- spring-boot-modules/spring-boot-properties-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-properties-2/README.md b/spring-boot-modules/spring-boot-properties-2/README.md index 4e03a4125c..c81ad50e40 100644 --- a/spring-boot-modules/spring-boot-properties-2/README.md +++ b/spring-boot-modules/spring-boot-properties-2/README.md @@ -10,4 +10,5 @@ This module contains articles about Properties in Spring Boot. - [@PropertySource with YAML Files in Spring Boot](https://www.baeldung.com/spring-yaml-propertysource) - [Inject Arrays and Lists From Spring Properties Files](https://www.baeldung.com/spring-inject-arrays-lists) - [Inject a Map from a YAML File with Spring](https://www.baeldung.com/spring-yaml-inject-map) +- [YAML to List of Objects in Spring Boot](https://www.baeldung.com/spring-boot-yaml-list) - More articles: [[<-- prev]](../spring-boot-properties) From 8365e6f44fe7f5052b2dacfc25af1f02fbf34f42 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:33:56 +0800 Subject: [PATCH 083/102] Update README.md --- persistence-modules/core-java-persistence/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/core-java-persistence/README.md b/persistence-modules/core-java-persistence/README.md index f5d3f12d7a..88442a94c8 100644 --- a/persistence-modules/core-java-persistence/README.md +++ b/persistence-modules/core-java-persistence/README.md @@ -10,3 +10,4 @@ - [Guide to the JDBC ResultSet Interface](https://www.baeldung.com/jdbc-resultset) - [Types of SQL Joins](https://www.baeldung.com/sql-joins) - [Returning the Generated Keys in JDBC](https://www.baeldung.com/jdbc-returning-generated-keys) +- [Loading JDBC Drivers](https://www.baeldung.com/java-jdbc-loading-drivers) From 02feb454d3b1c9cd9b0231d58efaadfb41c86f56 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:36:52 +0800 Subject: [PATCH 084/102] Update README.md --- apache-shiro/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apache-shiro/README.md b/apache-shiro/README.md index ed63c569da..3a0088072f 100644 --- a/apache-shiro/README.md +++ b/apache-shiro/README.md @@ -6,4 +6,4 @@ This module contains articles about Apache Shiro - [Introduction to Apache Shiro](https://www.baeldung.com/apache-shiro) - [Permissions-Based Access Control with Apache Shiro](https://www.baeldung.com/apache-shiro-access-control) - +- [Spring Security vs Apache Shiro](https://www.baeldung.com/spring-security-vs-apache-shiro) From d5e59a20fe16d5de0b32bea33927ed4a6c7d3019 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:39:16 +0800 Subject: [PATCH 085/102] Update README.md --- core-java-modules/core-java-collections-3/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-java-modules/core-java-collections-3/README.md b/core-java-modules/core-java-collections-3/README.md index fb983d9abc..4349ef6be3 100644 --- a/core-java-modules/core-java-collections-3/README.md +++ b/core-java-modules/core-java-collections-3/README.md @@ -3,6 +3,7 @@ ## Core Java Collections Cookbooks and Examples ### Relevant Articles: + - [Time Comparison of Arrays.sort(Object[]) and Arrays.sort(int[])](https://www.baeldung.com/arrays-sortobject-vs-sortint) - [Java ArrayList vs Vector](https://www.baeldung.com/java-arraylist-vs-vector) - [Differences Between HashMap and Hashtable](https://www.baeldung.com/hashmap-hashtable-differences) @@ -10,3 +11,4 @@ - [Performance of contains() in a HashSet vs ArrayList](https://www.baeldung.com/java-hashset-arraylist-contains-performance) - [Fail-Safe Iterator vs Fail-Fast Iterator](https://www.baeldung.com/java-fail-safe-vs-fail-fast-iterator) - [Quick Guide to the Java Stack](https://www.baeldung.com/java-stack) +- [Convert an Array of Primitives to a List](https://www.baeldung.com/java-primitive-array-to-list) From 73af9abcd61a2b8f8179377c4b130c43a076e417 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:48:24 +0800 Subject: [PATCH 086/102] Update README.md --- core-java-modules/core-java-jvm-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-jvm-2/README.md b/core-java-modules/core-java-jvm-2/README.md index 7a189ceec5..7206a9eef7 100644 --- a/core-java-modules/core-java-jvm-2/README.md +++ b/core-java-modules/core-java-jvm-2/README.md @@ -9,4 +9,5 @@ This module contains articles about working with the Java Virtual Machine (JVM). - [Adding Shutdown Hooks for JVM Applications](https://www.baeldung.com/jvm-shutdown-hooks) - [boolean and boolean[] Memory Layout in the JVM](https://www.baeldung.com/jvm-boolean-memory-layout) - [Where Is the Array Length Stored in JVM?](https://www.baeldung.com/java-jvm-array-length) +- [Memory Address of Objects in Java](https://www.baeldung.com/java-object-memory-address) - More articles: [[<-- prev]](/core-java-modules/core-java-jvm) From 22cf2a621f620e63e3033e5205a54b35157c0098 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:57:49 +0800 Subject: [PATCH 087/102] Update README.md --- algorithms-miscellaneous-6/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/algorithms-miscellaneous-6/README.md b/algorithms-miscellaneous-6/README.md index 6e435e3741..6ddae75f43 100644 --- a/algorithms-miscellaneous-6/README.md +++ b/algorithms-miscellaneous-6/README.md @@ -8,4 +8,5 @@ - [Introduction to Greedy Algorithms with Java](https://www.baeldung.com/java-greedy-algorithms) - [The Caesar Cipher in Java](https://www.baeldung.com/java-caesar-cipher) - [Implementing a 2048 Solver in Java](https://www.baeldung.com/2048-java-solver) +- [Finding Top K Elements in an Array](https://www.baeldung.com/java-array-top-elements) - More articles: [[<-- prev]](/../algorithms-miscellaneous-5) From 112b08d139ded2d5ca7791bea7146fdaf596e0aa Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:02:12 +0800 Subject: [PATCH 088/102] Update README.md --- patterns/solid/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/patterns/solid/README.md b/patterns/solid/README.md index f5146732a0..41e986f544 100644 --- a/patterns/solid/README.md +++ b/patterns/solid/README.md @@ -3,3 +3,4 @@ - [A Solid Guide to Solid Principles](https://www.baeldung.com/solid-principles) - [Single Responsibility Principle in Java](https://www.baeldung.com/java-single-responsibility-principle) - [Open/Closed Principle in Java](https://www.baeldung.com/java-open-closed-principle) +- [Interface Segregation Principle in Java](https://www.baeldung.com/java-interface-segregation) From 986e54120654c80fcfa7758f3d626fcea5da3166 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:04:14 +0800 Subject: [PATCH 089/102] Update README.md --- persistence-modules/core-java-persistence/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/persistence-modules/core-java-persistence/README.md b/persistence-modules/core-java-persistence/README.md index 88442a94c8..a760489480 100644 --- a/persistence-modules/core-java-persistence/README.md +++ b/persistence-modules/core-java-persistence/README.md @@ -3,6 +3,7 @@ ## Core Java Persistence Examples ### Relevant Articles: + - [Introduction to JDBC](http://www.baeldung.com/java-jdbc) - [Batch Processing in JDBC](http://www.baeldung.com/jdbc-batch-processing) - [Introduction to the JDBC RowSet Interface in Java](http://www.baeldung.com/java-jdbc-rowset) @@ -11,3 +12,4 @@ - [Types of SQL Joins](https://www.baeldung.com/sql-joins) - [Returning the Generated Keys in JDBC](https://www.baeldung.com/jdbc-returning-generated-keys) - [Loading JDBC Drivers](https://www.baeldung.com/java-jdbc-loading-drivers) +- [Difference Between Statement and PreparedStatement](https://www.baeldung.com/java-statement-preparedstatement) From 3090571ce55d6d52df6ec376a7cd8cadc9935285 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:06:39 +0800 Subject: [PATCH 090/102] Update README.md --- spring-core-4/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-core-4/README.md b/spring-core-4/README.md index 706c330f39..83b5c4933d 100644 --- a/spring-core-4/README.md +++ b/spring-core-4/README.md @@ -11,4 +11,5 @@ This module contains articles about core Spring functionality - [Using @Autowired in Abstract Classes](https://www.baeldung.com/spring-autowired-abstract-class) - [Running Setup Data on Startup in Spring](https://www.baeldung.com/running-setup-logic-on-startup-in-spring) - [Constructor Injection in Spring with Lombok](https://www.baeldung.com/spring-injection-lombok) +- [The Spring ApplicationContext](https://www.baeldung.com/spring-application-context) - More articles: [[<-- prev]](/spring-core-3) From 0743a159d501958100088341674dc5e93c92501a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:10:10 +0800 Subject: [PATCH 091/102] Update README.md --- jmh/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jmh/README.md b/jmh/README.md index 3a5370c9f2..41bf16d6bb 100644 --- a/jmh/README.md +++ b/jmh/README.md @@ -5,4 +5,4 @@ This module contains articles about the Java Microbenchmark Harness (JMH). ### Relevant articles: - [Microbenchmarking with Java](https://www.baeldung.com/java-microbenchmark-harness) - +- [A Guide to False Sharing and @Contended](https://www.baeldung.com/java-false-sharing-contended) From 9922d9d297fe4d0f3ca8b0c746850f6e01ff696c Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:11:49 +0800 Subject: [PATCH 092/102] Update README.md --- testing-modules/testing-libraries/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/testing-libraries/README.md b/testing-modules/testing-libraries/README.md index b1e1575e63..4db7fb8e7a 100644 --- a/testing-modules/testing-libraries/README.md +++ b/testing-modules/testing-libraries/README.md @@ -10,3 +10,4 @@ - [Cucumber Data Tables](https://www.baeldung.com/cucumber-data-tables) - [Cucumber Background](https://www.baeldung.com/java-cucumber-background) - [Cucumber Hooks](https://www.baeldung.com/java-cucumber-hooks) +- [Unit Testing of System.out.println() with JUnit](https://www.baeldung.com/java-testing-system-out-println) From 2374e863d52f08fd4839a78961f93442b6783ead Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:17:28 +0800 Subject: [PATCH 093/102] Update README.md --- maven-modules/maven-properties/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-modules/maven-properties/README.md b/maven-modules/maven-properties/README.md index 65d976189c..52ac8506b3 100644 --- a/maven-modules/maven-properties/README.md +++ b/maven-modules/maven-properties/README.md @@ -5,4 +5,4 @@ have their own dedicated modules. ### Relevant Articles -- [Accessing Maven Properties in Java] \ No newline at end of file +- [Accessing Maven Properties in Java](https://www.baeldung.com/java-accessing-maven-properties) From 3f1fa1491fab606bf7e53c22edf96fd607922d39 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:19:29 +0800 Subject: [PATCH 094/102] Update README.md --- core-java-modules/core-java-io-3/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-java-modules/core-java-io-3/README.md b/core-java-modules/core-java-io-3/README.md index 39752346d3..61a040c1ce 100644 --- a/core-java-modules/core-java-io-3/README.md +++ b/core-java-modules/core-java-io-3/README.md @@ -3,5 +3,7 @@ This module contains articles about core Java input and output (IO) ### Relevant Articles: + - [Java – Create a File](https://www.baeldung.com/java-how-to-create-a-file) +- [Check If a Directory Is Empty in Java](https://www.baeldung.com/java-check-empty-directory) - [[<-- Prev]](/core-java-modules/core-java-io-2) From 6c74b5ad329e6a002e4fe0a99af06ddafc354e2f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:41:33 +0800 Subject: [PATCH 095/102] Update README.md --- core-kotlin-modules/core-kotlin-collections/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-kotlin-modules/core-kotlin-collections/README.md b/core-kotlin-modules/core-kotlin-collections/README.md index dcf2743577..2ebb748cba 100644 --- a/core-kotlin-modules/core-kotlin-collections/README.md +++ b/core-kotlin-modules/core-kotlin-collections/README.md @@ -3,6 +3,7 @@ This module contains articles about core Kotlin collections. ### Relevant articles: + - [Split a List Into Parts in Kotlin](https://www.baeldung.com/kotlin-split-list-into-parts) - [Finding an Element in a List Using Kotlin](https://www.baeldung.com/kotlin-finding-element-in-list) - [Overview of Kotlin Collections API](https://www.baeldung.com/kotlin-collections-api) @@ -12,3 +13,4 @@ This module contains articles about core Kotlin collections. - [Difference between fold and reduce in Kotlin](https://www.baeldung.com/kotlin/fold-vs-reduce) - [Guide to Sorting in Kotlin](https://www.baeldung.com/kotlin-sort) - [Working With Lists in Kotlin](https://www.baeldung.com/kotlin/lists) +- [Iterating Collections by Index in Kotlin](https://www.baeldung.com/kotlin/iterating-collections-by-index) From 0bf56056fa02c4de239c0748185d73a3063b8c43 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:42:52 +0800 Subject: [PATCH 096/102] Update README.md --- core-kotlin-modules/core-kotlin-lang-oop-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/README.md b/core-kotlin-modules/core-kotlin-lang-oop-2/README.md index 27536273dc..a62a25c01d 100644 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/README.md +++ b/core-kotlin-modules/core-kotlin-lang-oop-2/README.md @@ -7,4 +7,5 @@ This module contains articles about Object-Oriented Programming in Kotlin - [Generics in Kotlin](https://www.baeldung.com/kotlin-generics) - [Delegated Properties in Kotlin](https://www.baeldung.com/kotlin-delegated-properties) - [Delegation Pattern in Kotlin](https://www.baeldung.com/kotlin-delegation-pattern) +- [Anonymous Inner Classes in Kotlin](https://www.baeldung.com/kotlin/anonymous-inner-classes) - [[<-- Prev]](/core-kotlin-modules/core-kotlin-lang-oop) From 0768021cd344b06c623faad1ffe273d21b13997e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Fri, 24 Jul 2020 13:24:43 +0800 Subject: [PATCH 097/102] Update README.md --- core-java-modules/core-java-security-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-security-2/README.md b/core-java-modules/core-java-security-2/README.md index 24a821bd4d..ba8cce46a0 100644 --- a/core-java-modules/core-java-security-2/README.md +++ b/core-java-modules/core-java-security-2/README.md @@ -9,4 +9,5 @@ This module contains articles about core Java Security - [Hashing a Password in Java](https://www.baeldung.com/java-password-hashing) - [SHA-256 and SHA3-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java) - [Checksums in Java](https://www.baeldung.com/java-checksums) +- [How to Read PEM File to Get Public and Private Keys](https://www.baeldung.com/java-read-pem-file-keys) - More articles: [[<-- prev]](/core-java-modules/core-java-security) From 9d9b293431291f456b175160929c053f9f313f28 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Fri, 24 Jul 2020 13:26:05 +0800 Subject: [PATCH 098/102] Update README.md --- libraries-security/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries-security/README.md b/libraries-security/README.md index 580ebdeab0..5ec85a15e9 100644 --- a/libraries-security/README.md +++ b/libraries-security/README.md @@ -10,3 +10,4 @@ This module contains articles about security libraries. - [Introduction to BouncyCastle with Java](https://www.baeldung.com/java-bouncy-castle) - [Intro to Jasypt](https://www.baeldung.com/jasypt) - [Digital Signatures in Java](https://www.baeldung.com/java-digital-signature) +- [How to Read PEM File to Get Public and Private Keys](https://www.baeldung.com/java-read-pem-file-keys) From 676c89a8a5fe8582a1696b0a4239825f8f6dafa8 Mon Sep 17 00:00:00 2001 From: rdevarakonda Date: Sat, 25 Jul 2020 10:43:52 +0100 Subject: [PATCH 099/102] BAEL-4006 | Liskov Substitution Principle in Java (#9431) * BAEL-4006 | Liskov Substitution Principle in Java * BAEL-4006 | UNDO unintentional commit to pom.xml * BAEL-4006 | Code review feedback implementation * BAEL-4006 | Changes made to support the article review feedback implementation * BAEL-4006 | Minor change to a comment --- .../java/com/baeldung/l/advanced/Account.java | 17 +++++++++++ .../advanced/BankingAppWithdrawalService.java | 15 ++++++++++ .../java/com/baeldung/l/advanced/Bar.java | 27 ++++++++++++++++++ .../java/com/baeldung/l/advanced/Car.java | 26 +++++++++++++++++ .../baeldung/l/advanced/CurrentAccount.java | 15 ++++++++++ .../com/baeldung/l/advanced/ElectricCar.java | 23 +++++++++++++++ .../baeldung/l/advanced/FilePurgingJob.java | 18 ++++++++++++ .../com/baeldung/l/advanced/FileSystem.java | 10 +++++++ .../l/advanced/FixedTermDepositAccount.java | 15 ++++++++++ .../java/com/baeldung/l/advanced/Foo.java | 22 +++++++++++++++ .../com/baeldung/l/advanced/HybridCar.java | 28 +++++++++++++++++++ .../com/baeldung/l/advanced/MotorCar.java | 25 +++++++++++++++++ .../l/advanced/ReadOnlyFileSystem.java | 16 +++++++++++ .../baeldung/l/advanced/SavingsAccount.java | 15 ++++++++++ .../java/com/baeldung/l/advanced/ToyCar.java | 24 ++++++++++++++++ .../l/advanced/refactored/Account.java | 7 +++++ .../BankingAppWithdrawalService.java | 17 +++++++++++ .../l/advanced/refactored/CurrentAccount.java | 13 +++++++++ .../refactored/FixedTermDepositAccount.java | 9 ++++++ .../l/advanced/refactored/SavingsAccount.java | 13 +++++++++ .../refactored/WithdrawableAccount.java | 14 ++++++++++ 21 files changed, 369 insertions(+) create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/Account.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/BankingAppWithdrawalService.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/Bar.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/Car.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/CurrentAccount.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/ElectricCar.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/FilePurgingJob.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/FileSystem.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/FixedTermDepositAccount.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/Foo.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/HybridCar.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/MotorCar.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/ReadOnlyFileSystem.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/SavingsAccount.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/ToyCar.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/Account.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/BankingAppWithdrawalService.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/CurrentAccount.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/FixedTermDepositAccount.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/SavingsAccount.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/WithdrawableAccount.java diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/Account.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/Account.java new file mode 100644 index 0000000000..3a8260924b --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/Account.java @@ -0,0 +1,17 @@ +package com.baeldung.l.advanced; + +import java.math.BigDecimal; + +public abstract class Account { + protected abstract void deposit(BigDecimal amount); + + /** + * Reduces the account balance by the specified amount + * provided given amount > 0 and account meets minimum available + * balance criteria. + * + * @param amount + */ + protected abstract void withdraw(BigDecimal amount); + +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/BankingAppWithdrawalService.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/BankingAppWithdrawalService.java new file mode 100644 index 0000000000..6689b1dc8c --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/BankingAppWithdrawalService.java @@ -0,0 +1,15 @@ +package com.baeldung.l.advanced; + +import java.math.BigDecimal; + +public class BankingAppWithdrawalService { + private Account account; + + public BankingAppWithdrawalService(Account account) { + this.account = account; + } + + public void withdraw(BigDecimal amount) { + account.withdraw(amount); + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/Bar.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/Bar.java new file mode 100644 index 0000000000..8f421cebaa --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/Bar.java @@ -0,0 +1,27 @@ +package com.baeldung.l.advanced; + +public class Bar extends Foo { + + @Override + // precondition: 0 < num <= 10 + public void doStuff(int num) { + if (num <= 0 || num > 10) { + throw new IllegalArgumentException("Input out of range 1-10"); + } + // some logic here... + } + + @Override + // precondition: 0 < num <= 3 + public void doOtherStuff(int num) { + if (num <= 0 || num > 3) { + throw new IllegalArgumentException("Input out of range 1-3"); + } + // some logic here... + } + + @Override + public Integer generateNumber() { + return new Integer(10); + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/Car.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/Car.java new file mode 100644 index 0000000000..48688d9a45 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/Car.java @@ -0,0 +1,26 @@ +package com.baeldung.l.advanced; + +public abstract class Car { + protected int limit; + + // invariant: speed < limit; + protected int speed; + + // Allowed to be set once at the time of creation. + // Value can only increment thereafter. + // Value cannot be reset. + protected int mileage; + + public Car(int mileage) { + this.mileage = mileage; + } + + protected abstract void turnOnEngine(); + + // postcondition: speed < limit + protected abstract void accelerate(); + + // postcondition: speed must reduce + protected abstract void brake(); + +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/CurrentAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/CurrentAccount.java new file mode 100644 index 0000000000..7187582126 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/CurrentAccount.java @@ -0,0 +1,15 @@ +package com.baeldung.l.advanced; + +import java.math.BigDecimal; + +public class CurrentAccount extends Account { + @Override + protected void deposit(BigDecimal amount) { + // Deposit into CurrentAccount + } + + @Override + protected void withdraw(BigDecimal amount) { + // Withdraw from CurrentAccount + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/ElectricCar.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/ElectricCar.java new file mode 100644 index 0000000000..ca78af633f --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/ElectricCar.java @@ -0,0 +1,23 @@ +package com.baeldung.l.advanced; + +public class ElectricCar extends Car { + + public ElectricCar(int mileage) { + super(mileage); + } + + @Override + protected void turnOnEngine() { + throw new AssertionError("I am an Electric Car. I don't have an engine!"); + } + + @Override + protected void accelerate() { + // this acceleration is crazy! + } + + @Override + protected void brake() { + // Apply ElectricCar brake + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/FilePurgingJob.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/FilePurgingJob.java new file mode 100644 index 0000000000..57334696b0 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/FilePurgingJob.java @@ -0,0 +1,18 @@ +package com.baeldung.l.advanced; + +import java.io.IOException; + +public class FilePurgingJob { + private FileSystem fileSystem; + + public FilePurgingJob(FileSystem fileSystem) { + this.fileSystem = fileSystem; + } + + public void purgeOldestFile(String path) throws IOException { + if (!(fileSystem instanceof ReadOnlyFileSystem)) { + // code to detect oldest file + fileSystem.deleteFile(path); + } + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/FileSystem.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/FileSystem.java new file mode 100644 index 0000000000..00a8fb8ec7 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/FileSystem.java @@ -0,0 +1,10 @@ +package com.baeldung.l.advanced; + +import java.io.File; +import java.io.IOException; + +public interface FileSystem { + File[] listFiles(String path); + + void deleteFile(String path) throws IOException; +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/FixedTermDepositAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/FixedTermDepositAccount.java new file mode 100644 index 0000000000..50dd4f3d17 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/FixedTermDepositAccount.java @@ -0,0 +1,15 @@ +package com.baeldung.l.advanced; + +import java.math.BigDecimal; + +public class FixedTermDepositAccount extends Account { + @Override + protected void deposit(BigDecimal amount) { + // Deposit into this account + } + + @Override + protected void withdraw(BigDecimal amount) { + throw new UnsupportedOperationException("Withdrawals are not supported by FixedTermDepositAccount!!"); + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/Foo.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/Foo.java new file mode 100644 index 0000000000..f61577c18f --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/Foo.java @@ -0,0 +1,22 @@ +package com.baeldung.l.advanced; + +public abstract class Foo { + + // precondition: 0 < num <=5 + public void doStuff(int num) { + if (num <= 0 || num > 5) { + throw new IllegalArgumentException("Input out of range 1-5"); + } + // some logic here... + } + + // precondition: 0 < num <=5 + public void doOtherStuff(int num) { + if (num <= 0 || num > 5) { + throw new IllegalArgumentException("Input out of range 1-5"); + } + // some logic here... + } + + public abstract Number generateNumber(); +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/HybridCar.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/HybridCar.java new file mode 100644 index 0000000000..ea643a7419 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/HybridCar.java @@ -0,0 +1,28 @@ +package com.baeldung.l.advanced; + +public class HybridCar extends Car { + // invariant: charge >= 0; + private int charge; + + public HybridCar(int mileage) { + super(mileage); + } + + @Override + protected void turnOnEngine() { + // Start HybridCar + } + + @Override + // postcondition: speed < limit + protected void accelerate() { + // Accelerate HybridCar speed < limit + } + + @Override + // postcondition: speed must reduce + // postcondition: charge must increase + protected void brake() { + // Apply HybridCar brake + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/MotorCar.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/MotorCar.java new file mode 100644 index 0000000000..68a54966cc --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/MotorCar.java @@ -0,0 +1,25 @@ +package com.baeldung.l.advanced; + +public class MotorCar extends Car { + + public MotorCar(int mileage) { + super(mileage); + } + + @Override + protected void turnOnEngine() { + // Start MotorCar + } + + @Override + // postcondition: speed < limit + protected void accelerate() { + // Accelerate MotorCar + } + + @Override + // postcondition: speed must reduce + protected void brake() { + // Apply MotorCar brake + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/ReadOnlyFileSystem.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/ReadOnlyFileSystem.java new file mode 100644 index 0000000000..6ba3d9770d --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/ReadOnlyFileSystem.java @@ -0,0 +1,16 @@ +package com.baeldung.l.advanced; + +import java.io.File; +import java.io.IOException; + +public class ReadOnlyFileSystem implements FileSystem { + public File[] listFiles(String path) { + // code to list files + return new File[0]; + } + + public void deleteFile(String path) throws IOException { + // Do nothing. + // deleteFile operation is not supported on a read-only file system + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/SavingsAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/SavingsAccount.java new file mode 100644 index 0000000000..8dbb5eb4d4 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/SavingsAccount.java @@ -0,0 +1,15 @@ +package com.baeldung.l.advanced; + +import java.math.BigDecimal; + +public class SavingsAccount extends Account { + @Override + protected void deposit(BigDecimal amount) { + // Deposit into SavingsAccount + } + + @Override + protected void withdraw(BigDecimal amount) { + // Withdraw from SavingsAccount + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/ToyCar.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/ToyCar.java new file mode 100644 index 0000000000..a41694deef --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/ToyCar.java @@ -0,0 +1,24 @@ +package com.baeldung.l.advanced; + +public class ToyCar extends Car { + + public ToyCar(int mileage) { + super(mileage); + } + + protected void turnOnEngine() { + + } + + protected void accelerate() { + + } + + protected void brake() { + + } + + public void reset() { + mileage = 0; + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/Account.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/Account.java new file mode 100644 index 0000000000..cb950df164 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/Account.java @@ -0,0 +1,7 @@ +package com.baeldung.l.advanced.refactored; + +import java.math.BigDecimal; + +public abstract class Account { + protected abstract void deposit(BigDecimal amount); +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/BankingAppWithdrawalService.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/BankingAppWithdrawalService.java new file mode 100644 index 0000000000..cbb375dd52 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/BankingAppWithdrawalService.java @@ -0,0 +1,17 @@ +package com.baeldung.l.advanced.refactored; + +import com.baeldung.l.advanced.Account; + +import java.math.BigDecimal; + +public class BankingAppWithdrawalService { + private WithdrawableAccount withdrawableAccount; + + public BankingAppWithdrawalService(WithdrawableAccount withdrawableAccount) { + this.withdrawableAccount = withdrawableAccount; + } + + public void withdraw(BigDecimal amount) { + withdrawableAccount.withdraw(amount); + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/CurrentAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/CurrentAccount.java new file mode 100644 index 0000000000..5b5b9efe04 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/CurrentAccount.java @@ -0,0 +1,13 @@ +package com.baeldung.l.advanced.refactored; + +import java.math.BigDecimal; + +public class CurrentAccount extends WithdrawableAccount { + protected void deposit(BigDecimal amount) { + // Deposit into CurrentAccount + } + + protected void withdraw(BigDecimal amount) { + // Withdraw from CurrentAccount + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/FixedTermDepositAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/FixedTermDepositAccount.java new file mode 100644 index 0000000000..14461b85a3 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/FixedTermDepositAccount.java @@ -0,0 +1,9 @@ +package com.baeldung.l.advanced.refactored; + +import java.math.BigDecimal; + +public class FixedTermDepositAccount extends Account { + protected void deposit(BigDecimal amount) { + // Deposit into this account + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/SavingsAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/SavingsAccount.java new file mode 100644 index 0000000000..45c50079bf --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/SavingsAccount.java @@ -0,0 +1,13 @@ +package com.baeldung.l.advanced.refactored; + +import java.math.BigDecimal; + +public class SavingsAccount extends WithdrawableAccount { + protected void deposit(BigDecimal amount) { + // Deposit into SavingsAccount + } + + protected void withdraw(BigDecimal amount) { + // Withdraw from SavingsAccount + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/WithdrawableAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/WithdrawableAccount.java new file mode 100644 index 0000000000..b3c7606cb7 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/WithdrawableAccount.java @@ -0,0 +1,14 @@ +package com.baeldung.l.advanced.refactored; + +import java.math.BigDecimal; + +public abstract class WithdrawableAccount extends Account { + /** + * Reduces the account balance by the specified amount + * provided given amount > 0 and account meets minimum available + * balance criteria. + * + * @param amount + */ + protected abstract void withdraw(BigDecimal amount); +} From aa4da284f2af0702f24513b9757ab62f6dd6ad26 Mon Sep 17 00:00:00 2001 From: Roger <587230+rojyates@users.noreply.github.com> Date: Sat, 25 Jul 2020 23:45:41 +1000 Subject: [PATCH 100/102] BAEL-1258 Added example code for Jess and JSR94 (#9693) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * BAEL-1258 Added example code for Jess and JSR94 * BAEL-1258 Relocate to rule-modules * BAEL-1258 Remove README as per PR review * šBAEL-1258 Declared exceptions and replace System.out.println with log statements * BAEL-1258 Removed Lombok * BAEL-1258 Removed Lombok * BAEL-1258 Rename artifactId to match directory name --- rule-engines/jess/pom.xml | 25 +++++ .../com/baeldung/rules/jess/JessHello.java | 17 ++++ .../com/baeldung/rules/jess/JessWithData.java | 42 ++++++++ .../baeldung/rules/jess/JessWithJsr94.java | 98 +++++++++++++++++++ .../com/baeldung/rules/jess/model/Answer.java | 31 ++++++ .../baeldung/rules/jess/model/Question.java | 32 ++++++ .../jess/src/main/resources/bonus.clp | 8 ++ .../jess/src/main/resources/helloJess.clp | 3 + 8 files changed, 256 insertions(+) create mode 100644 rule-engines/jess/pom.xml create mode 100644 rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessHello.java create mode 100644 rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithData.java create mode 100644 rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithJsr94.java create mode 100644 rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Answer.java create mode 100644 rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Question.java create mode 100644 rule-engines/jess/src/main/resources/bonus.clp create mode 100644 rule-engines/jess/src/main/resources/helloJess.clp diff --git a/rule-engines/jess/pom.xml b/rule-engines/jess/pom.xml new file mode 100644 index 0000000000..40d50fae70 --- /dev/null +++ b/rule-engines/jess/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + com.baeldung.rules.jess + jess + 1.0-SNAPSHOT + + + + + jsr94 + jsr94 + 1.1 + + + gov.sandia + jess + 7.1p2 + + + + \ No newline at end of file diff --git a/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessHello.java b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessHello.java new file mode 100644 index 0000000000..1462996a4c --- /dev/null +++ b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessHello.java @@ -0,0 +1,17 @@ +package com.baeldung.rules.jess; + +import jess.JessException; +import jess.Rete; + +public class JessHello { + public static final String RULES_FILE = "helloJess.clp"; + + public static void main(String[] args) throws JessException { + Rete engine = new Rete(); + engine.reset(); + + engine.batch(RULES_FILE); + + engine.run(); + } +} diff --git a/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithData.java b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithData.java new file mode 100644 index 0000000000..5d5dc9b983 --- /dev/null +++ b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithData.java @@ -0,0 +1,42 @@ +package com.baeldung.rules.jess; + +import com.baeldung.rules.jess.model.Answer; +import com.baeldung.rules.jess.model.Question; +import jess.Filter; +import jess.JessException; +import jess.Rete; + +import java.util.Iterator; +import java.util.logging.Logger; + +public class JessWithData { + public static final String RULES_BONUS_FILE = "bonus.clp"; + private static Logger log = Logger.getLogger("JessWithData"); + + public static void main(String[] args) throws JessException { + Rete engine = new Rete(); + engine.reset(); + + engine.batch(RULES_BONUS_FILE); + + prepareData(engine); + + engine.run(); + + checkResults(engine); + } + + private static void checkResults(Rete engine) { + Iterator results = engine.getObjects(new Filter.ByClass(Answer.class)); + while (results.hasNext()) { + Answer answer = (Answer) results.next(); + log.info(answer.toString()); + } + } + + private static void prepareData(Rete engine) throws JessException { + Question question = new Question("Can I have a bonus?", -5); + log.info(question.toString()); + engine.add(question); + } +} diff --git a/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithJsr94.java b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithJsr94.java new file mode 100644 index 0000000000..f07bf10a7a --- /dev/null +++ b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithJsr94.java @@ -0,0 +1,98 @@ +package com.baeldung.rules.jess; + +import com.baeldung.rules.jess.model.Answer; +import com.baeldung.rules.jess.model.Question; + +import javax.rules.*; +import javax.rules.admin.RuleAdministrator; +import javax.rules.admin.RuleExecutionSet; +import javax.rules.admin.RuleExecutionSetCreateException; +import javax.rules.admin.RuleExecutionSetRegisterException; +import java.io.IOException; +import java.io.InputStream; +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.logging.Logger; + +public class JessWithJsr94 { + public static final String RULES_BONUS_FILE = "/bonus.clp"; + public static final String RULES_URI = "com/baeldung/rules/bonus"; + private static final String RULE_SERVICE_PROVIDER = "jess.jsr94"; + private static Logger log = Logger.getLogger("JessWithData"); + + public static void main(String[] args) throws Exception { + RuleServiceProvider ruleServiceProvider = instantiateJessInstance(); + + // load our rules and register them with the rules provider + registerRules(RULES_BONUS_FILE, RULES_URI, ruleServiceProvider); + + runRules(RULES_URI, ruleServiceProvider); + } + + private static RuleServiceProvider instantiateJessInstance() throws ClassNotFoundException, ConfigurationException { + // Load the rule service provider of the reference implementation. + // Loading this class will automatically register this provider with the provider manager. + Class.forName(RULE_SERVICE_PROVIDER + ".RuleServiceProviderImpl"); + + // Get the rule service provider from the provider manager. + return RuleServiceProviderManager.getRuleServiceProvider(RULE_SERVICE_PROVIDER); + } + + private static void runRules(String rulesURI, RuleServiceProvider ruleServiceProvider) + throws ConfigurationException, RuleSessionTypeUnsupportedException, RuleSessionCreateException, RuleExecutionSetNotFoundException, RemoteException, InvalidRuleSessionException { + // Get a RuleRuntime and invoke the rule engine. + RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime(); + + //Create a statelessRuleSession. + StatelessRuleSession statelessRuleSession = (StatelessRuleSession) ruleRuntime.createRuleSession(rulesURI, new HashMap(), RuleRuntime.STATELESS_SESSION_TYPE); + + calculateResults(statelessRuleSession); + + statelessRuleSession.release(); + } + + private static void calculateResults(StatelessRuleSession statelessRuleSession) throws InvalidRuleSessionException, RemoteException { + List data = prepareData(); + + // execute the rules + List results = statelessRuleSession.executeRules(data); + + checkResults(results); + } + + private static List prepareData() { + List data = new ArrayList(); + data.add(new Question("Can I have a bonus?", -5)); + return data; + } + + private static void checkResults(List results) { + Iterator itr = results.iterator(); + while (itr.hasNext()) { + Object obj = itr.next(); + if (obj instanceof Answer) { + log.info(obj.toString()); + } + } + } + + private static void registerRules(String rulesFile, String rulesURI, RuleServiceProvider serviceProvider) throws ConfigurationException, RuleExecutionSetCreateException, IOException, RuleExecutionSetRegisterException { + // Get the rule administrator. + RuleAdministrator ruleAdministrator = serviceProvider.getRuleAdministrator(); + + // load the rules + InputStream ruleInput = JessWithJsr94.class.getResourceAsStream(rulesFile); + HashMap vendorProperties = new HashMap(); + + // Create the RuleExecutionSet + RuleExecutionSet ruleExecutionSet = ruleAdministrator + .getLocalRuleExecutionSetProvider(vendorProperties) + .createRuleExecutionSet(ruleInput, vendorProperties); + + // Register the rule execution set. + ruleAdministrator.registerRuleExecutionSet(rulesURI, ruleExecutionSet, vendorProperties); + } +} \ No newline at end of file diff --git a/rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Answer.java b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Answer.java new file mode 100644 index 0000000000..d690d04e13 --- /dev/null +++ b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Answer.java @@ -0,0 +1,31 @@ +package com.baeldung.rules.jess.model; + +public class Answer { + private String answer; + private int newBalance; + + public Answer(String answer, int newBalance) { + this.answer = answer; + this.newBalance = newBalance; + } + + public int getNewBalance() { + return newBalance; + } + + public void setNewBalance(int newBalance) { + this.newBalance = newBalance; + } + + public String getAnswer() { + return answer; + } + + public void setAnswer(String answer) { + this.answer = answer; + } + + public String toString() { + return "Answer(answer=" + answer + ", newBalance=" + newBalance + ")"; + } +} diff --git a/rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Question.java b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Question.java new file mode 100644 index 0000000000..499113d0fc --- /dev/null +++ b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Question.java @@ -0,0 +1,32 @@ +package com.baeldung.rules.jess.model; + +public class Question { + private String question; + private int balance; + + public Question(String question, int balance) { + this.question = question; + this.balance = balance; + } + + public String getQuestion() { + return question; + } + + public void setQuestion(String question) { + this.question = question; + } + + public int getBalance() { + return balance; + } + + public void setBalance(int balance) { + this.balance = balance; + } + + public String toString() { + return "Question(question=" + question + ", balance=" + balance + ")"; + } + +} diff --git a/rule-engines/jess/src/main/resources/bonus.clp b/rule-engines/jess/src/main/resources/bonus.clp new file mode 100644 index 0000000000..7f430bc43f --- /dev/null +++ b/rule-engines/jess/src/main/resources/bonus.clp @@ -0,0 +1,8 @@ +(import com.baeldung.rules.jess.model.*) +(deftemplate Question (declare (from-class Question))) +(deftemplate Answer (declare (from-class Answer))) + +(defrule avoid-overdraft "Give $50 to anyone overdrawn" + ?q <- (Question { balance < 0 }) + => + (add (new Answer "Overdrawn bonus" (+ ?q.balance 50)))) diff --git a/rule-engines/jess/src/main/resources/helloJess.clp b/rule-engines/jess/src/main/resources/helloJess.clp new file mode 100644 index 0000000000..547294eca6 --- /dev/null +++ b/rule-engines/jess/src/main/resources/helloJess.clp @@ -0,0 +1,3 @@ +;; Hello, world in Jess! + +(printout t "Hello from Jess!" crlf) From bc5f22d88b46016e95dd595f6dea47e546ae4245 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 26 Jul 2020 06:43:57 +0300 Subject: [PATCH 101/102] Update pom.xml (#9767) --- rule-engines/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/rule-engines/pom.xml b/rule-engines/pom.xml index d3d3127ce0..27748a5c3e 100644 --- a/rule-engines/pom.xml +++ b/rule-engines/pom.xml @@ -16,6 +16,7 @@ easy-rules openl-tablets rulebook + From 1b7d00d907c518fa22727246f48657e028b5b23c Mon Sep 17 00:00:00 2001 From: TJ Date: Sun, 26 Jul 2020 09:29:54 +0530 Subject: [PATCH 102/102] BAEL-4403 (#9740) * Hexagonal architecture in Java * BAEL-4403 * Revert "Hexagonal architecture in Java" This reverts commit 7ba4c9dcbd99ca418c070a73bd9ab9f6c956d185. * Updated code to use only Console * Added System.out * Created seaprate method for each functionality * Added Unit Test Case for ConsoleAndOut class Co-authored-by: Tarun Jain --- .../baeldung/consoleout/ConsoleAndOut.java | 31 +++++++++++++++++++ .../consoleout/ConsoleAndOutUnitTest.java | 27 ++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 core-java-modules/core-java-console/src/main/java/com/baeldung/consoleout/ConsoleAndOut.java create mode 100644 core-java-modules/core-java-console/src/test/java/com/baeldung/consoleout/ConsoleAndOutUnitTest.java diff --git a/core-java-modules/core-java-console/src/main/java/com/baeldung/consoleout/ConsoleAndOut.java b/core-java-modules/core-java-console/src/main/java/com/baeldung/consoleout/ConsoleAndOut.java new file mode 100644 index 0000000000..082a5219c9 --- /dev/null +++ b/core-java-modules/core-java-console/src/main/java/com/baeldung/consoleout/ConsoleAndOut.java @@ -0,0 +1,31 @@ +package com.baeldung.consoleout; + +import java.io.Console; + +public class ConsoleAndOut { + public static void main(String[] args) { + try { + printConsoleObject(); + readPasswordFromConsole(); + } catch (Exception ex) { + // Eating NullPointerExcpetion which will occur when this + // program will be run from mediums other than console + } + printSysOut(); + } + + static void printConsoleObject() { + Console console = System.console(); + console.writer().print(console); + } + + static void readPasswordFromConsole() { + Console console = System.console(); + char[] password = console.readPassword("Enter password: "); + console.printf(String.valueOf(password)); + } + + static void printSysOut() { + System.out.println(System.out); + } +} diff --git a/core-java-modules/core-java-console/src/test/java/com/baeldung/consoleout/ConsoleAndOutUnitTest.java b/core-java-modules/core-java-console/src/test/java/com/baeldung/consoleout/ConsoleAndOutUnitTest.java new file mode 100644 index 0000000000..619a65a1fc --- /dev/null +++ b/core-java-modules/core-java-console/src/test/java/com/baeldung/consoleout/ConsoleAndOutUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.consoleout; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +class ConsoleAndOutUnitTest { + + @Test + void whenRetreivingConsole_thenPrintConsoleObject() { + assertThrows(NullPointerException.class, () -> { + ConsoleAndOut.printConsoleObject(); + }); + } + + @Test + void whenReadingPassword_thenReadPassword() { + assertThrows(NullPointerException.class, () -> { + ConsoleAndOut.readPasswordFromConsole(); + }); + } + + @Test + void whenRetrievingSysOut_thenPrintSysOutObject() { + ConsoleAndOut.printSysOut(); + } +}