diff --git a/.gitignore b/.gitignore index 21586748b7..50cb889e5b 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ .idea/ *.iml *.iws +out/ # Mac .DS_Store @@ -27,6 +28,9 @@ log/ target/ +# Gradle +.gradle/ + spring-openid/src/main/resources/application.properties .recommenders/ /spring-hibernate4/nbproject/ @@ -72,4 +76,5 @@ persistence-modules/hibernate5/transaction.log apache-avro/src/main/java/com/baeldung/avro/model/ jta/transaction-logs/ software-security/sql-injection-samples/derby.log -spring-soap/src/main/java/com/baeldung/springsoap/gen/ \ No newline at end of file +spring-soap/src/main/java/com/baeldung/springsoap/gen/ +/report-*.json \ No newline at end of file diff --git a/algorithms-miscellaneous-1/README.md b/algorithms-miscellaneous-1/README.md index ea6d6f379b..479c2792f6 100644 --- a/algorithms-miscellaneous-1/README.md +++ b/algorithms-miscellaneous-1/README.md @@ -14,7 +14,5 @@ - [Calculate Factorial in Java](https://www.baeldung.com/java-calculate-factorial) - [Find Substrings That Are Palindromes in Java](https://www.baeldung.com/java-palindrome-substrings) - [Find the Longest Substring without Repeating Characters](https://www.baeldung.com/java-longest-substring-without-repeated-characters) -- [Java Two Pointer Technique](https://www.baeldung.com/java-two-pointer-technique) - [Permutations of an Array in Java](https://www.baeldung.com/java-array-permutations) -- [Implementing Simple State Machines with Java Enums](https://www.baeldung.com/java-enum-simple-state-machine) - [Generate Combinations in Java](https://www.baeldung.com/java-combinations-algorithm) diff --git a/algorithms-miscellaneous-2/README.md b/algorithms-miscellaneous-2/README.md index d693a44f66..de054566ed 100644 --- a/algorithms-miscellaneous-2/README.md +++ b/algorithms-miscellaneous-2/README.md @@ -8,9 +8,6 @@ - [Create a Sudoku Solver in Java](http://www.baeldung.com/java-sudoku) - [Displaying Money Amounts in Words](http://www.baeldung.com/java-money-into-words) - [A Collaborative Filtering Recommendation System in Java](http://www.baeldung.com/java-collaborative-filtering-recommendations) -- [Converting Between Roman and Arabic Numerals in Java](http://www.baeldung.com/java-convert-roman-arabic) -- [Practical Java Examples of the Big O Notation](http://www.baeldung.com/java-algorithm-complexity) -- [An Introduction to the Theory of Big-O Notation](http://www.baeldung.com/big-o-notation) - [Check If Two Rectangles Overlap In Java](https://www.baeldung.com/java-check-if-two-rectangles-overlap) - [Calculate the Distance Between Two Points in Java](https://www.baeldung.com/java-distance-between-two-points) - [Find the Intersection of Two Lines in Java](https://www.baeldung.com/java-intersection-of-two-lines) diff --git a/algorithms-miscellaneous-3/.gitignore b/algorithms-miscellaneous-3/.gitignore new file mode 100644 index 0000000000..30b2b7442c --- /dev/null +++ b/algorithms-miscellaneous-3/.gitignore @@ -0,0 +1,4 @@ +/target/ +.settings/ +.classpath +.project \ No newline at end of file diff --git a/algorithms-miscellaneous-3/README.md b/algorithms-miscellaneous-3/README.md new file mode 100644 index 0000000000..f299492d9c --- /dev/null +++ b/algorithms-miscellaneous-3/README.md @@ -0,0 +1,7 @@ +## Relevant articles: + +- [Java Two Pointer Technique](https://www.baeldung.com/java-two-pointer-technique) +- [Implementing Simple State Machines with Java Enums](https://www.baeldung.com/java-enum-simple-state-machine) +- [Converting Between Roman and Arabic Numerals in Java](http://www.baeldung.com/java-convert-roman-arabic) +- [Practical Java Examples of the Big O Notation](http://www.baeldung.com/java-algorithm-complexity) +- [An Introduction to the Theory of Big-O Notation](http://www.baeldung.com/big-o-notation) \ No newline at end of file diff --git a/algorithms-miscellaneous-3/pom.xml b/algorithms-miscellaneous-3/pom.xml new file mode 100644 index 0000000000..c4017144c8 --- /dev/null +++ b/algorithms-miscellaneous-3/pom.xml @@ -0,0 +1,39 @@ + + 4.0.0 + algorithms-miscellaneous-3 + 0.0.1-SNAPSHOT + algorithms-miscellaneous-3 + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.assertj + assertj-core + ${org.assertj.core.version} + test + + + + + + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin.version} + + + + + + + 3.9.0 + + + \ No newline at end of file diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/enumstatemachine/LeaveRequestState.java b/algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/enumstatemachine/LeaveRequestState.java similarity index 100% rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/enumstatemachine/LeaveRequestState.java rename to algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/enumstatemachine/LeaveRequestState.java diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/romannumerals/RomanArabicConverter.java b/algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/romannumerals/RomanArabicConverter.java similarity index 100% rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/romannumerals/RomanArabicConverter.java rename to algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/romannumerals/RomanArabicConverter.java diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/romannumerals/RomanNumeral.java b/algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/romannumerals/RomanNumeral.java similarity index 100% rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/romannumerals/RomanNumeral.java rename to algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/romannumerals/RomanNumeral.java diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/twopointertechnique/LinkedListFindMiddle.java b/algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/twopointertechnique/LinkedListFindMiddle.java similarity index 100% rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/twopointertechnique/LinkedListFindMiddle.java rename to algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/twopointertechnique/LinkedListFindMiddle.java diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/twopointertechnique/MyNode.java b/algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/twopointertechnique/MyNode.java similarity index 100% rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/twopointertechnique/MyNode.java rename to algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/twopointertechnique/MyNode.java diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/twopointertechnique/RotateArray.java b/algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/twopointertechnique/RotateArray.java similarity index 100% rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/twopointertechnique/RotateArray.java rename to algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/twopointertechnique/RotateArray.java diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/twopointertechnique/TwoSum.java b/algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/twopointertechnique/TwoSum.java similarity index 100% rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/twopointertechnique/TwoSum.java rename to algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/twopointertechnique/TwoSum.java diff --git a/core-java-10/src/main/resources/logback.xml b/algorithms-miscellaneous-3/src/main/resources/logback.xml similarity index 100% rename from core-java-10/src/main/resources/logback.xml rename to algorithms-miscellaneous-3/src/main/resources/logback.xml diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/analysis/AnalysisRunnerLiveTest.java b/algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/analysis/AnalysisRunnerLiveTest.java similarity index 100% rename from algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/analysis/AnalysisRunnerLiveTest.java rename to algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/analysis/AnalysisRunnerLiveTest.java diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/enumstatemachine/LeaveRequestStateUnitTest.java b/algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/enumstatemachine/LeaveRequestStateUnitTest.java similarity index 100% rename from algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/enumstatemachine/LeaveRequestStateUnitTest.java rename to algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/enumstatemachine/LeaveRequestStateUnitTest.java diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/romannumerals/RomanArabicConverterUnitTest.java b/algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/romannumerals/RomanArabicConverterUnitTest.java similarity index 100% rename from algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/romannumerals/RomanArabicConverterUnitTest.java rename to algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/romannumerals/RomanArabicConverterUnitTest.java diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/twopointertechnique/LinkedListFindMiddleUnitTest.java b/algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/twopointertechnique/LinkedListFindMiddleUnitTest.java similarity index 100% rename from algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/twopointertechnique/LinkedListFindMiddleUnitTest.java rename to algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/twopointertechnique/LinkedListFindMiddleUnitTest.java diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/twopointertechnique/RotateArrayUnitTest.java b/algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/twopointertechnique/RotateArrayUnitTest.java similarity index 100% rename from algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/twopointertechnique/RotateArrayUnitTest.java rename to algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/twopointertechnique/RotateArrayUnitTest.java diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/twopointertechnique/TwoSumUnitTest.java b/algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/twopointertechnique/TwoSumUnitTest.java similarity index 100% rename from algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/twopointertechnique/TwoSumUnitTest.java rename to algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/twopointertechnique/TwoSumUnitTest.java diff --git a/apache-meecrowave/pom.xml b/apache-meecrowave/pom.xml index bb851577e2..4eb1094f94 100644 --- a/apache-meecrowave/pom.xml +++ b/apache-meecrowave/pom.xml @@ -60,7 +60,6 @@ 1.8 1.8 - 4.10 1.2.0 3.10.0 1.2.1 diff --git a/apache-velocity/pom.xml b/apache-velocity/pom.xml index a0a8389f7d..24ab0b861d 100644 --- a/apache-velocity/pom.xml +++ b/apache-velocity/pom.xml @@ -59,7 +59,6 @@ - 1.2 4.5.2 1.7 2.0 diff --git a/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java b/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java index e0ee8879a5..65d0eb6f58 100644 --- a/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java +++ b/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java @@ -1,8 +1,9 @@ package com.baeldung.autofactory.provided; +import com.baeldung.autofactory.model.Camera; import com.google.auto.factory.AutoFactory; import com.google.auto.factory.Provided; -import javafx.scene.Camera; + import javax.inject.Provider; diff --git a/cdi/pom.xml b/cdi/pom.xml index 85da8518d0..c98ad57495 100644 --- a/cdi/pom.xml +++ b/cdi/pom.xml @@ -27,7 +27,7 @@ org.hamcrest hamcrest-core - ${hamcrest-core.version} + ${org.hamcrest.version} test @@ -64,7 +64,6 @@ 2.0.SP1 3.0.5.Final 1.9.2 - 1.3 3.10.0 5.1.2.RELEASE diff --git a/cloud-foundry-uaa/README.md b/cloud-foundry-uaa/README.md new file mode 100644 index 0000000000..b2f382cad1 --- /dev/null +++ b/cloud-foundry-uaa/README.md @@ -0,0 +1,3 @@ +### Revelant Articles + +- [A Quick Guide To Using Cloud Foundry UAA](https://www.baeldung.com/cloud-foundry-uaa) diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml b/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml index f650498b69..c6de00dbe9 100644 --- a/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml +++ b/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml @@ -34,8 +34,5 @@ - - - 1.8 - + diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml index 710cecbd4e..56fb23e9d8 100644 --- a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml +++ b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml @@ -35,8 +35,4 @@ - - 1.8 - - diff --git a/core-groovy-2/README.md b/core-groovy-2/README.md new file mode 100644 index 0000000000..f60bdb3cbe --- /dev/null +++ b/core-groovy-2/README.md @@ -0,0 +1,7 @@ +# Groovy + +## Relevant articles: + +- [String Matching in Groovy](http://www.baeldung.com/) +- [Groovy def Keyword] + diff --git a/core-groovy-2/pom.xml b/core-groovy-2/pom.xml new file mode 100644 index 0000000000..77de9c8fc8 --- /dev/null +++ b/core-groovy-2/pom.xml @@ -0,0 +1,131 @@ + + + 4.0.0 + core-groovy-2 + 1.0-SNAPSHOT + core-groovy-2 + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.codehaus.groovy + groovy + ${groovy.version} + + + org.codehaus.groovy + groovy-all + ${groovy-all.version} + pom + + + org.codehaus.groovy + groovy-dateutil + ${groovy.version} + + + org.codehaus.groovy + groovy-sql + ${groovy-sql.version} + + + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + org.hsqldb + hsqldb + ${hsqldb.version} + test + + + org.spockframework + spock-core + ${spock-core.version} + test + + + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + ${gmavenplus-plugin.version} + + + + addSources + addTestSources + compile + compileTests + + + + + + maven-failsafe-plugin + ${maven-failsafe-plugin.version} + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + junit5 + + integration-test + verify + + + + **/*Test5.java + + + + + + + maven-surefire-plugin + 2.20.1 + + false + + **/*Test.java + **/*Spec.java + + + + + + + + + central + http://jcenter.bintray.com + + + + + 1.0.0 + 2.5.6 + 2.5.6 + 2.5.6 + 2.4.0 + 1.1-groovy-2.4 + 1.6 + + + diff --git a/core-groovy-2/src/test/groovy/com/baeldung/defkeyword/DefUnitTest.groovy b/core-groovy-2/src/test/groovy/com/baeldung/defkeyword/DefUnitTest.groovy new file mode 100644 index 0000000000..310d97d3fd --- /dev/null +++ b/core-groovy-2/src/test/groovy/com/baeldung/defkeyword/DefUnitTest.groovy @@ -0,0 +1,79 @@ +package com.baeldung.defkeyword + +import org.codehaus.groovy.runtime.NullObject +import org.codehaus.groovy.runtime.typehandling.GroovyCastException + +import groovy.transform.TypeChecked +import groovy.transform.TypeCheckingMode + +@TypeChecked +class DefUnitTest extends GroovyTestCase { + + def id + def firstName = "Samwell" + def listOfCountries = ['USA', 'UK', 'FRANCE', 'INDIA'] + + @TypeChecked(TypeCheckingMode.SKIP) + def multiply(x, y) { + return x*y + } + + @TypeChecked(TypeCheckingMode.SKIP) + void testDefVariableDeclaration() { + + def list + assert list.getClass() == org.codehaus.groovy.runtime.NullObject + assert list.is(null) + + list = [1,2,4] + assert list instanceof ArrayList + } + + @TypeChecked(TypeCheckingMode.SKIP) + void testTypeVariables() { + int rate = 200 + try { + rate = [12] //GroovyCastException + rate = "nill" //GroovyCastException + } catch(GroovyCastException) { + println "Cannot assign anything other than integer" + } + } + + @TypeChecked(TypeCheckingMode.SKIP) + void testDefVariableMultipleAssignment() { + def rate + assert rate == null + assert rate.getClass() == org.codehaus.groovy.runtime.NullObject + + rate = 12 + assert rate instanceof Integer + + rate = "Not Available" + assert rate instanceof String + + rate = [1, 4] + assert rate instanceof List + + assert divide(12, 3) instanceof BigDecimal + assert divide(1, 0) instanceof String + + } + + def divide(int x, int y) { + if(y==0) { + return "Should not divide by 0" + } else { + return x/y + } + } + + def greetMsg() { + println "Hello! I am Groovy" + } + + void testDefVsType() { + def int count + assert count instanceof Integer + } +} \ No newline at end of file diff --git a/core-groovy-2/src/test/groovy/com/baeldung/strings/StringMatchingSpec.groovy b/core-groovy-2/src/test/groovy/com/baeldung/strings/StringMatchingSpec.groovy new file mode 100644 index 0000000000..3865bc73fa --- /dev/null +++ b/core-groovy-2/src/test/groovy/com/baeldung/strings/StringMatchingSpec.groovy @@ -0,0 +1,44 @@ +package com.baeldung.strings + +import spock.lang.Specification + +import java.util.regex.Pattern + +class StringMatchingSpec extends Specification { + + def "pattern operator example"() { + given: "a pattern" + def p = ~'foo' + + expect: + p instanceof Pattern + + and: "you can use slash strings to avoid escaping of blackslash" + def digitPattern = ~/\d*/ + digitPattern.matcher('4711').matches() + } + + def "match operator example"() { + expect: + 'foobar' ==~ /.*oba.*/ + + and: "matching is strict" + !('foobar' ==~ /foo/) + } + + def "find operator example"() { + when: "using the find operator" + def matcher = 'foo and bar, baz and buz' =~ /(\w+) and (\w+)/ + + then: "will find groups" + matcher.size() == 2 + + and: "can access groups using array" + matcher[0][0] == 'foo and bar' + matcher[1][2] == 'buz' + + and: "you can use it as a predicate" + 'foobarbaz' =~ /bar/ + } + +} diff --git a/core-groovy-collections/README.md b/core-groovy-collections/README.md new file mode 100644 index 0000000000..482e33bce1 --- /dev/null +++ b/core-groovy-collections/README.md @@ -0,0 +1,6 @@ +# Groovy + +## Relevant articles: + +- [Maps in Groovy](http://www.baeldung.com/) + diff --git a/core-groovy-collections/pom.xml b/core-groovy-collections/pom.xml new file mode 100644 index 0000000000..bf3ae26592 --- /dev/null +++ b/core-groovy-collections/pom.xml @@ -0,0 +1,131 @@ + + + 4.0.0 + core-groovy-collections + 1.0-SNAPSHOT + core-groovy-collections + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.codehaus.groovy + groovy + ${groovy.version} + + + org.codehaus.groovy + groovy-all + ${groovy-all.version} + pom + + + org.codehaus.groovy + groovy-dateutil + ${groovy.version} + + + org.codehaus.groovy + groovy-sql + ${groovy-sql.version} + + + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + org.hsqldb + hsqldb + ${hsqldb.version} + test + + + org.spockframework + spock-core + ${spock-core.version} + test + + + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + ${gmavenplus-plugin.version} + + + + addSources + addTestSources + compile + compileTests + + + + + + maven-failsafe-plugin + ${maven-failsafe-plugin.version} + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + junit5 + + integration-test + verify + + + + **/*Test5.java + + + + + + + maven-surefire-plugin + 2.20.1 + + false + + **/*Test.java + **/*Spec.java + + + + + + + + + central + http://jcenter.bintray.com + + + + + 1.0.0 + 2.5.6 + 2.5.6 + 2.5.6 + 2.4.0 + 1.1-groovy-2.4 + 1.6 + + + diff --git a/core-groovy-collections/src/test/groovy/com/baeldung/map/MapTest.groovy b/core-groovy-collections/src/test/groovy/com/baeldung/map/MapTest.groovy new file mode 100644 index 0000000000..c6105eb1c4 --- /dev/null +++ b/core-groovy-collections/src/test/groovy/com/baeldung/map/MapTest.groovy @@ -0,0 +1,148 @@ +package com.baeldung.map; + +import static groovy.test.GroovyAssert.* +import org.junit.Test + +class MapTest{ + + @Test + void createMap() { + + def emptyMap = [:] + assertNotNull(emptyMap) + + assertTrue(emptyMap instanceof java.util.LinkedHashMap) + + def map = [name:"Jerry", age: 42, city: "New York"] + assertTrue(map.size() == 3) + } + + @Test + void addItemsToMap() { + + def map = [name:"Jerry"] + + map["age"] = 42 + + map.city = "New York" + + def hobbyLiteral = "hobby" + def hobbyMap = [(hobbyLiteral): "Singing"] + map.putAll(hobbyMap) + + assertTrue(map == [name:"Jerry", age: 42, city: "New York", hobby:"Singing"]) + assertTrue(hobbyMap.hobby == "Singing") + assertTrue(hobbyMap[hobbyLiteral] == "Singing") + + map.plus([1:20]) // returns new map + + map << [2:30] + + } + + @Test + void getItemsFromMap() { + + def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"] + + assertTrue(map["name"] == "Jerry") + + assertTrue(map.name == "Jerry") + + def propertyAge = "age" + assertTrue(map[propertyAge] == 42) + } + + @Test + void removeItemsFromMap() { + + def map = [1:20, a:30, 2:42, 4:34, ba:67, 6:39, 7:49] + + def minusMap = map.minus([2:42, 4:34]); + assertTrue(minusMap == [1:20, a:30, ba:67, 6:39, 7:49]) + + minusMap.removeAll{it -> it.key instanceof String} + assertTrue( minusMap == [ 1:20, 6:39, 7:49]) + + minusMap.retainAll{it -> it.value %2 == 0} + assertTrue( minusMap == [1:20]) + } + + @Test + void iteratingOnMaps(){ + def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"] + + map.each{ entry -> println "$entry.key: $entry.value" } + + map.eachWithIndex{ entry, i -> println "$i $entry.key: $entry.value" } + + map.eachWithIndex{ key, value, i -> println "$i $key: $value" } + } + + @Test + void filteringAndSearchingMaps(){ + def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"] + + assertTrue(map.find{ it.value == "New York"}.key == "city") + + assertTrue(map.findAll{ it.value == "New York"} == [city : "New York"]) + + map.grep{it.value == "New York"}.each{ it -> assertTrue(it.key == "city" && it.value == "New York")} + + assertTrue(map.every{it -> it.value instanceof String} == false) + + assertTrue(map.any{it -> it.value instanceof String} == true) + } + + @Test + void collect(){ + + def map = [1: [name:"Jerry", age: 42, city: "New York"], + 2: [name:"Long", age: 25, city: "New York"], + 3: [name:"Dustin", age: 29, city: "New York"], + 4: [name:"Dustin", age: 34, city: "New York"]] + + def names = map.collect{entry -> entry.value.name} // returns only list + assertTrue(names == ["Jerry", "Long", "Dustin", "Dustin"]) + + def uniqueNames = map.collect([] as HashSet){entry -> entry.value.name} + assertTrue(uniqueNames == ["Jerry", "Long", "Dustin"] as Set) + + def idNames = map.collectEntries{key, value -> [key, value.name]} + assertTrue(idNames == [1:"Jerry", 2: "Long", 3:"Dustin", 4: "Dustin"]) + + def below30Names = map.findAll{it.value.age < 30}.collect{key, value -> value.name} + assertTrue(below30Names == ["Long", "Dustin"]) + + + } + + @Test + void group(){ + def map = [1:20, 2: 40, 3: 11, 4: 93] + + def subMap = map.groupBy{it.value % 2} + println subMap + assertTrue(subMap == [0:[1:20, 2:40 ], 1:[3:11, 4:93]]) + + def keySubMap = map.subMap([1, 2]) + assertTrue(keySubMap == [1:20, 2:40]) + + } + + @Test + void sorting(){ + def map = [ab:20, a: 40, cb: 11, ba: 93] + + def naturallyOrderedMap = map.sort() + assertTrue([a:40, ab:20, ba:93, cb:11] == naturallyOrderedMap) + + def compSortedMap = map.sort({ k1, k2 -> k1 <=> k2 } as Comparator) + assertTrue([a:40, ab:20, ba:93, cb:11] == compSortedMap) + + def cloSortedMap = map.sort({ it1, it2 -> it1.value <=> it1.value }) + assertTrue([cb:11, ab:20, a:40, ba:93] == cloSortedMap) + + } + +} diff --git a/core-groovy/.gitignore b/core-groovy/.gitignore new file mode 100644 index 0000000000..09220fdf52 --- /dev/null +++ b/core-groovy/.gitignore @@ -0,0 +1 @@ +/src/main/resources/ioSerializedObject.txt \ No newline at end of file diff --git a/core-groovy/src/main/resources/ioSerializedObject.txt b/core-groovy/src/main/resources/ioSerializedObject.txt deleted file mode 100644 index 833ed32bf1..0000000000 Binary files a/core-groovy/src/main/resources/ioSerializedObject.txt and /dev/null differ diff --git a/core-groovy/src/test/groovy/com/baeldung/io/DataAndObjectsUnitTest.groovy b/core-groovy/src/test/groovy/com/baeldung/io/DataAndObjectsUnitTest.groovy index 0b413cf76c..32a21f6b38 100644 --- a/core-groovy/src/test/groovy/com/baeldung/io/DataAndObjectsUnitTest.groovy +++ b/core-groovy/src/test/groovy/com/baeldung/io/DataAndObjectsUnitTest.groovy @@ -34,7 +34,9 @@ class DataAndObjectsUnitTest { @Test void whenUsingWithObjectOutputStream_thenObjectIsSerializedToFile() { Task task = new Task(description:'Take out the trash', startDate:new Date(), status:0) - new File('src/main/resources/ioSerializedObject.txt').withObjectOutputStream { out -> + def serializedDataFile = new File('src/main/resources/ioSerializedObject.txt') + serializedDataFile.createNewFile() + serializedDataFile.withObjectOutputStream { out -> out.writeObject(task) } diff --git a/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy b/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy new file mode 100644 index 0000000000..f1d528207f --- /dev/null +++ b/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy @@ -0,0 +1,148 @@ +package com.baeldung.groovy.map; + +import static groovy.test.GroovyAssert.* +import org.junit.Test + +class MapTest{ + + @Test + void createMap() { + + def emptyMap = [:] + assertNotNull(emptyMap) + + assertTrue(emptyMap instanceof java.util.LinkedHashMap) + + def map = [name:"Jerry", age: 42, city: "New York"] + assertTrue(map.size() == 3) + } + + @Test + void addItemsToMap() { + + def map = [name:"Jerry"] + + map["age"] = 42 + + map.city = "New York" + + def hobbyLiteral = "hobby" + def hobbyMap = [(hobbyLiteral): "Singing"] + map.putAll(hobbyMap) + + assertTrue(map == [name:"Jerry", age: 42, city: "New York", hobby:"Singing"]) + assertTrue(hobbyMap.hobby == "Singing") + assertTrue(hobbyMap[hobbyLiteral] == "Singing") + + map.plus([1:20]) // returns new map + + map << [2:30] + + } + + @Test + void getItemsFromMap() { + + def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"] + + assertTrue(map["name"] == "Jerry") + + assertTrue(map.name == "Jerry") + + def propertyAge = "age" + assertTrue(map[propertyAge] == 42) + } + + @Test + void removeItemsFromMap() { + + def map = [1:20, a:30, 2:42, 4:34, ba:67, 6:39, 7:49] + + def minusMap = map.minus([2:42, 4:34]); + assertTrue(minusMap == [1:20, a:30, ba:67, 6:39, 7:49]) + + minusMap.removeAll{it -> it.key instanceof String} + assertTrue( minusMap == [ 1:20, 6:39, 7:49]) + + minusMap.retainAll{it -> it.value %2 == 0} + assertTrue( minusMap == [1:20]) + } + + @Test + void iteratingOnMaps(){ + def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"] + + map.each{ entry -> println "$entry.key: $entry.value" } + + map.eachWithIndex{ entry, i -> println "$i $entry.key: $entry.value" } + + map.eachWithIndex{ key, value, i -> println "$i $key: $value" } + } + + @Test + void filteringAndSearchingMaps(){ + def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"] + + assertTrue(map.find{ it.value == "New York"}.key == "city") + + assertTrue(map.findAll{ it.value == "New York"} == [city : "New York"]) + + map.grep{it.value == "New York"}.each{ it -> assertTrue(it.key == "city" && it.value == "New York")} + + assertTrue(map.every{it -> it.value instanceof String} == false) + + assertTrue(map.any{it -> it.value instanceof String} == true) + } + + @Test + void collect(){ + + def map = [1: [name:"Jerry", age: 42, city: "New York"], + 2: [name:"Long", age: 25, city: "New York"], + 3: [name:"Dustin", age: 29, city: "New York"], + 4: [name:"Dustin", age: 34, city: "New York"]] + + def names = map.collect{entry -> entry.value.name} // returns only list + assertTrue(names == ["Jerry", "Long", "Dustin", "Dustin"]) + + def uniqueNames = map.collect([] as HashSet){entry -> entry.value.name} + assertTrue(uniqueNames == ["Jerry", "Long", "Dustin"] as Set) + + def idNames = map.collectEntries{key, value -> [key, value.name]} + assertTrue(idNames == [1:"Jerry", 2: "Long", 3:"Dustin", 4: "Dustin"]) + + def below30Names = map.findAll{it.value.age < 30}.collect{key, value -> value.name} + assertTrue(below30Names == ["Long", "Dustin"]) + + + } + + @Test + void group(){ + def map = [1:20, 2: 40, 3: 11, 4: 93] + + def subMap = map.groupBy{it.value % 2} + println subMap + assertTrue(subMap == [0:[1:20, 2:40 ], 1:[3:11, 4:93]]) + + def keySubMap = map.subMap([1, 2]) + assertTrue(keySubMap == [1:20, 2:40]) + + } + + @Test + void sorting(){ + def map = [ab:20, a: 40, cb: 11, ba: 93] + + def naturallyOrderedMap = map.sort() + assertTrue([a:40, ab:20, ba:93, cb:11] == naturallyOrderedMap) + + def compSortedMap = map.sort({ k1, k2 -> k1 <=> k2 } as Comparator) + assertTrue([a:40, ab:20, ba:93, cb:11] == compSortedMap) + + def cloSortedMap = map.sort({ it1, it2 -> it1.value <=> it1.value }) + assertTrue([cb:11, ab:20, a:40, ba:93] == cloSortedMap) + + } + +} diff --git a/core-java-8-2/src/test/java/com/baeldung/UnitTest.java b/core-java-8-2/src/test/java/com/baeldung/UnitTest.java deleted file mode 100644 index 9757901f52..0000000000 --- a/core-java-8-2/src/test/java/com/baeldung/UnitTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -/** - * Unit test for simple App. - */ -public class UnitTest { - /** - * Stub test - */ - @Test - public void givenPreconditions_whenCondition_shouldResult() { - assertTrue(true); - } -} diff --git a/core-java-collections-map/README.md b/core-java-collections-map/README.md deleted file mode 100644 index da02928118..0000000000 --- a/core-java-collections-map/README.md +++ /dev/null @@ -1,6 +0,0 @@ -========= - -## Core Java Collections 2 - -### Relevant Articles: -- Java - Copying a HashMap diff --git a/core-java-collections-map/pom.xml b/core-java-collections-map/pom.xml deleted file mode 100644 index 8c0aef54bf..0000000000 --- a/core-java-collections-map/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - 4.0.0 - core-java-collections-map - 0.1.0-SNAPSHOT - core-java-collections-map - jar - - - com.baeldung - parent-java - 0.0.1-SNAPSHOT - ../parent-java - - - - - org.apache.commons - commons-collections4 - ${commons-collections4.version} - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - org.eclipse.collections - eclipse-collections - ${eclipse.collections.version} - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.junit.platform - junit-platform-runner - ${junit.platform.version} - test - - - org.openjdk.jmh - jmh-core - ${openjdk.jmh.version} - - - org.openjdk.jmh - jmh-generator-annprocess - ${openjdk.jmh.version} - - - org.apache.commons - commons-exec - ${commons-exec.version} - - - org.projectlombok - lombok - ${lombok.version} - provided - - - - - 1.19 - 1.2.0 - 3.8.1 - 4.1 - 4.01 - 1.7.0 - 3.11.1 - 7.1.0 - 1.3 - - diff --git a/core-java-lang-oop-2/README.md b/core-java-lang-oop-2/README.md deleted file mode 100644 index e309810ba2..0000000000 --- a/core-java-lang-oop-2/README.md +++ /dev/null @@ -1,5 +0,0 @@ -========= - -## Core Java Lang OOP 2 Cookbooks and Examples - -### Relevant Articles: diff --git a/core-java-lang/native/nativedatetimeutils.dll b/core-java-lang/native/nativedatetimeutils.dll deleted file mode 100644 index ecdd388380..0000000000 Binary files a/core-java-lang/native/nativedatetimeutils.dll and /dev/null differ diff --git a/core-java-modules/README.md b/core-java-modules/README.md new file mode 100644 index 0000000000..a90535a44f --- /dev/null +++ b/core-java-modules/README.md @@ -0,0 +1,3 @@ +## Relevant articles: + +- [Multi-Module Maven Application with Java Modules](https://www.baeldung.com/maven-multi-module-project-java-jpms) diff --git a/core-java-10/README.md b/core-java-modules/core-java-10/README.md similarity index 100% rename from core-java-10/README.md rename to core-java-modules/core-java-10/README.md diff --git a/core-java-10/pom.xml b/core-java-modules/core-java-10/pom.xml similarity index 96% rename from core-java-10/pom.xml rename to core-java-modules/core-java-10/pom.xml index b15f8b5d63..7163619679 100644 --- a/core-java-10/pom.xml +++ b/core-java-modules/core-java-10/pom.xml @@ -12,6 +12,7 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT + ../../ diff --git a/core-java-10/src/main/java/com/baeldung/App.java b/core-java-modules/core-java-10/src/main/java/com/baeldung/App.java similarity index 100% rename from core-java-10/src/main/java/com/baeldung/App.java rename to core-java-modules/core-java-10/src/main/java/com/baeldung/App.java diff --git a/core-java-10/src/main/java/com/baeldung/graal/CountUppercase.java b/core-java-modules/core-java-10/src/main/java/com/baeldung/graal/CountUppercase.java similarity index 100% rename from core-java-10/src/main/java/com/baeldung/graal/CountUppercase.java rename to core-java-modules/core-java-10/src/main/java/com/baeldung/graal/CountUppercase.java diff --git a/core-java-11/src/main/resources/logback.xml b/core-java-modules/core-java-10/src/main/resources/logback.xml similarity index 100% rename from core-java-11/src/main/resources/logback.xml rename to core-java-modules/core-java-10/src/main/resources/logback.xml diff --git a/core-java-10/src/test/java/com/baeldung/AppTest.java b/core-java-modules/core-java-10/src/test/java/com/baeldung/AppTest.java similarity index 100% rename from core-java-10/src/test/java/com/baeldung/AppTest.java rename to core-java-modules/core-java-10/src/test/java/com/baeldung/AppTest.java diff --git a/core-java-10/src/test/java/com/baeldung/java10/Java10FeaturesUnitTest.java b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/Java10FeaturesUnitTest.java similarity index 100% rename from core-java-10/src/test/java/com/baeldung/java10/Java10FeaturesUnitTest.java rename to core-java-modules/core-java-10/src/test/java/com/baeldung/java10/Java10FeaturesUnitTest.java diff --git a/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java similarity index 100% rename from core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java rename to core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java diff --git a/core-java-11/README.md b/core-java-modules/core-java-11/README.md similarity index 100% rename from core-java-11/README.md rename to core-java-modules/core-java-11/README.md diff --git a/core-java-11/pom.xml b/core-java-modules/core-java-11/pom.xml similarity index 97% rename from core-java-11/pom.xml rename to core-java-modules/core-java-11/pom.xml index 933acdbecc..b78c141552 100644 --- a/core-java-11/pom.xml +++ b/core-java-modules/core-java-11/pom.xml @@ -12,6 +12,7 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT + ../../ diff --git a/core-java-11/src/main/java/com/baeldung/App.java b/core-java-modules/core-java-11/src/main/java/com/baeldung/App.java similarity index 100% rename from core-java-11/src/main/java/com/baeldung/App.java rename to core-java-modules/core-java-11/src/main/java/com/baeldung/App.java diff --git a/core-java-11/src/main/java/com/baeldung/Outer.java b/core-java-modules/core-java-11/src/main/java/com/baeldung/Outer.java similarity index 100% rename from core-java-11/src/main/java/com/baeldung/Outer.java rename to core-java-modules/core-java-11/src/main/java/com/baeldung/Outer.java diff --git a/core-java-11/src/main/java/com/baeldung/add b/core-java-modules/core-java-11/src/main/java/com/baeldung/add old mode 100755 new mode 100644 similarity index 100% rename from core-java-11/src/main/java/com/baeldung/add rename to core-java-modules/core-java-11/src/main/java/com/baeldung/add diff --git a/core-java-11/src/main/java/com/baeldung/epsilongc/MemoryPolluter.java b/core-java-modules/core-java-11/src/main/java/com/baeldung/epsilongc/MemoryPolluter.java similarity index 100% rename from core-java-11/src/main/java/com/baeldung/epsilongc/MemoryPolluter.java rename to core-java-modules/core-java-11/src/main/java/com/baeldung/epsilongc/MemoryPolluter.java diff --git a/core-java-11/src/main/java/com/baeldung/java11/httpclient/HttpClientExample.java b/core-java-modules/core-java-11/src/main/java/com/baeldung/java11/httpclient/HttpClientExample.java similarity index 97% rename from core-java-11/src/main/java/com/baeldung/java11/httpclient/HttpClientExample.java rename to core-java-modules/core-java-11/src/main/java/com/baeldung/java11/httpclient/HttpClientExample.java index fb4abd3bb6..725f969596 100644 --- a/core-java-11/src/main/java/com/baeldung/java11/httpclient/HttpClientExample.java +++ b/core-java-modules/core-java-11/src/main/java/com/baeldung/java11/httpclient/HttpClientExample.java @@ -1,132 +1,132 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package com.baeldung.java11.httpclient; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.http.HttpClient; -import java.net.http.HttpClient.Version; -import java.net.http.HttpRequest; -import java.net.http.HttpRequest.BodyPublishers; -import java.net.http.HttpResponse; -import java.net.http.HttpResponse.BodyHandlers; -import java.net.http.HttpResponse.PushPromiseHandler; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.function.Function; -import java.util.stream.Collectors; - -public class HttpClientExample { - - public static void main(String[] args) throws Exception { - httpGetRequest(); - httpPostRequest(); - asynchronousGetRequest(); - asynchronousMultipleRequests(); - pushRequest(); - } - - public static void httpGetRequest() throws URISyntaxException, IOException, InterruptedException { - HttpClient client = HttpClient.newHttpClient(); - HttpRequest request = HttpRequest.newBuilder() - .version(HttpClient.Version.HTTP_2) - .uri(URI.create("http://jsonplaceholder.typicode.com/posts/1")) - .headers("Accept-Enconding", "gzip, deflate") - .build(); - HttpResponse response = client.send(request, BodyHandlers.ofString()); - - String responseBody = response.body(); - int responseStatusCode = response.statusCode(); - - System.out.println("httpGetRequest: " + responseBody); - System.out.println("httpGetRequest status code: " + responseStatusCode); - } - - public static void httpPostRequest() throws URISyntaxException, IOException, InterruptedException { - HttpClient client = HttpClient.newBuilder() - .version(HttpClient.Version.HTTP_2) - .build(); - HttpRequest request = HttpRequest.newBuilder(new URI("http://jsonplaceholder.typicode.com/posts")) - .version(HttpClient.Version.HTTP_2) - .POST(BodyPublishers.ofString("Sample Post Request")) - .build(); - HttpResponse response = client.send(request, BodyHandlers.ofString()); - String responseBody = response.body(); - System.out.println("httpPostRequest : " + responseBody); - } - - public static void asynchronousGetRequest() throws URISyntaxException { - HttpClient client = HttpClient.newHttpClient(); - URI httpURI = new URI("http://jsonplaceholder.typicode.com/posts/1"); - HttpRequest request = HttpRequest.newBuilder(httpURI) - .version(HttpClient.Version.HTTP_2) - .build(); - CompletableFuture futureResponse = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()) - .thenAccept(resp -> { - System.out.println("Got pushed response " + resp.uri()); - System.out.println("Response statuscode: " + resp.statusCode()); - System.out.println("Response body: " + resp.body()); - }); - System.out.println("futureResponse" + futureResponse); - - } - - public static void asynchronousMultipleRequests() throws URISyntaxException { - HttpClient client = HttpClient.newHttpClient(); - List uris = Arrays.asList(new URI("http://jsonplaceholder.typicode.com/posts/1"), new URI("http://jsonplaceholder.typicode.com/posts/2")); - List requests = uris.stream() - .map(HttpRequest::newBuilder) - .map(reqBuilder -> reqBuilder.build()) - .collect(Collectors.toList()); - System.out.println("Got pushed response1 " + requests); - CompletableFuture.allOf(requests.stream() - .map(request -> client.sendAsync(request, BodyHandlers.ofString())) - .toArray(CompletableFuture[]::new)) - .thenAccept(System.out::println) - .join(); - } - - public static void pushRequest() throws URISyntaxException, InterruptedException { - System.out.println("Running HTTP/2 Server Push example..."); - - HttpClient httpClient = HttpClient.newBuilder() - .version(Version.HTTP_2) - .build(); - - HttpRequest pageRequest = HttpRequest.newBuilder() - .uri(URI.create("https://http2.golang.org/serverpush")) - .build(); - - // Interface HttpResponse.PushPromiseHandler - // void applyPushPromise​(HttpRequest initiatingRequest, HttpRequest pushPromiseRequest, Function,​CompletableFuture>> acceptor) - httpClient.sendAsync(pageRequest, BodyHandlers.ofString(), pushPromiseHandler()) - .thenAccept(pageResponse -> { - System.out.println("Page response status code: " + pageResponse.statusCode()); - System.out.println("Page response headers: " + pageResponse.headers()); - String responseBody = pageResponse.body(); - System.out.println(responseBody); - }).join(); - - Thread.sleep(1000); // waiting for full response - } - - private static PushPromiseHandler pushPromiseHandler() { - return (HttpRequest initiatingRequest, - HttpRequest pushPromiseRequest, - Function, - CompletableFuture>> acceptor) -> { - acceptor.apply(BodyHandlers.ofString()) - .thenAccept(resp -> { - System.out.println(" Pushed response: " + resp.uri() + ", headers: " + resp.headers()); - }); - System.out.println("Promise request: " + pushPromiseRequest.uri()); - System.out.println("Promise request: " + pushPromiseRequest.headers()); - }; - } - -} +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.java11.httpclient; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.http.HttpClient; +import java.net.http.HttpClient.Version; +import java.net.http.HttpRequest; +import java.net.http.HttpRequest.BodyPublishers; +import java.net.http.HttpResponse; +import java.net.http.HttpResponse.BodyHandlers; +import java.net.http.HttpResponse.PushPromiseHandler; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class HttpClientExample { + + public static void main(String[] args) throws Exception { + httpGetRequest(); + httpPostRequest(); + asynchronousGetRequest(); + asynchronousMultipleRequests(); + pushRequest(); + } + + public static void httpGetRequest() throws URISyntaxException, IOException, InterruptedException { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .version(HttpClient.Version.HTTP_2) + .uri(URI.create("http://jsonplaceholder.typicode.com/posts/1")) + .headers("Accept-Enconding", "gzip, deflate") + .build(); + HttpResponse response = client.send(request, BodyHandlers.ofString()); + + String responseBody = response.body(); + int responseStatusCode = response.statusCode(); + + System.out.println("httpGetRequest: " + responseBody); + System.out.println("httpGetRequest status code: " + responseStatusCode); + } + + public static void httpPostRequest() throws URISyntaxException, IOException, InterruptedException { + HttpClient client = HttpClient.newBuilder() + .version(HttpClient.Version.HTTP_2) + .build(); + HttpRequest request = HttpRequest.newBuilder(new URI("http://jsonplaceholder.typicode.com/posts")) + .version(HttpClient.Version.HTTP_2) + .POST(BodyPublishers.ofString("Sample Post Request")) + .build(); + HttpResponse response = client.send(request, BodyHandlers.ofString()); + String responseBody = response.body(); + System.out.println("httpPostRequest : " + responseBody); + } + + public static void asynchronousGetRequest() throws URISyntaxException { + HttpClient client = HttpClient.newHttpClient(); + URI httpURI = new URI("http://jsonplaceholder.typicode.com/posts/1"); + HttpRequest request = HttpRequest.newBuilder(httpURI) + .version(HttpClient.Version.HTTP_2) + .build(); + CompletableFuture futureResponse = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()) + .thenAccept(resp -> { + System.out.println("Got pushed response " + resp.uri()); + System.out.println("Response statuscode: " + resp.statusCode()); + System.out.println("Response body: " + resp.body()); + }); + System.out.println("futureResponse" + futureResponse); + + } + + public static void asynchronousMultipleRequests() throws URISyntaxException { + HttpClient client = HttpClient.newHttpClient(); + List uris = Arrays.asList(new URI("http://jsonplaceholder.typicode.com/posts/1"), new URI("http://jsonplaceholder.typicode.com/posts/2")); + List requests = uris.stream() + .map(HttpRequest::newBuilder) + .map(reqBuilder -> reqBuilder.build()) + .collect(Collectors.toList()); + System.out.println("Got pushed response1 " + requests); + CompletableFuture.allOf(requests.stream() + .map(request -> client.sendAsync(request, BodyHandlers.ofString())) + .toArray(CompletableFuture[]::new)) + .thenAccept(System.out::println) + .join(); + } + + public static void pushRequest() throws URISyntaxException, InterruptedException { + System.out.println("Running HTTP/2 Server Push example..."); + + HttpClient httpClient = HttpClient.newBuilder() + .version(Version.HTTP_2) + .build(); + + HttpRequest pageRequest = HttpRequest.newBuilder() + .uri(URI.create("https://http2.golang.org/serverpush")) + .build(); + + // Interface HttpResponse.PushPromiseHandler + // void applyPushPromise​(HttpRequest initiatingRequest, HttpRequest pushPromiseRequest, Function,​CompletableFuture>> acceptor) + httpClient.sendAsync(pageRequest, BodyHandlers.ofString(), pushPromiseHandler()) + .thenAccept(pageResponse -> { + System.out.println("Page response status code: " + pageResponse.statusCode()); + System.out.println("Page response headers: " + pageResponse.headers()); + String responseBody = pageResponse.body(); + System.out.println(responseBody); + }).join(); + + Thread.sleep(1000); // waiting for full response + } + + private static PushPromiseHandler pushPromiseHandler() { + return (HttpRequest initiatingRequest, + HttpRequest pushPromiseRequest, + Function, + CompletableFuture>> acceptor) -> { + acceptor.apply(BodyHandlers.ofString()) + .thenAccept(resp -> { + System.out.println(" Pushed response: " + resp.uri() + ", headers: " + resp.headers()); + }); + System.out.println("Promise request: " + pushPromiseRequest.uri()); + System.out.println("Promise request: " + pushPromiseRequest.headers()); + }; + } + +} diff --git a/core-java-8/src/main/resources/logback.xml b/core-java-modules/core-java-11/src/main/resources/logback.xml similarity index 100% rename from core-java-8/src/main/resources/logback.xml rename to core-java-modules/core-java-11/src/main/resources/logback.xml diff --git a/core-java-11/src/modules/jlinkModule/com/baeldung/jlink/HelloWorld.java b/core-java-modules/core-java-11/src/modules/jlinkModule/com/baeldung/jlink/HelloWorld.java similarity index 100% rename from core-java-11/src/modules/jlinkModule/com/baeldung/jlink/HelloWorld.java rename to core-java-modules/core-java-11/src/modules/jlinkModule/com/baeldung/jlink/HelloWorld.java diff --git a/core-java-11/src/modules/jlinkModule/module-info.java b/core-java-modules/core-java-11/src/modules/jlinkModule/module-info.java similarity index 100% rename from core-java-11/src/modules/jlinkModule/module-info.java rename to core-java-modules/core-java-11/src/modules/jlinkModule/module-info.java diff --git a/core-java-11/src/test/java/com/baeldung/AppTest.java b/core-java-modules/core-java-11/src/test/java/com/baeldung/AppTest.java similarity index 100% rename from core-java-11/src/test/java/com/baeldung/AppTest.java rename to core-java-modules/core-java-11/src/test/java/com/baeldung/AppTest.java diff --git a/core-java-11/src/test/java/com/baeldung/EmptyStringToEmptyOptionalUnitTest.java b/core-java-modules/core-java-11/src/test/java/com/baeldung/EmptyStringToEmptyOptionalUnitTest.java similarity index 100% rename from core-java-11/src/test/java/com/baeldung/EmptyStringToEmptyOptionalUnitTest.java rename to core-java-modules/core-java-11/src/test/java/com/baeldung/EmptyStringToEmptyOptionalUnitTest.java diff --git a/core-java-11/src/test/java/com/baeldung/NewStringAPIUnitTest.java b/core-java-modules/core-java-11/src/test/java/com/baeldung/NewStringAPIUnitTest.java similarity index 100% rename from core-java-11/src/test/java/com/baeldung/NewStringAPIUnitTest.java rename to core-java-modules/core-java-11/src/test/java/com/baeldung/NewStringAPIUnitTest.java diff --git a/core-java-11/src/test/java/com/baeldung/OuterUnitTest.java b/core-java-modules/core-java-11/src/test/java/com/baeldung/OuterUnitTest.java similarity index 100% rename from core-java-11/src/test/java/com/baeldung/OuterUnitTest.java rename to core-java-modules/core-java-11/src/test/java/com/baeldung/OuterUnitTest.java diff --git a/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientTest.java b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientTest.java similarity index 97% rename from core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientTest.java rename to core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientTest.java index bade666636..0e9c12675c 100644 --- a/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientTest.java +++ b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientTest.java @@ -1,240 +1,240 @@ -package com.baeldung.java11.httpclient.test; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.net.Authenticator; -import java.net.CookieManager; -import java.net.CookiePolicy; -import java.net.HttpURLConnection; -import java.net.PasswordAuthentication; -import java.net.ProxySelector; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; -import java.net.http.HttpResponse.BodyHandlers; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -import org.junit.jupiter.api.Test; - -public class HttpClientTest { - - @Test - public void shouldReturnSampleDataContentWhenConnectViaSystemProxy() throws IOException, InterruptedException, URISyntaxException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/post")) - .headers("Content-Type", "text/plain;charset=UTF-8") - .POST(HttpRequest.BodyPublishers.ofString("Sample body")) - .build(); - - - HttpResponse response = HttpClient.newBuilder() - .proxy(ProxySelector.getDefault()) - .build() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - assertThat(response.body(), containsString("Sample body")); - } - - @Test - public void shouldNotFollowRedirectWhenSetToDefaultNever() throws IOException, InterruptedException, URISyntaxException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("http://stackoverflow.com")) - .version(HttpClient.Version.HTTP_1_1) - .GET() - .build(); - HttpResponse response = HttpClient.newBuilder() - .build() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_MOVED_PERM)); - assertThat(response.body(), containsString("https://stackoverflow.com/")); - } - - @Test - public void shouldFollowRedirectWhenSetToAlways() throws IOException, InterruptedException, URISyntaxException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("http://stackoverflow.com")) - .version(HttpClient.Version.HTTP_1_1) - .GET() - .build(); - HttpResponse response = HttpClient.newBuilder() - .followRedirects(HttpClient.Redirect.ALWAYS) - .build() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - assertThat(response.request() - .uri() - .toString(), equalTo("https://stackoverflow.com/")); - } - - @Test - public void shouldReturnOKStatusForAuthenticatedAccess() throws URISyntaxException, IOException, InterruptedException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/basic-auth")) - .GET() - .build(); - HttpResponse response = HttpClient.newBuilder() - .authenticator(new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication("postman", "password".toCharArray()); - } - }) - .build() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - } - - @Test - public void shouldSendRequestAsync() throws URISyntaxException, InterruptedException, ExecutionException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/post")) - .headers("Content-Type", "text/plain;charset=UTF-8") - .POST(HttpRequest.BodyPublishers.ofString("Sample body")) - .build(); - CompletableFuture> response = HttpClient.newBuilder() - .build() - .sendAsync(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.get() - .statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - } - - @Test - public void shouldUseJustTwoThreadWhenProcessingSendAsyncRequest() throws URISyntaxException, InterruptedException, ExecutionException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/get")) - .GET() - .build(); - - ExecutorService executorService = Executors.newFixedThreadPool(2); - - CompletableFuture> response1 = HttpClient.newBuilder() - .executor(executorService) - .build() - .sendAsync(request, HttpResponse.BodyHandlers.ofString()); - - CompletableFuture> response2 = HttpClient.newBuilder() - .executor(executorService) - .build() - .sendAsync(request, HttpResponse.BodyHandlers.ofString()); - - CompletableFuture> response3 = HttpClient.newBuilder() - .executor(executorService) - .build() - .sendAsync(request, HttpResponse.BodyHandlers.ofString()); - - CompletableFuture.allOf(response1, response2, response3) - .join(); - - assertThat(response1.get() - .statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - assertThat(response2.get() - .statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - assertThat(response3.get() - .statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - } - - @Test - public void shouldNotStoreCookieWhenPolicyAcceptNone() throws URISyntaxException, IOException, InterruptedException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/get")) - .GET() - .build(); - - HttpClient httpClient = HttpClient.newBuilder() - .cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_NONE)) - .build(); - - httpClient.send(request, HttpResponse.BodyHandlers.ofString()); - - assertTrue(httpClient.cookieHandler() - .isPresent()); - } - - @Test - public void shouldStoreCookieWhenPolicyAcceptAll() throws URISyntaxException, IOException, InterruptedException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/get")) - .GET() - .build(); - - HttpClient httpClient = HttpClient.newBuilder() - .cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ALL)) - .build(); - - httpClient.send(request, HttpResponse.BodyHandlers.ofString()); - - assertTrue(httpClient.cookieHandler() - .isPresent()); - } - - @Test - public void shouldProcessMultipleRequestViaStream() throws URISyntaxException, ExecutionException, InterruptedException { - List targets = Arrays.asList(new URI("https://postman-echo.com/get?foo1=bar1"), new URI("https://postman-echo.com/get?foo2=bar2")); - - HttpClient client = HttpClient.newHttpClient(); - - List> futures = targets.stream() - .map(target -> client.sendAsync(HttpRequest.newBuilder(target) - .GET() - .build(), HttpResponse.BodyHandlers.ofString()) - .thenApply(response -> response.body())) - .collect(Collectors.toList()); - - CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) - .join(); - - if (futures.get(0) - .get() - .contains("foo1")) { - assertThat(futures.get(0) - .get(), containsString("bar1")); - assertThat(futures.get(1) - .get(), containsString("bar2")); - } else { - assertThat(futures.get(1) - .get(), containsString("bar2")); - assertThat(futures.get(1) - .get(), containsString("bar1")); - } - - } - - @Test - public void completeExceptionallyExample() { - CompletableFuture cf = CompletableFuture.completedFuture("message").thenApplyAsync(String::toUpperCase, - CompletableFuture.delayedExecutor(1, TimeUnit.SECONDS)); - CompletableFuture exceptionHandler = cf.handle((s, th) -> { return (th != null) ? "message upon cancel" : ""; }); - cf.completeExceptionally(new RuntimeException("completed exceptionally")); - assertTrue("Was not completed exceptionally", cf.isCompletedExceptionally()); - try { - cf.join(); - fail("Should have thrown an exception"); - } catch (CompletionException ex) { // just for testing - assertEquals("completed exceptionally", ex.getCause().getMessage()); - } - - assertEquals("message upon cancel", exceptionHandler.join()); - } - -} +package com.baeldung.java11.httpclient.test; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.net.Authenticator; +import java.net.CookieManager; +import java.net.CookiePolicy; +import java.net.HttpURLConnection; +import java.net.PasswordAuthentication; +import java.net.ProxySelector; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.net.http.HttpResponse.BodyHandlers; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.Test; + +public class HttpClientTest { + + @Test + public void shouldReturnSampleDataContentWhenConnectViaSystemProxy() throws IOException, InterruptedException, URISyntaxException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/post")) + .headers("Content-Type", "text/plain;charset=UTF-8") + .POST(HttpRequest.BodyPublishers.ofString("Sample body")) + .build(); + + + HttpResponse response = HttpClient.newBuilder() + .proxy(ProxySelector.getDefault()) + .build() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + assertThat(response.body(), containsString("Sample body")); + } + + @Test + public void shouldNotFollowRedirectWhenSetToDefaultNever() throws IOException, InterruptedException, URISyntaxException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("http://stackoverflow.com")) + .version(HttpClient.Version.HTTP_1_1) + .GET() + .build(); + HttpResponse response = HttpClient.newBuilder() + .build() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_MOVED_PERM)); + assertThat(response.body(), containsString("https://stackoverflow.com/")); + } + + @Test + public void shouldFollowRedirectWhenSetToAlways() throws IOException, InterruptedException, URISyntaxException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("http://stackoverflow.com")) + .version(HttpClient.Version.HTTP_1_1) + .GET() + .build(); + HttpResponse response = HttpClient.newBuilder() + .followRedirects(HttpClient.Redirect.ALWAYS) + .build() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + assertThat(response.request() + .uri() + .toString(), equalTo("https://stackoverflow.com/")); + } + + @Test + public void shouldReturnOKStatusForAuthenticatedAccess() throws URISyntaxException, IOException, InterruptedException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/basic-auth")) + .GET() + .build(); + HttpResponse response = HttpClient.newBuilder() + .authenticator(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication("postman", "password".toCharArray()); + } + }) + .build() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + } + + @Test + public void shouldSendRequestAsync() throws URISyntaxException, InterruptedException, ExecutionException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/post")) + .headers("Content-Type", "text/plain;charset=UTF-8") + .POST(HttpRequest.BodyPublishers.ofString("Sample body")) + .build(); + CompletableFuture> response = HttpClient.newBuilder() + .build() + .sendAsync(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.get() + .statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + } + + @Test + public void shouldUseJustTwoThreadWhenProcessingSendAsyncRequest() throws URISyntaxException, InterruptedException, ExecutionException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/get")) + .GET() + .build(); + + ExecutorService executorService = Executors.newFixedThreadPool(2); + + CompletableFuture> response1 = HttpClient.newBuilder() + .executor(executorService) + .build() + .sendAsync(request, HttpResponse.BodyHandlers.ofString()); + + CompletableFuture> response2 = HttpClient.newBuilder() + .executor(executorService) + .build() + .sendAsync(request, HttpResponse.BodyHandlers.ofString()); + + CompletableFuture> response3 = HttpClient.newBuilder() + .executor(executorService) + .build() + .sendAsync(request, HttpResponse.BodyHandlers.ofString()); + + CompletableFuture.allOf(response1, response2, response3) + .join(); + + assertThat(response1.get() + .statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + assertThat(response2.get() + .statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + assertThat(response3.get() + .statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + } + + @Test + public void shouldNotStoreCookieWhenPolicyAcceptNone() throws URISyntaxException, IOException, InterruptedException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/get")) + .GET() + .build(); + + HttpClient httpClient = HttpClient.newBuilder() + .cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_NONE)) + .build(); + + httpClient.send(request, HttpResponse.BodyHandlers.ofString()); + + assertTrue(httpClient.cookieHandler() + .isPresent()); + } + + @Test + public void shouldStoreCookieWhenPolicyAcceptAll() throws URISyntaxException, IOException, InterruptedException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/get")) + .GET() + .build(); + + HttpClient httpClient = HttpClient.newBuilder() + .cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ALL)) + .build(); + + httpClient.send(request, HttpResponse.BodyHandlers.ofString()); + + assertTrue(httpClient.cookieHandler() + .isPresent()); + } + + @Test + public void shouldProcessMultipleRequestViaStream() throws URISyntaxException, ExecutionException, InterruptedException { + List targets = Arrays.asList(new URI("https://postman-echo.com/get?foo1=bar1"), new URI("https://postman-echo.com/get?foo2=bar2")); + + HttpClient client = HttpClient.newHttpClient(); + + List> futures = targets.stream() + .map(target -> client.sendAsync(HttpRequest.newBuilder(target) + .GET() + .build(), HttpResponse.BodyHandlers.ofString()) + .thenApply(response -> response.body())) + .collect(Collectors.toList()); + + CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) + .join(); + + if (futures.get(0) + .get() + .contains("foo1")) { + assertThat(futures.get(0) + .get(), containsString("bar1")); + assertThat(futures.get(1) + .get(), containsString("bar2")); + } else { + assertThat(futures.get(1) + .get(), containsString("bar2")); + assertThat(futures.get(1) + .get(), containsString("bar1")); + } + + } + + @Test + public void completeExceptionallyExample() { + CompletableFuture cf = CompletableFuture.completedFuture("message").thenApplyAsync(String::toUpperCase, + CompletableFuture.delayedExecutor(1, TimeUnit.SECONDS)); + CompletableFuture exceptionHandler = cf.handle((s, th) -> { return (th != null) ? "message upon cancel" : ""; }); + cf.completeExceptionally(new RuntimeException("completed exceptionally")); + assertTrue("Was not completed exceptionally", cf.isCompletedExceptionally()); + try { + cf.join(); + fail("Should have thrown an exception"); + } catch (CompletionException ex) { // just for testing + assertEquals("completed exceptionally", ex.getCause().getMessage()); + } + + assertEquals("message upon cancel", exceptionHandler.join()); + } + +} diff --git a/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestTest.java b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestTest.java similarity index 97% rename from core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestTest.java rename to core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestTest.java index 7d138bd8d5..274d3a93fc 100644 --- a/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestTest.java +++ b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestTest.java @@ -1,168 +1,168 @@ -package com.baeldung.java11.httpclient.test; - -import static java.time.temporal.ChronoUnit.SECONDS; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; -import java.nio.file.Paths; -import java.security.NoSuchAlgorithmException; -import java.time.Duration; - -import org.junit.Test; - -public class HttpRequestTest { - - @Test - public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/get")) - .GET() - .build(); - - HttpResponse response = HttpClient.newHttpClient() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - } - - @Test - public void shouldUseHttp2WhenWebsiteUsesHttp2() throws IOException, InterruptedException, URISyntaxException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://stackoverflow.com")) - .version(HttpClient.Version.HTTP_2) - .GET() - .build(); - HttpResponse response = HttpClient.newHttpClient() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - assertThat(response.version(), equalTo(HttpClient.Version.HTTP_2)); - } - - @Test - public void shouldFallbackToHttp1_1WhenWebsiteDoesNotUseHttp2() throws IOException, InterruptedException, URISyntaxException, NoSuchAlgorithmException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/get")) - .version(HttpClient.Version.HTTP_2) - .GET() - .build(); - - HttpResponse response = HttpClient.newHttpClient() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.version(), equalTo(HttpClient.Version.HTTP_1_1)); - } - - @Test - public void shouldReturnStatusOKWhenSendGetRequestWithDummyHeaders() throws IOException, InterruptedException, URISyntaxException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/get")) - .headers("key1", "value1", "key2", "value2") - .GET() - .build(); - - HttpResponse response = HttpClient.newHttpClient() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - } - - @Test - public void shouldReturnStatusOKWhenSendGetRequestTimeoutSet() throws IOException, InterruptedException, URISyntaxException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/get")) - .timeout(Duration.of(10, SECONDS)) - .GET() - .build(); - - HttpResponse response = HttpClient.newHttpClient() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - } - - @Test - public void shouldReturnNoContentWhenPostWithNoBody() throws IOException, InterruptedException, URISyntaxException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/post")) - .POST(HttpRequest.BodyPublishers.noBody()) - .build(); - - HttpResponse response = HttpClient.newHttpClient() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - } - - @Test - public void shouldReturnSampleDataContentWhenPostWithBodyText() throws IOException, InterruptedException, URISyntaxException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/post")) - .headers("Content-Type", "text/plain;charset=UTF-8") - .POST(HttpRequest.BodyPublishers.ofString("Sample request body")) - .build(); - - HttpResponse response = HttpClient.newHttpClient() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - assertThat(response.body(), containsString("Sample request body")); - } - - @Test - public void shouldReturnSampleDataContentWhenPostWithInputStream() throws IOException, InterruptedException, URISyntaxException { - byte[] sampleData = "Sample request body".getBytes(); - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/post")) - .headers("Content-Type", "text/plain;charset=UTF-8") - .POST(HttpRequest.BodyPublishers.ofInputStream(() -> new ByteArrayInputStream(sampleData))) - .build(); - - HttpResponse response = HttpClient.newHttpClient() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - assertThat(response.body(), containsString("Sample request body")); - } - - @Test - public void shouldReturnSampleDataContentWhenPostWithByteArrayProcessorStream() throws IOException, InterruptedException, URISyntaxException { - byte[] sampleData = "Sample request body".getBytes(); - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/post")) - .headers("Content-Type", "text/plain;charset=UTF-8") - .POST(HttpRequest.BodyPublishers.ofByteArray(sampleData)) - .build(); - - HttpResponse response = HttpClient.newHttpClient() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - assertThat(response.body(), containsString("Sample request body")); - } - - @Test - public void shouldReturnSampleDataContentWhenPostWithFileProcessorStream() throws IOException, InterruptedException, URISyntaxException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/post")) - .headers("Content-Type", "text/plain;charset=UTF-8") - .POST(HttpRequest.BodyPublishers.ofFile(Paths.get("src/test/resources/sample.txt"))) - .build(); - - HttpResponse response = HttpClient.newHttpClient() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - assertThat(response.body(), containsString("Sample file content")); - } - -} +package com.baeldung.java11.httpclient.test; + +import static java.time.temporal.ChronoUnit.SECONDS; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.nio.file.Paths; +import java.security.NoSuchAlgorithmException; +import java.time.Duration; + +import org.junit.Test; + +public class HttpRequestTest { + + @Test + public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/get")) + .GET() + .build(); + + HttpResponse response = HttpClient.newHttpClient() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + } + + @Test + public void shouldUseHttp2WhenWebsiteUsesHttp2() throws IOException, InterruptedException, URISyntaxException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://stackoverflow.com")) + .version(HttpClient.Version.HTTP_2) + .GET() + .build(); + HttpResponse response = HttpClient.newHttpClient() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + assertThat(response.version(), equalTo(HttpClient.Version.HTTP_2)); + } + + @Test + public void shouldFallbackToHttp1_1WhenWebsiteDoesNotUseHttp2() throws IOException, InterruptedException, URISyntaxException, NoSuchAlgorithmException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/get")) + .version(HttpClient.Version.HTTP_2) + .GET() + .build(); + + HttpResponse response = HttpClient.newHttpClient() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.version(), equalTo(HttpClient.Version.HTTP_1_1)); + } + + @Test + public void shouldReturnStatusOKWhenSendGetRequestWithDummyHeaders() throws IOException, InterruptedException, URISyntaxException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/get")) + .headers("key1", "value1", "key2", "value2") + .GET() + .build(); + + HttpResponse response = HttpClient.newHttpClient() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + } + + @Test + public void shouldReturnStatusOKWhenSendGetRequestTimeoutSet() throws IOException, InterruptedException, URISyntaxException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/get")) + .timeout(Duration.of(10, SECONDS)) + .GET() + .build(); + + HttpResponse response = HttpClient.newHttpClient() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + } + + @Test + public void shouldReturnNoContentWhenPostWithNoBody() throws IOException, InterruptedException, URISyntaxException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/post")) + .POST(HttpRequest.BodyPublishers.noBody()) + .build(); + + HttpResponse response = HttpClient.newHttpClient() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + } + + @Test + public void shouldReturnSampleDataContentWhenPostWithBodyText() throws IOException, InterruptedException, URISyntaxException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/post")) + .headers("Content-Type", "text/plain;charset=UTF-8") + .POST(HttpRequest.BodyPublishers.ofString("Sample request body")) + .build(); + + HttpResponse response = HttpClient.newHttpClient() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + assertThat(response.body(), containsString("Sample request body")); + } + + @Test + public void shouldReturnSampleDataContentWhenPostWithInputStream() throws IOException, InterruptedException, URISyntaxException { + byte[] sampleData = "Sample request body".getBytes(); + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/post")) + .headers("Content-Type", "text/plain;charset=UTF-8") + .POST(HttpRequest.BodyPublishers.ofInputStream(() -> new ByteArrayInputStream(sampleData))) + .build(); + + HttpResponse response = HttpClient.newHttpClient() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + assertThat(response.body(), containsString("Sample request body")); + } + + @Test + public void shouldReturnSampleDataContentWhenPostWithByteArrayProcessorStream() throws IOException, InterruptedException, URISyntaxException { + byte[] sampleData = "Sample request body".getBytes(); + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/post")) + .headers("Content-Type", "text/plain;charset=UTF-8") + .POST(HttpRequest.BodyPublishers.ofByteArray(sampleData)) + .build(); + + HttpResponse response = HttpClient.newHttpClient() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + assertThat(response.body(), containsString("Sample request body")); + } + + @Test + public void shouldReturnSampleDataContentWhenPostWithFileProcessorStream() throws IOException, InterruptedException, URISyntaxException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/post")) + .headers("Content-Type", "text/plain;charset=UTF-8") + .POST(HttpRequest.BodyPublishers.ofFile(Paths.get("src/test/resources/sample.txt"))) + .build(); + + HttpResponse response = HttpClient.newHttpClient() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + assertThat(response.body(), containsString("Sample file content")); + } + +} diff --git a/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpResponseTest.java b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpResponseTest.java similarity index 97% rename from core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpResponseTest.java rename to core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpResponseTest.java index 78d86fbf4e..abbc0233c1 100644 --- a/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpResponseTest.java +++ b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpResponseTest.java @@ -1,54 +1,54 @@ -package com.baeldung.java11.httpclient.test; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; - -import org.junit.Test; - -public class HttpResponseTest { - - @Test - public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("https://postman-echo.com/get")) - .version(HttpClient.Version.HTTP_2) - .GET() - .build(); - - HttpResponse response = HttpClient.newBuilder() - .followRedirects(HttpClient.Redirect.NORMAL) - .build() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); - assertNotNull(response.body()); - } - - @Test - public void shouldResponseURIDifferentThanRequestUIRWhenRedirect() throws IOException, InterruptedException, URISyntaxException { - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI("http://stackoverflow.com")) - .version(HttpClient.Version.HTTP_2) - .GET() - .build(); - HttpResponse response = HttpClient.newBuilder() - .followRedirects(HttpClient.Redirect.NORMAL) - .build() - .send(request, HttpResponse.BodyHandlers.ofString()); - - assertThat(request.uri() - .toString(), equalTo("http://stackoverflow.com")); - assertThat(response.uri() - .toString(), equalTo("https://stackoverflow.com/")); - } - -} +package com.baeldung.java11.httpclient.test; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; + +import org.junit.Test; + +public class HttpResponseTest { + + @Test + public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("https://postman-echo.com/get")) + .version(HttpClient.Version.HTTP_2) + .GET() + .build(); + + HttpResponse response = HttpClient.newBuilder() + .followRedirects(HttpClient.Redirect.NORMAL) + .build() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_OK)); + assertNotNull(response.body()); + } + + @Test + public void shouldResponseURIDifferentThanRequestUIRWhenRedirect() throws IOException, InterruptedException, URISyntaxException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI("http://stackoverflow.com")) + .version(HttpClient.Version.HTTP_2) + .GET() + .build(); + HttpResponse response = HttpClient.newBuilder() + .followRedirects(HttpClient.Redirect.NORMAL) + .build() + .send(request, HttpResponse.BodyHandlers.ofString()); + + assertThat(request.uri() + .toString(), equalTo("http://stackoverflow.com")); + assertThat(response.uri() + .toString(), equalTo("https://stackoverflow.com/")); + } + +} diff --git a/core-java-11/src/test/java/com/baeldung/optional/OptionalUnitTest.java b/core-java-modules/core-java-11/src/test/java/com/baeldung/optional/OptionalUnitTest.java similarity index 100% rename from core-java-11/src/test/java/com/baeldung/optional/OptionalUnitTest.java rename to core-java-modules/core-java-11/src/test/java/com/baeldung/optional/OptionalUnitTest.java diff --git a/core-java-12/pom.xml b/core-java-modules/core-java-12/pom.xml similarity index 97% rename from core-java-12/pom.xml rename to core-java-modules/core-java-12/pom.xml index c5eec1a4bb..06c49a0021 100644 --- a/core-java-12/pom.xml +++ b/core-java-modules/core-java-12/pom.xml @@ -14,6 +14,7 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT + ../../ diff --git a/core-java-12/src/test/java/com/baeldung/collectors/CollectorsUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/collectors/CollectorsUnitTest.java similarity index 100% rename from core-java-12/src/test/java/com/baeldung/collectors/CollectorsUnitTest.java rename to core-java-modules/core-java-12/src/test/java/com/baeldung/collectors/CollectorsUnitTest.java diff --git a/core-java-12/src/test/java/com/baeldung/switchExpression/SwitchUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/switchExpression/SwitchUnitTest.java similarity index 100% rename from core-java-12/src/test/java/com/baeldung/switchExpression/SwitchUnitTest.java rename to core-java-modules/core-java-12/src/test/java/com/baeldung/switchExpression/SwitchUnitTest.java diff --git a/core-java-arrays/.gitignore b/core-java-modules/core-java-8-2/.gitignore similarity index 100% rename from core-java-arrays/.gitignore rename to core-java-modules/core-java-8-2/.gitignore diff --git a/core-java-8-2/README.md b/core-java-modules/core-java-8-2/README.md similarity index 100% rename from core-java-8-2/README.md rename to core-java-modules/core-java-8-2/README.md diff --git a/core-java-8-2/pom.xml b/core-java-modules/core-java-8-2/pom.xml similarity index 83% rename from core-java-8-2/pom.xml rename to core-java-modules/core-java-8-2/pom.xml index 7035f12fb7..fbaf795b95 100644 --- a/core-java-8-2/pom.xml +++ b/core-java-modules/core-java-8-2/pom.xml @@ -14,16 +14,23 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java UTF-8 1.8 1.8 + 64.2 + + com.ibm.icu + icu4j + ${icu.version} + + diff --git a/core-java-modules/core-java-8-2/src/main/java/com/baeldung/jarArguments/JarExample.java b/core-java-modules/core-java-8-2/src/main/java/com/baeldung/jarArguments/JarExample.java new file mode 100644 index 0000000000..c2fb809790 --- /dev/null +++ b/core-java-modules/core-java-8-2/src/main/java/com/baeldung/jarArguments/JarExample.java @@ -0,0 +1,18 @@ +package com.baeldung.jarArguments; + +public class JarExample { + + public static void main(String[] args) { + System.out.println("Hello Baeldung Reader in JarExample!"); + + if(args == null) { + System.out.println("You have not provided any arguments!"); + }else { + System.out.println("There are "+args.length+" argument(s)!"); + for(int i=0; i locales = Arrays.asList(new Locale[] { Locale.UK, Locale.ITALY, Locale.FRANCE, Locale.forLanguageTag("pl-PL") }); + Localization.run(locales); + JavaSEFormat.run(locales); + ICUFormat.run(locales); + } + +} diff --git a/core-java-modules/core-java-8-2/src/main/java/com/baeldung/localization/ICUFormat.java b/core-java-modules/core-java-8-2/src/main/java/com/baeldung/localization/ICUFormat.java new file mode 100644 index 0000000000..f7bc357933 --- /dev/null +++ b/core-java-modules/core-java-8-2/src/main/java/com/baeldung/localization/ICUFormat.java @@ -0,0 +1,29 @@ +package com.baeldung.localization; + +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; + +import com.ibm.icu.text.MessageFormat; + +public class ICUFormat { + + public static String getLabel(Locale locale, Object[] data) { + ResourceBundle bundle = ResourceBundle.getBundle("formats", locale); + String format = bundle.getString("label-icu"); + MessageFormat formatter = new MessageFormat(format, locale); + return formatter.format(data); + } + + public static void run(List locales) { + System.out.println("ICU formatter"); + locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 0 }))); + locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 1 }))); + locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 2 }))); + locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 3 }))); + locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 0 }))); + locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 1 }))); + locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 2 }))); + locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 3 }))); + } +} diff --git a/core-java-modules/core-java-8-2/src/main/java/com/baeldung/localization/JavaSEFormat.java b/core-java-modules/core-java-8-2/src/main/java/com/baeldung/localization/JavaSEFormat.java new file mode 100644 index 0000000000..c95dfffa13 --- /dev/null +++ b/core-java-modules/core-java-8-2/src/main/java/com/baeldung/localization/JavaSEFormat.java @@ -0,0 +1,24 @@ +package com.baeldung.localization; + +import java.text.MessageFormat; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; + +public class JavaSEFormat { + + public static String getLabel(Locale locale, Object[] data) { + ResourceBundle bundle = ResourceBundle.getBundle("formats", locale); + final String pattern = bundle.getString("label"); + final MessageFormat formatter = new MessageFormat(pattern, locale); + return formatter.format(data); + } + + public static void run(List locales) { + System.out.println("Java formatter"); + final Date date = new Date(System.currentTimeMillis()); + locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { date, "Alice", 0 }))); + locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { date, "Alice", 2 }))); + } +} diff --git a/core-java-modules/core-java-8-2/src/main/java/com/baeldung/localization/Localization.java b/core-java-modules/core-java-8-2/src/main/java/com/baeldung/localization/Localization.java new file mode 100644 index 0000000000..17a6598ce0 --- /dev/null +++ b/core-java-modules/core-java-8-2/src/main/java/com/baeldung/localization/Localization.java @@ -0,0 +1,18 @@ +package com.baeldung.localization; + +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; + +public class Localization { + + public static String getLabel(Locale locale) { + final ResourceBundle bundle = ResourceBundle.getBundle("messages", locale); + return bundle.getString("label"); + } + + public static void run(List locales) { + locales.forEach(locale -> System.out.println(getLabel(locale))); + } + +} diff --git a/core-java-modules/core-java-8-2/src/main/resources/example_manifest.txt b/core-java-modules/core-java-8-2/src/main/resources/example_manifest.txt new file mode 100644 index 0000000000..71abcb05fb --- /dev/null +++ b/core-java-modules/core-java-8-2/src/main/resources/example_manifest.txt @@ -0,0 +1 @@ +Main-Class: com.baeldung.jarArguments.JarExample diff --git a/core-java-modules/core-java-8-2/src/main/resources/formats_en.properties b/core-java-modules/core-java-8-2/src/main/resources/formats_en.properties new file mode 100644 index 0000000000..41e0e00119 --- /dev/null +++ b/core-java-modules/core-java-8-2/src/main/resources/formats_en.properties @@ -0,0 +1,2 @@ +label=On {0, date, short} {1} has sent you {2, choice, 0#no messages|1#a message|2#two messages|2<{2,number,integer} messages}. +label-icu={0} has sent you {2, plural, =0 {no messages} =1 {a message} other {{2, number, integer} messages}}. \ No newline at end of file diff --git a/core-java-modules/core-java-8-2/src/main/resources/formats_fr.properties b/core-java-modules/core-java-8-2/src/main/resources/formats_fr.properties new file mode 100644 index 0000000000..c2d5159b32 --- /dev/null +++ b/core-java-modules/core-java-8-2/src/main/resources/formats_fr.properties @@ -0,0 +1,2 @@ +label={0, date, short}, {1}{2, choice, 0# ne|0<} vous a envoyé {2, choice, 0#aucun message|1#un message|2#deux messages|2<{2,number,integer} messages}. +label-icu={0} {2, plural, =0 {ne } other {}}vous a envoyé {2, plural, =0 {aucun message} =1 {un message} other {{2, number, integer} messages}}. \ No newline at end of file diff --git a/core-java-modules/core-java-8-2/src/main/resources/formats_it.properties b/core-java-modules/core-java-8-2/src/main/resources/formats_it.properties new file mode 100644 index 0000000000..43fd1eee1c --- /dev/null +++ b/core-java-modules/core-java-8-2/src/main/resources/formats_it.properties @@ -0,0 +1,2 @@ +label={0, date, short} {1} ti ha inviato {2, choice, 0#nessun messagio|1#un messaggio|2#due messaggi|2<{2, number, integer} messaggi}. +label-icu={0} {2, plural, =0 {non } other {}}ti ha inviato {2, plural, =0 {nessun messaggio} =1 {un messaggio} other {{2, number, integer} messaggi}}. \ No newline at end of file diff --git a/core-java-modules/core-java-8-2/src/main/resources/formats_pl.properties b/core-java-modules/core-java-8-2/src/main/resources/formats_pl.properties new file mode 100644 index 0000000000..9333ec3396 --- /dev/null +++ b/core-java-modules/core-java-8-2/src/main/resources/formats_pl.properties @@ -0,0 +1,2 @@ +label=W {0, date, short} {1}{2, choice, 0# nie|0<} wys\u0142a\u0142a ci {2, choice, 0#\u017Cadnych wiadomo\u015Bci|1#wiadomo\u015B\u0107|2#dwie wiadomo\u015Bci|2<{2, number, integer} wiadomo\u015Bci}. +label-icu={0} {2, plural, =0 {nie } other {}}{1, select, male {wys\u0142a\u0142} female {wys\u0142a\u0142a} other {wys\u0142a\u0142o}} ci {2, plural, =0 {\u017Cadnej wiadomo\u015Bci} =1 {wiadomo\u015B\u0107} other {{2, number, integer} wiadomo\u015Bci}}. diff --git a/core-java-modules/core-java-8-2/src/main/resources/messages_en.properties b/core-java-modules/core-java-8-2/src/main/resources/messages_en.properties new file mode 100644 index 0000000000..bcbca9483c --- /dev/null +++ b/core-java-modules/core-java-8-2/src/main/resources/messages_en.properties @@ -0,0 +1 @@ +label=Alice has sent you a message. diff --git a/core-java-modules/core-java-8-2/src/main/resources/messages_fr.properties b/core-java-modules/core-java-8-2/src/main/resources/messages_fr.properties new file mode 100644 index 0000000000..6716102568 --- /dev/null +++ b/core-java-modules/core-java-8-2/src/main/resources/messages_fr.properties @@ -0,0 +1 @@ +label=Alice vous a envoyé un message. \ No newline at end of file diff --git a/core-java-modules/core-java-8-2/src/main/resources/messages_it.properties b/core-java-modules/core-java-8-2/src/main/resources/messages_it.properties new file mode 100644 index 0000000000..6929a8c091 --- /dev/null +++ b/core-java-modules/core-java-8-2/src/main/resources/messages_it.properties @@ -0,0 +1 @@ +label=Alice ti ha inviato un messaggio. \ No newline at end of file diff --git a/core-java-modules/core-java-8-2/src/main/resources/messages_pl.properties b/core-java-modules/core-java-8-2/src/main/resources/messages_pl.properties new file mode 100644 index 0000000000..5515a9920e --- /dev/null +++ b/core-java-modules/core-java-8-2/src/main/resources/messages_pl.properties @@ -0,0 +1 @@ +label=Alice wys\u0142a\u0142a ci wiadomo\u015B\u0107. \ No newline at end of file diff --git a/core-java-modules/core-java-8-2/src/test/java/com/baeldung/localization/ICUFormatUnitTest.java b/core-java-modules/core-java-8-2/src/test/java/com/baeldung/localization/ICUFormatUnitTest.java new file mode 100644 index 0000000000..2c8f9b47f3 --- /dev/null +++ b/core-java-modules/core-java-8-2/src/test/java/com/baeldung/localization/ICUFormatUnitTest.java @@ -0,0 +1,74 @@ +package com.baeldung.localization; + +import static org.junit.Assert.assertEquals; + +import java.util.Locale; + +import org.junit.Test; + +import com.baeldung.localization.ICUFormat; + +public class ICUFormatUnitTest { + + @Test + public void givenInUK_whenAliceSendsNothing_thenCorrectMessage() { + assertEquals("Alice has sent you no messages.", ICUFormat.getLabel(Locale.UK, new Object[] { "Alice", "female", 0 })); + } + + @Test + public void givenInUK_whenAliceSendsOneMessage_thenCorrectMessage() { + assertEquals("Alice has sent you a message.", ICUFormat.getLabel(Locale.UK, new Object[] { "Alice", "female", 1 })); + } + + @Test + public void givenInUK_whenBobSendsSixMessages_thenCorrectMessage() { + assertEquals("Bob has sent you 6 messages.", ICUFormat.getLabel(Locale.UK, new Object[] { "Bob", "male", 6 })); + } + + @Test + public void givenInItaly_whenAliceSendsNothing_thenCorrectMessage() { + assertEquals("Alice non ti ha inviato nessun messaggio.", ICUFormat.getLabel(Locale.ITALY, new Object[] { "Alice", "female", 0 })); + } + + @Test + public void givenInItaly_whenAliceSendsOneMessage_thenCorrectMessage() { + assertEquals("Alice ti ha inviato un messaggio.", ICUFormat.getLabel(Locale.ITALY, new Object[] { "Alice", "female", 1 })); + } + + @Test + public void givenInItaly_whenBobSendsSixMessages_thenCorrectMessage() { + assertEquals("Bob ti ha inviato 6 messaggi.", ICUFormat.getLabel(Locale.ITALY, new Object[] { "Bob", "male", 6 })); + } + + @Test + public void givenInFrance_whenAliceSendsNothing_thenCorrectMessage() { + assertEquals("Alice ne vous a envoyé aucun message.", ICUFormat.getLabel(Locale.FRANCE, new Object[] { "Alice", "female", 0 })); + } + + @Test + public void givenInFrance_whenAliceSendsOneMessage_thenCorrectMessage() { + assertEquals("Alice vous a envoyé un message.", ICUFormat.getLabel(Locale.FRANCE, new Object[] { "Alice", "female", 1 })); + } + + @Test + public void givenInFrance_whenBobSendsSixMessages_thenCorrectMessage() { + assertEquals("Bob vous a envoyé 6 messages.", ICUFormat.getLabel(Locale.FRANCE, new Object[] { "Bob", "male", 6 })); + } + + + @Test + public void givenInPoland_whenAliceSendsNothing_thenCorrectMessage() { + assertEquals("Alice nie wysÅ‚aÅ‚a ci żadnej wiadomoÅ›ci.", ICUFormat.getLabel(Locale.forLanguageTag("pl-PL"), new Object[] { "Alice", "female", 0 })); + } + + @Test + public void givenInPoland_whenAliceSendsOneMessage_thenCorrectMessage() { + assertEquals("Alice wysÅ‚aÅ‚a ci wiadomość.", ICUFormat.getLabel(Locale.forLanguageTag("pl-PL"), new Object[] { "Alice", "female", 1 })); + } + + @Test + public void givenInPoland_whenBobSendsSixMessages_thenCorrectMessage() { + assertEquals("Bob wysÅ‚aÅ‚ ci 6 wiadomoÅ›ci.", ICUFormat.getLabel(Locale.forLanguageTag("pl-PL"), new Object[] { "Bob", "male", 6 })); + } + +} diff --git a/core-java-8/.gitignore b/core-java-modules/core-java-8/.gitignore similarity index 100% rename from core-java-8/.gitignore rename to core-java-modules/core-java-8/.gitignore diff --git a/core-java-8/README.md b/core-java-modules/core-java-8/README.md similarity index 100% rename from core-java-8/README.md rename to core-java-modules/core-java-8/README.md diff --git a/core-java-8/pom.xml b/core-java-modules/core-java-8/pom.xml similarity index 96% rename from core-java-8/pom.xml rename to core-java-modules/core-java-8/pom.xml index b63afef7d4..c09c970e07 100644 --- a/core-java-8/pom.xml +++ b/core-java-modules/core-java-8/pom.xml @@ -1,199 +1,199 @@ - - 4.0.0 - com.baeldung - core-java-8 - 0.1.0-SNAPSHOT - core-java-8 - jar - - - com.baeldung - parent-java - 0.0.1-SNAPSHOT - ../parent-java - - - - - org.apache.commons - commons-collections4 - ${commons-collections4.version} - - - commons-io - commons-io - ${commons-io.version} - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - org.apache.commons - commons-math3 - ${commons-math3.version} - - - log4j - log4j - ${log4j.version} - - - commons-codec - commons-codec - ${commons-codec.version} - - - org.projectlombok - lombok - ${lombok.version} - provided - - - - org.assertj - assertj-core - ${assertj.version} - test - - - com.jayway.awaitility - awaitility - ${avaitility.version} - test - - - org.openjdk.jmh - jmh-core - ${jmh-core.version} - - - org.openjdk.jmh - jmh-generator-annprocess - ${jmh-generator.version} - - - org.openjdk.jmh - jmh-generator-bytecode - ${jmh-generator.version} - - - com.codepoetics - protonpack - ${protonpack.version} - - - io.vavr - vavr - ${vavr.version} - - - joda-time - joda-time - ${joda.version} - - - org.aspectj - aspectjrt - ${asspectj.version} - - - org.aspectj - aspectjweaver - ${asspectj.version} - - - org.powermock - powermock-module-junit4 - ${powermock.version} - test - - - org.powermock - powermock-api-mockito2 - ${powermock.version} - test - - - org.jmockit - jmockit - ${jmockit.version} - test - - - - - core-java-8 - - - src/main/resources - true - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - -parameters - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - repackage - - - spring-boot - org.baeldung.executable.ExecutableMavenJar - - - - - - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - -javaagent:${settings.localRepository}/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar - - true - - - - - - - - 3.5 - 3.6.1 - 4.1 - 4.01 - 1.10 - 0.9.0 - 1.13 - 2.10 - - 3.6.1 - 1.8.9 - 2.0.0-RC.4 - 1.44 - 1.7.0 - 1.19 - 1.19 - 2.0.4.RELEASE - - 3.8.0 - 2.22.1 - - + + 4.0.0 + com.baeldung + core-java-8 + 0.1.0-SNAPSHOT + core-java-8 + jar + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + + + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + + + commons-io + commons-io + ${commons-io.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.apache.commons + commons-math3 + ${commons-math3.version} + + + log4j + log4j + ${log4j.version} + + + commons-codec + commons-codec + ${commons-codec.version} + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + org.assertj + assertj-core + ${assertj.version} + test + + + com.jayway.awaitility + awaitility + ${avaitility.version} + test + + + org.openjdk.jmh + jmh-core + ${jmh-core.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh-generator.version} + + + org.openjdk.jmh + jmh-generator-bytecode + ${jmh-generator.version} + + + com.codepoetics + protonpack + ${protonpack.version} + + + io.vavr + vavr + ${vavr.version} + + + joda-time + joda-time + ${joda.version} + + + org.aspectj + aspectjrt + ${asspectj.version} + + + org.aspectj + aspectjweaver + ${asspectj.version} + + + org.powermock + powermock-module-junit4 + ${powermock.version} + test + + + org.powermock + powermock-api-mockito2 + ${powermock.version} + test + + + org.jmockit + jmockit + ${jmockit.version} + test + + + + + core-java-8 + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + -parameters + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-maven-plugin.version} + + + + repackage + + + spring-boot + org.baeldung.executable.ExecutableMavenJar + + + + + + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + -javaagent:${settings.localRepository}/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar + + true + + + + + + + + 3.5 + 3.6.1 + 4.1 + 4.01 + 1.10 + 0.9.0 + 1.13 + 2.10 + + 3.6.1 + 1.8.9 + 2.0.0-RC.4 + 1.44 + 1.7.0 + 1.19 + 1.19 + 2.0.4.RELEASE + + 3.8.0 + 2.22.1 + + diff --git a/core-java-8/src/main/java/com/baeldung/annotations/ClassWithAnnotation.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/ClassWithAnnotation.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/annotations/ClassWithAnnotation.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/ClassWithAnnotation.java diff --git a/core-java-8/src/main/java/com/baeldung/annotations/ClassWithDeprecatedMethod.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/ClassWithDeprecatedMethod.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/annotations/ClassWithDeprecatedMethod.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/ClassWithDeprecatedMethod.java diff --git a/core-java-8/src/main/java/com/baeldung/annotations/ClassWithSafeVarargs.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/ClassWithSafeVarargs.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/annotations/ClassWithSafeVarargs.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/ClassWithSafeVarargs.java diff --git a/core-java-8/src/main/java/com/baeldung/annotations/ClassWithSuppressWarnings.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/ClassWithSuppressWarnings.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/annotations/ClassWithSuppressWarnings.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/ClassWithSuppressWarnings.java diff --git a/core-java-8/src/main/java/com/baeldung/annotations/IntConsumer.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/IntConsumer.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/annotations/IntConsumer.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/IntConsumer.java diff --git a/core-java-8/src/main/java/com/baeldung/annotations/Interval.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/Interval.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/annotations/Interval.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/Interval.java diff --git a/core-java-8/src/main/java/com/baeldung/annotations/IntervalUsage.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/IntervalUsage.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/annotations/IntervalUsage.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/IntervalUsage.java diff --git a/core-java-8/src/main/java/com/baeldung/annotations/Intervals.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/Intervals.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/annotations/Intervals.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/Intervals.java diff --git a/core-java-8/src/main/java/com/baeldung/annotations/MyAnnotation.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/MyAnnotation.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/annotations/MyAnnotation.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/MyAnnotation.java diff --git a/core-java-8/src/main/java/com/baeldung/annotations/MyAnnotationTarget.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/MyAnnotationTarget.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/annotations/MyAnnotationTarget.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/MyAnnotationTarget.java diff --git a/core-java-8/src/main/java/com/baeldung/annotations/MyOperation.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/MyOperation.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/annotations/MyOperation.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/MyOperation.java diff --git a/core-java-8/src/main/java/com/baeldung/annotations/MyOperationImpl.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/MyOperationImpl.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/annotations/MyOperationImpl.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/annotations/MyOperationImpl.java diff --git a/core-java-8/src/main/java/com/baeldung/aspect/ChangeCallsToCurrentTimeInMillisMethod.aj b/core-java-modules/core-java-8/src/main/java/com/baeldung/aspect/ChangeCallsToCurrentTimeInMillisMethod.aj similarity index 100% rename from core-java-8/src/main/java/com/baeldung/aspect/ChangeCallsToCurrentTimeInMillisMethod.aj rename to core-java-modules/core-java-8/src/main/java/com/baeldung/aspect/ChangeCallsToCurrentTimeInMillisMethod.aj diff --git a/core-java-8/src/main/java/com/baeldung/customannotations/Init.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/Init.java similarity index 95% rename from core-java-8/src/main/java/com/baeldung/customannotations/Init.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/Init.java index 265e7ba1d6..c27d7d7980 100644 --- a/core-java-8/src/main/java/com/baeldung/customannotations/Init.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/Init.java @@ -1,13 +1,13 @@ -package com.baeldung.customannotations; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -@Retention(RUNTIME) -@Target(METHOD) -public @interface Init { - -} +package com.baeldung.customannotations; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Retention(RUNTIME) +@Target(METHOD) +public @interface Init { + +} diff --git a/core-java-8/src/main/java/com/baeldung/customannotations/JsonElement.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/JsonElement.java similarity index 96% rename from core-java-8/src/main/java/com/baeldung/customannotations/JsonElement.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/JsonElement.java index e41a5b1e30..3c953f9081 100644 --- a/core-java-8/src/main/java/com/baeldung/customannotations/JsonElement.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/JsonElement.java @@ -1,13 +1,13 @@ -package com.baeldung.customannotations; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -@Retention(RUNTIME) -@Target({ FIELD }) -public @interface JsonElement { - public String key() default ""; -} +package com.baeldung.customannotations; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Retention(RUNTIME) +@Target({ FIELD }) +public @interface JsonElement { + public String key() default ""; +} diff --git a/core-java-8/src/main/java/com/baeldung/customannotations/JsonSerializable.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/JsonSerializable.java similarity index 95% rename from core-java-8/src/main/java/com/baeldung/customannotations/JsonSerializable.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/JsonSerializable.java index 48eeb09a1b..f6feba1b7b 100644 --- a/core-java-8/src/main/java/com/baeldung/customannotations/JsonSerializable.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/JsonSerializable.java @@ -1,13 +1,13 @@ -package com.baeldung.customannotations; - -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -@Retention(RUNTIME) -@Target(TYPE) -public @interface JsonSerializable { - -} +package com.baeldung.customannotations; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Retention(RUNTIME) +@Target(TYPE) +public @interface JsonSerializable { + +} diff --git a/core-java-8/src/main/java/com/baeldung/customannotations/JsonSerializationException.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/JsonSerializationException.java similarity index 96% rename from core-java-8/src/main/java/com/baeldung/customannotations/JsonSerializationException.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/JsonSerializationException.java index f2c29855ac..544d1311aa 100644 --- a/core-java-8/src/main/java/com/baeldung/customannotations/JsonSerializationException.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/JsonSerializationException.java @@ -1,10 +1,10 @@ -package com.baeldung.customannotations; - -public class JsonSerializationException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public JsonSerializationException(String message) { - super(message); - } -} +package com.baeldung.customannotations; + +public class JsonSerializationException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public JsonSerializationException(String message) { + super(message); + } +} diff --git a/core-java-8/src/main/java/com/baeldung/customannotations/ObjectToJsonConverter.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/ObjectToJsonConverter.java similarity index 97% rename from core-java-8/src/main/java/com/baeldung/customannotations/ObjectToJsonConverter.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/ObjectToJsonConverter.java index dd126be8ed..b809ea0d1d 100644 --- a/core-java-8/src/main/java/com/baeldung/customannotations/ObjectToJsonConverter.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/ObjectToJsonConverter.java @@ -1,67 +1,67 @@ -package com.baeldung.customannotations; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; - -public class ObjectToJsonConverter { - public String convertToJson(Object object) throws JsonSerializationException { - try { - - checkIfSerializable(object); - initializeObject(object); - return getJsonString(object); - - } catch (Exception e) { - throw new JsonSerializationException(e.getMessage()); - } - } - - private void checkIfSerializable(Object object) { - if (Objects.isNull(object)) { - throw new JsonSerializationException("Can't serialize a null object"); - } - - Class clazz = object.getClass(); - if (!clazz.isAnnotationPresent(JsonSerializable.class)) { - throw new JsonSerializationException("The class " + clazz.getSimpleName() + " is not annotated with JsonSerializable"); - } - } - - private void initializeObject(Object object) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { - Class clazz = object.getClass(); - for (Method method : clazz.getDeclaredMethods()) { - if (method.isAnnotationPresent(Init.class)) { - method.setAccessible(true); - method.invoke(object); - } - } - } - - private String getJsonString(Object object) throws IllegalArgumentException, IllegalAccessException { - Class clazz = object.getClass(); - Map jsonElementsMap = new HashMap<>(); - for (Field field : clazz.getDeclaredFields()) { - field.setAccessible(true); - if (field.isAnnotationPresent(JsonElement.class)) { - jsonElementsMap.put(getKey(field), (String) field.get(object)); - } - } - - String jsonString = jsonElementsMap.entrySet() - .stream() - .map(entry -> "\"" + entry.getKey() + "\":\"" + entry.getValue() + "\"") - .collect(Collectors.joining(",")); - return "{" + jsonString + "}"; - } - - private String getKey(Field field) { - String value = field.getAnnotation(JsonElement.class) - .key(); - return value.isEmpty() ? field.getName() : value; - } -} +package com.baeldung.customannotations; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +public class ObjectToJsonConverter { + public String convertToJson(Object object) throws JsonSerializationException { + try { + + checkIfSerializable(object); + initializeObject(object); + return getJsonString(object); + + } catch (Exception e) { + throw new JsonSerializationException(e.getMessage()); + } + } + + private void checkIfSerializable(Object object) { + if (Objects.isNull(object)) { + throw new JsonSerializationException("Can't serialize a null object"); + } + + Class clazz = object.getClass(); + if (!clazz.isAnnotationPresent(JsonSerializable.class)) { + throw new JsonSerializationException("The class " + clazz.getSimpleName() + " is not annotated with JsonSerializable"); + } + } + + private void initializeObject(Object object) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Class clazz = object.getClass(); + for (Method method : clazz.getDeclaredMethods()) { + if (method.isAnnotationPresent(Init.class)) { + method.setAccessible(true); + method.invoke(object); + } + } + } + + private String getJsonString(Object object) throws IllegalArgumentException, IllegalAccessException { + Class clazz = object.getClass(); + Map jsonElementsMap = new HashMap<>(); + for (Field field : clazz.getDeclaredFields()) { + field.setAccessible(true); + if (field.isAnnotationPresent(JsonElement.class)) { + jsonElementsMap.put(getKey(field), (String) field.get(object)); + } + } + + String jsonString = jsonElementsMap.entrySet() + .stream() + .map(entry -> "\"" + entry.getKey() + "\":\"" + entry.getValue() + "\"") + .collect(Collectors.joining(",")); + return "{" + jsonString + "}"; + } + + private String getKey(Field field) { + String value = field.getAnnotation(JsonElement.class) + .key(); + return value.isEmpty() ? field.getName() : value; + } +} diff --git a/core-java-8/src/main/java/com/baeldung/customannotations/Person.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/Person.java similarity index 95% rename from core-java-8/src/main/java/com/baeldung/customannotations/Person.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/Person.java index 5db1a7f279..ba702d6d76 100644 --- a/core-java-8/src/main/java/com/baeldung/customannotations/Person.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/Person.java @@ -1,66 +1,66 @@ -package com.baeldung.customannotations; - -@JsonSerializable -public class Person { - @JsonElement - private String firstName; - @JsonElement - private String lastName; - @JsonElement(key = "personAge") - private String age; - - private String address; - - public Person(String firstName, String lastName) { - super(); - this.firstName = firstName; - this.lastName = lastName; - } - - public Person(String firstName, String lastName, String age) { - this.firstName = firstName; - this.lastName = lastName; - this.age = age; - } - - @Init - private void initNames() { - this.firstName = this.firstName.substring(0, 1) - .toUpperCase() + this.firstName.substring(1); - this.lastName = this.lastName.substring(0, 1) - .toUpperCase() + this.lastName.substring(1); - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getAge() { - return age; - } - - public void setAge(String age) { - this.age = age; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - -} +package com.baeldung.customannotations; + +@JsonSerializable +public class Person { + @JsonElement + private String firstName; + @JsonElement + private String lastName; + @JsonElement(key = "personAge") + private String age; + + private String address; + + public Person(String firstName, String lastName) { + super(); + this.firstName = firstName; + this.lastName = lastName; + } + + public Person(String firstName, String lastName, String age) { + this.firstName = firstName; + this.lastName = lastName; + this.age = age; + } + + @Init + private void initNames() { + this.firstName = this.firstName.substring(0, 1) + .toUpperCase() + this.firstName.substring(1); + this.lastName = this.lastName.substring(0, 1) + .toUpperCase() + this.lastName.substring(1); + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getAge() { + return age; + } + + public void setAge(String age) { + this.age = age; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + +} diff --git a/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/application/Application.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/application/Application.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/application/Application.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/application/Application.java diff --git a/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Alarm.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Alarm.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Alarm.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Alarm.java diff --git a/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Car.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Car.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Car.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Car.java diff --git a/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Motorbike.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Motorbike.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Motorbike.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Motorbike.java diff --git a/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/MultiAlarmCar.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/MultiAlarmCar.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/MultiAlarmCar.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/MultiAlarmCar.java diff --git a/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Vehicle.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Vehicle.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Vehicle.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/defaultstaticinterfacemethods/model/Vehicle.java diff --git a/core-java-8/src/main/java/com/baeldung/doublecolon/Computer.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/doublecolon/Computer.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/doublecolon/Computer.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/doublecolon/Computer.java diff --git a/core-java-8/src/main/java/com/baeldung/doublecolon/ComputerUtils.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/doublecolon/ComputerUtils.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/doublecolon/ComputerUtils.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/doublecolon/ComputerUtils.java diff --git a/core-java-8/src/main/java/com/baeldung/doublecolon/MacbookPro.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/doublecolon/MacbookPro.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/doublecolon/MacbookPro.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/doublecolon/MacbookPro.java diff --git a/core-java-8/src/main/java/com/baeldung/doublecolon/function/ComputerPredicate.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/doublecolon/function/ComputerPredicate.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/doublecolon/function/ComputerPredicate.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/doublecolon/function/ComputerPredicate.java diff --git a/core-java-8/src/main/java/com/baeldung/doublecolon/function/TriFunction.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/doublecolon/function/TriFunction.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/doublecolon/function/TriFunction.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/doublecolon/function/TriFunction.java diff --git a/core-java-8/src/main/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappers.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappers.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappers.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappers.java diff --git a/core-java-8/src/main/java/com/baeldung/java8/lambda/exceptions/ThrowingConsumer.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/exceptions/ThrowingConsumer.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java8/lambda/exceptions/ThrowingConsumer.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/exceptions/ThrowingConsumer.java diff --git a/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Bar.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Bar.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Bar.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Bar.java diff --git a/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Baz.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Baz.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Baz.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Baz.java diff --git a/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Foo.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Foo.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Foo.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Foo.java diff --git a/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/FooExtended.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/FooExtended.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java8/lambda/tips/FooExtended.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/FooExtended.java diff --git a/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Processor.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Processor.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Processor.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Processor.java diff --git a/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/ProcessorImpl.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/ProcessorImpl.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java8/lambda/tips/ProcessorImpl.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/ProcessorImpl.java diff --git a/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/UseFoo.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/UseFoo.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java8/lambda/tips/UseFoo.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/UseFoo.java diff --git a/core-java-8/src/main/java/com/baeldung/java_8_features/Address.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/Address.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java_8_features/Address.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/Address.java diff --git a/core-java-8/src/main/java/com/baeldung/java_8_features/CustomException.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/CustomException.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java_8_features/CustomException.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/CustomException.java diff --git a/core-java-8/src/main/java/com/baeldung/java_8_features/OptionalAddress.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/OptionalAddress.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java_8_features/OptionalAddress.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/OptionalAddress.java diff --git a/core-java-8/src/main/java/com/baeldung/java_8_features/OptionalUser.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/OptionalUser.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java_8_features/OptionalUser.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/OptionalUser.java diff --git a/core-java-8/src/main/java/com/baeldung/java_8_features/User.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/User.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java_8_features/User.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/User.java diff --git a/core-java-8/src/main/java/com/baeldung/java_8_features/Vehicle.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/Vehicle.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java_8_features/Vehicle.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/Vehicle.java diff --git a/core-java-8/src/main/java/com/baeldung/java_8_features/VehicleImpl.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/VehicleImpl.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java_8_features/VehicleImpl.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/VehicleImpl.java diff --git a/core-java-8/src/main/java/com/baeldung/java_8_features/groupingby/BlogPost.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/groupingby/BlogPost.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java_8_features/groupingby/BlogPost.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/groupingby/BlogPost.java diff --git a/core-java-8/src/main/java/com/baeldung/java_8_features/groupingby/BlogPostType.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/groupingby/BlogPostType.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/java_8_features/groupingby/BlogPostType.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/java_8_features/groupingby/BlogPostType.java diff --git a/core-java-8/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNull.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNull.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNull.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNull.java diff --git a/core-java-8/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainer.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainer.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainer.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainer.java diff --git a/core-java-8/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheck.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheck.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheck.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheck.java diff --git a/core-java-8/src/main/java/com/baeldung/optional/Modem.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/optional/Modem.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/optional/Modem.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/optional/Modem.java diff --git a/core-java-8/src/main/java/com/baeldung/optional/OrElseAndOrElseGet.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/optional/OrElseAndOrElseGet.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/optional/OrElseAndOrElseGet.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/optional/OrElseAndOrElseGet.java diff --git a/core-java-8/src/main/java/com/baeldung/optional/OrElseAndOrElseGetBenchmarkRunner.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/optional/OrElseAndOrElseGetBenchmarkRunner.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/optional/OrElseAndOrElseGetBenchmarkRunner.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/optional/OrElseAndOrElseGetBenchmarkRunner.java diff --git a/core-java-8/src/main/java/com/baeldung/optional/Person.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/optional/Person.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/optional/Person.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/optional/Person.java diff --git a/core-java-8/src/main/java/com/baeldung/optional/PersonRepository.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/optional/PersonRepository.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/optional/PersonRepository.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/optional/PersonRepository.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/BenchmarkRunner.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/BenchmarkRunner.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/BenchmarkRunner.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/BenchmarkRunner.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/BooleanPrimitiveLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/BooleanPrimitiveLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/BooleanPrimitiveLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/BooleanPrimitiveLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/BooleanWrapperLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/BooleanWrapperLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/BooleanWrapperLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/BooleanWrapperLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/BytePrimitiveLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/BytePrimitiveLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/BytePrimitiveLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/BytePrimitiveLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/ByteWrapperLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/ByteWrapperLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/ByteWrapperLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/ByteWrapperLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/CharPrimitiveLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/CharPrimitiveLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/CharPrimitiveLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/CharPrimitiveLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/CharacterWrapperLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/CharacterWrapperLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/CharacterWrapperLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/CharacterWrapperLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/DoublePrimitiveLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/DoublePrimitiveLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/DoublePrimitiveLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/DoublePrimitiveLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/DoubleWrapperLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/DoubleWrapperLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/DoubleWrapperLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/DoubleWrapperLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/FloatPrimitiveLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/FloatPrimitiveLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/FloatPrimitiveLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/FloatPrimitiveLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/FloatWrapperLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/FloatWrapperLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/FloatWrapperLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/FloatWrapperLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/IntPrimitiveLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/IntPrimitiveLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/IntPrimitiveLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/IntPrimitiveLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/IntegerWrapperLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/IntegerWrapperLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/IntegerWrapperLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/IntegerWrapperLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/LongPrimitiveLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/LongPrimitiveLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/LongPrimitiveLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/LongPrimitiveLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/LongWrapperLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/LongWrapperLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/LongWrapperLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/LongWrapperLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/Lookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/Lookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/Lookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/Lookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/ShortPrimitiveLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/ShortPrimitiveLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/ShortPrimitiveLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/ShortPrimitiveLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/primitive/ShortWrapperLookup.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/ShortWrapperLookup.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/primitive/ShortWrapperLookup.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/primitive/ShortWrapperLookup.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/AddCommand.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/AddCommand.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/AddCommand.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/AddCommand.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/AddRule.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/AddRule.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/AddRule.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/AddRule.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/Addition.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Addition.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/Addition.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Addition.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/Calculator.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Calculator.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/Calculator.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Calculator.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/Command.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Command.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/Command.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Command.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/Division.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Division.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/Division.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Division.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/Expression.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Expression.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/Expression.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Expression.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/Modulo.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Modulo.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/Modulo.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Modulo.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/Multiplication.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Multiplication.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/Multiplication.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Multiplication.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/Operation.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Operation.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/Operation.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Operation.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/Operator.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Operator.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/Operator.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Operator.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/OperatorFactory.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/OperatorFactory.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/OperatorFactory.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/OperatorFactory.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/Result.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Result.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/Result.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Result.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/Rule.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Rule.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/Rule.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Rule.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/RuleEngine.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/RuleEngine.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/RuleEngine.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/RuleEngine.java diff --git a/core-java-8/src/main/java/com/baeldung/reducingIfElse/Subtraction.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Subtraction.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/reducingIfElse/Subtraction.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reducingIfElse/Subtraction.java diff --git a/core-java-8/src/main/java/com/baeldung/reflect/Person.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/reflect/Person.java similarity index 93% rename from core-java-8/src/main/java/com/baeldung/reflect/Person.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/reflect/Person.java index fba25aca8b..f15250869d 100644 --- a/core-java-8/src/main/java/com/baeldung/reflect/Person.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/reflect/Person.java @@ -1,18 +1,18 @@ -package com.baeldung.reflect; - -public class Person { - - private String fullName; - - public Person(String fullName) { - this.fullName = fullName; - } - - public void setFullName(String fullName) { - this.fullName = fullName; - } - - public String getFullName() { - return fullName; - } -} +package com.baeldung.reflect; + +public class Person { + + private String fullName; + + public Person(String fullName) { + this.fullName = fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } + + public String getFullName() { + return fullName; + } +} diff --git a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Article.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Article.java similarity index 95% rename from core-java-8/src/main/java/com/baeldung/spliteratorAPI/Article.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Article.java index 402ec6ec5f..3cd2a00da1 100644 --- a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Article.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Article.java @@ -1,44 +1,44 @@ -package com.baeldung.spliteratorAPI; - -import java.util.List; - -public class Article { - private List listOfAuthors; - private int id; - private String name; - - public Article(String name) { - this.name = name; - } - - public Article(List listOfAuthors, int id) { - super(); - this.listOfAuthors = listOfAuthors; - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public List getListOfAuthors() { - return listOfAuthors; - } - - public void setListOfAuthors(List listOfAuthors) { - this.listOfAuthors = listOfAuthors; - } - +package com.baeldung.spliteratorAPI; + +import java.util.List; + +public class Article { + private List listOfAuthors; + private int id; + private String name; + + public Article(String name) { + this.name = name; + } + + public Article(List listOfAuthors, int id) { + super(); + this.listOfAuthors = listOfAuthors; + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public List getListOfAuthors() { + return listOfAuthors; + } + + public void setListOfAuthors(List listOfAuthors) { + this.listOfAuthors = listOfAuthors; + } + } \ No newline at end of file diff --git a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Author.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Author.java similarity index 95% rename from core-java-8/src/main/java/com/baeldung/spliteratorAPI/Author.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Author.java index 40c381f4a6..18bbbd073e 100644 --- a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Author.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Author.java @@ -1,33 +1,33 @@ -package com.baeldung.spliteratorAPI; - -public class Author { - private String name; - private int relatedArticleId; - - public Author(String name, int relatedArticleId) { - this.name = name; - this.relatedArticleId = relatedArticleId; - } - - public int getRelatedArticleId() { - return relatedArticleId; - } - - public void setRelatedArticleId(int relatedArticleId) { - this.relatedArticleId = relatedArticleId; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @Override - public String toString() { - return "[name: " + name + ", relatedId: " + relatedArticleId + "]"; - } -} - +package com.baeldung.spliteratorAPI; + +public class Author { + private String name; + private int relatedArticleId; + + public Author(String name, int relatedArticleId) { + this.name = name; + this.relatedArticleId = relatedArticleId; + } + + public int getRelatedArticleId() { + return relatedArticleId; + } + + public void setRelatedArticleId(int relatedArticleId) { + this.relatedArticleId = relatedArticleId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "[name: " + name + ", relatedId: " + relatedArticleId + "]"; + } +} + diff --git a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Executor.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Executor.java similarity index 96% rename from core-java-8/src/main/java/com/baeldung/spliteratorAPI/Executor.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Executor.java index 024d5dabdb..dd124948d8 100644 --- a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Executor.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Executor.java @@ -1,19 +1,19 @@ -package com.baeldung.spliteratorAPI; - -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class Executor { - - public static int countAutors(Stream stream) { - RelatedAuthorCounter wordCounter = stream.reduce(new RelatedAuthorCounter(0, true), - RelatedAuthorCounter::accumulate, RelatedAuthorCounter::combine); - return wordCounter.getCounter(); - } - - public static List
generateElements() { - return Stream.generate(() -> new Article("Java")).limit(35000).collect(Collectors.toList()); - } - +package com.baeldung.spliteratorAPI; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class Executor { + + public static int countAutors(Stream stream) { + RelatedAuthorCounter wordCounter = stream.reduce(new RelatedAuthorCounter(0, true), + RelatedAuthorCounter::accumulate, RelatedAuthorCounter::combine); + return wordCounter.getCounter(); + } + + public static List
generateElements() { + return Stream.generate(() -> new Article("Java")).limit(35000).collect(Collectors.toList()); + } + } \ No newline at end of file diff --git a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorCounter.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorCounter.java similarity index 96% rename from core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorCounter.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorCounter.java index b7120b3af2..282c0be727 100644 --- a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorCounter.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorCounter.java @@ -1,27 +1,27 @@ -package com.baeldung.spliteratorAPI; - -public class RelatedAuthorCounter { - private final int counter; - private final boolean isRelated; - - public RelatedAuthorCounter(int counter, boolean isRelated) { - this.counter = counter; - this.isRelated = isRelated; - } - - public RelatedAuthorCounter accumulate(Author author) { - if (author.getRelatedArticleId() == 0) { - return isRelated ? this : new RelatedAuthorCounter(counter, true); - } else { - return isRelated ? new RelatedAuthorCounter(counter + 1, false) : this; - } - } - - public RelatedAuthorCounter combine(RelatedAuthorCounter RelatedAuthorCounter) { - return new RelatedAuthorCounter(counter + RelatedAuthorCounter.counter, RelatedAuthorCounter.isRelated); - } - - public int getCounter() { - return counter; - } -} +package com.baeldung.spliteratorAPI; + +public class RelatedAuthorCounter { + private final int counter; + private final boolean isRelated; + + public RelatedAuthorCounter(int counter, boolean isRelated) { + this.counter = counter; + this.isRelated = isRelated; + } + + public RelatedAuthorCounter accumulate(Author author) { + if (author.getRelatedArticleId() == 0) { + return isRelated ? this : new RelatedAuthorCounter(counter, true); + } else { + return isRelated ? new RelatedAuthorCounter(counter + 1, false) : this; + } + } + + public RelatedAuthorCounter combine(RelatedAuthorCounter RelatedAuthorCounter) { + return new RelatedAuthorCounter(counter + RelatedAuthorCounter.counter, RelatedAuthorCounter.isRelated); + } + + public int getCounter() { + return counter; + } +} diff --git a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorSpliterator.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorSpliterator.java similarity index 96% rename from core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorSpliterator.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorSpliterator.java index 0a7190964e..094638da37 100644 --- a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorSpliterator.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorSpliterator.java @@ -1,49 +1,49 @@ -package com.baeldung.spliteratorAPI; - -import java.util.List; -import java.util.Spliterator; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; - -public class RelatedAuthorSpliterator implements Spliterator { - private final List list; - AtomicInteger current = new AtomicInteger(); - - public RelatedAuthorSpliterator(List list) { - this.list = list; - } - - @Override - public boolean tryAdvance(Consumer action) { - - action.accept(list.get(current.getAndIncrement())); - return current.get() < list.size(); - } - - @Override - public Spliterator trySplit() { - int currentSize = list.size() - current.get(); - if (currentSize < 10) { - return null; - } - for (int splitPos = currentSize / 2 + current.intValue(); splitPos < list.size(); splitPos++) { - if (list.get(splitPos).getRelatedArticleId() == 0) { - Spliterator spliterator = new RelatedAuthorSpliterator(list.subList(current.get(), splitPos)); - current.set(splitPos); - return spliterator; - } - } - return null; - } - - @Override - public long estimateSize() { - return list.size() - current.get(); - } - - @Override - public int characteristics() { - return CONCURRENT; - } - -} +package com.baeldung.spliteratorAPI; + +import java.util.List; +import java.util.Spliterator; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; + +public class RelatedAuthorSpliterator implements Spliterator { + private final List list; + AtomicInteger current = new AtomicInteger(); + + public RelatedAuthorSpliterator(List list) { + this.list = list; + } + + @Override + public boolean tryAdvance(Consumer action) { + + action.accept(list.get(current.getAndIncrement())); + return current.get() < list.size(); + } + + @Override + public Spliterator trySplit() { + int currentSize = list.size() - current.get(); + if (currentSize < 10) { + return null; + } + for (int splitPos = currentSize / 2 + current.intValue(); splitPos < list.size(); splitPos++) { + if (list.get(splitPos).getRelatedArticleId() == 0) { + Spliterator spliterator = new RelatedAuthorSpliterator(list.subList(current.get(), splitPos)); + current.set(splitPos); + return spliterator; + } + } + return null; + } + + @Override + public long estimateSize() { + return list.size() - current.get(); + } + + @Override + public int characteristics() { + return CONCURRENT; + } + +} diff --git a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Task.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Task.java similarity index 96% rename from core-java-8/src/main/java/com/baeldung/spliteratorAPI/Task.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Task.java index 70435d1c75..06a124cc98 100644 --- a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Task.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Task.java @@ -1,27 +1,27 @@ -package com.baeldung.spliteratorAPI; - -import java.util.Spliterator; -import java.util.concurrent.Callable; - -public class Task implements Callable { - private Spliterator
spliterator; - private final static String SUFFIX = "- published by Baeldung"; - - public Task(Spliterator
spliterator) { - this.spliterator = spliterator; - } - - @Override - public String call() { - int current = 0; - while (spliterator.tryAdvance(article -> { - article.setName(article.getName() - .concat(SUFFIX)); - })) { - current++; - } - ; - return Thread.currentThread() - .getName() + ":" + current; - } -} +package com.baeldung.spliteratorAPI; + +import java.util.Spliterator; +import java.util.concurrent.Callable; + +public class Task implements Callable { + private Spliterator
spliterator; + private final static String SUFFIX = "- published by Baeldung"; + + public Task(Spliterator
spliterator) { + this.spliterator = spliterator; + } + + @Override + public String call() { + int current = 0; + while (spliterator.tryAdvance(article -> { + article.setName(article.getName() + .concat(SUFFIX)); + })) { + current++; + } + ; + return Thread.currentThread() + .getName() + ":" + current; + } +} diff --git a/core-java-8/src/main/java/com/baeldung/strategy/ChristmasDiscounter.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/strategy/ChristmasDiscounter.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/strategy/ChristmasDiscounter.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/strategy/ChristmasDiscounter.java diff --git a/core-java-8/src/main/java/com/baeldung/strategy/Discounter.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/strategy/Discounter.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/strategy/Discounter.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/strategy/Discounter.java diff --git a/core-java-8/src/main/java/com/baeldung/strategy/EasterDiscounter.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/strategy/EasterDiscounter.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/strategy/EasterDiscounter.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/strategy/EasterDiscounter.java diff --git a/core-java-8/src/main/java/com/baeldung/streamreduce/application/Application.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/application/Application.java similarity index 97% rename from core-java-8/src/main/java/com/baeldung/streamreduce/application/Application.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/application/Application.java index 0b1dd952dc..00fc45ccae 100644 --- a/core-java-8/src/main/java/com/baeldung/streamreduce/application/Application.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/application/Application.java @@ -1,62 +1,62 @@ -package com.baeldung.streamreduce.application; - -import com.baeldung.streamreduce.entities.User; -import com.baeldung.streamreduce.utilities.NumberUtils; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class Application { - - public static void main(String[] args) { - List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); - int result1 = numbers.stream().reduce(0, (a, b) -> a + b); - System.out.println(result1); - - int result2 = numbers.stream().reduce(0, Integer::sum); - System.out.println(result2); - - List letters = Arrays.asList("a", "b", "c", "d", "e"); - String result3 = letters.stream().reduce("", (a, b) -> a + b); - System.out.println(result3); - - String result4 = letters.stream().reduce("", String::concat); - System.out.println(result4); - - String result5 = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase()); - System.out.println(result5); - - List users = Arrays.asList(new User("John", 30), new User("Julie", 35)); - int result6 = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); - System.out.println(result6); - - String result7 = letters.parallelStream().reduce("", String::concat); - System.out.println(result7); - - int result8 = users.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); - System.out.println(result8); - - List userList = new ArrayList<>(); - for (int i = 0; i <= 1000000; i++) { - userList.add(new User("John" + i, i)); - } - - long t1 = System.currentTimeMillis(); - int result9 = userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); - long t2 = System.currentTimeMillis(); - System.out.println(result9); - System.out.println("Sequential stream time: " + (t2 - t1) + "ms"); - - long t3 = System.currentTimeMillis(); - int result10 = userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); - long t4 = System.currentTimeMillis(); - System.out.println(result10); - System.out.println("Parallel stream time: " + (t4 - t3) + "ms"); - - int result11 = NumberUtils.divideListElements(numbers, 1); - System.out.println(result11); - - int result12 = NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 0); - System.out.println(result12); - } -} +package com.baeldung.streamreduce.application; + +import com.baeldung.streamreduce.entities.User; +import com.baeldung.streamreduce.utilities.NumberUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Application { + + public static void main(String[] args) { + List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); + int result1 = numbers.stream().reduce(0, (a, b) -> a + b); + System.out.println(result1); + + int result2 = numbers.stream().reduce(0, Integer::sum); + System.out.println(result2); + + List letters = Arrays.asList("a", "b", "c", "d", "e"); + String result3 = letters.stream().reduce("", (a, b) -> a + b); + System.out.println(result3); + + String result4 = letters.stream().reduce("", String::concat); + System.out.println(result4); + + String result5 = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase()); + System.out.println(result5); + + List users = Arrays.asList(new User("John", 30), new User("Julie", 35)); + int result6 = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); + System.out.println(result6); + + String result7 = letters.parallelStream().reduce("", String::concat); + System.out.println(result7); + + int result8 = users.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); + System.out.println(result8); + + List userList = new ArrayList<>(); + for (int i = 0; i <= 1000000; i++) { + userList.add(new User("John" + i, i)); + } + + long t1 = System.currentTimeMillis(); + int result9 = userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); + long t2 = System.currentTimeMillis(); + System.out.println(result9); + System.out.println("Sequential stream time: " + (t2 - t1) + "ms"); + + long t3 = System.currentTimeMillis(); + int result10 = userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); + long t4 = System.currentTimeMillis(); + System.out.println(result10); + System.out.println("Parallel stream time: " + (t4 - t3) + "ms"); + + int result11 = NumberUtils.divideListElements(numbers, 1); + System.out.println(result11); + + int result12 = NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 0); + System.out.println(result12); + } +} diff --git a/core-java-8/src/main/java/com/baeldung/streamreduce/entities/User.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/User.java similarity index 94% rename from core-java-8/src/main/java/com/baeldung/streamreduce/entities/User.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/User.java index bc13a8cde6..39a42beab7 100644 --- a/core-java-8/src/main/java/com/baeldung/streamreduce/entities/User.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/entities/User.java @@ -1,25 +1,25 @@ -package com.baeldung.streamreduce.entities; - -public class User { - - private final String name; - private final int age; - - public User(String name, int age) { - this.name = name; - this.age = age; - } - - public String getName() { - return name; - } - - public int getAge() { - return age; - } - - @Override - public String toString() { - return "User{" + "name=" + name + ", age=" + age + '}'; - } -} +package com.baeldung.streamreduce.entities; + +public class User { + + private final String name; + private final int age; + + public User(String name, int age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public int getAge() { + return age; + } + + @Override + public String toString() { + return "User{" + "name=" + name + ", age=" + age + '}'; + } +} diff --git a/core-java-8/src/main/java/com/baeldung/streamreduce/utilities/NumberUtils.java b/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/utilities/NumberUtils.java similarity index 97% rename from core-java-8/src/main/java/com/baeldung/streamreduce/utilities/NumberUtils.java rename to core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/utilities/NumberUtils.java index 7a6a85e6c4..a2325cc701 100644 --- a/core-java-8/src/main/java/com/baeldung/streamreduce/utilities/NumberUtils.java +++ b/core-java-modules/core-java-8/src/main/java/com/baeldung/streamreduce/utilities/NumberUtils.java @@ -1,52 +1,52 @@ -package com.baeldung.streamreduce.utilities; - -import java.util.List; -import java.util.function.BiFunction; -import java.util.logging.Level; -import java.util.logging.Logger; - -public abstract class NumberUtils { - - private static final Logger LOGGER = Logger.getLogger(NumberUtils.class.getName()); - - public static int divideListElements(List values, Integer divider) { - return values.stream() - .reduce(0, (a, b) -> { - try { - return a / divider + b / divider; - } catch (ArithmeticException e) { - LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero"); - } - return 0; - }); - } - - public static int divideListElementsWithExtractedTryCatchBlock(List values, int divider) { - return values.stream().reduce(0, (a, b) -> divide(a, divider) + divide(b, divider)); - } - - public static int divideListElementsWithApplyFunctionMethod(List values, int divider) { - BiFunction division = (a, b) -> a / b; - return values.stream().reduce(0, (a, b) -> applyFunction(division, a, divider) + applyFunction(division, b, divider)); - } - - private static int divide(int value, int factor) { - int result = 0; - try { - result = value / factor; - } catch (ArithmeticException e) { - LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero"); - } - return result; - } - - private static int applyFunction(BiFunction function, int a, int b) { - try { - return function.apply(a, b); - } - catch(Exception e) { - LOGGER.log(Level.INFO, "Exception occurred!"); - } - return 0; - } -} +package com.baeldung.streamreduce.utilities; + +import java.util.List; +import java.util.function.BiFunction; +import java.util.logging.Level; +import java.util.logging.Logger; + +public abstract class NumberUtils { + + private static final Logger LOGGER = Logger.getLogger(NumberUtils.class.getName()); + + public static int divideListElements(List values, Integer divider) { + return values.stream() + .reduce(0, (a, b) -> { + try { + return a / divider + b / divider; + } catch (ArithmeticException e) { + LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero"); + } + return 0; + }); + } + + public static int divideListElementsWithExtractedTryCatchBlock(List values, int divider) { + return values.stream().reduce(0, (a, b) -> divide(a, divider) + divide(b, divider)); + } + + public static int divideListElementsWithApplyFunctionMethod(List values, int divider) { + BiFunction division = (a, b) -> a / b; + return values.stream().reduce(0, (a, b) -> applyFunction(division, a, divider) + applyFunction(division, b, divider)); + } + + private static int divide(int value, int factor) { + int result = 0; + try { + result = value / factor; + } catch (ArithmeticException e) { + LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero"); + } + return result; + } + + private static int applyFunction(BiFunction function, int a, int b) { + try { + return function.apply(a, b); + } + catch(Exception e) { + LOGGER.log(Level.INFO, "Exception occurred!"); + } + return 0; + } +} diff --git a/core-java-collections-list/src/main/resources/logback.xml b/core-java-modules/core-java-8/src/main/resources/logback.xml similarity index 100% rename from core-java-collections-list/src/main/resources/logback.xml rename to core-java-modules/core-java-8/src/main/resources/logback.xml diff --git a/core-java-8/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/counter/CounterStatistics.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/counter/CounterStatistics.java similarity index 97% rename from core-java-8/src/test/java/com/baeldung/counter/CounterStatistics.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/counter/CounterStatistics.java index 015ca3f942..e5b03bf355 100644 --- a/core-java-8/src/test/java/com/baeldung/counter/CounterStatistics.java +++ b/core-java-modules/core-java-8/src/test/java/com/baeldung/counter/CounterStatistics.java @@ -1,61 +1,61 @@ -package com.baeldung.counter; - -import java.util.HashMap; -import java.util.Map; -import java.util.Random; - -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.BenchmarkMode; -import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Mode; - -import com.baeldung.counter.CounterUtil.MutableInteger; - -@Fork(value = 1, warmups = 3) -@BenchmarkMode(Mode.All) -public class CounterStatistics { - - private static final Map counterMap = new HashMap<>(); - private static final Map counterWithMutableIntMap = new HashMap<>(); - private static final Map counterWithIntArrayMap = new HashMap<>(); - private static final Map counterWithLongWrapperMap = new HashMap<>(); - private static final Map counterWithLongWrapperStreamMap = new HashMap<>(); - - static { - CounterUtil.COUNTRY_NAMES = new String[10000]; - final String prefix = "NewString"; - Random random = new Random(); - for (int i=0; i<10000; i++) { - CounterUtil.COUNTRY_NAMES[i] = new String(prefix + random.nextInt(1000)); - } - } - - @Benchmark - public void wrapperAsCounter() { - CounterUtil.counterWithWrapperObject(counterMap); - } - - @Benchmark - public void lambdaExpressionWithWrapper() { - CounterUtil.counterWithLambdaAndWrapper(counterWithLongWrapperMap); - } - - @Benchmark - public void parallelStreamWithWrapper() { - CounterUtil.counterWithParallelStreamAndWrapper(counterWithLongWrapperStreamMap); - } - - @Benchmark - public void mutableIntegerAsCounter() { - CounterUtil.counterWithMutableInteger(counterWithMutableIntMap); - } - - @Benchmark - public void primitiveArrayAsCounter() { - CounterUtil.counterWithPrimitiveArray(counterWithIntArrayMap); - } - - public static void main(String[] args) throws Exception { - org.openjdk.jmh.Main.main(args); - } -} +package com.baeldung.counter; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Mode; + +import com.baeldung.counter.CounterUtil.MutableInteger; + +@Fork(value = 1, warmups = 3) +@BenchmarkMode(Mode.All) +public class CounterStatistics { + + private static final Map counterMap = new HashMap<>(); + private static final Map counterWithMutableIntMap = new HashMap<>(); + private static final Map counterWithIntArrayMap = new HashMap<>(); + private static final Map counterWithLongWrapperMap = new HashMap<>(); + private static final Map counterWithLongWrapperStreamMap = new HashMap<>(); + + static { + CounterUtil.COUNTRY_NAMES = new String[10000]; + final String prefix = "NewString"; + Random random = new Random(); + for (int i=0; i<10000; i++) { + CounterUtil.COUNTRY_NAMES[i] = new String(prefix + random.nextInt(1000)); + } + } + + @Benchmark + public void wrapperAsCounter() { + CounterUtil.counterWithWrapperObject(counterMap); + } + + @Benchmark + public void lambdaExpressionWithWrapper() { + CounterUtil.counterWithLambdaAndWrapper(counterWithLongWrapperMap); + } + + @Benchmark + public void parallelStreamWithWrapper() { + CounterUtil.counterWithParallelStreamAndWrapper(counterWithLongWrapperStreamMap); + } + + @Benchmark + public void mutableIntegerAsCounter() { + CounterUtil.counterWithMutableInteger(counterWithMutableIntMap); + } + + @Benchmark + public void primitiveArrayAsCounter() { + CounterUtil.counterWithPrimitiveArray(counterWithIntArrayMap); + } + + public static void main(String[] args) throws Exception { + org.openjdk.jmh.Main.main(args); + } +} diff --git a/core-java-8/src/test/java/com/baeldung/counter/CounterUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/counter/CounterUnitTest.java similarity index 96% rename from core-java-8/src/test/java/com/baeldung/counter/CounterUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/counter/CounterUnitTest.java index ef57fc2c6e..4f914bd289 100644 --- a/core-java-8/src/test/java/com/baeldung/counter/CounterUnitTest.java +++ b/core-java-modules/core-java-8/src/test/java/com/baeldung/counter/CounterUnitTest.java @@ -1,53 +1,53 @@ -package com.baeldung.counter; - -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.*; - -import org.junit.Test; - -import com.baeldung.counter.CounterUtil.MutableInteger; - -public class CounterUnitTest { - - @Test - public void whenMapWithWrapperAsCounter_runsSuccessfully() { - Map counterMap = new HashMap<>(); - CounterUtil.counterWithWrapperObject(counterMap); - - assertEquals(3, counterMap.get("China") - .intValue()); - assertEquals(2, counterMap.get("India") - .intValue()); - } - - @Test - public void whenMapWithLambdaAndWrapperCounter_runsSuccessfully() { - Map counterMap = new HashMap<>(); - CounterUtil.counterWithLambdaAndWrapper(counterMap); - - assertEquals(3l, counterMap.get("China") - .longValue()); - assertEquals(2l, counterMap.get("India") - .longValue()); - } - - @Test - public void whenMapWithMutableIntegerCounter_runsSuccessfully() { - Map counterMap = new HashMap<>(); - CounterUtil.counterWithMutableInteger(counterMap); - assertEquals(3, counterMap.get("China") - .getCount()); - assertEquals(2, counterMap.get("India") - .getCount()); - } - - @Test - public void whenMapWithPrimitiveArray_runsSuccessfully() { - Map counterMap = new HashMap<>(); - CounterUtil.counterWithPrimitiveArray(counterMap); - assertEquals(3, counterMap.get("China")[0]); - assertEquals(2, counterMap.get("India")[0]); - } -} +package com.baeldung.counter; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.baeldung.counter.CounterUtil.MutableInteger; + +public class CounterUnitTest { + + @Test + public void whenMapWithWrapperAsCounter_runsSuccessfully() { + Map counterMap = new HashMap<>(); + CounterUtil.counterWithWrapperObject(counterMap); + + assertEquals(3, counterMap.get("China") + .intValue()); + assertEquals(2, counterMap.get("India") + .intValue()); + } + + @Test + public void whenMapWithLambdaAndWrapperCounter_runsSuccessfully() { + Map counterMap = new HashMap<>(); + CounterUtil.counterWithLambdaAndWrapper(counterMap); + + assertEquals(3l, counterMap.get("China") + .longValue()); + assertEquals(2l, counterMap.get("India") + .longValue()); + } + + @Test + public void whenMapWithMutableIntegerCounter_runsSuccessfully() { + Map counterMap = new HashMap<>(); + CounterUtil.counterWithMutableInteger(counterMap); + assertEquals(3, counterMap.get("China") + .getCount()); + assertEquals(2, counterMap.get("India") + .getCount()); + } + + @Test + public void whenMapWithPrimitiveArray_runsSuccessfully() { + Map counterMap = new HashMap<>(); + CounterUtil.counterWithPrimitiveArray(counterMap); + assertEquals(3, counterMap.get("China")[0]); + assertEquals(2, counterMap.get("India")[0]); + } +} diff --git a/core-java-8/src/test/java/com/baeldung/counter/CounterUtil.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/counter/CounterUtil.java similarity index 97% rename from core-java-8/src/test/java/com/baeldung/counter/CounterUtil.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/counter/CounterUtil.java index c2bf47e213..7e15fa1356 100644 --- a/core-java-8/src/test/java/com/baeldung/counter/CounterUtil.java +++ b/core-java-modules/core-java-8/src/test/java/com/baeldung/counter/CounterUtil.java @@ -1,57 +1,57 @@ -package com.baeldung.counter; - -import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class CounterUtil { - - public static String[] COUNTRY_NAMES = { "China", "Australia", "India", "USA", "USSR", "UK", "China", "France", "Poland", "Austria", "India", "USA", "Egypt", "China" }; - - public static void counterWithWrapperObject(Map counterMap) { - for (String country : COUNTRY_NAMES) { - counterMap.compute(country, (k, v) -> v == null ? 1 : v + 1); - } - } - - public static void counterWithLambdaAndWrapper(Map counterMap) { - Stream.of(COUNTRY_NAMES) - .collect(Collectors.groupingBy(k -> k, () -> counterMap, Collectors.counting())); - } - - public static void counterWithParallelStreamAndWrapper(Map counterMap) { - Stream.of(COUNTRY_NAMES) - .parallel() - .collect(Collectors.groupingBy(k -> k, () -> counterMap, Collectors.counting())); - } - - public static class MutableInteger { - int count; - - public MutableInteger(int count) { - this.count = count; - } - - public void increment() { - this.count++; - } - - public int getCount() { - return this.count; - } - } - - public static void counterWithMutableInteger(Map counterMap) { - for (String country : COUNTRY_NAMES) { - counterMap.compute(country, (k, v) -> v == null ? new MutableInteger(0) : v) - .increment(); - } - } - - public static void counterWithPrimitiveArray(Map counterMap) { - for (String country : COUNTRY_NAMES) { - counterMap.compute(country, (k, v) -> v == null ? new int[] { 0 } : v)[0]++; - } - } - +package com.baeldung.counter; + +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class CounterUtil { + + public static String[] COUNTRY_NAMES = { "China", "Australia", "India", "USA", "USSR", "UK", "China", "France", "Poland", "Austria", "India", "USA", "Egypt", "China" }; + + public static void counterWithWrapperObject(Map counterMap) { + for (String country : COUNTRY_NAMES) { + counterMap.compute(country, (k, v) -> v == null ? 1 : v + 1); + } + } + + public static void counterWithLambdaAndWrapper(Map counterMap) { + Stream.of(COUNTRY_NAMES) + .collect(Collectors.groupingBy(k -> k, () -> counterMap, Collectors.counting())); + } + + public static void counterWithParallelStreamAndWrapper(Map counterMap) { + Stream.of(COUNTRY_NAMES) + .parallel() + .collect(Collectors.groupingBy(k -> k, () -> counterMap, Collectors.counting())); + } + + public static class MutableInteger { + int count; + + public MutableInteger(int count) { + this.count = count; + } + + public void increment() { + this.count++; + } + + public int getCount() { + return this.count; + } + } + + public static void counterWithMutableInteger(Map counterMap) { + for (String country : COUNTRY_NAMES) { + counterMap.compute(country, (k, v) -> v == null ? new MutableInteger(0) : v) + .increment(); + } + } + + public static void counterWithPrimitiveArray(Map counterMap) { + for (String country : COUNTRY_NAMES) { + counterMap.compute(country, (k, v) -> v == null ? new int[] { 0 } : v)[0]++; + } + } + } \ No newline at end of file diff --git a/core-java-8/src/test/java/com/baeldung/customannotations/JsonSerializerUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/customannotations/JsonSerializerUnitTest.java similarity index 97% rename from core-java-8/src/test/java/com/baeldung/customannotations/JsonSerializerUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/customannotations/JsonSerializerUnitTest.java index f24b37aef7..fd8f8ba8b3 100644 --- a/core-java-8/src/test/java/com/baeldung/customannotations/JsonSerializerUnitTest.java +++ b/core-java-modules/core-java-8/src/test/java/com/baeldung/customannotations/JsonSerializerUnitTest.java @@ -1,26 +1,26 @@ -package com.baeldung.customannotations; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import org.junit.jupiter.api.Test; - -public class JsonSerializerUnitTest { - - @Test - public void givenObjectNotSerializedThenExceptionThrown() throws JsonSerializationException { - Object object = new Object(); - ObjectToJsonConverter serializer = new ObjectToJsonConverter(); - assertThrows(JsonSerializationException.class, () -> { - serializer.convertToJson(object); - }); - } - - @Test - public void givenObjectSerializedThenTrueReturned() throws JsonSerializationException { - Person person = new Person("soufiane", "cheouati", "34"); - ObjectToJsonConverter serializer = new ObjectToJsonConverter(); - String jsonString = serializer.convertToJson(person); - assertEquals("{\"personAge\":\"34\",\"firstName\":\"Soufiane\",\"lastName\":\"Cheouati\"}", jsonString); - } -} +package com.baeldung.customannotations; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +public class JsonSerializerUnitTest { + + @Test + public void givenObjectNotSerializedThenExceptionThrown() throws JsonSerializationException { + Object object = new Object(); + ObjectToJsonConverter serializer = new ObjectToJsonConverter(); + assertThrows(JsonSerializationException.class, () -> { + serializer.convertToJson(object); + }); + } + + @Test + public void givenObjectSerializedThenTrueReturned() throws JsonSerializationException { + Person person = new Person("soufiane", "cheouati", "34"); + ObjectToJsonConverter serializer = new ObjectToJsonConverter(); + String jsonString = serializer.convertToJson(person); + assertEquals("{\"personAge\":\"34\",\"firstName\":\"Soufiane\",\"lastName\":\"Cheouati\"}", jsonString); + } +} diff --git a/core-java-8/src/test/java/com/baeldung/defaultistaticinterfacemethods/test/StaticDefaulInterfaceMethodUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/defaultistaticinterfacemethods/test/StaticDefaulInterfaceMethodUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/defaultistaticinterfacemethods/test/StaticDefaulInterfaceMethodUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/defaultistaticinterfacemethods/test/StaticDefaulInterfaceMethodUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/doublecolon/ComputerUtilsUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/doublecolon/ComputerUtilsUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/doublecolon/ComputerUtilsUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/doublecolon/ComputerUtilsUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/functionalinterface/FunctionalInterfaceUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/functionalinterface/FunctionalInterfaceUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/functionalinterface/FunctionalInterfaceUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/functionalinterface/FunctionalInterfaceUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/functionalinterface/ShortToByteFunction.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/functionalinterface/ShortToByteFunction.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/functionalinterface/ShortToByteFunction.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/functionalinterface/ShortToByteFunction.java diff --git a/core-java-8/src/test/java/com/baeldung/internationalization/DateFormatUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/internationalization/DateFormatUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/internationalization/DateFormatUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/internationalization/DateFormatUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/internationalization/NumbersCurrenciesFormattingUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/internationalization/NumbersCurrenciesFormattingUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/internationalization/NumbersCurrenciesFormattingUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/internationalization/NumbersCurrenciesFormattingUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/Java8DefaultStaticIntefaceMethodsUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8DefaultStaticIntefaceMethodsUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/Java8DefaultStaticIntefaceMethodsUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8DefaultStaticIntefaceMethodsUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/Java8ForEachUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8ForEachUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/Java8ForEachUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8ForEachUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/Java8GroupingByCollectorUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8GroupingByCollectorUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/Java8GroupingByCollectorUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8GroupingByCollectorUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/Java8MethodReferenceUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8MethodReferenceUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/Java8MethodReferenceUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8MethodReferenceUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/Java8OptionalUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8OptionalUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/Java8OptionalUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8OptionalUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/Java8PredicateChainUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8PredicateChainUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/Java8PredicateChainUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8PredicateChainUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/Java8SortUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8SortUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/Java8SortUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/Java8SortUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/JavaTryWithResourcesLongRunningUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/JavaTryWithResourcesLongRunningUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/JavaTryWithResourcesLongRunningUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/JavaTryWithResourcesLongRunningUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/UnsignedArithmeticUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/UnsignedArithmeticUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/UnsignedArithmeticUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/UnsignedArithmeticUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/comparator/Employee.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/comparator/Employee.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/comparator/Employee.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/comparator/Employee.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/comparator/Java8ComparatorUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/comparator/Java8ComparatorUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/comparator/Java8ComparatorUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/comparator/Java8ComparatorUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/entity/Human.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/entity/Human.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/entity/Human.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/entity/Human.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappersUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappersUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappersUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappersUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/Bicycle.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/Bicycle.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/Bicycle.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/Bicycle.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/BicycleComparator.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/BicycleComparator.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/BicycleComparator.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/BicycleComparator.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/MethodReferenceUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/MethodReferenceUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/MethodReferenceUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/lambda/methodreference/MethodReferenceUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/lambda/tips/Java8FunctionalInteracesLambdasUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/lambda/tips/Java8FunctionalInteracesLambdasUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/lambda/tips/Java8FunctionalInteracesLambdasUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/lambda/tips/Java8FunctionalInteracesLambdasUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalChainingUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalChainingUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/optional/OptionalChainingUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalChainingUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java similarity index 97% rename from core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java index 4cb2551fae..bd7943c77b 100644 --- a/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java +++ b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java @@ -27,34 +27,35 @@ public class OptionalUnitTest { @Test public void givenNonNull_whenCreatesNonNullable_thenCorrect() { String name = "baeldung"; - Optional.of(name); + Optional opt = Optional.of(name); + assertTrue(opt.isPresent()); } @Test(expected = NullPointerException.class) public void givenNull_whenThrowsErrorOnCreate_thenCorrect() { String name = null; - Optional opt = Optional.of(name); + Optional.of(name); } @Test public void givenNonNull_whenCreatesOptional_thenCorrect() { String name = "baeldung"; Optional opt = Optional.of(name); - assertEquals("Optional[baeldung]", opt.toString()); + assertTrue(opt.isPresent()); } @Test public void givenNonNull_whenCreatesNullable_thenCorrect() { String name = "baeldung"; Optional opt = Optional.ofNullable(name); - assertEquals("Optional[baeldung]", opt.toString()); + assertTrue(opt.isPresent()); } @Test public void givenNull_whenCreatesNullable_thenCorrect() { String name = null; Optional opt = Optional.ofNullable(name); - assertEquals("Optional.empty", opt.toString()); + assertFalse(opt.isPresent()); } // Checking Value With isPresent() diff --git a/core-java-8/src/test/java/com/baeldung/java8/optional/OrElseAndOrElseGetUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/java8/optional/OrElseAndOrElseGetUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/java8/optional/OrElseAndOrElseGetUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/java8/optional/OrElseAndOrElseGetUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/math/MathNewMethodsUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/math/MathNewMethodsUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/math/MathNewMethodsUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/math/MathNewMethodsUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNullUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNullUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNullUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNullUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainerUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainerUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainerUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainerUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheckUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheckUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheckUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheckUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/optional/PersonRepositoryUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/optional/PersonRepositoryUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/optional/PersonRepositoryUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/optional/PersonRepositoryUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/reduceIfelse/CalculatorUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/reduceIfelse/CalculatorUnitTest.java similarity index 80% rename from core-java-8/src/test/java/com/baeldung/reduceIfelse/CalculatorUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/reduceIfelse/CalculatorUnitTest.java index fa351930d8..1ff34bee89 100644 --- a/core-java-8/src/test/java/com/baeldung/reduceIfelse/CalculatorUnitTest.java +++ b/core-java-modules/core-java-8/src/test/java/com/baeldung/reduceIfelse/CalculatorUnitTest.java @@ -29,4 +29,11 @@ public class CalculatorUnitTest { int result = calculator.calculate(new AddCommand(3, 7)); assertEquals(10, result); } + + @Test + public void whenCalculateUsingFactory_thenReturnCorrectResult() { + Calculator calculator = new Calculator(); + int result = calculator.calculateUsingFactory(3, 4, "add"); + assertEquals(7, result); + } } diff --git a/core-java-8/src/test/java/com/baeldung/reduceIfelse/RuleEngineUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/reduceIfelse/RuleEngineUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/reduceIfelse/RuleEngineUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/reduceIfelse/RuleEngineUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameUnitTest.java similarity index 97% rename from core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameUnitTest.java index b191c94826..dadd6d7543 100644 --- a/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameUnitTest.java +++ b/core-java-modules/core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameUnitTest.java @@ -1,34 +1,34 @@ -package com.baeldung.reflect; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.lang.reflect.Parameter; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import org.junit.Test; - -public class MethodParamNameUnitTest { - - @Test - public void whenGetConstructorParams_thenOk() - throws NoSuchMethodException, SecurityException { - List parameters - = Arrays.asList(Person.class.getConstructor(String.class).getParameters()); - Optional parameter - = parameters.stream().filter(Parameter::isNamePresent).findFirst(); - assertThat(parameter.get().getName()).isEqualTo("fullName"); - } - - @Test - public void whenGetMethodParams_thenOk() - throws NoSuchMethodException, SecurityException { - List parameters - = Arrays.asList( - Person.class.getMethod("setFullName", String.class).getParameters()); - Optional parameter - = parameters.stream().filter(Parameter::isNamePresent).findFirst(); - assertThat(parameter.get().getName()).isEqualTo("fullName"); - } -} +package com.baeldung.reflect; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.lang.reflect.Parameter; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import org.junit.Test; + +public class MethodParamNameUnitTest { + + @Test + public void whenGetConstructorParams_thenOk() + throws NoSuchMethodException, SecurityException { + List parameters + = Arrays.asList(Person.class.getConstructor(String.class).getParameters()); + Optional parameter + = parameters.stream().filter(Parameter::isNamePresent).findFirst(); + assertThat(parameter.get().getName()).isEqualTo("fullName"); + } + + @Test + public void whenGetMethodParams_thenOk() + throws NoSuchMethodException, SecurityException { + List parameters + = Arrays.asList( + Person.class.getMethod("setFullName", String.class).getParameters()); + Optional parameter + = parameters.stream().filter(Parameter::isNamePresent).findFirst(); + assertThat(parameter.get().getName()).isEqualTo("fullName"); + } +} diff --git a/core-java-8/src/test/java/com/baeldung/spliteratorAPI/ExecutorUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/spliteratorAPI/ExecutorUnitTest.java similarity index 97% rename from core-java-8/src/test/java/com/baeldung/spliteratorAPI/ExecutorUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/spliteratorAPI/ExecutorUnitTest.java index 81fad12eb0..6981898500 100644 --- a/core-java-8/src/test/java/com/baeldung/spliteratorAPI/ExecutorUnitTest.java +++ b/core-java-modules/core-java-8/src/test/java/com/baeldung/spliteratorAPI/ExecutorUnitTest.java @@ -1,44 +1,44 @@ -package com.baeldung.spliteratorAPI; - -import java.util.Arrays; -import java.util.Spliterator; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -import static org.assertj.core.api.Assertions.*; -import org.junit.Before; -import org.junit.Test; - -public class ExecutorUnitTest { - Article article; - Stream stream; - Spliterator spliterator; - Spliterator
split1; - Spliterator
split2; - - @Before - public void init() { - article = new Article(Arrays.asList(new Author("Ahmad", 0), new Author("Eugen", 0), new Author("Alice", 1), - new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), - new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), - new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), - new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), - new Author("Mike", 0), new Author("Michał", 0), new Author("Loredana", 1)), 0); - stream = article.getListOfAuthors().stream(); - split1 = Executor.generateElements().spliterator(); - split2 = split1.trySplit(); - spliterator = new RelatedAuthorSpliterator(article.getListOfAuthors()); - } - - @Test - public void givenAstreamOfAuthors_whenProcessedInParallelWithCustomSpliterator_coubtProducessRightOutput() { - Stream stream2 = StreamSupport.stream(spliterator, true); - assertThat(Executor.countAutors(stream2.parallel())).isEqualTo(9); - } - - @Test - public void givenSpliterator_whenAppliedToAListOfArticle_thenSplittedInHalf() { - assertThat(new Task(split1).call()).containsSequence(Executor.generateElements().size() / 2 + ""); - assertThat(new Task(split2).call()).containsSequence(Executor.generateElements().size() / 2 + ""); - } -} +package com.baeldung.spliteratorAPI; + +import java.util.Arrays; +import java.util.Spliterator; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +import static org.assertj.core.api.Assertions.*; +import org.junit.Before; +import org.junit.Test; + +public class ExecutorUnitTest { + Article article; + Stream stream; + Spliterator spliterator; + Spliterator
split1; + Spliterator
split2; + + @Before + public void init() { + article = new Article(Arrays.asList(new Author("Ahmad", 0), new Author("Eugen", 0), new Author("Alice", 1), + new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), + new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), + new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), + new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), + new Author("Mike", 0), new Author("Michał", 0), new Author("Loredana", 1)), 0); + stream = article.getListOfAuthors().stream(); + split1 = Executor.generateElements().spliterator(); + split2 = split1.trySplit(); + spliterator = new RelatedAuthorSpliterator(article.getListOfAuthors()); + } + + @Test + public void givenAstreamOfAuthors_whenProcessedInParallelWithCustomSpliterator_coubtProducessRightOutput() { + Stream stream2 = StreamSupport.stream(spliterator, true); + assertThat(Executor.countAutors(stream2.parallel())).isEqualTo(9); + } + + @Test + public void givenSpliterator_whenAppliedToAListOfArticle_thenSplittedInHalf() { + assertThat(new Task(split1).call()).containsSequence(Executor.generateElements().size() / 2 + ""); + assertThat(new Task(split2).call()).containsSequence(Executor.generateElements().size() / 2 + ""); + } +} diff --git a/core-java-8/src/test/java/com/baeldung/strategy/StrategyDesignPatternUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/strategy/StrategyDesignPatternUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/strategy/StrategyDesignPatternUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/strategy/StrategyDesignPatternUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/stream/conditional/StreamForEachIfElseUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/stream/conditional/StreamForEachIfElseUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/stream/conditional/StreamForEachIfElseUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/stream/conditional/StreamForEachIfElseUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/streamreduce/tests/StreamReduceManualTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/streamreduce/tests/StreamReduceManualTest.java similarity index 97% rename from core-java-8/src/test/java/com/baeldung/streamreduce/tests/StreamReduceManualTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/streamreduce/tests/StreamReduceManualTest.java index 9222cbb689..0bf1a5837e 100644 --- a/core-java-8/src/test/java/com/baeldung/streamreduce/tests/StreamReduceManualTest.java +++ b/core-java-modules/core-java-8/src/test/java/com/baeldung/streamreduce/tests/StreamReduceManualTest.java @@ -1,126 +1,126 @@ -package com.baeldung.streamreduce.tests; - -import com.baeldung.streamreduce.entities.User; -import com.baeldung.streamreduce.utilities.NumberUtils; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; - -public class StreamReduceManualTest { - - @Test - public void givenIntegerList_whenReduceWithSumAccumulatorLambda_thenCorrect() { - List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); - - int result = numbers.stream().reduce(0, (a, b) -> a + b); - - assertThat(result).isEqualTo(21); - } - - @Test - public void givenIntegerList_whenReduceWithSumAccumulatorMethodReference_thenCorrect() { - List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); - - int result = numbers.stream().reduce(0, Integer::sum); - - assertThat(result).isEqualTo(21); - } - - @Test - public void givenStringList_whenReduceWithConcatenatorAccumulatorLambda_thenCorrect() { - List letters = Arrays.asList("a", "b", "c", "d", "e"); - - String result = letters.stream().reduce("", (a, b) -> a + b); - - assertThat(result).isEqualTo("abcde"); - } - - @Test - public void givenStringList_whenReduceWithConcatenatorAccumulatorMethodReference_thenCorrect() { - List letters = Arrays.asList("a", "b", "c", "d", "e"); - - String result = letters.stream().reduce("", String::concat); - - assertThat(result).isEqualTo("abcde"); - } - - @Test - public void givenStringList_whenReduceWithUppercaseConcatenatorAccumulator_thenCorrect() { - List letters = Arrays.asList("a", "b", "c", "d", "e"); - - String result = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase()); - - assertThat(result).isEqualTo("ABCDE"); - } - - @Test - public void givenUserList_whenReduceWithAgeAccumulatorAndSumCombiner_thenCorrect() { - List users = Arrays.asList(new User("John", 30), new User("Julie", 35)); - - int result = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); - - assertThat(result).isEqualTo(65); - } - - @Test - public void givenStringList_whenReduceWithParallelStream_thenCorrect() { - List letters = Arrays.asList("a", "b", "c", "d", "e"); - - String result = letters.parallelStream().reduce("", String::concat); - - assertThat(result).isEqualTo("abcde"); - } - - @Test - public void givenNumberUtilsClass_whenCalledDivideListElements_thenCorrect() { - List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); - - assertThat(NumberUtils.divideListElements(numbers, 1)).isEqualTo(21); - } - - @Test - public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlock_thenCorrect() { - List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); - - assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21); - } - - @Test - public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlockAndListContainsZero_thenCorrect() { - List numbers = Arrays.asList(0, 1, 2, 3, 4, 5, 6); - - assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21); - } - - @Test - public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlockAndDividerIsZero_thenCorrect() { - List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); - - assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 0)).isEqualTo(0); - } - - @Test - public void givenStream_whneCalleddivideListElementsWithApplyFunctionMethod_thenCorrect() { - List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); - - assertThat(NumberUtils.divideListElementsWithApplyFunctionMethod(numbers, 1)).isEqualTo(21); - } - - @Test - public void givenTwoStreams_whenCalledReduceOnParallelizedStream_thenFasterExecutionTime() { - List userList = new ArrayList<>(); - for (int i = 0; i <= 1000000; i++) { - userList.add(new User("John" + i, i)); - } - long currentTime1 = System.currentTimeMillis(); - userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); - long sequentialExecutionTime = System.currentTimeMillis() -currentTime1; - long currentTime2 = System.currentTimeMillis(); - userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); - long parallelizedExecutionTime = System.currentTimeMillis() - currentTime2; - - assertThat(parallelizedExecutionTime).isLessThan(sequentialExecutionTime); - } -} +package com.baeldung.streamreduce.tests; + +import com.baeldung.streamreduce.entities.User; +import com.baeldung.streamreduce.utilities.NumberUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; + +public class StreamReduceManualTest { + + @Test + public void givenIntegerList_whenReduceWithSumAccumulatorLambda_thenCorrect() { + List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); + + int result = numbers.stream().reduce(0, (a, b) -> a + b); + + assertThat(result).isEqualTo(21); + } + + @Test + public void givenIntegerList_whenReduceWithSumAccumulatorMethodReference_thenCorrect() { + List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); + + int result = numbers.stream().reduce(0, Integer::sum); + + assertThat(result).isEqualTo(21); + } + + @Test + public void givenStringList_whenReduceWithConcatenatorAccumulatorLambda_thenCorrect() { + List letters = Arrays.asList("a", "b", "c", "d", "e"); + + String result = letters.stream().reduce("", (a, b) -> a + b); + + assertThat(result).isEqualTo("abcde"); + } + + @Test + public void givenStringList_whenReduceWithConcatenatorAccumulatorMethodReference_thenCorrect() { + List letters = Arrays.asList("a", "b", "c", "d", "e"); + + String result = letters.stream().reduce("", String::concat); + + assertThat(result).isEqualTo("abcde"); + } + + @Test + public void givenStringList_whenReduceWithUppercaseConcatenatorAccumulator_thenCorrect() { + List letters = Arrays.asList("a", "b", "c", "d", "e"); + + String result = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase()); + + assertThat(result).isEqualTo("ABCDE"); + } + + @Test + public void givenUserList_whenReduceWithAgeAccumulatorAndSumCombiner_thenCorrect() { + List users = Arrays.asList(new User("John", 30), new User("Julie", 35)); + + int result = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); + + assertThat(result).isEqualTo(65); + } + + @Test + public void givenStringList_whenReduceWithParallelStream_thenCorrect() { + List letters = Arrays.asList("a", "b", "c", "d", "e"); + + String result = letters.parallelStream().reduce("", String::concat); + + assertThat(result).isEqualTo("abcde"); + } + + @Test + public void givenNumberUtilsClass_whenCalledDivideListElements_thenCorrect() { + List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); + + assertThat(NumberUtils.divideListElements(numbers, 1)).isEqualTo(21); + } + + @Test + public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlock_thenCorrect() { + List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); + + assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21); + } + + @Test + public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlockAndListContainsZero_thenCorrect() { + List numbers = Arrays.asList(0, 1, 2, 3, 4, 5, 6); + + assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21); + } + + @Test + public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlockAndDividerIsZero_thenCorrect() { + List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); + + assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 0)).isEqualTo(0); + } + + @Test + public void givenStream_whneCalleddivideListElementsWithApplyFunctionMethod_thenCorrect() { + List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); + + assertThat(NumberUtils.divideListElementsWithApplyFunctionMethod(numbers, 1)).isEqualTo(21); + } + + @Test + public void givenTwoStreams_whenCalledReduceOnParallelizedStream_thenFasterExecutionTime() { + List userList = new ArrayList<>(); + for (int i = 0; i <= 1000000; i++) { + userList.add(new User("John" + i, i)); + } + long currentTime1 = System.currentTimeMillis(); + userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); + long sequentialExecutionTime = System.currentTimeMillis() -currentTime1; + long currentTime2 = System.currentTimeMillis(); + userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); + long parallelizedExecutionTime = System.currentTimeMillis() - currentTime2; + + assertThat(parallelizedExecutionTime).isLessThan(sequentialExecutionTime); + } +} diff --git a/core-java-8/src/test/java/com/baeldung/time/InstantUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/time/InstantUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/time/InstantUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/time/InstantUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/time/InstantWithJMockUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/time/InstantWithJMockUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/time/InstantWithJMockUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/time/InstantWithJMockUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/time/LocalDateTimeWithJMockUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/time/LocalDateTimeWithJMockUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/time/LocalDateTimeWithJMockUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/time/LocalDateTimeWithJMockUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/typeinference/TypeInferenceUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/typeinference/TypeInferenceUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/typeinference/TypeInferenceUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/typeinference/TypeInferenceUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/util/CurrentDateTimeUnitTest.java b/core-java-modules/core-java-8/src/test/java/com/baeldung/util/CurrentDateTimeUnitTest.java similarity index 100% rename from core-java-8/src/test/java/com/baeldung/util/CurrentDateTimeUnitTest.java rename to core-java-modules/core-java-8/src/test/java/com/baeldung/util/CurrentDateTimeUnitTest.java diff --git a/core-java-8/src/test/resources/.gitignore b/core-java-modules/core-java-8/src/test/resources/.gitignore similarity index 100% rename from core-java-8/src/test/resources/.gitignore rename to core-java-modules/core-java-8/src/test/resources/.gitignore diff --git a/core-java-9/.gitignore b/core-java-modules/core-java-9/.gitignore similarity index 100% rename from core-java-9/.gitignore rename to core-java-modules/core-java-9/.gitignore diff --git a/core-java-9/README.md b/core-java-modules/core-java-9/README.md similarity index 100% rename from core-java-9/README.md rename to core-java-modules/core-java-9/README.md diff --git a/core-java-9/compile-aot.sh b/core-java-modules/core-java-9/compile-aot.sh old mode 100755 new mode 100644 similarity index 100% rename from core-java-9/compile-aot.sh rename to core-java-modules/core-java-9/compile-aot.sh diff --git a/core-java-9/compile-httpclient.bat b/core-java-modules/core-java-9/compile-httpclient.bat similarity index 100% rename from core-java-9/compile-httpclient.bat rename to core-java-modules/core-java-9/compile-httpclient.bat diff --git a/core-java-9/compile-modules.sh b/core-java-modules/core-java-9/compile-modules.sh old mode 100755 new mode 100644 similarity index 100% rename from core-java-9/compile-modules.sh rename to core-java-modules/core-java-9/compile-modules.sh diff --git a/core-java-9/compile-simple-modules.sh b/core-java-modules/core-java-9/compile-simple-modules.sh old mode 100755 new mode 100644 similarity index 100% rename from core-java-9/compile-simple-modules.sh rename to core-java-modules/core-java-9/compile-simple-modules.sh diff --git a/core-java-9/compile-student-client.bat b/core-java-modules/core-java-9/compile-student-client.bat similarity index 100% rename from core-java-9/compile-student-client.bat rename to core-java-modules/core-java-9/compile-student-client.bat diff --git a/core-java-9/compile-student-model.bat b/core-java-modules/core-java-9/compile-student-model.bat similarity index 100% rename from core-java-9/compile-student-model.bat rename to core-java-modules/core-java-9/compile-student-model.bat diff --git a/core-java-9/compile-student-service-dbimpl.bat b/core-java-modules/core-java-9/compile-student-service-dbimpl.bat similarity index 100% rename from core-java-9/compile-student-service-dbimpl.bat rename to core-java-modules/core-java-9/compile-student-service-dbimpl.bat diff --git a/core-java-9/compile-student-service.bat b/core-java-modules/core-java-9/compile-student-service.bat similarity index 100% rename from core-java-9/compile-student-service.bat rename to core-java-modules/core-java-9/compile-student-service.bat diff --git a/core-java-9/logging.sh b/core-java-modules/core-java-9/logging.sh old mode 100755 new mode 100644 similarity index 100% rename from core-java-9/logging.sh rename to core-java-modules/core-java-9/logging.sh diff --git a/core-java-9/mods/logback.xml b/core-java-modules/core-java-9/mods/logback.xml similarity index 100% rename from core-java-9/mods/logback.xml rename to core-java-modules/core-java-9/mods/logback.xml diff --git a/core-java-9/pom.xml b/core-java-modules/core-java-9/pom.xml similarity index 98% rename from core-java-9/pom.xml rename to core-java-modules/core-java-9/pom.xml index cd1fa74dbb..aee289c79f 100644 --- a/core-java-9/pom.xml +++ b/core-java-modules/core-java-9/pom.xml @@ -9,6 +9,7 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT + ../../ diff --git a/core-java-9/run-aot.sh b/core-java-modules/core-java-9/run-aot.sh old mode 100755 new mode 100644 similarity index 100% rename from core-java-9/run-aot.sh rename to core-java-modules/core-java-9/run-aot.sh diff --git a/core-java-9/run-httpclient.bat b/core-java-modules/core-java-9/run-httpclient.bat similarity index 100% rename from core-java-9/run-httpclient.bat rename to core-java-modules/core-java-9/run-httpclient.bat diff --git a/core-java-9/run-simple-module-app.sh b/core-java-modules/core-java-9/run-simple-module-app.sh old mode 100755 new mode 100644 similarity index 100% rename from core-java-9/run-simple-module-app.sh rename to core-java-modules/core-java-9/run-simple-module-app.sh diff --git a/core-java-9/run-student-client.bat b/core-java-modules/core-java-9/run-student-client.bat similarity index 100% rename from core-java-9/run-student-client.bat rename to core-java-modules/core-java-9/run-student-client.bat diff --git a/core-java-9/run-student-client.sh b/core-java-modules/core-java-9/run-student-client.sh old mode 100755 new mode 100644 similarity index 100% rename from core-java-9/run-student-client.sh rename to core-java-modules/core-java-9/run-student-client.sh diff --git a/core-java-9/src/main/java/.gitignore b/core-java-modules/core-java-9/src/main/java/.gitignore similarity index 100% rename from core-java-9/src/main/java/.gitignore rename to core-java-modules/core-java-9/src/main/java/.gitignore diff --git a/core-java-9/src/main/java/com/baeldung/java9/aot/JaotCompilation.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/aot/JaotCompilation.java similarity index 100% rename from core-java-9/src/main/java/com/baeldung/java9/aot/JaotCompilation.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/java9/aot/JaotCompilation.java diff --git a/core-java-9/src/main/java/com/baeldung/java9/language/PrivateInterface.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/language/PrivateInterface.java similarity index 96% rename from core-java-9/src/main/java/com/baeldung/java9/language/PrivateInterface.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/java9/language/PrivateInterface.java index f7b2fad891..3055f82fdb 100644 --- a/core-java-9/src/main/java/com/baeldung/java9/language/PrivateInterface.java +++ b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/language/PrivateInterface.java @@ -1,23 +1,23 @@ -package com.baeldung.java9.language; - -public interface PrivateInterface { - - private static String staticPrivate() { - return "static private"; - } - - private String instancePrivate() { - return "instance private"; - } - - public default void check() { - String result = staticPrivate(); - if (!result.equals("static private")) - throw new AssertionError("Incorrect result for static private interface method"); - PrivateInterface pvt = new PrivateInterface() { - }; - result = pvt.instancePrivate(); - if (!result.equals("instance private")) - throw new AssertionError("Incorrect result for instance private interface method"); - } -} +package com.baeldung.java9.language; + +public interface PrivateInterface { + + private static String staticPrivate() { + return "static private"; + } + + private String instancePrivate() { + return "instance private"; + } + + public default void check() { + String result = staticPrivate(); + if (!result.equals("static private")) + throw new AssertionError("Incorrect result for static private interface method"); + PrivateInterface pvt = new PrivateInterface() { + }; + result = pvt.instancePrivate(); + if (!result.equals("instance private")) + throw new AssertionError("Incorrect result for instance private interface method"); + } +} diff --git a/core-java-9/src/main/java/com/baeldung/java9/language/stream/StreamsGroupingCollectionFilter.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/language/stream/StreamsGroupingCollectionFilter.java similarity index 100% rename from core-java-9/src/main/java/com/baeldung/java9/language/stream/StreamsGroupingCollectionFilter.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/java9/language/stream/StreamsGroupingCollectionFilter.java diff --git a/core-java-9/src/main/java/com/baeldung/java9/maps/initialize/MapsInitializer.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/maps/initialize/MapsInitializer.java similarity index 100% rename from core-java-9/src/main/java/com/baeldung/java9/maps/initialize/MapsInitializer.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/java9/maps/initialize/MapsInitializer.java diff --git a/core-java-9/src/main/java/com/baeldung/java9/methodhandles/Book.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/methodhandles/Book.java similarity index 100% rename from core-java-9/src/main/java/com/baeldung/java9/methodhandles/Book.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/java9/methodhandles/Book.java diff --git a/core-java-9/src/main/java/com/baeldung/java9/rangedates/DatesCollectionIteration.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/rangedates/DatesCollectionIteration.java similarity index 100% rename from core-java-9/src/main/java/com/baeldung/java9/rangedates/DatesCollectionIteration.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/java9/rangedates/DatesCollectionIteration.java diff --git a/core-java-9/src/main/java/com/baeldung/java9/rangedates/RangeDatesIteration.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/rangedates/RangeDatesIteration.java similarity index 100% rename from core-java-9/src/main/java/com/baeldung/java9/rangedates/RangeDatesIteration.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/java9/rangedates/RangeDatesIteration.java diff --git a/core-java-9/src/main/java/com/baeldung/java9/reactive/BaeldungBatchSubscriberImpl.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/reactive/BaeldungBatchSubscriberImpl.java similarity index 96% rename from core-java-9/src/main/java/com/baeldung/java9/reactive/BaeldungBatchSubscriberImpl.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/java9/reactive/BaeldungBatchSubscriberImpl.java index 46eee4883a..962df447b6 100644 --- a/core-java-9/src/main/java/com/baeldung/java9/reactive/BaeldungBatchSubscriberImpl.java +++ b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/reactive/BaeldungBatchSubscriberImpl.java @@ -1,82 +1,82 @@ -package com.baeldung.java9.reactive; - -import java.util.ArrayList; -import java.util.concurrent.Flow.Subscriber; -import java.util.concurrent.Flow.Subscription; - -public class BaeldungBatchSubscriberImpl implements Subscriber { - private Subscription subscription; - private boolean completed = false; - private int counter; - private ArrayList buffer; - public static final int BUFFER_SIZE = 5; - - public BaeldungBatchSubscriberImpl() { - buffer = new ArrayList(); - } - - public boolean isCompleted() { - return completed; - } - - public void setCompleted(boolean completed) { - this.completed = completed; - } - - public int getCounter() { - return counter; - } - - public void setCounter(int counter) { - this.counter = counter; - } - - @Override - public void onSubscribe(Subscription subscription) { - this.subscription = subscription; - subscription.request(BUFFER_SIZE); - } - - @Override - public void onNext(String item) { - buffer.add(item); - // if buffer is full, process the items. - if (buffer.size() >= BUFFER_SIZE) { - processBuffer(); - } - //request more items. - subscription.request(1); - } - - private void processBuffer() { - if (buffer.isEmpty()) - return; - // Process all items in the buffer. Here, we just print it and sleep for 1 second. - System.out.print("Processed items: "); - buffer.stream() - .forEach(item -> { - System.out.print(" " + item); - }); - System.out.println(); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - counter = counter + buffer.size(); - buffer.clear(); - } - - @Override - public void onError(Throwable t) { - t.printStackTrace(); - } - - @Override - public void onComplete() { - completed = true; - // process any remaining items in buffer before - processBuffer(); - subscription.cancel(); - } -} +package com.baeldung.java9.reactive; + +import java.util.ArrayList; +import java.util.concurrent.Flow.Subscriber; +import java.util.concurrent.Flow.Subscription; + +public class BaeldungBatchSubscriberImpl implements Subscriber { + private Subscription subscription; + private boolean completed = false; + private int counter; + private ArrayList buffer; + public static final int BUFFER_SIZE = 5; + + public BaeldungBatchSubscriberImpl() { + buffer = new ArrayList(); + } + + public boolean isCompleted() { + return completed; + } + + public void setCompleted(boolean completed) { + this.completed = completed; + } + + public int getCounter() { + return counter; + } + + public void setCounter(int counter) { + this.counter = counter; + } + + @Override + public void onSubscribe(Subscription subscription) { + this.subscription = subscription; + subscription.request(BUFFER_SIZE); + } + + @Override + public void onNext(String item) { + buffer.add(item); + // if buffer is full, process the items. + if (buffer.size() >= BUFFER_SIZE) { + processBuffer(); + } + //request more items. + subscription.request(1); + } + + private void processBuffer() { + if (buffer.isEmpty()) + return; + // Process all items in the buffer. Here, we just print it and sleep for 1 second. + System.out.print("Processed items: "); + buffer.stream() + .forEach(item -> { + System.out.print(" " + item); + }); + System.out.println(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + counter = counter + buffer.size(); + buffer.clear(); + } + + @Override + public void onError(Throwable t) { + t.printStackTrace(); + } + + @Override + public void onComplete() { + completed = true; + // process any remaining items in buffer before + processBuffer(); + subscription.cancel(); + } +} diff --git a/core-java-9/src/main/java/com/baeldung/java9/reactive/BaeldungSubscriberImpl.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/reactive/BaeldungSubscriberImpl.java similarity index 95% rename from core-java-9/src/main/java/com/baeldung/java9/reactive/BaeldungSubscriberImpl.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/java9/reactive/BaeldungSubscriberImpl.java index bacd777255..3534324675 100644 --- a/core-java-9/src/main/java/com/baeldung/java9/reactive/BaeldungSubscriberImpl.java +++ b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/reactive/BaeldungSubscriberImpl.java @@ -1,55 +1,55 @@ -package com.baeldung.java9.reactive; - -import java.util.concurrent.Flow.Subscriber; -import java.util.concurrent.Flow.Subscription; - -public class BaeldungSubscriberImpl implements Subscriber { - private Subscription subscription; - private boolean completed = false; - private int counter; - - public boolean isCompleted() { - return completed; - } - - public void setCompleted(boolean completed) { - this.completed = completed; - } - - public int getCounter() { - return counter; - } - - public void setCounter(int counter) { - this.counter = counter; - } - - @Override - public void onSubscribe(Subscription subscription) { - this.subscription = subscription; - subscription.request(1); - } - - @Override - public void onNext(String item) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - counter++; - System.out.println("Processed item : " + item); - subscription.request(1); - } - - @Override - public void onError(Throwable t) { - t.printStackTrace(); - } - - @Override - public void onComplete() { - completed = true; - subscription.cancel(); - } -} +package com.baeldung.java9.reactive; + +import java.util.concurrent.Flow.Subscriber; +import java.util.concurrent.Flow.Subscription; + +public class BaeldungSubscriberImpl implements Subscriber { + private Subscription subscription; + private boolean completed = false; + private int counter; + + public boolean isCompleted() { + return completed; + } + + public void setCompleted(boolean completed) { + this.completed = completed; + } + + public int getCounter() { + return counter; + } + + public void setCounter(int counter) { + this.counter = counter; + } + + @Override + public void onSubscribe(Subscription subscription) { + this.subscription = subscription; + subscription.request(1); + } + + @Override + public void onNext(String item) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + counter++; + System.out.println("Processed item : " + item); + subscription.request(1); + } + + @Override + public void onError(Throwable t) { + t.printStackTrace(); + } + + @Override + public void onComplete() { + completed = true; + subscription.cancel(); + } +} diff --git a/core-java-9/src/main/java/com/baeldung/java9/set/UnmodifiableSet.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/set/UnmodifiableSet.java similarity index 100% rename from core-java-9/src/main/java/com/baeldung/java9/set/UnmodifiableSet.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/java9/set/UnmodifiableSet.java diff --git a/core-java-9/src/main/java/com/baeldung/java9/stackwalker/StackWalkerDemo.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/stackwalker/StackWalkerDemo.java similarity index 100% rename from core-java-9/src/main/java/com/baeldung/java9/stackwalker/StackWalkerDemo.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/java9/stackwalker/StackWalkerDemo.java diff --git a/core-java-9/src/main/java/com/baeldung/java9/streams.reactive/EndSubscriber.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/streams.reactive/EndSubscriber.java similarity index 100% rename from core-java-9/src/main/java/com/baeldung/java9/streams.reactive/EndSubscriber.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/java9/streams.reactive/EndSubscriber.java diff --git a/core-java-9/src/main/java/com/baeldung/java9/streams.reactive/TransformProcessor.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/java9/streams.reactive/TransformProcessor.java similarity index 100% rename from core-java-9/src/main/java/com/baeldung/java9/streams.reactive/TransformProcessor.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/java9/streams.reactive/TransformProcessor.java diff --git a/core-java-9/src/main/java/com/baeldung/multireleaseapp/App.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/multireleaseapp/App.java similarity index 100% rename from core-java-9/src/main/java/com/baeldung/multireleaseapp/App.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/multireleaseapp/App.java diff --git a/core-java-9/src/main/java/com/baeldung/multireleaseapp/DateHelper.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/multireleaseapp/DateHelper.java similarity index 100% rename from core-java-9/src/main/java/com/baeldung/multireleaseapp/DateHelper.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/multireleaseapp/DateHelper.java diff --git a/core-java-9/src/main/java/com/baeldung/optionals/Optionals.java b/core-java-modules/core-java-9/src/main/java/com/baeldung/optionals/Optionals.java similarity index 100% rename from core-java-9/src/main/java/com/baeldung/optionals/Optionals.java rename to core-java-modules/core-java-9/src/main/java/com/baeldung/optionals/Optionals.java diff --git a/core-java-9/src/main/java9/com/baeldung/multireleaseapp/DateHelper.java b/core-java-modules/core-java-9/src/main/java9/com/baeldung/multireleaseapp/DateHelper.java similarity index 100% rename from core-java-9/src/main/java9/com/baeldung/multireleaseapp/DateHelper.java rename to core-java-modules/core-java-9/src/main/java9/com/baeldung/multireleaseapp/DateHelper.java diff --git a/core-java-9/src/main/resources/logback.xml b/core-java-modules/core-java-9/src/main/resources/logback.xml similarity index 100% rename from core-java-9/src/main/resources/logback.xml rename to core-java-modules/core-java-9/src/main/resources/logback.xml diff --git a/core-java-9/src/modules/com.baeldung.httpclient/com/baeldung/httpclient/HttpClientExample.java b/core-java-modules/core-java-9/src/modules/com.baeldung.httpclient/com/baeldung/httpclient/HttpClientExample.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.httpclient/com/baeldung/httpclient/HttpClientExample.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.httpclient/com/baeldung/httpclient/HttpClientExample.java diff --git a/core-java-9/src/modules/com.baeldung.httpclient/module-info.java b/core-java-modules/core-java-9/src/modules/com.baeldung.httpclient/module-info.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.httpclient/module-info.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.httpclient/module-info.java diff --git a/core-java-9/src/modules/com.baeldung.logging.app/com/baeldung/logging/app/MainApp.java b/core-java-modules/core-java-9/src/modules/com.baeldung.logging.app/com/baeldung/logging/app/MainApp.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.logging.app/com/baeldung/logging/app/MainApp.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.logging.app/com/baeldung/logging/app/MainApp.java diff --git a/core-java-9/src/modules/com.baeldung.logging.app/module-info.java b/core-java-modules/core-java-9/src/modules/com.baeldung.logging.app/module-info.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.logging.app/module-info.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.logging.app/module-info.java diff --git a/core-java-9/src/modules/com.baeldung.logging.slf4j/com/baeldung/logging/slf4j/Slf4jLogger.java b/core-java-modules/core-java-9/src/modules/com.baeldung.logging.slf4j/com/baeldung/logging/slf4j/Slf4jLogger.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.logging.slf4j/com/baeldung/logging/slf4j/Slf4jLogger.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.logging.slf4j/com/baeldung/logging/slf4j/Slf4jLogger.java diff --git a/core-java-9/src/modules/com.baeldung.logging.slf4j/com/baeldung/logging/slf4j/Slf4jLoggerFinder.java b/core-java-modules/core-java-9/src/modules/com.baeldung.logging.slf4j/com/baeldung/logging/slf4j/Slf4jLoggerFinder.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.logging.slf4j/com/baeldung/logging/slf4j/Slf4jLoggerFinder.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.logging.slf4j/com/baeldung/logging/slf4j/Slf4jLoggerFinder.java diff --git a/core-java-9/src/modules/com.baeldung.logging.slf4j/module-info.java b/core-java-modules/core-java-9/src/modules/com.baeldung.logging.slf4j/module-info.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.logging.slf4j/module-info.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.logging.slf4j/module-info.java diff --git a/core-java-9/src/modules/com.baeldung.logging/com/baeldung/logging/ConsoleLogger.java b/core-java-modules/core-java-9/src/modules/com.baeldung.logging/com/baeldung/logging/ConsoleLogger.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.logging/com/baeldung/logging/ConsoleLogger.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.logging/com/baeldung/logging/ConsoleLogger.java diff --git a/core-java-9/src/modules/com.baeldung.logging/com/baeldung/logging/CustomLoggerFinder.java b/core-java-modules/core-java-9/src/modules/com.baeldung.logging/com/baeldung/logging/CustomLoggerFinder.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.logging/com/baeldung/logging/CustomLoggerFinder.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.logging/com/baeldung/logging/CustomLoggerFinder.java diff --git a/core-java-9/src/modules/com.baeldung.logging/module-info.java b/core-java-modules/core-java-9/src/modules/com.baeldung.logging/module-info.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.logging/module-info.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.logging/module-info.java diff --git a/core-java-9/src/modules/com.baeldung.student.client/com/baeldung/student/client/StudentClient.java b/core-java-modules/core-java-9/src/modules/com.baeldung.student.client/com/baeldung/student/client/StudentClient.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.student.client/com/baeldung/student/client/StudentClient.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.student.client/com/baeldung/student/client/StudentClient.java diff --git a/core-java-9/src/modules/com.baeldung.student.client/module-info.java b/core-java-modules/core-java-9/src/modules/com.baeldung.student.client/module-info.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.student.client/module-info.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.student.client/module-info.java diff --git a/core-java-9/src/modules/com.baeldung.student.model/com/baeldung/student/model/Student.java b/core-java-modules/core-java-9/src/modules/com.baeldung.student.model/com/baeldung/student/model/Student.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.student.model/com/baeldung/student/model/Student.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.student.model/com/baeldung/student/model/Student.java diff --git a/core-java-9/src/modules/com.baeldung.student.model/module-info.java b/core-java-modules/core-java-9/src/modules/com.baeldung.student.model/module-info.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.student.model/module-info.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.student.model/module-info.java diff --git a/core-java-9/src/modules/com.baeldung.student.service.dbimpl/com/baeldung/student/service/dbimpl/StudentDbService.java b/core-java-modules/core-java-9/src/modules/com.baeldung.student.service.dbimpl/com/baeldung/student/service/dbimpl/StudentDbService.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.student.service.dbimpl/com/baeldung/student/service/dbimpl/StudentDbService.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.student.service.dbimpl/com/baeldung/student/service/dbimpl/StudentDbService.java diff --git a/core-java-9/src/modules/com.baeldung.student.service.dbimpl/module-info.java b/core-java-modules/core-java-9/src/modules/com.baeldung.student.service.dbimpl/module-info.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.student.service.dbimpl/module-info.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.student.service.dbimpl/module-info.java diff --git a/core-java-9/src/modules/com.baeldung.student.service/com/baeldung/student/service/StudentService.java b/core-java-modules/core-java-9/src/modules/com.baeldung.student.service/com/baeldung/student/service/StudentService.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.student.service/com/baeldung/student/service/StudentService.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.student.service/com/baeldung/student/service/StudentService.java diff --git a/core-java-9/src/modules/com.baeldung.student.service/module-info.java b/core-java-modules/core-java-9/src/modules/com.baeldung.student.service/module-info.java similarity index 100% rename from core-java-9/src/modules/com.baeldung.student.service/module-info.java rename to core-java-modules/core-java-9/src/modules/com.baeldung.student.service/module-info.java diff --git a/core-java-9/src/simple-modules/hello.modules/com/baeldung/modules/hello/HelloInterface.java b/core-java-modules/core-java-9/src/simple-modules/hello.modules/com/baeldung/modules/hello/HelloInterface.java similarity index 100% rename from core-java-9/src/simple-modules/hello.modules/com/baeldung/modules/hello/HelloInterface.java rename to core-java-modules/core-java-9/src/simple-modules/hello.modules/com/baeldung/modules/hello/HelloInterface.java diff --git a/core-java-9/src/simple-modules/hello.modules/com/baeldung/modules/hello/HelloModules.java b/core-java-modules/core-java-9/src/simple-modules/hello.modules/com/baeldung/modules/hello/HelloModules.java similarity index 100% rename from core-java-9/src/simple-modules/hello.modules/com/baeldung/modules/hello/HelloModules.java rename to core-java-modules/core-java-9/src/simple-modules/hello.modules/com/baeldung/modules/hello/HelloModules.java diff --git a/core-java-9/src/simple-modules/hello.modules/module-info.java b/core-java-modules/core-java-9/src/simple-modules/hello.modules/module-info.java similarity index 100% rename from core-java-9/src/simple-modules/hello.modules/module-info.java rename to core-java-modules/core-java-9/src/simple-modules/hello.modules/module-info.java diff --git a/core-java-9/src/simple-modules/main.app/com/baeldung/modules/main/MainApp.java b/core-java-modules/core-java-9/src/simple-modules/main.app/com/baeldung/modules/main/MainApp.java similarity index 100% rename from core-java-9/src/simple-modules/main.app/com/baeldung/modules/main/MainApp.java rename to core-java-modules/core-java-9/src/simple-modules/main.app/com/baeldung/modules/main/MainApp.java diff --git a/core-java-9/src/simple-modules/main.app/module-info.java b/core-java-modules/core-java-9/src/simple-modules/main.app/module-info.java similarity index 100% rename from core-java-9/src/simple-modules/main.app/module-info.java rename to core-java-modules/core-java-9/src/simple-modules/main.app/module-info.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/Java9OptionalTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/Java9OptionalTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/Java9OptionalTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/Java9OptionalTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/Java9OptionalsStreamUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/Java9OptionalsStreamUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/Java9OptionalsStreamUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/Java9OptionalsStreamUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/MultiResultionImageUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/MultiResultionImageUnitTest.java similarity index 97% rename from core-java-9/src/test/java/com/baeldung/java9/MultiResultionImageUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/MultiResultionImageUnitTest.java index 2c383a44b4..442d85e3f2 100644 --- a/core-java-9/src/test/java/com/baeldung/java9/MultiResultionImageUnitTest.java +++ b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/MultiResultionImageUnitTest.java @@ -1,44 +1,44 @@ -package com.baeldung.java9; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; - -import java.awt.Image; -import java.awt.image.BaseMultiResolutionImage; -import java.awt.image.BufferedImage; -import java.awt.image.MultiResolutionImage; -import java.util.List; - -import org.junit.Test; - -public class MultiResultionImageUnitTest { - - @Test - public void baseMultiResImageTest() { - int baseIndex = 1; - int length = 4; - BufferedImage[] resolutionVariants = new BufferedImage[length]; - for (int i = 0; i < length; i++) { - resolutionVariants[i] = createImage(i); - } - MultiResolutionImage bmrImage = new BaseMultiResolutionImage(baseIndex, resolutionVariants); - List rvImageList = bmrImage.getResolutionVariants(); - assertEquals("MultiResoltion Image shoudl contain the same number of resolution variants!", rvImageList.size(), length); - - for (int i = 0; i < length; i++) { - int imageSize = getSize(i); - Image testRVImage = bmrImage.getResolutionVariant(imageSize, imageSize); - assertSame("Images should be the same", testRVImage, resolutionVariants[i]); - } - - } - - private static int getSize(int i) { - return 8 * (i + 1); - } - - private static BufferedImage createImage(int i) { - return new BufferedImage(getSize(i), getSize(i), BufferedImage.TYPE_INT_RGB); - } - -} +package com.baeldung.java9; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import java.awt.Image; +import java.awt.image.BaseMultiResolutionImage; +import java.awt.image.BufferedImage; +import java.awt.image.MultiResolutionImage; +import java.util.List; + +import org.junit.Test; + +public class MultiResultionImageUnitTest { + + @Test + public void baseMultiResImageTest() { + int baseIndex = 1; + int length = 4; + BufferedImage[] resolutionVariants = new BufferedImage[length]; + for (int i = 0; i < length; i++) { + resolutionVariants[i] = createImage(i); + } + MultiResolutionImage bmrImage = new BaseMultiResolutionImage(baseIndex, resolutionVariants); + List rvImageList = bmrImage.getResolutionVariants(); + assertEquals("MultiResoltion Image shoudl contain the same number of resolution variants!", rvImageList.size(), length); + + for (int i = 0; i < length; i++) { + int imageSize = getSize(i); + Image testRVImage = bmrImage.getResolutionVariant(imageSize, imageSize); + assertSame("Images should be the same", testRVImage, resolutionVariants[i]); + } + + } + + private static int getSize(int i) { + return 8 * (i + 1); + } + + private static BufferedImage createImage(int i) { + return new BufferedImage(getSize(i), getSize(i), BufferedImage.TYPE_INT_RGB); + } + +} diff --git a/core-java-9/src/test/java/com/baeldung/java9/OptionalToStreamUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/OptionalToStreamUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/OptionalToStreamUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/OptionalToStreamUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/README.MD b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/README.MD similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/README.MD rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/README.MD diff --git a/core-java-9/src/test/java/com/baeldung/java9/SetExamplesUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/SetExamplesUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/SetExamplesUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/SetExamplesUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/concurrent/future/CompletableFutureUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/concurrent/future/CompletableFutureUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/concurrent/future/CompletableFutureUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/concurrent/future/CompletableFutureUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/httpclient/HttpClientTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/httpclient/HttpClientTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/httpclient/HttpClientTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/httpclient/HttpClientTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/httpclient/HttpRequestTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/httpclient/HttpRequestTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/httpclient/HttpRequestTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/httpclient/HttpRequestTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/httpclient/HttpResponseTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/httpclient/HttpResponseTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/httpclient/HttpResponseTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/httpclient/HttpResponseTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/DiamondUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/DiamondUnitTest.java similarity index 95% rename from core-java-9/src/test/java/com/baeldung/java9/language/DiamondUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/DiamondUnitTest.java index 4868d37b6a..b1cb4ef63b 100644 --- a/core-java-9/src/test/java/com/baeldung/java9/language/DiamondUnitTest.java +++ b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/DiamondUnitTest.java @@ -1,36 +1,36 @@ -package com.baeldung.java9.language; - -import org.junit.Test; - -public class DiamondUnitTest { - - static class FooClass { - FooClass(X x) { - } - - FooClass(X x, Z z) { - } - } - - @Test - public void diamondTest() { - FooClass fc = new FooClass<>(1) { - }; - FooClass fc0 = new FooClass<>(1) { - }; - FooClass fc1 = new FooClass<>(1) { - }; - FooClass fc2 = new FooClass<>(1) { - }; - - FooClass fc3 = new FooClass<>(1, "") { - }; - FooClass fc4 = new FooClass<>(1, "") { - }; - FooClass fc5 = new FooClass<>(1, "") { - }; - FooClass fc6 = new FooClass<>(1, "") { - }; - - } -} +package com.baeldung.java9.language; + +import org.junit.Test; + +public class DiamondUnitTest { + + static class FooClass { + FooClass(X x) { + } + + FooClass(X x, Z z) { + } + } + + @Test + public void diamondTest() { + FooClass fc = new FooClass<>(1) { + }; + FooClass fc0 = new FooClass<>(1) { + }; + FooClass fc1 = new FooClass<>(1) { + }; + FooClass fc2 = new FooClass<>(1) { + }; + + FooClass fc3 = new FooClass<>(1, "") { + }; + FooClass fc4 = new FooClass<>(1, "") { + }; + FooClass fc5 = new FooClass<>(1, "") { + }; + FooClass fc6 = new FooClass<>(1, "") { + }; + + } +} diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/Java9ObjectsAPIUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/Java9ObjectsAPIUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/language/Java9ObjectsAPIUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/Java9ObjectsAPIUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/PrivateInterfaceUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/PrivateInterfaceUnitTest.java similarity index 95% rename from core-java-9/src/test/java/com/baeldung/java9/language/PrivateInterfaceUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/PrivateInterfaceUnitTest.java index fb00fe45c3..08aee72f6e 100644 --- a/core-java-9/src/test/java/com/baeldung/java9/language/PrivateInterfaceUnitTest.java +++ b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/PrivateInterfaceUnitTest.java @@ -1,15 +1,15 @@ -package com.baeldung.java9.language; - -import com.baeldung.java9.language.PrivateInterface; -import org.junit.Test; - -public class PrivateInterfaceUnitTest { - - @Test - public void test() { - PrivateInterface piClass = new PrivateInterface() { - }; - piClass.check(); - } - -} +package com.baeldung.java9.language; + +import com.baeldung.java9.language.PrivateInterface; +import org.junit.Test; + +public class PrivateInterfaceUnitTest { + + @Test + public void test() { + PrivateInterface piClass = new PrivateInterface() { + }; + piClass.check(); + } + +} diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/TryWithResourcesUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/TryWithResourcesUnitTest.java similarity index 96% rename from core-java-9/src/test/java/com/baeldung/java9/language/TryWithResourcesUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/TryWithResourcesUnitTest.java index d623bd9965..9afa1c90dd 100644 --- a/core-java-9/src/test/java/com/baeldung/java9/language/TryWithResourcesUnitTest.java +++ b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/TryWithResourcesUnitTest.java @@ -1,67 +1,67 @@ -package com.baeldung.java9.language; - -import static org.junit.Assert.assertEquals; -import org.junit.Test; - -public class TryWithResourcesUnitTest { - - static int closeCount = 0; - - static class MyAutoCloseable implements AutoCloseable { - final FinalWrapper finalWrapper = new FinalWrapper(); - - public void close() { - closeCount++; - } - - static class FinalWrapper { - public final AutoCloseable finalCloseable = new AutoCloseable() { - @Override - public void close() throws Exception { - closeCount++; - } - }; - } - } - - @Test - public void tryWithResourcesTest() { - MyAutoCloseable mac = new MyAutoCloseable(); - - try (mac) { - assertEquals("Expected and Actual does not match", 0, closeCount); - } - - try (mac.finalWrapper.finalCloseable) { - assertEquals("Expected and Actual does not match", 1, closeCount); - } catch (Exception ex) { - } - - try (new MyAutoCloseable() { }.finalWrapper.finalCloseable) { - assertEquals("Expected and Actual does not match", 2, closeCount); - } catch (Exception ex) { - } - - try ((closeCount > 0 ? mac : new MyAutoCloseable()).finalWrapper.finalCloseable) { - assertEquals("Expected and Actual does not match", 3, closeCount); - } catch (Exception ex) { - } - - try { - throw new CloseableException(); - } catch (CloseableException ex) { - try (ex) { - assertEquals("Expected and Actual does not match", 4, closeCount); - } - } - assertEquals("Expected and Actual does not match", 5, closeCount); - } - - static class CloseableException extends Exception implements AutoCloseable { - @Override - public void close() { - closeCount++; - } - } - -} +package com.baeldung.java9.language; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class TryWithResourcesUnitTest { + + static int closeCount = 0; + + static class MyAutoCloseable implements AutoCloseable { + final FinalWrapper finalWrapper = new FinalWrapper(); + + public void close() { + closeCount++; + } + + static class FinalWrapper { + public final AutoCloseable finalCloseable = new AutoCloseable() { + @Override + public void close() throws Exception { + closeCount++; + } + }; + } + } + + @Test + public void tryWithResourcesTest() { + MyAutoCloseable mac = new MyAutoCloseable(); + + try (mac) { + assertEquals("Expected and Actual does not match", 0, closeCount); + } + + try (mac.finalWrapper.finalCloseable) { + assertEquals("Expected and Actual does not match", 1, closeCount); + } catch (Exception ex) { + } + + try (new MyAutoCloseable() { }.finalWrapper.finalCloseable) { + assertEquals("Expected and Actual does not match", 2, closeCount); + } catch (Exception ex) { + } + + try ((closeCount > 0 ? mac : new MyAutoCloseable()).finalWrapper.finalCloseable) { + assertEquals("Expected and Actual does not match", 3, closeCount); + } catch (Exception ex) { + } + + try { + throw new CloseableException(); + } catch (CloseableException ex) { + try (ex) { + assertEquals("Expected and Actual does not match", 4, closeCount); + } + } + assertEquals("Expected and Actual does not match", 5, closeCount); + } + + static class CloseableException extends Exception implements AutoCloseable { + @Override + public void close() { + closeCount++; + } + } + +} diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/collections/ListFactoryMethodsUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/collections/ListFactoryMethodsUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/language/collections/ListFactoryMethodsUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/collections/ListFactoryMethodsUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/collections/MapFactoryMethodsUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/collections/MapFactoryMethodsUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/language/collections/MapFactoryMethodsUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/collections/MapFactoryMethodsUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/collections/SetFactoryMethodsUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/collections/SetFactoryMethodsUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/language/collections/SetFactoryMethodsUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/collections/SetFactoryMethodsUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/stream/CollectionFilterUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/stream/CollectionFilterUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/language/stream/CollectionFilterUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/stream/CollectionFilterUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/stream/CollectorImprovementUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/stream/CollectorImprovementUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/language/stream/CollectorImprovementUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/stream/CollectorImprovementUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/language/stream/StreamFeaturesUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/stream/StreamFeaturesUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/language/stream/StreamFeaturesUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/language/stream/StreamFeaturesUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/rangedates/DatesCollectionIterationUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/rangedates/DatesCollectionIterationUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/rangedates/DatesCollectionIterationUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/rangedates/DatesCollectionIterationUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/rangedates/RangeDatesIterationUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/rangedates/RangeDatesIterationUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/rangedates/RangeDatesIterationUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/rangedates/RangeDatesIterationUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/reactive/BaeldungBatchSubscriberImplIntegrationTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/reactive/BaeldungBatchSubscriberImplIntegrationTest.java similarity index 96% rename from core-java-9/src/test/java/com/baeldung/java9/reactive/BaeldungBatchSubscriberImplIntegrationTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/reactive/BaeldungBatchSubscriberImplIntegrationTest.java index cbc3946999..15dc13ec71 100644 --- a/core-java-9/src/test/java/com/baeldung/java9/reactive/BaeldungBatchSubscriberImplIntegrationTest.java +++ b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/reactive/BaeldungBatchSubscriberImplIntegrationTest.java @@ -1,75 +1,75 @@ -package com.baeldung.java9.reactive; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.concurrent.ForkJoinPool; -import java.util.concurrent.SubmissionPublisher; -import java.util.concurrent.TimeUnit; -import java.util.stream.IntStream; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.Stopwatch; - -public class BaeldungBatchSubscriberImplIntegrationTest { - - private static final int ITEM_SIZE = 10; - private SubmissionPublisher publisher; - private BaeldungBatchSubscriberImpl subscriber; - - @Before - public void initialize() { - this.publisher = new SubmissionPublisher(ForkJoinPool.commonPool(), 6); - this.subscriber = new BaeldungBatchSubscriberImpl(); - publisher.subscribe(subscriber); - } - - @Rule - public Stopwatch stopwatch = new Stopwatch() { - - }; - - @Test - public void testReactiveStreamCount() { - IntStream.range(0, ITEM_SIZE) - .forEach(item -> publisher.submit(item + "")); - publisher.close(); - - do { - // wait for subscribers to complete all processing. - try { - Thread.sleep(100); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } while (!subscriber.isCompleted()); - - int count = subscriber.getCounter(); - - assertEquals(ITEM_SIZE, count); - } - - @Test - public void testReactiveStreamTime() { - IntStream.range(0, ITEM_SIZE) - .forEach(item -> publisher.submit(item + "")); - publisher.close(); - - do { - // wait for subscribers to complete all processing. - try { - Thread.sleep(100); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } while (!subscriber.isCompleted()); - - // The runtime in seconds should be equal to the number of items in each batch. - assertTrue(stopwatch.runtime(TimeUnit.SECONDS) >= (ITEM_SIZE / subscriber.BUFFER_SIZE)); - } - -} +package com.baeldung.java9.reactive; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.SubmissionPublisher; +import java.util.concurrent.TimeUnit; +import java.util.stream.IntStream; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.Stopwatch; + +public class BaeldungBatchSubscriberImplIntegrationTest { + + private static final int ITEM_SIZE = 10; + private SubmissionPublisher publisher; + private BaeldungBatchSubscriberImpl subscriber; + + @Before + public void initialize() { + this.publisher = new SubmissionPublisher(ForkJoinPool.commonPool(), 6); + this.subscriber = new BaeldungBatchSubscriberImpl(); + publisher.subscribe(subscriber); + } + + @Rule + public Stopwatch stopwatch = new Stopwatch() { + + }; + + @Test + public void testReactiveStreamCount() { + IntStream.range(0, ITEM_SIZE) + .forEach(item -> publisher.submit(item + "")); + publisher.close(); + + do { + // wait for subscribers to complete all processing. + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } while (!subscriber.isCompleted()); + + int count = subscriber.getCounter(); + + assertEquals(ITEM_SIZE, count); + } + + @Test + public void testReactiveStreamTime() { + IntStream.range(0, ITEM_SIZE) + .forEach(item -> publisher.submit(item + "")); + publisher.close(); + + do { + // wait for subscribers to complete all processing. + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } while (!subscriber.isCompleted()); + + // The runtime in seconds should be equal to the number of items in each batch. + assertTrue(stopwatch.runtime(TimeUnit.SECONDS) >= (ITEM_SIZE / subscriber.BUFFER_SIZE)); + } + +} diff --git a/core-java-9/src/test/java/com/baeldung/java9/reactive/BaeldungSubscriberImplIntegrationTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/reactive/BaeldungSubscriberImplIntegrationTest.java similarity index 96% rename from core-java-9/src/test/java/com/baeldung/java9/reactive/BaeldungSubscriberImplIntegrationTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/reactive/BaeldungSubscriberImplIntegrationTest.java index 6fd093b362..84877db500 100644 --- a/core-java-9/src/test/java/com/baeldung/java9/reactive/BaeldungSubscriberImplIntegrationTest.java +++ b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/reactive/BaeldungSubscriberImplIntegrationTest.java @@ -1,100 +1,100 @@ -package com.baeldung.java9.reactive; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.concurrent.ForkJoinPool; -import java.util.concurrent.SubmissionPublisher; -import java.util.concurrent.TimeUnit; -import java.util.stream.IntStream; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.Stopwatch; - -public class BaeldungSubscriberImplIntegrationTest { - - private static final int ITEM_SIZE = 10; - private SubmissionPublisher publisher; - private BaeldungSubscriberImpl subscriber; - - @Before - public void initialize() { - // create Publisher with max buffer capacity 3. - this.publisher = new SubmissionPublisher(ForkJoinPool.commonPool(), 3); - this.subscriber = new BaeldungSubscriberImpl(); - publisher.subscribe(subscriber); - } - - @Rule - public Stopwatch stopwatch = new Stopwatch() { - - }; - - @Test - public void testReactiveStreamCount() { - IntStream.range(0, ITEM_SIZE) - .forEach(item -> publisher.submit(item + "")); - publisher.close(); - - do { - // wait for subscribers to complete all processing. - try { - Thread.sleep(100); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } while (!subscriber.isCompleted()); - - int count = subscriber.getCounter(); - - assertEquals(ITEM_SIZE, count); - } - - @Test - public void testReactiveStreamTime() { - IntStream.range(0, ITEM_SIZE) - .forEach(item -> publisher.submit(item + "")); - publisher.close(); - - do { - // wait for subscribers to complete all processing. - try { - Thread.sleep(100); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } while (!subscriber.isCompleted()); - - // The runtime in seconds should be equal to the number of items. - assertTrue(stopwatch.runtime(TimeUnit.SECONDS) >= ITEM_SIZE); - } - - @Test - public void testReactiveStreamOffer() { - IntStream.range(0, ITEM_SIZE) - .forEach(item -> publisher.offer(item + "", (subscriber, string) -> { - // Returning false means this item will be dropped (no retry), if blocked. - return false; - })); - publisher.close(); - - do { - // wait for subscribers to complete all processing. - try { - Thread.sleep(100); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } while (!subscriber.isCompleted()); - - int count = subscriber.getCounter(); - // Because 10 items were offered and the buffer capacity was 3, few items will not be processed. - assertTrue(ITEM_SIZE > count); - } - -} +package com.baeldung.java9.reactive; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.SubmissionPublisher; +import java.util.concurrent.TimeUnit; +import java.util.stream.IntStream; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.Stopwatch; + +public class BaeldungSubscriberImplIntegrationTest { + + private static final int ITEM_SIZE = 10; + private SubmissionPublisher publisher; + private BaeldungSubscriberImpl subscriber; + + @Before + public void initialize() { + // create Publisher with max buffer capacity 3. + this.publisher = new SubmissionPublisher(ForkJoinPool.commonPool(), 3); + this.subscriber = new BaeldungSubscriberImpl(); + publisher.subscribe(subscriber); + } + + @Rule + public Stopwatch stopwatch = new Stopwatch() { + + }; + + @Test + public void testReactiveStreamCount() { + IntStream.range(0, ITEM_SIZE) + .forEach(item -> publisher.submit(item + "")); + publisher.close(); + + do { + // wait for subscribers to complete all processing. + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } while (!subscriber.isCompleted()); + + int count = subscriber.getCounter(); + + assertEquals(ITEM_SIZE, count); + } + + @Test + public void testReactiveStreamTime() { + IntStream.range(0, ITEM_SIZE) + .forEach(item -> publisher.submit(item + "")); + publisher.close(); + + do { + // wait for subscribers to complete all processing. + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } while (!subscriber.isCompleted()); + + // The runtime in seconds should be equal to the number of items. + assertTrue(stopwatch.runtime(TimeUnit.SECONDS) >= ITEM_SIZE); + } + + @Test + public void testReactiveStreamOffer() { + IntStream.range(0, ITEM_SIZE) + .forEach(item -> publisher.offer(item + "", (subscriber, string) -> { + // Returning false means this item will be dropped (no retry), if blocked. + return false; + })); + publisher.close(); + + do { + // wait for subscribers to complete all processing. + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } while (!subscriber.isCompleted()); + + int count = subscriber.getCounter(); + // Because 10 items were offered and the buffer capacity was 3, few items will not be processed. + assertTrue(ITEM_SIZE > count); + } + +} diff --git a/core-java-9/src/test/java/com/baeldung/java9/stackwalker/StackWalkerDemoUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/stackwalker/StackWalkerDemoUnitTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/stackwalker/StackWalkerDemoUnitTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/stackwalker/StackWalkerDemoUnitTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/streams.reactive/ReactiveStreamsTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/streams.reactive/ReactiveStreamsTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/streams.reactive/ReactiveStreamsTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/streams.reactive/ReactiveStreamsTest.java diff --git a/core-java-9/src/test/java/com/baeldung/java9/varhandles/VariableHandlesTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/varhandles/VariableHandlesTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/java9/varhandles/VariableHandlesTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/varhandles/VariableHandlesTest.java diff --git a/core-java-9/src/test/java/com/baeldung/optionals/OptionalsTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/optionals/OptionalsTest.java similarity index 100% rename from core-java-9/src/test/java/com/baeldung/optionals/OptionalsTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/optionals/OptionalsTest.java diff --git a/core-java-9/src/test/resources/.gitignore b/core-java-modules/core-java-9/src/test/resources/.gitignore similarity index 100% rename from core-java-9/src/test/resources/.gitignore rename to core-java-modules/core-java-9/src/test/resources/.gitignore diff --git a/core-java-lang-syntax/.gitignore b/core-java-modules/core-java-arrays/.gitignore similarity index 100% rename from core-java-lang-syntax/.gitignore rename to core-java-modules/core-java-arrays/.gitignore diff --git a/core-java-arrays/README.md b/core-java-modules/core-java-arrays/README.md similarity index 100% rename from core-java-arrays/README.md rename to core-java-modules/core-java-arrays/README.md diff --git a/core-java-arrays/pom.xml b/core-java-modules/core-java-arrays/pom.xml similarity index 99% rename from core-java-arrays/pom.xml rename to core-java-modules/core-java-arrays/pom.xml index ac9f7d08f0..b713c196b5 100644 --- a/core-java-arrays/pom.xml +++ b/core-java-modules/core-java-arrays/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java new file mode 100644 index 0000000000..dcd61cdfa7 --- /dev/null +++ b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java @@ -0,0 +1,34 @@ +package com.baeldung.array; + +import java.util.ArrayList; +import java.util.Arrays; + +public class AddElementToEndOfArray { + + public Integer[] addElementUsingArraysCopyOf(Integer[] srcArray, int elementToAdd) { + Integer[] destArray = Arrays.copyOf(srcArray, srcArray.length + 1); + + destArray[destArray.length - 1] = elementToAdd; + return destArray; + } + + public Integer[] addElementUsingArrayList(Integer[] srcArray, int elementToAdd) { + Integer[] destArray = new Integer[srcArray.length + 1]; + + ArrayList arrayList = new ArrayList<>(Arrays.asList(srcArray)); + arrayList.add(elementToAdd); + + return arrayList.toArray(destArray); + } + + public Integer[] addElementUsingSystemArrayCopy(Integer[] srcArray, int elementToAdd) { + Integer[] destArray = new Integer[srcArray.length + 1]; + + System.arraycopy(srcArray, 0, destArray, 0, srcArray.length); + + destArray[destArray.length - 1] = elementToAdd; + + return destArray; + } + +} diff --git a/core-java-arrays/src/main/java/com/baeldung/array/ArrayBenchmarkRunner.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/ArrayBenchmarkRunner.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/array/ArrayBenchmarkRunner.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/ArrayBenchmarkRunner.java diff --git a/core-java-arrays/src/main/java/com/baeldung/array/ArrayInitializer.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/ArrayInitializer.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/array/ArrayInitializer.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/ArrayInitializer.java diff --git a/core-java-arrays/src/main/java/com/baeldung/array/ArrayInverter.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/ArrayInverter.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/array/ArrayInverter.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/ArrayInverter.java diff --git a/core-java-arrays/src/main/java/com/baeldung/array/ArrayReferenceGuide.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/ArrayReferenceGuide.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/array/ArrayReferenceGuide.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/ArrayReferenceGuide.java diff --git a/core-java-arrays/src/main/java/com/baeldung/array/Find2ndLargestInArray.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/Find2ndLargestInArray.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/array/Find2ndLargestInArray.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/Find2ndLargestInArray.java diff --git a/core-java-arrays/src/main/java/com/baeldung/array/FindElementInArray.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/FindElementInArray.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/array/FindElementInArray.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/FindElementInArray.java diff --git a/core-java-arrays/src/main/java/com/baeldung/array/JaggedArray.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/JaggedArray.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/array/JaggedArray.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/JaggedArray.java diff --git a/core-java-arrays/src/main/java/com/baeldung/array/SearchArrayUnitTest.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/SearchArrayUnitTest.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/array/SearchArrayUnitTest.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/SearchArrayUnitTest.java diff --git a/core-java-arrays/src/main/java/com/baeldung/array/SumAndAverageInArray.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/SumAndAverageInArray.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/array/SumAndAverageInArray.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/SumAndAverageInArray.java diff --git a/core-java-arrays/src/main/java/com/baeldung/array/conversions/FloatToByteArray.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/conversions/FloatToByteArray.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/array/conversions/FloatToByteArray.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/conversions/FloatToByteArray.java diff --git a/core-java-arrays/src/main/java/com/baeldung/array/operations/ArrayOperations.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/operations/ArrayOperations.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/array/operations/ArrayOperations.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/array/operations/ArrayOperations.java diff --git a/core-java-arrays/src/main/java/com/baeldung/arraycopy/model/Address.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/arraycopy/model/Address.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/arraycopy/model/Address.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/arraycopy/model/Address.java diff --git a/core-java-arrays/src/main/java/com/baeldung/arraycopy/model/Employee.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/arraycopy/model/Employee.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/arraycopy/model/Employee.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/arraycopy/model/Employee.java diff --git a/core-java-arrays/src/main/java/com/baeldung/arrays/ParallelPrefixBenchmark.java b/core-java-modules/core-java-arrays/src/main/java/com/baeldung/arrays/ParallelPrefixBenchmark.java similarity index 100% rename from core-java-arrays/src/main/java/com/baeldung/arrays/ParallelPrefixBenchmark.java rename to core-java-modules/core-java-arrays/src/main/java/com/baeldung/arrays/ParallelPrefixBenchmark.java diff --git a/core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java new file mode 100644 index 0000000000..f6f1f954f6 --- /dev/null +++ b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java @@ -0,0 +1,49 @@ +package com.baeldung.array; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; + +public class AddElementToEndOfArrayUnitTest { + + AddElementToEndOfArray addElementToEndOfArray; + + @Before + public void init() { + addElementToEndOfArray = new AddElementToEndOfArray(); + } + + @Test + public void givenSourceArrayAndElement_whenAddElementUsingArraysCopyIsInvoked_thenNewElementMustBeAdded() { + Integer[] sourceArray = {1, 2, 3, 4}; + int elementToAdd = 5; + + Integer[] destArray = addElementToEndOfArray.addElementUsingArraysCopyOf(sourceArray, elementToAdd); + + Integer[] expectedArray = {1, 2, 3, 4, 5}; + assertArrayEquals(expectedArray, destArray); + } + + @Test + public void givenSourceArrayAndElement_whenAddElementUsingArrayListIsInvoked_thenNewElementMustBeAdded() { + Integer[] sourceArray = {1, 2, 3, 4}; + int elementToAdd = 5; + + Integer[] destArray = addElementToEndOfArray.addElementUsingArrayList(sourceArray, elementToAdd); + + Integer[] expectedArray = {1, 2, 3, 4, 5}; + assertArrayEquals(expectedArray, destArray); + } + + @Test + public void givenSourceArrayAndElement_whenAddElementUsingSystemArrayCopyIsInvoked_thenNewElementMustBeAdded() { + Integer[] sourceArray = {1, 2, 3, 4}; + int elementToAdd = 5; + + Integer[] destArray = addElementToEndOfArray.addElementUsingSystemArrayCopy(sourceArray, elementToAdd); + + Integer[] expectedArray = {1, 2, 3, 4, 5}; + assertArrayEquals(expectedArray, destArray); + } +} diff --git a/core-java-arrays/src/test/java/com/baeldung/array/ArrayInitializerUnitTest.java b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/ArrayInitializerUnitTest.java similarity index 100% rename from core-java-arrays/src/test/java/com/baeldung/array/ArrayInitializerUnitTest.java rename to core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/ArrayInitializerUnitTest.java diff --git a/core-java-arrays/src/test/java/com/baeldung/array/ArrayInverterUnitTest.java b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/ArrayInverterUnitTest.java similarity index 100% rename from core-java-arrays/src/test/java/com/baeldung/array/ArrayInverterUnitTest.java rename to core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/ArrayInverterUnitTest.java diff --git a/core-java-arrays/src/test/java/com/baeldung/array/Find2ndLargestInArrayUnitTest.java b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/Find2ndLargestInArrayUnitTest.java similarity index 100% rename from core-java-arrays/src/test/java/com/baeldung/array/Find2ndLargestInArrayUnitTest.java rename to core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/Find2ndLargestInArrayUnitTest.java diff --git a/core-java-arrays/src/test/java/com/baeldung/array/FindElementInArrayUnitTest.java b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/FindElementInArrayUnitTest.java similarity index 100% rename from core-java-arrays/src/test/java/com/baeldung/array/FindElementInArrayUnitTest.java rename to core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/FindElementInArrayUnitTest.java diff --git a/core-java-arrays/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java similarity index 100% rename from core-java-arrays/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java rename to core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java diff --git a/core-java-arrays/src/test/java/com/baeldung/array/SumAndAverageInArrayUnitTest.java b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/SumAndAverageInArrayUnitTest.java similarity index 100% rename from core-java-arrays/src/test/java/com/baeldung/array/SumAndAverageInArrayUnitTest.java rename to core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/SumAndAverageInArrayUnitTest.java diff --git a/core-java-arrays/src/test/java/com/baeldung/array/conversions/FloatToByteArrayUnitTest.java b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/conversions/FloatToByteArrayUnitTest.java similarity index 100% rename from core-java-arrays/src/test/java/com/baeldung/array/conversions/FloatToByteArrayUnitTest.java rename to core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/conversions/FloatToByteArrayUnitTest.java diff --git a/core-java-arrays/src/test/java/com/baeldung/array/operations/ArrayOperationsUnitTest.java b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/operations/ArrayOperationsUnitTest.java similarity index 100% rename from core-java-arrays/src/test/java/com/baeldung/array/operations/ArrayOperationsUnitTest.java rename to core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/operations/ArrayOperationsUnitTest.java diff --git a/core-java-arrays/src/test/java/com/baeldung/array/operations/IntersectionUnitTest.java b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/operations/IntersectionUnitTest.java similarity index 100% rename from core-java-arrays/src/test/java/com/baeldung/array/operations/IntersectionUnitTest.java rename to core-java-modules/core-java-arrays/src/test/java/com/baeldung/array/operations/IntersectionUnitTest.java diff --git a/core-java-arrays/src/test/java/com/baeldung/arraycopy/ArrayCopyUtilUnitTest.java b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/arraycopy/ArrayCopyUtilUnitTest.java similarity index 100% rename from core-java-arrays/src/test/java/com/baeldung/arraycopy/ArrayCopyUtilUnitTest.java rename to core-java-modules/core-java-arrays/src/test/java/com/baeldung/arraycopy/ArrayCopyUtilUnitTest.java diff --git a/core-java-arrays/src/test/java/com/baeldung/arrays/ArraysUnitTest.java b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/arrays/ArraysUnitTest.java similarity index 100% rename from core-java-arrays/src/test/java/com/baeldung/arrays/ArraysUnitTest.java rename to core-java-modules/core-java-arrays/src/test/java/com/baeldung/arrays/ArraysUnitTest.java diff --git a/core-java-arrays/src/test/java/com/baeldung/sort/ArraySortUnitTest.java b/core-java-modules/core-java-arrays/src/test/java/com/baeldung/sort/ArraySortUnitTest.java similarity index 100% rename from core-java-arrays/src/test/java/com/baeldung/sort/ArraySortUnitTest.java rename to core-java-modules/core-java-arrays/src/test/java/com/baeldung/sort/ArraySortUnitTest.java diff --git a/core-java-collections-list/README.md b/core-java-modules/core-java-collections-list/README.md similarity index 100% rename from core-java-collections-list/README.md rename to core-java-modules/core-java-collections-list/README.md diff --git a/core-java-collections-list/pom.xml b/core-java-modules/core-java-collections-list/pom.xml similarity index 98% rename from core-java-collections-list/pom.xml rename to core-java-modules/core-java-collections-list/pom.xml index 217278bdf6..1a0b1615c8 100644 --- a/core-java-collections-list/pom.xml +++ b/core-java-modules/core-java-collections-list/pom.xml @@ -10,7 +10,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-collections-list/src/main/java/com/baeldung/allequalelements/VerifyAllEqualListElements.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/allequalelements/VerifyAllEqualListElements.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/allequalelements/VerifyAllEqualListElements.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/allequalelements/VerifyAllEqualListElements.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/classcastexception/ClassCastException.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/classcastexception/ClassCastException.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/classcastexception/ClassCastException.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/classcastexception/ClassCastException.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/collection/filtering/Employee.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/collection/filtering/Employee.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/collection/filtering/Employee.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/collection/filtering/Employee.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/findanelement/Customer.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/findanelement/Customer.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/findanelement/Customer.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/findanelement/Customer.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/findanelement/FindACustomerInGivenList.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/findanelement/FindACustomerInGivenList.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/findanelement/FindACustomerInGivenList.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/findanelement/FindACustomerInGivenList.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/java/list/CopyListService.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java/list/CopyListService.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/java/list/CopyListService.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java/list/CopyListService.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/java/list/CustomList.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java/list/CustomList.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/java/list/CustomList.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java/list/CustomList.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/java/list/Flower.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java/list/Flower.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/java/list/Flower.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java/list/Flower.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/java/list/ReverseIterator.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java/list/ReverseIterator.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/java/list/ReverseIterator.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java/list/ReverseIterator.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/java/list/WaysToIterate.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java/list/WaysToIterate.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/java/list/WaysToIterate.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java/list/WaysToIterate.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/java_8_features/Car.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java_8_features/Car.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/java_8_features/Car.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java_8_features/Car.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/java_8_features/Person.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java_8_features/Person.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/java_8_features/Person.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/java_8_features/Person.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/list/Flower.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/Flower.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/list/Flower.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/Flower.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Pen.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Pen.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Pen.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Pen.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Pencil.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Pencil.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Pencil.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Pencil.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Rubber.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Rubber.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Rubber.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Rubber.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Stationery.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Stationery.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Stationery.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/listoflist/Stationery.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/list/multidimensional/ArrayListOfArrayList.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/multidimensional/ArrayListOfArrayList.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/list/multidimensional/ArrayListOfArrayList.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/multidimensional/ArrayListOfArrayList.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/list/multidimensional/ThreeDimensionalArrayList.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/multidimensional/ThreeDimensionalArrayList.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/list/multidimensional/ThreeDimensionalArrayList.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/multidimensional/ThreeDimensionalArrayList.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/list/primitive/PrimitiveCollections.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/primitive/PrimitiveCollections.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/list/primitive/PrimitiveCollections.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/primitive/PrimitiveCollections.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/list/primitive/PrimitivesListPerformance.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/primitive/PrimitivesListPerformance.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/list/primitive/PrimitivesListPerformance.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/primitive/PrimitivesListPerformance.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/list/removeall/RemoveAll.java b/core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/removeall/RemoveAll.java similarity index 100% rename from core-java-collections-list/src/main/java/com/baeldung/list/removeall/RemoveAll.java rename to core-java-modules/core-java-collections-list/src/main/java/com/baeldung/list/removeall/RemoveAll.java diff --git a/core-java-collections/src/main/resources/logback.xml b/core-java-modules/core-java-collections-list/src/main/resources/logback.xml similarity index 100% rename from core-java-collections/src/main/resources/logback.xml rename to core-java-modules/core-java-collections-list/src/main/resources/logback.xml diff --git a/core-java-collections-list/src/test/java/com/baeldung/allequalelements/VerifyAllEqualListElementsUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/allequalelements/VerifyAllEqualListElementsUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/allequalelements/VerifyAllEqualListElementsUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/allequalelements/VerifyAllEqualListElementsUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/array/converter/ArrayConvertToListUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/array/converter/ArrayConvertToListUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/array/converter/ArrayConvertToListUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/array/converter/ArrayConvertToListUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/collection/ClearVsRemoveAllUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/collection/ClearVsRemoveAllUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/collection/ClearVsRemoveAllUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/collection/ClearVsRemoveAllUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/collection/CollectionsEmpty.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/collection/CollectionsEmpty.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/collection/CollectionsEmpty.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/collection/CollectionsEmpty.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/findItems/FindItemsBasedOnOtherStreamUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/findItems/FindItemsBasedOnOtherStreamUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/findItems/FindItemsBasedOnOtherStreamUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/findItems/FindItemsBasedOnOtherStreamUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/findanelement/FindACustomerInGivenListUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/findanelement/FindACustomerInGivenListUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/findanelement/FindACustomerInGivenListUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/findanelement/FindACustomerInGivenListUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/java/list/CopyListServiceUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java/list/CopyListServiceUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/java/list/CopyListServiceUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java/list/CopyListServiceUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/java/list/CustomListUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java/list/CustomListUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/java/list/CustomListUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java/list/CustomListUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/java/list/ReverseIteratorUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java/list/ReverseIteratorUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/java/list/ReverseIteratorUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java/list/ReverseIteratorUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/java/list/WaysToIterateUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java/list/WaysToIterateUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/java/list/WaysToIterateUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java/list/WaysToIterateUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/java/listInitialization/ListInitializationUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java/listInitialization/ListInitializationUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/java/listInitialization/ListInitializationUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java/listInitialization/ListInitializationUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/java8/Java8CollectionCleanupUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java8/Java8CollectionCleanupUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/java8/Java8CollectionCleanupUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java8/Java8CollectionCleanupUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/java8/Java8MaxMinUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java8/Java8MaxMinUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/java8/Java8MaxMinUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/java8/Java8MaxMinUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/list/AddElementsUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/list/AddElementsUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/list/AddElementsUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/list/AddElementsUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/list/flattennestedlist/FlattenNestedListUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/list/flattennestedlist/FlattenNestedListUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/list/flattennestedlist/FlattenNestedListUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/list/flattennestedlist/FlattenNestedListUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/list/listoflist/AddElementsToListUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/list/listoflist/AddElementsToListUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/list/listoflist/AddElementsToListUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/list/listoflist/AddElementsToListUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/list/listoflist/ListOfListsUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/list/listoflist/ListOfListsUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/list/listoflist/ListOfListsUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/list/listoflist/ListOfListsUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/list/removeall/RemoveAllUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/list/removeall/RemoveAllUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/list/removeall/RemoveAllUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/list/removeall/RemoveAllUnitTest.java diff --git a/core-java-collections-list/src/test/java/com/baeldung/list/removefirst/RemoveFirstElementUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/com/baeldung/list/removefirst/RemoveFirstElementUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/com/baeldung/list/removefirst/RemoveFirstElementUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/com/baeldung/list/removefirst/RemoveFirstElementUnitTest.java diff --git a/core-java-collections-list/src/test/java/org/baeldung/RandomListElementUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/org/baeldung/RandomListElementUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/org/baeldung/RandomListElementUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/org/baeldung/RandomListElementUnitTest.java diff --git a/core-java-collections-list/src/test/java/org/baeldung/java/collections/ArrayListUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/collections/ArrayListUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/org/baeldung/java/collections/ArrayListUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/collections/ArrayListUnitTest.java diff --git a/core-java-collections-list/src/test/java/org/baeldung/java/collections/CoreJavaCollectionsUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/collections/CoreJavaCollectionsUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/org/baeldung/java/collections/CoreJavaCollectionsUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/collections/CoreJavaCollectionsUnitTest.java diff --git a/core-java-collections-list/src/test/java/org/baeldung/java/collections/JavaCollectionCleanupUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/collections/JavaCollectionCleanupUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/org/baeldung/java/collections/JavaCollectionCleanupUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/collections/JavaCollectionCleanupUnitTest.java diff --git a/core-java-collections-list/src/test/java/org/baeldung/java/lists/ListAssertJUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/lists/ListAssertJUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/org/baeldung/java/lists/ListAssertJUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/lists/ListAssertJUnitTest.java diff --git a/core-java-collections-list/src/test/java/org/baeldung/java/lists/ListJUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/lists/ListJUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/org/baeldung/java/lists/ListJUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/lists/ListJUnitTest.java diff --git a/core-java-collections-list/src/test/java/org/baeldung/java/lists/ListTestNgUnitTest.java b/core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/lists/ListTestNgUnitTest.java similarity index 100% rename from core-java-collections-list/src/test/java/org/baeldung/java/lists/ListTestNgUnitTest.java rename to core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/lists/ListTestNgUnitTest.java diff --git a/core-java-collections-list/src/test/java/org/baeldung/java/lists/README.md b/core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/lists/README.md similarity index 100% rename from core-java-collections-list/src/test/java/org/baeldung/java/lists/README.md rename to core-java-modules/core-java-collections-list/src/test/java/org/baeldung/java/lists/README.md diff --git a/core-java-modules/core-java-collections-set/README.md b/core-java-modules/core-java-collections-set/README.md new file mode 100644 index 0000000000..217e9ee6a5 --- /dev/null +++ b/core-java-modules/core-java-collections-set/README.md @@ -0,0 +1,11 @@ +========= + +## Core Java Sets Cookbooks and Examples + +### Relevant Articles: +- [Set Operations in Java](http://www.baeldung.com/set-operations-in-java) +- [HashSet and TreeSet Comparison](http://www.baeldung.com/java-hashset-vs-treeset) +- [A Guide to HashSet in Java](http://www.baeldung.com/java-hashset) +- [A Guide to TreeSet in Java](http://www.baeldung.com/java-tree-set) +- [Initializing HashSet at the Time of Construction](http://www.baeldung.com/java-initialize-hashset) +- [Guide to EnumSet](https://www.baeldung.com/java-enumset) \ No newline at end of file diff --git a/core-java-modules/core-java-collections-set/pom.xml b/core-java-modules/core-java-collections-set/pom.xml new file mode 100644 index 0000000000..2a930efde8 --- /dev/null +++ b/core-java-modules/core-java-collections-set/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + core-java-collections-set + 0.1.0-SNAPSHOT + core-java-collections-set + jar + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + + + + + com.google.guava + guava + ${guava.version} + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + + + + + 4.3 + 27.1-jre + + diff --git a/core-java-collections/src/main/java/com/baeldung/enumset/EnumSets.java b/core-java-modules/core-java-collections-set/src/main/java/com/baeldung/enumset/EnumSets.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/enumset/EnumSets.java rename to core-java-modules/core-java-collections-set/src/main/java/com/baeldung/enumset/EnumSets.java diff --git a/core-java-collections/src/test/java/com/baeldung/collection/WhenUsingHashSet.java b/core-java-modules/core-java-collections-set/src/test/java/com/baeldung/collection/WhenUsingHashSet.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/collection/WhenUsingHashSet.java rename to core-java-modules/core-java-collections-set/src/test/java/com/baeldung/collection/WhenUsingHashSet.java diff --git a/core-java-collections/src/test/java/com/baeldung/collection/WhenUsingTreeSet.java b/core-java-modules/core-java-collections-set/src/test/java/com/baeldung/collection/WhenUsingTreeSet.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/collection/WhenUsingTreeSet.java rename to core-java-modules/core-java-collections-set/src/test/java/com/baeldung/collection/WhenUsingTreeSet.java diff --git a/core-java-collections/src/test/java/com/baeldung/java/set/HashSetInitalizingUnitTest.java b/core-java-modules/core-java-collections-set/src/test/java/com/baeldung/java/set/HashSetInitalizingUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/java/set/HashSetInitalizingUnitTest.java rename to core-java-modules/core-java-collections-set/src/test/java/com/baeldung/java/set/HashSetInitalizingUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/java/set/SetUnitTest.java b/core-java-modules/core-java-collections-set/src/test/java/com/baeldung/java/set/SetUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/java/set/SetUnitTest.java rename to core-java-modules/core-java-collections-set/src/test/java/com/baeldung/java/set/SetUnitTest.java diff --git a/core-java-modules/core-java-collections-set/src/test/java/com/baeldung/set/SetOperationsUnitTest.java b/core-java-modules/core-java-collections-set/src/test/java/com/baeldung/set/SetOperationsUnitTest.java new file mode 100644 index 0000000000..7c25585e49 --- /dev/null +++ b/core-java-modules/core-java-collections-set/src/test/java/com/baeldung/set/SetOperationsUnitTest.java @@ -0,0 +1,93 @@ +package com.baeldung.set; + +import static org.junit.Assert.*; + +import org.apache.commons.collections4.SetUtils; +import org.junit.Test; + +import com.google.common.collect.Sets; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class SetOperationsUnitTest { + + private Set setA = setOf(1,2,3,4); + private Set setB = setOf(2,4,6,8); + + private static Set setOf(Integer... values) { + return new HashSet(Arrays.asList(values)); + } + + @Test + public void givenTwoSets_WhenWeRetainAll_ThenWeIntersectThem() { + Set intersectSet = new HashSet<>(setA); + intersectSet.retainAll(setB); + assertEquals(setOf(2,4), intersectSet); + } + + @Test + public void givenTwoSets_WhenWeAddAll_ThenWeUnionThem() { + Set unionSet = new HashSet<>(setA); + unionSet.addAll(setB); + assertEquals(setOf(1,2,3,4,6,8), unionSet); + } + + @Test + public void givenTwoSets_WhenRemoveAll_ThenWeGetTheDifference() { + Set differenceSet = new HashSet<>(setA); + differenceSet.removeAll(setB); + assertEquals(setOf(1,3), differenceSet); + } + + @Test + public void givenTwoStreams_WhenWeFilterThem_ThenWeCanGetTheIntersect() { + Set intersectSet = setA.stream() + .filter(setB::contains) + .collect(Collectors.toSet()); + assertEquals(setOf(2,4), intersectSet); + } + + @Test + public void givenTwoStreams_WhenWeConcatThem_ThenWeGetTheUnion() { + Set unionSet = Stream.concat(setA.stream(), setB.stream()) + .collect(Collectors.toSet()); + assertEquals(setOf(1,2,3,4,6,8), unionSet); + } + + @Test + public void givenTwoStreams_WhenWeFilterThem_ThenWeCanGetTheDifference() { + Set differenceSet = setA.stream() + .filter(val -> !setB.contains(val)) + .collect(Collectors.toSet()); + assertEquals(setOf(1,3), differenceSet); + } + + @Test + public void givenTwoSets_WhenWeUseApacheCommonsIntersect_ThenWeGetTheIntersect() { + Set intersectSet = SetUtils.intersection(setA, setB); + assertEquals(setOf(2,4), intersectSet); + } + + @Test + public void givenTwoSets_WhenWeUseApacheCommonsUnion_ThenWeGetTheUnion() { + Set unionSet = SetUtils.union(setA, setB); + assertEquals(setOf(1,2,3,4,6,8), unionSet); + } + + + @Test + public void givenTwoSets_WhenWeUseGuavaIntersect_ThenWeGetTheIntersect() { + Set intersectSet = Sets.intersection(setA, setB); + assertEquals(setOf(2,4), intersectSet); + } + + @Test + public void givenTwoSets_WhenWeUseGuavaUnion_ThenWeGetTheUnion() { + Set unionSet = Sets.union(setA, setB); + assertEquals(setOf(1,2,3,4,6,8), unionSet); + } +} diff --git a/core-java-collections/README.md b/core-java-modules/core-java-collections/README.md similarity index 87% rename from core-java-collections/README.md rename to core-java-modules/core-java-collections/README.md index 43f5bfc384..b34293769d 100644 --- a/core-java-collections/README.md +++ b/core-java-modules/core-java-collections/README.md @@ -4,14 +4,10 @@ ### Relevant Articles: - [Java – Combine Multiple Collections](http://www.baeldung.com/java-combine-multiple-collections) -- [HashSet and TreeSet Comparison](http://www.baeldung.com/java-hashset-vs-treeset) - [Collect a Java Stream to an Immutable Collection](http://www.baeldung.com/java-stream-immutable-collection) - [Introduction to the Java ArrayDeque](http://www.baeldung.com/java-array-deque) -- [A Guide to HashSet in Java](http://www.baeldung.com/java-hashset) -- [A Guide to TreeSet in Java](http://www.baeldung.com/java-tree-set) - [Getting the Size of an Iterable in Java](http://www.baeldung.com/java-iterable-size) - [How to Filter a Collection in Java](http://www.baeldung.com/java-collection-filtering) -- [Initializing HashSet at the Time of Construction](http://www.baeldung.com/java-initialize-hashset) - [Removing the First Element of an Array](https://www.baeldung.com/java-array-remove-first-element) - [Fail-Safe Iterator vs Fail-Fast Iterator](http://www.baeldung.com/java-fail-safe-vs-fail-fast-iterator) - [Shuffling Collections In Java](http://www.baeldung.com/java-shuffle-collection) @@ -23,7 +19,6 @@ - [Time Complexity of Java Collections](https://www.baeldung.com/java-collections-complexity) - [Operating on and Removing an Item from Stream](https://www.baeldung.com/java-use-remove-item-stream) - [An Introduction to Synchronized Java Collections](https://www.baeldung.com/java-synchronized-collections) -- [Guide to EnumSet](https://www.baeldung.com/java-enumset) - [Removing Elements from Java Collections](https://www.baeldung.com/java-collection-remove-elements) - [Combining Different Types of Collections in Java](https://www.baeldung.com/java-combine-collections) - [Sorting in Java](http://www.baeldung.com/java-sorting) diff --git a/core-java-collections/pom.xml b/core-java-modules/core-java-collections/pom.xml similarity index 95% rename from core-java-collections/pom.xml rename to core-java-modules/core-java-collections/pom.xml index b791f38b24..e5b89c3d16 100644 --- a/core-java-collections/pom.xml +++ b/core-java-modules/core-java-collections/pom.xml @@ -1,78 +1,78 @@ - - 4.0.0 - core-java-collections - 0.1.0-SNAPSHOT - core-java-collections - jar - - - com.baeldung - parent-java - 0.0.1-SNAPSHOT - ../parent-java - - - - - org.apache.commons - commons-collections4 - ${commons-collections4.version} - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - org.eclipse.collections - eclipse-collections - ${eclipse.collections.version} - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.junit.platform - junit-platform-runner - ${junit.platform.version} - test - - - org.openjdk.jmh - jmh-core - ${openjdk.jmh.version} - - - org.openjdk.jmh - jmh-generator-annprocess - ${openjdk.jmh.version} - - - org.apache.commons - commons-exec - ${commons-exec.version} - - - org.projectlombok - lombok - ${lombok.version} - provided - - - - - 1.19 - 1.2.0 - 3.8.1 - 4.1 - 4.01 - 1.7.0 - 3.11.1 - 7.1.0 - 1.3 - - + + 4.0.0 + core-java-collections + 0.1.0-SNAPSHOT + core-java-collections + jar + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + + + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.eclipse.collections + eclipse-collections + ${eclipse.collections.version} + + + org.assertj + assertj-core + ${assertj.version} + test + + + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + org.openjdk.jmh + jmh-core + ${openjdk.jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${openjdk.jmh.version} + + + org.apache.commons + commons-exec + ${commons-exec.version} + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + + 1.19 + 1.2.0 + 3.8.1 + 4.1 + 4.01 + 1.7.0 + 3.11.1 + 7.1.0 + 1.3 + + diff --git a/core-java-collections/src/main/java/com/baeldung/charstack/CharStack.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/charstack/CharStack.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/charstack/CharStack.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/charstack/CharStack.java diff --git a/core-java-collections/src/main/java/com/baeldung/charstack/CharStackWithArray.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/charstack/CharStackWithArray.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/charstack/CharStackWithArray.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/charstack/CharStackWithArray.java diff --git a/core-java-collections/src/main/java/com/baeldung/charstack/EmptyStackException.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/charstack/EmptyStackException.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/charstack/EmptyStackException.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/charstack/EmptyStackException.java diff --git a/core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningArrays.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningArrays.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningArrays.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningArrays.java diff --git a/core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningLists.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningLists.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningLists.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningLists.java diff --git a/core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningMaps.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningMaps.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningMaps.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningMaps.java diff --git a/core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningSets.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningSets.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningSets.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/combiningcollections/CombiningSets.java diff --git a/core-java-collections/src/main/java/com/baeldung/hashtable/Word.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/hashtable/Word.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/hashtable/Word.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/hashtable/Word.java diff --git a/core-java-collections/src/main/java/com/baeldung/iteratorguide/IteratorGuide.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/iteratorguide/IteratorGuide.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/iteratorguide/IteratorGuide.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/iteratorguide/IteratorGuide.java diff --git a/core-java-collections/src/main/java/com/baeldung/iterators/Iterators.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/iterators/Iterators.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/iterators/Iterators.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/iterators/Iterators.java diff --git a/core-java-collections/src/main/java/com/baeldung/java/filtering/CollectionUtilsCollectionFilter.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/java/filtering/CollectionUtilsCollectionFilter.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/java/filtering/CollectionUtilsCollectionFilter.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/java/filtering/CollectionUtilsCollectionFilter.java diff --git a/core-java-collections/src/main/java/com/baeldung/java/filtering/EclipseCollectionsCollectionFilter.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/java/filtering/EclipseCollectionsCollectionFilter.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/java/filtering/EclipseCollectionsCollectionFilter.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/java/filtering/EclipseCollectionsCollectionFilter.java diff --git a/core-java-collections/src/main/java/com/baeldung/java/filtering/GuavaCollectionFilter.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/java/filtering/GuavaCollectionFilter.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/java/filtering/GuavaCollectionFilter.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/java/filtering/GuavaCollectionFilter.java diff --git a/core-java-collections/src/main/java/com/baeldung/java/filtering/StreamsCollectionFilter.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/java/filtering/StreamsCollectionFilter.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/java/filtering/StreamsCollectionFilter.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/java/filtering/StreamsCollectionFilter.java diff --git a/core-java-collections/src/main/java/com/baeldung/java/iterable/IterableSize.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/java/iterable/IterableSize.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/java/iterable/IterableSize.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/java/iterable/IterableSize.java diff --git a/core-java-collections/src/main/java/com/baeldung/java/list/VectorExample.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/java/list/VectorExample.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/java/list/VectorExample.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/java/list/VectorExample.java diff --git a/core-java-collections/src/main/java/com/baeldung/java/sort/CollectionsSortCompare.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/java/sort/CollectionsSortCompare.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/java/sort/CollectionsSortCompare.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/java/sort/CollectionsSortCompare.java diff --git a/core-java-collections/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNull.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNull.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNull.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNull.java diff --git a/core-java-collections/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainer.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainer.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainer.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainer.java diff --git a/core-java-collections/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheck.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheck.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheck.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheck.java diff --git a/core-java-collections/src/main/java/com/baeldung/performance/ArrayListBenchmark.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/ArrayListBenchmark.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/performance/ArrayListBenchmark.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/ArrayListBenchmark.java diff --git a/core-java-collections/src/main/java/com/baeldung/performance/ArraySortBenchmark.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/ArraySortBenchmark.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/performance/ArraySortBenchmark.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/ArraySortBenchmark.java diff --git a/core-java-collections/src/main/java/com/baeldung/performance/CollectionsBenchmark.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/CollectionsBenchmark.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/performance/CollectionsBenchmark.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/CollectionsBenchmark.java diff --git a/core-java-collections/src/main/java/com/baeldung/performance/CopyOnWriteBenchmark.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/CopyOnWriteBenchmark.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/performance/CopyOnWriteBenchmark.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/CopyOnWriteBenchmark.java diff --git a/core-java-collections/src/main/java/com/baeldung/performance/Employee.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/Employee.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/performance/Employee.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/Employee.java diff --git a/core-java-collections/src/main/java/com/baeldung/performance/HashMapBenchmark.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/HashMapBenchmark.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/performance/HashMapBenchmark.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/HashMapBenchmark.java diff --git a/core-java-collections/src/main/java/com/baeldung/performance/SetBenchMark.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/SetBenchMark.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/performance/SetBenchMark.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/performance/SetBenchMark.java diff --git a/core-java-collections/src/main/java/com/baeldung/queueInterface/CustomBaeldungQueue.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/queueInterface/CustomBaeldungQueue.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/queueInterface/CustomBaeldungQueue.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/queueInterface/CustomBaeldungQueue.java diff --git a/core-java-collections/src/main/java/com/baeldung/removal/CollectionRemoveIf.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/removal/CollectionRemoveIf.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/removal/CollectionRemoveIf.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/removal/CollectionRemoveIf.java diff --git a/core-java-collections/src/main/java/com/baeldung/removal/Iterators.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/removal/Iterators.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/removal/Iterators.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/removal/Iterators.java diff --git a/core-java-collections/src/main/java/com/baeldung/removal/StreamFilterAndCollector.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/removal/StreamFilterAndCollector.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/removal/StreamFilterAndCollector.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/removal/StreamFilterAndCollector.java diff --git a/core-java-collections/src/main/java/com/baeldung/removal/StreamPartitioningBy.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/removal/StreamPartitioningBy.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/removal/StreamPartitioningBy.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/removal/StreamPartitioningBy.java diff --git a/core-java-collections/src/main/java/com/baeldung/synchronizedcollections/application/Application.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/synchronizedcollections/application/Application.java similarity index 97% rename from core-java-collections/src/main/java/com/baeldung/synchronizedcollections/application/Application.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/synchronizedcollections/application/Application.java index 1840c125d0..093308a34a 100644 --- a/core-java-collections/src/main/java/com/baeldung/synchronizedcollections/application/Application.java +++ b/core-java-modules/core-java-collections/src/main/java/com/baeldung/synchronizedcollections/application/Application.java @@ -1,18 +1,18 @@ -package com.baeldung.synchronizedcollections.application; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.logging.Logger; - -public class Application { - - private static final Logger LOGGER = Logger.getLogger(Application.class.getName()); - - public static void main(String[] args) throws InterruptedException { - List syncCollection = Collections.synchronizedList(Arrays.asList(1, 2, 3, 4, 5, 6)); - synchronized (syncCollection) { - syncCollection.forEach((e) -> {LOGGER.info(e.toString());}); - } - } -} +package com.baeldung.synchronizedcollections.application; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.logging.Logger; + +public class Application { + + private static final Logger LOGGER = Logger.getLogger(Application.class.getName()); + + public static void main(String[] args) throws InterruptedException { + List syncCollection = Collections.synchronizedList(Arrays.asList(1, 2, 3, 4, 5, 6)); + synchronized (syncCollection) { + syncCollection.forEach((e) -> {LOGGER.info(e.toString());}); + } + } +} diff --git a/core-java-collections/src/main/java/com/baeldung/thread_safe_lifo/DequeBasedSynchronizedStack.java b/core-java-modules/core-java-collections/src/main/java/com/baeldung/thread_safe_lifo/DequeBasedSynchronizedStack.java similarity index 100% rename from core-java-collections/src/main/java/com/baeldung/thread_safe_lifo/DequeBasedSynchronizedStack.java rename to core-java-modules/core-java-collections/src/main/java/com/baeldung/thread_safe_lifo/DequeBasedSynchronizedStack.java diff --git a/core-java-os/src/main/resources/logback.xml b/core-java-modules/core-java-collections/src/main/resources/logback.xml similarity index 100% rename from core-java-os/src/main/resources/logback.xml rename to core-java-modules/core-java-collections/src/main/resources/logback.xml diff --git a/core-java-collections/src/test/java/com/baeldung/arraydeque/ArrayDequeUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/arraydeque/ArrayDequeUnitTest.java similarity index 95% rename from core-java-collections/src/test/java/com/baeldung/arraydeque/ArrayDequeUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/arraydeque/ArrayDequeUnitTest.java index 71930eda97..5a76eb5402 100644 --- a/core-java-collections/src/test/java/com/baeldung/arraydeque/ArrayDequeUnitTest.java +++ b/core-java-modules/core-java-collections/src/test/java/com/baeldung/arraydeque/ArrayDequeUnitTest.java @@ -1,50 +1,50 @@ -package com.baeldung.arraydeque; - -import java.util.ArrayDeque; -import java.util.Deque; - -import static org.junit.Assert.*; -import org.junit.Test; - -public class ArrayDequeUnitTest { - - @Test - public void whenOffer_addsAtLast() { - final Deque deque = new ArrayDeque<>(); - - deque.offer("first"); - deque.offer("second"); - - assertEquals("second", deque.getLast()); - } - - @Test - public void whenPoll_removesFirst() { - final Deque deque = new ArrayDeque<>(); - - deque.offer("first"); - deque.offer("second"); - - assertEquals("first", deque.poll()); - } - - @Test - public void whenPush_addsAtFirst() { - final Deque deque = new ArrayDeque<>(); - - deque.push("first"); - deque.push("second"); - - assertEquals("second", deque.getFirst()); - } - - @Test - public void whenPop_removesLast() { - final Deque deque = new ArrayDeque<>(); - - deque.push("first"); - deque.push("second"); - - assertEquals("second", deque.pop()); - } -} +package com.baeldung.arraydeque; + +import java.util.ArrayDeque; +import java.util.Deque; + +import static org.junit.Assert.*; +import org.junit.Test; + +public class ArrayDequeUnitTest { + + @Test + public void whenOffer_addsAtLast() { + final Deque deque = new ArrayDeque<>(); + + deque.offer("first"); + deque.offer("second"); + + assertEquals("second", deque.getLast()); + } + + @Test + public void whenPoll_removesFirst() { + final Deque deque = new ArrayDeque<>(); + + deque.offer("first"); + deque.offer("second"); + + assertEquals("first", deque.poll()); + } + + @Test + public void whenPush_addsAtFirst() { + final Deque deque = new ArrayDeque<>(); + + deque.push("first"); + deque.push("second"); + + assertEquals("second", deque.getFirst()); + } + + @Test + public void whenPop_removesLast() { + final Deque deque = new ArrayDeque<>(); + + deque.push("first"); + deque.push("second"); + + assertEquals("second", deque.pop()); + } +} diff --git a/core-java-collections/src/test/java/com/baeldung/charstack/CharStackUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/charstack/CharStackUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/charstack/CharStackUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/charstack/CharStackUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/charstack/CharStackUsingJavaUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/charstack/CharStackUsingJavaUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/charstack/CharStackUsingJavaUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/charstack/CharStackUsingJavaUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/charstack/CharStackWithArrayUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/charstack/CharStackWithArrayUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/charstack/CharStackWithArrayUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/charstack/CharStackWithArrayUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningArraysUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningArraysUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningArraysUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningArraysUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningListsUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningListsUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningListsUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningListsUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningMapsUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningMapsUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningMapsUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningMapsUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningSetsUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningSetsUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningSetsUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/combiningcollections/CombiningSetsUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/enummap/DummyEnum.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/enummap/DummyEnum.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/enummap/DummyEnum.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/enummap/DummyEnum.java diff --git a/core-java-collections/src/test/java/com/baeldung/enummap/EnumMapBenchmarkLiveTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/enummap/EnumMapBenchmarkLiveTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/enummap/EnumMapBenchmarkLiveTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/enummap/EnumMapBenchmarkLiveTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/enummap/EnumMapUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/enummap/EnumMapUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/enummap/EnumMapUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/enummap/EnumMapUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/hashmapvshashtable/HashmapVsHashtableDifferenceUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/hashmapvshashtable/HashmapVsHashtableDifferenceUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/hashmapvshashtable/HashmapVsHashtableDifferenceUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/hashmapvshashtable/HashmapVsHashtableDifferenceUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/hashtable/HashtableUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/hashtable/HashtableUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/hashtable/HashtableUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/hashtable/HashtableUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/iterators/IteratorsUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/iterators/IteratorsUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/iterators/IteratorsUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/iterators/IteratorsUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/java/collections/ConcurrentModificationExceptionUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/java/collections/ConcurrentModificationExceptionUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/java/collections/ConcurrentModificationExceptionUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/java/collections/ConcurrentModificationExceptionUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/java/filtering/CollectionFiltersUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/java/filtering/CollectionFiltersUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/java/filtering/CollectionFiltersUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/java/filtering/CollectionFiltersUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/java/iterable/IterableSizeUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/java/iterable/IterableSizeUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/java/iterable/IterableSizeUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/java/iterable/IterableSizeUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNullUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNullUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNullUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingCommonsEmptyIfNullUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainerUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainerUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainerUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingJava8OptionalContainerUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheckUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheckUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheckUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/nullsafecollectionstreams/NullSafeCollectionStreamsUsingNullDereferenceCheckUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/queueInterface/CustomBaeldungQueueUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/queueInterface/CustomBaeldungQueueUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/queueInterface/CustomBaeldungQueueUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/queueInterface/CustomBaeldungQueueUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/queueInterface/PriorityQueueUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/queueInterface/PriorityQueueUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/queueInterface/PriorityQueueUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/queueInterface/PriorityQueueUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/removal/RemovalUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/removal/RemovalUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/removal/RemovalUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/removal/RemovalUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/shufflingcollections/ShufflingCollectionsUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/shufflingcollections/ShufflingCollectionsUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/shufflingcollections/ShufflingCollectionsUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/shufflingcollections/ShufflingCollectionsUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/stack_tests/MultithreadingCorrectnessStackUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/stack_tests/MultithreadingCorrectnessStackUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/stack_tests/MultithreadingCorrectnessStackUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/stack_tests/MultithreadingCorrectnessStackUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/stack_tests/StackUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/stack_tests/StackUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/stack_tests/StackUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/stack_tests/StackUnitTest.java diff --git a/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedCollectionUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedCollectionUnitTest.java similarity index 97% rename from core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedCollectionUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedCollectionUnitTest.java index 84feeb6eaa..fd84503226 100644 --- a/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedCollectionUnitTest.java +++ b/core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedCollectionUnitTest.java @@ -1,28 +1,28 @@ -package com.baeldung.synchronizedcollections.test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; - -public class SynchronizedCollectionUnitTest { - - @Test - public void givenSynchronizedCollection_whenTwoThreadsAddElements_thenCorrectCollectionSize() throws InterruptedException { - Collection syncCollection = Collections.synchronizedCollection(new ArrayList<>()); - - Runnable listOperations = () -> { - syncCollection.addAll(Arrays.asList(1, 2, 3, 4, 5, 6)); - }; - Thread thread1 = new Thread(listOperations); - Thread thread2 = new Thread(listOperations); - thread1.start(); - thread2.start(); - thread1.join(); - thread2.join(); - - assertThat(syncCollection.size()).isEqualTo(12); - } -} +package com.baeldung.synchronizedcollections.test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; + +public class SynchronizedCollectionUnitTest { + + @Test + public void givenSynchronizedCollection_whenTwoThreadsAddElements_thenCorrectCollectionSize() throws InterruptedException { + Collection syncCollection = Collections.synchronizedCollection(new ArrayList<>()); + + Runnable listOperations = () -> { + syncCollection.addAll(Arrays.asList(1, 2, 3, 4, 5, 6)); + }; + Thread thread1 = new Thread(listOperations); + Thread thread2 = new Thread(listOperations); + thread1.start(); + thread2.start(); + thread1.join(); + thread2.join(); + + assertThat(syncCollection.size()).isEqualTo(12); + } +} diff --git a/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedListUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedListUnitTest.java similarity index 97% rename from core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedListUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedListUnitTest.java index 68fc3becd4..72354622ae 100644 --- a/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedListUnitTest.java +++ b/core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedListUnitTest.java @@ -1,51 +1,51 @@ -package com.baeldung.synchronizedcollections.test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import org.junit.Test; -import static org.assertj.core.api.Assertions.*; - -public class SynchronizedListUnitTest { - - @Test - public void givenSynchronizedList_whenTwoThreadsAddElements_thenCorrectListSize() throws InterruptedException { - List syncList = Collections.synchronizedList(new ArrayList<>()); - - Runnable listOperations = () -> { - syncList.addAll(Arrays.asList(1, 2, 3, 4, 5, 6)); - }; - Thread thread1 = new Thread(listOperations); - Thread thread2 = new Thread(listOperations); - thread1.start(); - thread2.start(); - thread1.join(); - thread2.join(); - - assertThat(syncList.size()).isEqualTo(12); - } - - @Test - public void givenStringList_whenTwoThreadsIterateOnSynchronizedList_thenCorrectResult() throws InterruptedException { - List syncCollection = Collections.synchronizedList(Arrays.asList("a", "b", "c")); - List uppercasedCollection = new ArrayList<>(); - - Runnable listOperations = () -> { - synchronized (syncCollection) { - syncCollection.forEach((e) -> { - uppercasedCollection.add(e.toUpperCase()); - }); - } - }; - - Thread thread1 = new Thread(listOperations); - Thread thread2 = new Thread(listOperations); - thread1.start(); - thread2.start(); - thread1.join(); - thread2.join(); - - assertThat(uppercasedCollection.get(0)).isEqualTo("A"); - } -} +package com.baeldung.synchronizedcollections.test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.junit.Test; +import static org.assertj.core.api.Assertions.*; + +public class SynchronizedListUnitTest { + + @Test + public void givenSynchronizedList_whenTwoThreadsAddElements_thenCorrectListSize() throws InterruptedException { + List syncList = Collections.synchronizedList(new ArrayList<>()); + + Runnable listOperations = () -> { + syncList.addAll(Arrays.asList(1, 2, 3, 4, 5, 6)); + }; + Thread thread1 = new Thread(listOperations); + Thread thread2 = new Thread(listOperations); + thread1.start(); + thread2.start(); + thread1.join(); + thread2.join(); + + assertThat(syncList.size()).isEqualTo(12); + } + + @Test + public void givenStringList_whenTwoThreadsIterateOnSynchronizedList_thenCorrectResult() throws InterruptedException { + List syncCollection = Collections.synchronizedList(Arrays.asList("a", "b", "c")); + List uppercasedCollection = new ArrayList<>(); + + Runnable listOperations = () -> { + synchronized (syncCollection) { + syncCollection.forEach((e) -> { + uppercasedCollection.add(e.toUpperCase()); + }); + } + }; + + Thread thread1 = new Thread(listOperations); + Thread thread2 = new Thread(listOperations); + thread1.start(); + thread2.start(); + thread1.join(); + thread2.join(); + + assertThat(uppercasedCollection.get(0)).isEqualTo("A"); + } +} diff --git a/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedMapUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedMapUnitTest.java similarity index 96% rename from core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedMapUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedMapUnitTest.java index abfb866e9c..842e253e9e 100644 --- a/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedMapUnitTest.java +++ b/core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedMapUnitTest.java @@ -1,30 +1,30 @@ -package com.baeldung.synchronizedcollections.test; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import org.junit.Test; -import static org.assertj.core.api.Assertions.*; - -public class SynchronizedMapUnitTest { - - @Test - public void givenSynchronizedMap_whenTwoThreadsAddElements_thenCorrectMapSize() throws InterruptedException { - Map syncMap = Collections.synchronizedMap(new HashMap<>()); - - Runnable mapOperations = () -> { - syncMap.put(1, "one"); - syncMap.put(2, "two"); - syncMap.put(3, "three"); - - }; - Thread thread1 = new Thread(mapOperations); - Thread thread2 = new Thread(mapOperations); - thread1.start(); - thread2.start(); - thread1.join(); - thread2.join(); - - assertThat(syncMap.size()).isEqualTo(3); - } -} +package com.baeldung.synchronizedcollections.test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.junit.Test; +import static org.assertj.core.api.Assertions.*; + +public class SynchronizedMapUnitTest { + + @Test + public void givenSynchronizedMap_whenTwoThreadsAddElements_thenCorrectMapSize() throws InterruptedException { + Map syncMap = Collections.synchronizedMap(new HashMap<>()); + + Runnable mapOperations = () -> { + syncMap.put(1, "one"); + syncMap.put(2, "two"); + syncMap.put(3, "three"); + + }; + Thread thread1 = new Thread(mapOperations); + Thread thread2 = new Thread(mapOperations); + thread1.start(); + thread2.start(); + thread1.join(); + thread2.join(); + + assertThat(syncMap.size()).isEqualTo(3); + } +} diff --git a/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSetUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSetUnitTest.java similarity index 97% rename from core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSetUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSetUnitTest.java index 58a33b207d..f88f58a55b 100644 --- a/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSetUnitTest.java +++ b/core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSetUnitTest.java @@ -1,26 +1,26 @@ -package com.baeldung.synchronizedcollections.test; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import org.junit.Test; -import static org.assertj.core.api.Assertions.*; - -public class SynchronizedSetUnitTest { - - @Test - public void givenSynchronizedSet_whenTwoThreadsAddElements_thenCorrectSetSize() throws InterruptedException { - Set syncSet = Collections.synchronizedSet(new HashSet<>()); - - Runnable setOperations = () -> {syncSet.addAll(Arrays.asList(1, 2, 3, 4, 5, 6));}; - Thread thread1 = new Thread(setOperations); - Thread thread2 = new Thread(setOperations); - thread1.start(); - thread2.start(); - thread1.join(); - thread2.join(); - - assertThat(syncSet.size()).isEqualTo(6); - } -} +package com.baeldung.synchronizedcollections.test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import org.junit.Test; +import static org.assertj.core.api.Assertions.*; + +public class SynchronizedSetUnitTest { + + @Test + public void givenSynchronizedSet_whenTwoThreadsAddElements_thenCorrectSetSize() throws InterruptedException { + Set syncSet = Collections.synchronizedSet(new HashSet<>()); + + Runnable setOperations = () -> {syncSet.addAll(Arrays.asList(1, 2, 3, 4, 5, 6));}; + Thread thread1 = new Thread(setOperations); + Thread thread2 = new Thread(setOperations); + thread1.start(); + thread2.start(); + thread1.join(); + thread2.join(); + + assertThat(syncSet.size()).isEqualTo(6); + } +} diff --git a/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSortedMapUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSortedMapUnitTest.java similarity index 97% rename from core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSortedMapUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSortedMapUnitTest.java index 4b0ed6d8c8..23933b2b4b 100644 --- a/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSortedMapUnitTest.java +++ b/core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSortedMapUnitTest.java @@ -1,29 +1,29 @@ -package com.baeldung.synchronizedcollections.test; - -import java.util.Collections; -import java.util.Map; -import java.util.TreeMap; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; - -public class SynchronizedSortedMapUnitTest { - - @Test - public void givenSynchronizedSorteMap_whenTwoThreadsAddElements_thenCorrectSortedMapSize() throws InterruptedException { - Map syncSortedMap = Collections.synchronizedSortedMap(new TreeMap<>()); - - Runnable sortedMapOperations = () -> { - syncSortedMap.put(1, "One"); - syncSortedMap.put(2, "Two"); - syncSortedMap.put(3, "Three"); - }; - Thread thread1 = new Thread(sortedMapOperations); - Thread thread2 = new Thread(sortedMapOperations); - thread1.start(); - thread2.start(); - thread1.join(); - thread2.join(); - - assertThat(syncSortedMap.size()).isEqualTo(3); - } -} +package com.baeldung.synchronizedcollections.test; + +import java.util.Collections; +import java.util.Map; +import java.util.TreeMap; +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; + +public class SynchronizedSortedMapUnitTest { + + @Test + public void givenSynchronizedSorteMap_whenTwoThreadsAddElements_thenCorrectSortedMapSize() throws InterruptedException { + Map syncSortedMap = Collections.synchronizedSortedMap(new TreeMap<>()); + + Runnable sortedMapOperations = () -> { + syncSortedMap.put(1, "One"); + syncSortedMap.put(2, "Two"); + syncSortedMap.put(3, "Three"); + }; + Thread thread1 = new Thread(sortedMapOperations); + Thread thread2 = new Thread(sortedMapOperations); + thread1.start(); + thread2.start(); + thread1.join(); + thread2.join(); + + assertThat(syncSortedMap.size()).isEqualTo(3); + } +} diff --git a/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSortedSetUnitTest.java b/core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSortedSetUnitTest.java similarity index 97% rename from core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSortedSetUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSortedSetUnitTest.java index 0e26c6eb1c..3ce1e6ed26 100644 --- a/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSortedSetUnitTest.java +++ b/core-java-modules/core-java-collections/src/test/java/com/baeldung/synchronizedcollections/test/SynchronizedSortedSetUnitTest.java @@ -1,28 +1,28 @@ -package com.baeldung.synchronizedcollections.test; - -import java.util.Arrays; -import java.util.Collections; -import java.util.SortedSet; -import java.util.TreeSet; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; - -public class SynchronizedSortedSetUnitTest { - - @Test - public void givenSynchronizedSortedSet_whenTwoThreadsAddElements_thenCorrectSortedSetSize() throws InterruptedException { - SortedSet syncSortedSet = Collections.synchronizedSortedSet(new TreeSet<>()); - - Runnable sortedSetOperations = () -> {syncSortedSet.addAll(Arrays.asList(1, 2, 3, 4, 5, 6));}; - sortedSetOperations.run(); - sortedSetOperations.run(); - Thread thread1 = new Thread(sortedSetOperations); - Thread thread2 = new Thread(sortedSetOperations); - thread1.start(); - thread2.start(); - thread1.join(); - thread2.join(); - - assertThat(syncSortedSet.size()).isEqualTo(6); - } -} +package com.baeldung.synchronizedcollections.test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.SortedSet; +import java.util.TreeSet; +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; + +public class SynchronizedSortedSetUnitTest { + + @Test + public void givenSynchronizedSortedSet_whenTwoThreadsAddElements_thenCorrectSortedSetSize() throws InterruptedException { + SortedSet syncSortedSet = Collections.synchronizedSortedSet(new TreeSet<>()); + + Runnable sortedSetOperations = () -> {syncSortedSet.addAll(Arrays.asList(1, 2, 3, 4, 5, 6));}; + sortedSetOperations.run(); + sortedSetOperations.run(); + Thread thread1 = new Thread(sortedSetOperations); + Thread thread2 = new Thread(sortedSetOperations); + thread1.start(); + thread2.start(); + thread1.join(); + thread2.join(); + + assertThat(syncSortedSet.size()).isEqualTo(6); + } +} diff --git a/core-java-collections/src/test/java/org/baeldung/java/collections/CollectionsConcatenateUnitTest.java b/core-java-modules/core-java-collections/src/test/java/org/baeldung/java/collections/CollectionsConcatenateUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/org/baeldung/java/collections/CollectionsConcatenateUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/org/baeldung/java/collections/CollectionsConcatenateUnitTest.java diff --git a/core-java-collections/src/test/java/org/baeldung/java/collections/CollectionsJoinAndSplitJUnitTest.java b/core-java-modules/core-java-collections/src/test/java/org/baeldung/java/collections/CollectionsJoinAndSplitJUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/org/baeldung/java/collections/CollectionsJoinAndSplitJUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/org/baeldung/java/collections/CollectionsJoinAndSplitJUnitTest.java diff --git a/core-java-collections/src/test/java/org/baeldung/java/collections/JoinSplitCollectionsUnitTest.java b/core-java-modules/core-java-collections/src/test/java/org/baeldung/java/collections/JoinSplitCollectionsUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/org/baeldung/java/collections/JoinSplitCollectionsUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/org/baeldung/java/collections/JoinSplitCollectionsUnitTest.java diff --git a/core-java-collections/src/test/java/org/baeldung/java/collections/README.md b/core-java-modules/core-java-collections/src/test/java/org/baeldung/java/collections/README.md similarity index 100% rename from core-java-collections/src/test/java/org/baeldung/java/collections/README.md rename to core-java-modules/core-java-collections/src/test/java/org/baeldung/java/collections/README.md diff --git a/core-java-collections/src/test/java/org/baeldung/java/sorting/Employee.java b/core-java-modules/core-java-collections/src/test/java/org/baeldung/java/sorting/Employee.java similarity index 100% rename from core-java-collections/src/test/java/org/baeldung/java/sorting/Employee.java rename to core-java-modules/core-java-collections/src/test/java/org/baeldung/java/sorting/Employee.java diff --git a/core-java-collections/src/test/java/org/baeldung/java/sorting/JavaSortingUnitTest.java b/core-java-modules/core-java-collections/src/test/java/org/baeldung/java/sorting/JavaSortingUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/org/baeldung/java/sorting/JavaSortingUnitTest.java rename to core-java-modules/core-java-collections/src/test/java/org/baeldung/java/sorting/JavaSortingUnitTest.java diff --git a/core-java-concurrency-advanced/.gitignore b/core-java-modules/core-java-concurrency-advanced/.gitignore similarity index 100% rename from core-java-concurrency-advanced/.gitignore rename to core-java-modules/core-java-concurrency-advanced/.gitignore diff --git a/core-java-concurrency-advanced/README.md b/core-java-modules/core-java-concurrency-advanced/README.md similarity index 100% rename from core-java-concurrency-advanced/README.md rename to core-java-modules/core-java-concurrency-advanced/README.md diff --git a/core-java-concurrency-advanced/pom.xml b/core-java-modules/core-java-concurrency-advanced/pom.xml similarity index 98% rename from core-java-concurrency-advanced/pom.xml rename to core-java-modules/core-java-concurrency-advanced/pom.xml index 23032fb2e1..a3ac7aa88a 100644 --- a/core-java-concurrency-advanced/pom.xml +++ b/core-java-modules/core-java-concurrency-advanced/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithLock.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithLock.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithLock.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithLock.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithoutLock.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithoutLock.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithoutLock.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithoutLock.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/atomic/UnsafeCounter.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/atomic/UnsafeCounter.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/atomic/UnsafeCounter.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/atomic/UnsafeCounter.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/BrokenWorker.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/BrokenWorker.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/BrokenWorker.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/BrokenWorker.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExample.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExample.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExample.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExample.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/WaitingWorker.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/WaitingWorker.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/WaitingWorker.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/WaitingWorker.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/Worker.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/Worker.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/Worker.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/countdownlatch/Worker.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExample.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExample.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExample.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExample.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierDemo.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierDemo.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierDemo.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierDemo.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/daemon/MultipleThreadsExample.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/daemon/MultipleThreadsExample.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/daemon/MultipleThreadsExample.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/daemon/MultipleThreadsExample.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/daemon/NewThread.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/daemon/NewThread.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/daemon/NewThread.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/daemon/NewThread.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/daemon/SingleThreadExample.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/daemon/SingleThreadExample.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/daemon/SingleThreadExample.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/daemon/SingleThreadExample.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/diningphilosophers/DiningPhilosophers.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/diningphilosophers/DiningPhilosophers.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/diningphilosophers/DiningPhilosophers.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/diningphilosophers/DiningPhilosophers.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/diningphilosophers/Philosopher.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/diningphilosophers/Philosopher.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/diningphilosophers/Philosopher.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/diningphilosophers/Philosopher.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/evenandodd/PrintEvenOddSemaphore.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/evenandodd/PrintEvenOddSemaphore.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/evenandodd/PrintEvenOddSemaphore.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/evenandodd/PrintEvenOddSemaphore.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/evenandodd/PrintEvenOddWaitNotify.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/evenandodd/PrintEvenOddWaitNotify.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/evenandodd/PrintEvenOddWaitNotify.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/evenandodd/PrintEvenOddWaitNotify.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/ReentrantLockWithCondition.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/ReentrantLockWithCondition.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/ReentrantLockWithCondition.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/ReentrantLockWithCondition.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/SharedObjectWithLock.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/SharedObjectWithLock.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/SharedObjectWithLock.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/SharedObjectWithLock.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/StampedLockDemo.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/StampedLockDemo.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/StampedLockDemo.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/StampedLockDemo.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/SynchronizedHashMapWithRWLock.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/SynchronizedHashMapWithRWLock.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/SynchronizedHashMapWithRWLock.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/locks/SynchronizedHashMapWithRWLock.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/parameter/AverageCalculator.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/parameter/AverageCalculator.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/parameter/AverageCalculator.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/parameter/AverageCalculator.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/parameter/ParameterizedThreadExample.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/parameter/ParameterizedThreadExample.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/parameter/ParameterizedThreadExample.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/parameter/ParameterizedThreadExample.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/phaser/LongRunningAction.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/phaser/LongRunningAction.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/phaser/LongRunningAction.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/phaser/LongRunningAction.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/prioritytaskexecution/Job.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/prioritytaskexecution/Job.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/prioritytaskexecution/Job.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/prioritytaskexecution/Job.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/prioritytaskexecution/JobPriority.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/prioritytaskexecution/JobPriority.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/prioritytaskexecution/JobPriority.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/prioritytaskexecution/JobPriority.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/prioritytaskexecution/PriorityJobScheduler.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/prioritytaskexecution/PriorityJobScheduler.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/prioritytaskexecution/PriorityJobScheduler.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/prioritytaskexecution/PriorityJobScheduler.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/semaphores/CounterUsingMutex.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/semaphores/CounterUsingMutex.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/semaphores/CounterUsingMutex.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/semaphores/CounterUsingMutex.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/semaphores/DelayQueueUsingTimedSemaphore.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/semaphores/DelayQueueUsingTimedSemaphore.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/semaphores/DelayQueueUsingTimedSemaphore.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/semaphores/DelayQueueUsingTimedSemaphore.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/semaphores/LoginQueueUsingSemaphore.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/semaphores/LoginQueueUsingSemaphore.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/semaphores/LoginQueueUsingSemaphore.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/semaphores/LoginQueueUsingSemaphore.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/volatilekeyword/SharedObject.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/volatilekeyword/SharedObject.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/volatilekeyword/SharedObject.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/volatilekeyword/SharedObject.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/yield/ThreadYield.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/yield/ThreadYield.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/yield/ThreadYield.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/yield/ThreadYield.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/forkjoin/CustomRecursiveAction.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/forkjoin/CustomRecursiveAction.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/forkjoin/CustomRecursiveAction.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/forkjoin/CustomRecursiveAction.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/forkjoin/CustomRecursiveTask.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/forkjoin/CustomRecursiveTask.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/forkjoin/CustomRecursiveTask.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/forkjoin/CustomRecursiveTask.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/forkjoin/util/PoolUtil.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/forkjoin/util/PoolUtil.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/forkjoin/util/PoolUtil.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/forkjoin/util/PoolUtil.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/Context.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/Context.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/Context.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/Context.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/SharedMapWithUserContext.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/SharedMapWithUserContext.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/SharedMapWithUserContext.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/SharedMapWithUserContext.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/ThreadLocalWithUserContext.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/ThreadLocalWithUserContext.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/ThreadLocalWithUserContext.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/ThreadLocalWithUserContext.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/UserRepository.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/UserRepository.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/UserRepository.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/UserRepository.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocalrandom/ThreadLocalRandomBenchMarkRunner.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocalrandom/ThreadLocalRandomBenchMarkRunner.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocalrandom/ThreadLocalRandomBenchMarkRunner.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocalrandom/ThreadLocalRandomBenchMarkRunner.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocalrandom/ThreadLocalRandomBenchMarker.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocalrandom/ThreadLocalRandomBenchMarker.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocalrandom/ThreadLocalRandomBenchMarker.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocalrandom/ThreadLocalRandomBenchMarker.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/threadpool/CountingTask.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadpool/CountingTask.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/threadpool/CountingTask.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadpool/CountingTask.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/threadpool/ExitingExecutorServiceExample.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadpool/ExitingExecutorServiceExample.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/threadpool/ExitingExecutorServiceExample.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadpool/ExitingExecutorServiceExample.java diff --git a/core-java-concurrency-advanced/src/main/java/com/baeldung/threadpool/TreeNode.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadpool/TreeNode.java similarity index 100% rename from core-java-concurrency-advanced/src/main/java/com/baeldung/threadpool/TreeNode.java rename to core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadpool/TreeNode.java diff --git a/core-java-concurrency-advanced/src/main/java/log4j.properties b/core-java-modules/core-java-concurrency-advanced/src/main/java/log4j.properties similarity index 100% rename from core-java-concurrency-advanced/src/main/java/log4j.properties rename to core-java-modules/core-java-concurrency-advanced/src/main/java/log4j.properties diff --git a/core-java-concurrency-advanced/src/main/resources/logback.xml b/core-java-modules/core-java-concurrency-advanced/src/main/resources/logback.xml similarity index 100% rename from core-java-concurrency-advanced/src/main/resources/logback.xml rename to core-java-modules/core-java-concurrency-advanced/src/main/resources/logback.xml diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/accumulator/LongAccumulatorUnitTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/accumulator/LongAccumulatorUnitTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/accumulator/LongAccumulatorUnitTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/accumulator/LongAccumulatorUnitTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/adder/LongAdderUnitTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/adder/LongAdderUnitTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/adder/LongAdderUnitTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/adder/LongAdderUnitTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/atomic/ThreadSafeCounterIntegrationTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/atomic/ThreadSafeCounterIntegrationTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/atomic/ThreadSafeCounterIntegrationTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/atomic/ThreadSafeCounterIntegrationTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/atomic/ThreadUnsafeCounterManualTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/atomic/ThreadUnsafeCounterManualTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/atomic/ThreadUnsafeCounterManualTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/atomic/ThreadUnsafeCounterManualTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExampleUnitTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExampleUnitTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExampleUnitTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExampleUnitTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchExampleIntegrationTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchExampleIntegrationTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchExampleIntegrationTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchExampleIntegrationTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExampleUnitTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExampleUnitTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExampleUnitTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExampleUnitTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/daemon/DaemonThreadUnitTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/daemon/DaemonThreadUnitTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/daemon/DaemonThreadUnitTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/daemon/DaemonThreadUnitTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/locks/SharedObjectWithLockManualTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/locks/SharedObjectWithLockManualTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/locks/SharedObjectWithLockManualTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/locks/SharedObjectWithLockManualTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/locks/SynchronizedHashMapWithRWLockManualTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/locks/SynchronizedHashMapWithRWLockManualTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/locks/SynchronizedHashMapWithRWLockManualTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/locks/SynchronizedHashMapWithRWLockManualTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/phaser/PhaserUnitTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/phaser/PhaserUnitTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/phaser/PhaserUnitTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/phaser/PhaserUnitTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/prioritytaskexecution/PriorityJobSchedulerUnitTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/prioritytaskexecution/PriorityJobSchedulerUnitTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/prioritytaskexecution/PriorityJobSchedulerUnitTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/prioritytaskexecution/PriorityJobSchedulerUnitTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/semaphores/SemaphoresManualTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/semaphores/SemaphoresManualTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/semaphores/SemaphoresManualTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/semaphores/SemaphoresManualTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/java8/Java8ForkJoinIntegrationTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/java8/Java8ForkJoinIntegrationTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/java8/Java8ForkJoinIntegrationTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/java8/Java8ForkJoinIntegrationTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/parameters/ParameterizedThreadUnitTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/parameters/ParameterizedThreadUnitTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/parameters/ParameterizedThreadUnitTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/parameters/ParameterizedThreadUnitTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/thread/join/ThreadJoinUnitTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/thread/join/ThreadJoinUnitTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/thread/join/ThreadJoinUnitTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/thread/join/ThreadJoinUnitTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/threadlocal/ThreadLocalIntegrationTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/threadlocal/ThreadLocalIntegrationTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/threadlocal/ThreadLocalIntegrationTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/threadlocal/ThreadLocalIntegrationTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/threadlocalrandom/ThreadLocalRandomIntegrationTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/threadlocalrandom/ThreadLocalRandomIntegrationTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/threadlocalrandom/ThreadLocalRandomIntegrationTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/threadlocalrandom/ThreadLocalRandomIntegrationTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/threadpool/CoreThreadPoolIntegrationTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/threadpool/CoreThreadPoolIntegrationTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/threadpool/CoreThreadPoolIntegrationTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/threadpool/CoreThreadPoolIntegrationTest.java diff --git a/core-java-concurrency-advanced/src/test/java/com/baeldung/threadpool/GuavaThreadPoolIntegrationTest.java b/core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/threadpool/GuavaThreadPoolIntegrationTest.java similarity index 100% rename from core-java-concurrency-advanced/src/test/java/com/baeldung/threadpool/GuavaThreadPoolIntegrationTest.java rename to core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/threadpool/GuavaThreadPoolIntegrationTest.java diff --git a/core-java-concurrency-advanced/src/test/resources/.gitignore b/core-java-modules/core-java-concurrency-advanced/src/test/resources/.gitignore similarity index 100% rename from core-java-concurrency-advanced/src/test/resources/.gitignore rename to core-java-modules/core-java-concurrency-advanced/src/test/resources/.gitignore diff --git a/core-java-concurrency-basic/.gitignore b/core-java-modules/core-java-concurrency-basic/.gitignore similarity index 100% rename from core-java-concurrency-basic/.gitignore rename to core-java-modules/core-java-concurrency-basic/.gitignore diff --git a/core-java-concurrency-basic/README.md b/core-java-modules/core-java-concurrency-basic/README.md similarity index 100% rename from core-java-concurrency-basic/README.md rename to core-java-modules/core-java-concurrency-basic/README.md diff --git a/core-java-concurrency-basic/pom.xml b/core-java-modules/core-java-concurrency-basic/pom.xml similarity index 97% rename from core-java-concurrency-basic/pom.xml rename to core-java-modules/core-java-concurrency-basic/pom.xml index 35c360769b..aea4bef6a7 100644 --- a/core-java-concurrency-basic/pom.xml +++ b/core-java-modules/core-java-concurrency-basic/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/Scheduledexecutorservice/ScheduledExecutorServiceDemo.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/Scheduledexecutorservice/ScheduledExecutorServiceDemo.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/Scheduledexecutorservice/ScheduledExecutorServiceDemo.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/Scheduledexecutorservice/ScheduledExecutorServiceDemo.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/callable/FactorialTask.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/callable/FactorialTask.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/callable/FactorialTask.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/callable/FactorialTask.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierExample.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierExample.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierExample.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierExample.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/cyclicbarrier/Task.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/cyclicbarrier/Task.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/cyclicbarrier/Task.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/cyclicbarrier/Task.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executor/ExecutorDemo.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executor/ExecutorDemo.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executor/ExecutorDemo.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executor/ExecutorDemo.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executor/Invoker.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executor/Invoker.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executor/Invoker.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executor/Invoker.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executorservice/DelayedCallable.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executorservice/DelayedCallable.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executorservice/DelayedCallable.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executorservice/DelayedCallable.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executorservice/ExecutorServiceDemo.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executorservice/ExecutorServiceDemo.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executorservice/ExecutorServiceDemo.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executorservice/ExecutorServiceDemo.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executorservice/Task.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executorservice/Task.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executorservice/Task.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/executorservice/Task.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/future/FactorialSquareCalculator.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/future/FactorialSquareCalculator.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/future/FactorialSquareCalculator.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/future/FactorialSquareCalculator.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/future/FutureDemo.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/future/FutureDemo.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/future/FutureDemo.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/future/FutureDemo.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/future/SquareCalculator.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/future/SquareCalculator.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/future/SquareCalculator.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/future/SquareCalculator.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/runnable/EventLoggingTask.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/runnable/EventLoggingTask.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/runnable/EventLoggingTask.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/runnable/EventLoggingTask.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/runnable/TaskRunner.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/runnable/TaskRunner.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/runnable/TaskRunner.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/runnable/TaskRunner.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/semaphore/SemaPhoreDemo.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/semaphore/SemaPhoreDemo.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/semaphore/SemaPhoreDemo.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/semaphore/SemaPhoreDemo.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/sleepwait/ThreadA.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/sleepwait/ThreadA.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/sleepwait/ThreadA.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/sleepwait/ThreadA.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/sleepwait/ThreadB.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/sleepwait/ThreadB.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/sleepwait/ThreadB.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/sleepwait/ThreadB.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/sleepwait/WaitSleepExample.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/sleepwait/WaitSleepExample.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/sleepwait/WaitSleepExample.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/sleepwait/WaitSleepExample.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/stopping/ControlSubThread.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/stopping/ControlSubThread.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/stopping/ControlSubThread.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/stopping/ControlSubThread.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/synchronize/BaeldungSynchronizedBlocks.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/synchronize/BaeldungSynchronizedBlocks.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/synchronize/BaeldungSynchronizedBlocks.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/synchronize/BaeldungSynchronizedBlocks.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/synchronize/BaeldungSynchronizedMethods.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/synchronize/BaeldungSynchronizedMethods.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/synchronize/BaeldungSynchronizedMethods.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/synchronize/BaeldungSynchronizedMethods.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadfactory/BaeldungThreadFactory.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadfactory/BaeldungThreadFactory.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadfactory/BaeldungThreadFactory.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadfactory/BaeldungThreadFactory.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadfactory/Demo.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadfactory/Demo.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadfactory/Demo.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadfactory/Demo.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadfactory/Task.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadfactory/Task.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadfactory/Task.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadfactory/Task.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/BlockedState.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/BlockedState.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/BlockedState.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/BlockedState.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/NewState.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/NewState.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/NewState.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/NewState.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/RunnableState.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/RunnableState.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/RunnableState.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/RunnableState.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/TerminatedState.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/TerminatedState.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/TerminatedState.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/TerminatedState.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/TimedWaitingState.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/TimedWaitingState.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/TimedWaitingState.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/TimedWaitingState.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/WaitingState.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/WaitingState.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/WaitingState.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadlifecycle/WaitingState.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/application/Application.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/application/Application.java similarity index 98% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/application/Application.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/application/Application.java index 0c5caba8a0..5fcb28cd2a 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/application/Application.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/application/Application.java @@ -1,86 +1,86 @@ -package com.baeldung.concurrent.threadsafety.application; - -import com.baeldung.concurrent.threadsafety.callables.AtomicCounterCallable; -import com.baeldung.concurrent.threadsafety.mathutils.MathUtils; -import com.baeldung.concurrent.threadsafety.callables.CounterCallable; -import com.baeldung.concurrent.threadsafety.callables.ExtrinsicLockCounterCallable; -import com.baeldung.concurrent.threadsafety.callables.MessageServiceCallable; -import com.baeldung.concurrent.threadsafety.callables.ReentranReadWriteLockCounterCallable; -import com.baeldung.concurrent.threadsafety.callables.ReentrantLockCounterCallable; -import com.baeldung.concurrent.threadsafety.services.AtomicCounter; -import com.baeldung.concurrent.threadsafety.services.Counter; -import com.baeldung.concurrent.threadsafety.services.ExtrinsicLockCounter; -import com.baeldung.concurrent.threadsafety.services.MessageService; -import com.baeldung.concurrent.threadsafety.services.ReentrantLockCounter; -import com.baeldung.concurrent.threadsafety.services.ReentrantReadWriteLockCounter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -public class Application { - - public static void main(String[] args) throws InterruptedException, ExecutionException { - - new Thread(() -> { - System.out.println(MathUtils.factorial(10)); - }).start(); - new Thread(() -> { - System.out.println(MathUtils.factorial(5)); - }).start(); - - ExecutorService executorService = Executors.newFixedThreadPool(10); - MessageService messageService = new MessageService("Welcome to Baeldung!"); - Future future1 = (Future) executorService.submit(new MessageServiceCallable(messageService)); - Future future2 = (Future) executorService.submit(new MessageServiceCallable(messageService)); - System.out.println(future1.get()); - System.out.println(future2.get()); - - Counter counter = new Counter(); - Future future3 = (Future) executorService.submit(new CounterCallable(counter)); - Future future4 = (Future) executorService.submit(new CounterCallable(counter)); - System.out.println(future3.get()); - System.out.println(future4.get()); - - ExtrinsicLockCounter extrinsicLockCounter = new ExtrinsicLockCounter(); - Future future5 = (Future) executorService.submit(new ExtrinsicLockCounterCallable(extrinsicLockCounter)); - Future future6 = (Future) executorService.submit(new ExtrinsicLockCounterCallable(extrinsicLockCounter)); - System.out.println(future5.get()); - System.out.println(future6.get()); - - ReentrantLockCounter reentrantLockCounter = new ReentrantLockCounter(); - Future future7 = (Future) executorService.submit(new ReentrantLockCounterCallable(reentrantLockCounter)); - Future future8 = (Future) executorService.submit(new ReentrantLockCounterCallable(reentrantLockCounter)); - System.out.println(future7.get()); - System.out.println(future8.get()); - - ReentrantReadWriteLockCounter reentrantReadWriteLockCounter = new ReentrantReadWriteLockCounter(); - Future future9 = (Future) executorService.submit(new ReentranReadWriteLockCounterCallable(reentrantReadWriteLockCounter)); - Future future10 = (Future) executorService.submit(new ReentranReadWriteLockCounterCallable(reentrantReadWriteLockCounter)); - System.out.println(future9.get()); - System.out.println(future10.get()); - - AtomicCounter atomicCounter = new AtomicCounter(); - Future future11 = (Future) executorService.submit(new AtomicCounterCallable(atomicCounter)); - Future future12 = (Future) executorService.submit(new AtomicCounterCallable(atomicCounter)); - System.out.println(future11.get()); - System.out.println(future12.get()); - - Collection syncCollection = Collections.synchronizedCollection(new ArrayList<>()); - Thread thread11 = new Thread(() -> syncCollection.addAll(Arrays.asList(1, 2, 3, 4, 5, 6))); - Thread thread12 = new Thread(() -> syncCollection.addAll(Arrays.asList(1, 2, 3, 4, 5, 6))); - thread11.start(); - thread12.start(); - - Map concurrentMap = new ConcurrentHashMap<>(); - concurrentMap.put("1", "one"); - concurrentMap.put("2", "two"); - concurrentMap.put("3", "three"); - } -} +package com.baeldung.concurrent.threadsafety.application; + +import com.baeldung.concurrent.threadsafety.callables.AtomicCounterCallable; +import com.baeldung.concurrent.threadsafety.mathutils.MathUtils; +import com.baeldung.concurrent.threadsafety.callables.CounterCallable; +import com.baeldung.concurrent.threadsafety.callables.ExtrinsicLockCounterCallable; +import com.baeldung.concurrent.threadsafety.callables.MessageServiceCallable; +import com.baeldung.concurrent.threadsafety.callables.ReentranReadWriteLockCounterCallable; +import com.baeldung.concurrent.threadsafety.callables.ReentrantLockCounterCallable; +import com.baeldung.concurrent.threadsafety.services.AtomicCounter; +import com.baeldung.concurrent.threadsafety.services.Counter; +import com.baeldung.concurrent.threadsafety.services.ExtrinsicLockCounter; +import com.baeldung.concurrent.threadsafety.services.MessageService; +import com.baeldung.concurrent.threadsafety.services.ReentrantLockCounter; +import com.baeldung.concurrent.threadsafety.services.ReentrantReadWriteLockCounter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +public class Application { + + public static void main(String[] args) throws InterruptedException, ExecutionException { + + new Thread(() -> { + System.out.println(MathUtils.factorial(10)); + }).start(); + new Thread(() -> { + System.out.println(MathUtils.factorial(5)); + }).start(); + + ExecutorService executorService = Executors.newFixedThreadPool(10); + MessageService messageService = new MessageService("Welcome to Baeldung!"); + Future future1 = (Future) executorService.submit(new MessageServiceCallable(messageService)); + Future future2 = (Future) executorService.submit(new MessageServiceCallable(messageService)); + System.out.println(future1.get()); + System.out.println(future2.get()); + + Counter counter = new Counter(); + Future future3 = (Future) executorService.submit(new CounterCallable(counter)); + Future future4 = (Future) executorService.submit(new CounterCallable(counter)); + System.out.println(future3.get()); + System.out.println(future4.get()); + + ExtrinsicLockCounter extrinsicLockCounter = new ExtrinsicLockCounter(); + Future future5 = (Future) executorService.submit(new ExtrinsicLockCounterCallable(extrinsicLockCounter)); + Future future6 = (Future) executorService.submit(new ExtrinsicLockCounterCallable(extrinsicLockCounter)); + System.out.println(future5.get()); + System.out.println(future6.get()); + + ReentrantLockCounter reentrantLockCounter = new ReentrantLockCounter(); + Future future7 = (Future) executorService.submit(new ReentrantLockCounterCallable(reentrantLockCounter)); + Future future8 = (Future) executorService.submit(new ReentrantLockCounterCallable(reentrantLockCounter)); + System.out.println(future7.get()); + System.out.println(future8.get()); + + ReentrantReadWriteLockCounter reentrantReadWriteLockCounter = new ReentrantReadWriteLockCounter(); + Future future9 = (Future) executorService.submit(new ReentranReadWriteLockCounterCallable(reentrantReadWriteLockCounter)); + Future future10 = (Future) executorService.submit(new ReentranReadWriteLockCounterCallable(reentrantReadWriteLockCounter)); + System.out.println(future9.get()); + System.out.println(future10.get()); + + AtomicCounter atomicCounter = new AtomicCounter(); + Future future11 = (Future) executorService.submit(new AtomicCounterCallable(atomicCounter)); + Future future12 = (Future) executorService.submit(new AtomicCounterCallable(atomicCounter)); + System.out.println(future11.get()); + System.out.println(future12.get()); + + Collection syncCollection = Collections.synchronizedCollection(new ArrayList<>()); + Thread thread11 = new Thread(() -> syncCollection.addAll(Arrays.asList(1, 2, 3, 4, 5, 6))); + Thread thread12 = new Thread(() -> syncCollection.addAll(Arrays.asList(1, 2, 3, 4, 5, 6))); + thread11.start(); + thread12.start(); + + Map concurrentMap = new ConcurrentHashMap<>(); + concurrentMap.put("1", "one"); + concurrentMap.put("2", "two"); + concurrentMap.put("3", "three"); + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/AtomicCounterCallable.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/AtomicCounterCallable.java similarity index 96% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/AtomicCounterCallable.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/AtomicCounterCallable.java index d711299b5c..27f7bf598e 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/AtomicCounterCallable.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/AtomicCounterCallable.java @@ -1,19 +1,19 @@ -package com.baeldung.concurrent.threadsafety.callables; - -import com.baeldung.concurrent.threadsafety.services.AtomicCounter; -import java.util.concurrent.Callable; - -public class AtomicCounterCallable implements Callable { - - private final AtomicCounter counter; - - public AtomicCounterCallable(AtomicCounter counter) { - this.counter = counter; - } - - @Override - public Integer call() throws Exception { - counter.incrementCounter(); - return counter.getCounter(); - } -} +package com.baeldung.concurrent.threadsafety.callables; + +import com.baeldung.concurrent.threadsafety.services.AtomicCounter; +import java.util.concurrent.Callable; + +public class AtomicCounterCallable implements Callable { + + private final AtomicCounter counter; + + public AtomicCounterCallable(AtomicCounter counter) { + this.counter = counter; + } + + @Override + public Integer call() throws Exception { + counter.incrementCounter(); + return counter.getCounter(); + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/CounterCallable.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/CounterCallable.java similarity index 96% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/CounterCallable.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/CounterCallable.java index cdcd84a17b..feca4d7db5 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/CounterCallable.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/CounterCallable.java @@ -1,19 +1,19 @@ -package com.baeldung.concurrent.threadsafety.callables; - -import com.baeldung.concurrent.threadsafety.services.Counter; -import java.util.concurrent.Callable; - -public class CounterCallable implements Callable { - - private final Counter counter; - - public CounterCallable(Counter counter) { - this.counter = counter; - } - - @Override - public Integer call() throws Exception { - counter.incrementCounter(); - return counter.getCounter(); - } -} +package com.baeldung.concurrent.threadsafety.callables; + +import com.baeldung.concurrent.threadsafety.services.Counter; +import java.util.concurrent.Callable; + +public class CounterCallable implements Callable { + + private final Counter counter; + + public CounterCallable(Counter counter) { + this.counter = counter; + } + + @Override + public Integer call() throws Exception { + counter.incrementCounter(); + return counter.getCounter(); + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ExtrinsicLockCounterCallable.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ExtrinsicLockCounterCallable.java similarity index 96% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ExtrinsicLockCounterCallable.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ExtrinsicLockCounterCallable.java index 29533e7630..370e5d1f00 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ExtrinsicLockCounterCallable.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ExtrinsicLockCounterCallable.java @@ -1,19 +1,19 @@ -package com.baeldung.concurrent.threadsafety.callables; - -import com.baeldung.concurrent.threadsafety.services.ExtrinsicLockCounter; -import java.util.concurrent.Callable; - -public class ExtrinsicLockCounterCallable implements Callable { - - private final ExtrinsicLockCounter counter; - - public ExtrinsicLockCounterCallable(ExtrinsicLockCounter counter) { - this.counter = counter; - } - - @Override - public Integer call() throws Exception { - counter.incrementCounter(); - return counter.getCounter(); - } -} +package com.baeldung.concurrent.threadsafety.callables; + +import com.baeldung.concurrent.threadsafety.services.ExtrinsicLockCounter; +import java.util.concurrent.Callable; + +public class ExtrinsicLockCounterCallable implements Callable { + + private final ExtrinsicLockCounter counter; + + public ExtrinsicLockCounterCallable(ExtrinsicLockCounter counter) { + this.counter = counter; + } + + @Override + public Integer call() throws Exception { + counter.incrementCounter(); + return counter.getCounter(); + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/MessageServiceCallable.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/MessageServiceCallable.java similarity index 96% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/MessageServiceCallable.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/MessageServiceCallable.java index 84e8c7bb51..5fff2de0c8 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/MessageServiceCallable.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/MessageServiceCallable.java @@ -1,19 +1,19 @@ -package com.baeldung.concurrent.threadsafety.callables; - -import com.baeldung.concurrent.threadsafety.services.MessageService; -import java.util.concurrent.Callable; - -public class MessageServiceCallable implements Callable { - - private final MessageService messageService; - - public MessageServiceCallable(MessageService messageService) { - this.messageService = messageService; - - } - - @Override - public String call() { - return messageService.getMesssage(); - } -} +package com.baeldung.concurrent.threadsafety.callables; + +import com.baeldung.concurrent.threadsafety.services.MessageService; +import java.util.concurrent.Callable; + +public class MessageServiceCallable implements Callable { + + private final MessageService messageService; + + public MessageServiceCallable(MessageService messageService) { + this.messageService = messageService; + + } + + @Override + public String call() { + return messageService.getMesssage(); + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ReentranReadWriteLockCounterCallable.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ReentranReadWriteLockCounterCallable.java similarity index 96% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ReentranReadWriteLockCounterCallable.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ReentranReadWriteLockCounterCallable.java index e806460d50..f0948daa09 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ReentranReadWriteLockCounterCallable.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ReentranReadWriteLockCounterCallable.java @@ -1,20 +1,20 @@ -package com.baeldung.concurrent.threadsafety.callables; - -import com.baeldung.concurrent.threadsafety.services.ReentrantReadWriteLockCounter; -import java.util.concurrent.Callable; - -public class ReentranReadWriteLockCounterCallable implements Callable { - - private final ReentrantReadWriteLockCounter counter; - - public ReentranReadWriteLockCounterCallable(ReentrantReadWriteLockCounter counter) { - this.counter = counter; - } - - @Override - public Integer call() throws Exception { - counter.incrementCounter(); - return counter.getCounter(); - } - -} +package com.baeldung.concurrent.threadsafety.callables; + +import com.baeldung.concurrent.threadsafety.services.ReentrantReadWriteLockCounter; +import java.util.concurrent.Callable; + +public class ReentranReadWriteLockCounterCallable implements Callable { + + private final ReentrantReadWriteLockCounter counter; + + public ReentranReadWriteLockCounterCallable(ReentrantReadWriteLockCounter counter) { + this.counter = counter; + } + + @Override + public Integer call() throws Exception { + counter.incrementCounter(); + return counter.getCounter(); + } + +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ReentrantLockCounterCallable.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ReentrantLockCounterCallable.java similarity index 96% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ReentrantLockCounterCallable.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ReentrantLockCounterCallable.java index 3511a98c60..572d6ad22f 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ReentrantLockCounterCallable.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/callables/ReentrantLockCounterCallable.java @@ -1,19 +1,19 @@ -package com.baeldung.concurrent.threadsafety.callables; - -import com.baeldung.concurrent.threadsafety.services.ReentrantLockCounter; -import java.util.concurrent.Callable; - -public class ReentrantLockCounterCallable implements Callable { - - private final ReentrantLockCounter counter; - - public ReentrantLockCounterCallable(ReentrantLockCounter counter) { - this.counter = counter; - } - - @Override - public Integer call() throws Exception { - counter.incrementCounter(); - return counter.getCounter(); - } -} +package com.baeldung.concurrent.threadsafety.callables; + +import com.baeldung.concurrent.threadsafety.services.ReentrantLockCounter; +import java.util.concurrent.Callable; + +public class ReentrantLockCounterCallable implements Callable { + + private final ReentrantLockCounter counter; + + public ReentrantLockCounterCallable(ReentrantLockCounter counter) { + this.counter = counter; + } + + @Override + public Integer call() throws Exception { + counter.incrementCounter(); + return counter.getCounter(); + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/mathutils/MathUtils.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/mathutils/MathUtils.java similarity index 96% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/mathutils/MathUtils.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/mathutils/MathUtils.java index f560cd4281..fa84c9c04d 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/mathutils/MathUtils.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/mathutils/MathUtils.java @@ -1,14 +1,14 @@ -package com.baeldung.concurrent.threadsafety.mathutils; - -import java.math.BigInteger; - -public class MathUtils { - - public static BigInteger factorial(int number) { - BigInteger f = new BigInteger("1"); - for (int i = 2; i <= number; i++) { - f = f.multiply(BigInteger.valueOf(i)); - } - return f; - } -} +package com.baeldung.concurrent.threadsafety.mathutils; + +import java.math.BigInteger; + +public class MathUtils { + + public static BigInteger factorial(int number) { + BigInteger f = new BigInteger("1"); + for (int i = 2; i <= number; i++) { + f = f.multiply(BigInteger.valueOf(i)); + } + return f; + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/AtomicCounter.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/AtomicCounter.java similarity index 95% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/AtomicCounter.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/AtomicCounter.java index 32a373495c..0e95859265 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/AtomicCounter.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/AtomicCounter.java @@ -1,18 +1,18 @@ -package com.baeldung.concurrent.threadsafety.services; - -import java.util.concurrent.atomic.AtomicInteger; - -public class AtomicCounter { - - private final AtomicInteger counter = new AtomicInteger(); - - public AtomicCounter() {} - - public void incrementCounter() { - counter.incrementAndGet(); - } - - public synchronized int getCounter() { - return counter.get(); - } -} +package com.baeldung.concurrent.threadsafety.services; + +import java.util.concurrent.atomic.AtomicInteger; + +public class AtomicCounter { + + private final AtomicInteger counter = new AtomicInteger(); + + public AtomicCounter() {} + + public void incrementCounter() { + counter.incrementAndGet(); + } + + public synchronized int getCounter() { + return counter.get(); + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/Counter.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/Counter.java similarity index 94% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/Counter.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/Counter.java index f7dbc05639..52122ae049 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/Counter.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/Counter.java @@ -1,18 +1,18 @@ -package com.baeldung.concurrent.threadsafety.services; - -public class Counter { - - private volatile int counter; - - public Counter() { - this.counter = 0; - } - - public synchronized void incrementCounter() { - counter += 1; - } - - public int getCounter() { - return counter; - } -} +package com.baeldung.concurrent.threadsafety.services; + +public class Counter { + + private volatile int counter; + + public Counter() { + this.counter = 0; + } + + public synchronized void incrementCounter() { + counter += 1; + } + + public int getCounter() { + return counter; + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ExtrinsicLockCounter.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ExtrinsicLockCounter.java similarity index 95% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ExtrinsicLockCounter.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ExtrinsicLockCounter.java index 8ab431fbc3..0a6ff3f60e 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ExtrinsicLockCounter.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ExtrinsicLockCounter.java @@ -1,23 +1,23 @@ -package com.baeldung.concurrent.threadsafety.services; - -public class ExtrinsicLockCounter { - - private int counter; - private final Object lock = new Object(); - - public ExtrinsicLockCounter() { - this.counter = 0; - } - - public void incrementCounter() { - synchronized (lock) { - counter += 1; - } - } - - public int getCounter() { - synchronized (lock) { - return counter; - } - } -} +package com.baeldung.concurrent.threadsafety.services; + +public class ExtrinsicLockCounter { + + private int counter; + private final Object lock = new Object(); + + public ExtrinsicLockCounter() { + this.counter = 0; + } + + public void incrementCounter() { + synchronized (lock) { + counter += 1; + } + } + + public int getCounter() { + synchronized (lock) { + return counter; + } + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/MessageService.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/MessageService.java similarity index 95% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/MessageService.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/MessageService.java index 33981381ea..a2b5174a9b 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/MessageService.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/MessageService.java @@ -1,14 +1,14 @@ -package com.baeldung.concurrent.threadsafety.services; - -public class MessageService { - - private final String message; - - public MessageService(String message) { - this.message = message; - } - - public String getMesssage() { - return message; - } -} +package com.baeldung.concurrent.threadsafety.services; + +public class MessageService { + + private final String message; + + public MessageService(String message) { + this.message = message; + } + + public String getMesssage() { + return message; + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ReentrantLockCounter.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ReentrantLockCounter.java similarity index 95% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ReentrantLockCounter.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ReentrantLockCounter.java index 717f0717af..346cb14c35 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ReentrantLockCounter.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ReentrantLockCounter.java @@ -1,26 +1,26 @@ -package com.baeldung.concurrent.threadsafety.services; - -import java.util.concurrent.locks.ReentrantLock; - -public class ReentrantLockCounter { - - private int counter; - private final ReentrantLock reLock = new ReentrantLock(true); - - public ReentrantLockCounter() { - this.counter = 0; - } - - public void incrementCounter() { - reLock.lock(); - try { - counter += 1; - } finally { - reLock.unlock(); - } - } - - public int getCounter() { - return counter; - } -} +package com.baeldung.concurrent.threadsafety.services; + +import java.util.concurrent.locks.ReentrantLock; + +public class ReentrantLockCounter { + + private int counter; + private final ReentrantLock reLock = new ReentrantLock(true); + + public ReentrantLockCounter() { + this.counter = 0; + } + + public void incrementCounter() { + reLock.lock(); + try { + counter += 1; + } finally { + reLock.unlock(); + } + } + + public int getCounter() { + return counter; + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ReentrantReadWriteLockCounter.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ReentrantReadWriteLockCounter.java similarity index 96% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ReentrantReadWriteLockCounter.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ReentrantReadWriteLockCounter.java index f740c938b1..5e251441b5 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ReentrantReadWriteLockCounter.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/ReentrantReadWriteLockCounter.java @@ -1,34 +1,34 @@ -package com.baeldung.concurrent.threadsafety.services; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -public class ReentrantReadWriteLockCounter { - - private int counter; - private final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock(); - private final Lock readLock = rwLock.readLock(); - private final Lock writeLock = rwLock.writeLock(); - - public ReentrantReadWriteLockCounter() { - this.counter = 0; - } - - public void incrementCounter() { - writeLock.lock(); - try { - counter += 1; - } finally { - writeLock.unlock(); - } - } - - public int getCounter() { - readLock.lock(); - try { - return counter; - } finally { - readLock.unlock(); - } - } -} +package com.baeldung.concurrent.threadsafety.services; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +public class ReentrantReadWriteLockCounter { + + private int counter; + private final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock(); + private final Lock readLock = rwLock.readLock(); + private final Lock writeLock = rwLock.writeLock(); + + public ReentrantReadWriteLockCounter() { + this.counter = 0; + } + + public void incrementCounter() { + writeLock.lock(); + try { + counter += 1; + } finally { + writeLock.unlock(); + } + } + + public int getCounter() { + readLock.lock(); + try { + return counter; + } finally { + readLock.unlock(); + } + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/StateHolder.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/StateHolder.java similarity index 94% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/StateHolder.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/StateHolder.java index 5bbff9f39c..7e87214590 100644 --- a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/StateHolder.java +++ b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/threadsafety/services/StateHolder.java @@ -1,14 +1,14 @@ -package com.baeldung.concurrent.threadsafety.services; - -public class StateHolder { - - private final String state; - - public StateHolder(String state) { - this.state = state; - } - - public String getState() { - return state; - } -} +package com.baeldung.concurrent.threadsafety.services; + +public class StateHolder { + + private final String state; + + public StateHolder(String state) { + this.state = state; + } + + public String getState() { + return state; + } +} diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/Data.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/Data.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/Data.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/Data.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/NetworkDriver.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/NetworkDriver.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/NetworkDriver.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/NetworkDriver.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/Receiver.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/Receiver.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/Receiver.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/Receiver.java diff --git a/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/Sender.java b/core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/Sender.java similarity index 100% rename from core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/Sender.java rename to core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/waitandnotify/Sender.java diff --git a/core-java-concurrency-basic/src/main/resources/logback.xml b/core-java-modules/core-java-concurrency-basic/src/main/resources/logback.xml similarity index 100% rename from core-java-concurrency-basic/src/main/resources/logback.xml rename to core-java-modules/core-java-concurrency-basic/src/main/resources/logback.xml diff --git a/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/CounterTest.java b/core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/CounterTest.java similarity index 97% rename from core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/CounterTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/CounterTest.java index 3abbb1bdad..176151083c 100644 --- a/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/CounterTest.java +++ b/core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/CounterTest.java @@ -1,23 +1,23 @@ -package com.baeldung.concurrent.threadsafety.tests; - -import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; -import com.baeldung.concurrent.threadsafety.callables.CounterCallable; -import com.baeldung.concurrent.threadsafety.services.Counter; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -public class CounterTest { - - @Test - public void whenCalledIncrementCounter_thenCorrect() throws Exception { - ExecutorService executorService = Executors.newFixedThreadPool(2); - Counter counter = new Counter(); - Future future1 = (Future) executorService.submit(new CounterCallable(counter)); - Future future2 = (Future) executorService.submit(new CounterCallable(counter)); - - assertThat(future1.get()).isEqualTo(1); - assertThat(future2.get()).isEqualTo(2); - } -} +package com.baeldung.concurrent.threadsafety.tests; + +import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; +import com.baeldung.concurrent.threadsafety.callables.CounterCallable; +import com.baeldung.concurrent.threadsafety.services.Counter; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +public class CounterTest { + + @Test + public void whenCalledIncrementCounter_thenCorrect() throws Exception { + ExecutorService executorService = Executors.newFixedThreadPool(2); + Counter counter = new Counter(); + Future future1 = (Future) executorService.submit(new CounterCallable(counter)); + Future future2 = (Future) executorService.submit(new CounterCallable(counter)); + + assertThat(future1.get()).isEqualTo(1); + assertThat(future2.get()).isEqualTo(2); + } +} diff --git a/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ExtrinsicLockCounterTest.java b/core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ExtrinsicLockCounterTest.java similarity index 97% rename from core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ExtrinsicLockCounterTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ExtrinsicLockCounterTest.java index dba90f5b74..e34eb250bf 100644 --- a/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ExtrinsicLockCounterTest.java +++ b/core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ExtrinsicLockCounterTest.java @@ -1,23 +1,23 @@ -package com.baeldung.concurrent.threadsafety.tests; - -import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; -import com.baeldung.concurrent.threadsafety.callables.ExtrinsicLockCounterCallable; -import com.baeldung.concurrent.threadsafety.services.ExtrinsicLockCounter; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -public class ExtrinsicLockCounterTest { - - @Test - public void whenCalledIncrementCounter_thenCorrect() throws Exception { - ExecutorService executorService = Executors.newFixedThreadPool(2); - ExtrinsicLockCounter counter = new ExtrinsicLockCounter(); - Future future1 = (Future) executorService.submit(new ExtrinsicLockCounterCallable(counter)); - Future future2 = (Future) executorService.submit(new ExtrinsicLockCounterCallable(counter)); - - assertThat(future1.get()).isEqualTo(1); - assertThat(future2.get()).isEqualTo(2); - } -} +package com.baeldung.concurrent.threadsafety.tests; + +import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; +import com.baeldung.concurrent.threadsafety.callables.ExtrinsicLockCounterCallable; +import com.baeldung.concurrent.threadsafety.services.ExtrinsicLockCounter; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +public class ExtrinsicLockCounterTest { + + @Test + public void whenCalledIncrementCounter_thenCorrect() throws Exception { + ExecutorService executorService = Executors.newFixedThreadPool(2); + ExtrinsicLockCounter counter = new ExtrinsicLockCounter(); + Future future1 = (Future) executorService.submit(new ExtrinsicLockCounterCallable(counter)); + Future future2 = (Future) executorService.submit(new ExtrinsicLockCounterCallable(counter)); + + assertThat(future1.get()).isEqualTo(1); + assertThat(future2.get()).isEqualTo(2); + } +} diff --git a/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/MathUtilsTest.java b/core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/MathUtilsTest.java similarity index 96% rename from core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/MathUtilsTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/MathUtilsTest.java index 8f3f574b03..2708152906 100644 --- a/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/MathUtilsTest.java +++ b/core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/MathUtilsTest.java @@ -1,13 +1,13 @@ -package com.baeldung.concurrent.threadsafety.tests; - -import com.baeldung.concurrent.threadsafety.mathutils.MathUtils; -import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; - -public class MathUtilsTest { - - @Test - public void whenCalledFactorialMethod_thenCorrect() { - assertThat(MathUtils.factorial(2)).isEqualTo(2); - } -} +package com.baeldung.concurrent.threadsafety.tests; + +import com.baeldung.concurrent.threadsafety.mathutils.MathUtils; +import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; + +public class MathUtilsTest { + + @Test + public void whenCalledFactorialMethod_thenCorrect() { + assertThat(MathUtils.factorial(2)).isEqualTo(2); + } +} diff --git a/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/MessageServiceTest.java b/core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/MessageServiceTest.java similarity index 97% rename from core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/MessageServiceTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/MessageServiceTest.java index 8f1f1a8754..e62206c09a 100644 --- a/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/MessageServiceTest.java +++ b/core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/MessageServiceTest.java @@ -1,23 +1,23 @@ -package com.baeldung.concurrent.threadsafety.tests; - -import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; -import com.baeldung.concurrent.threadsafety.callables.MessageServiceCallable; -import com.baeldung.concurrent.threadsafety.services.MessageService; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -public class MessageServiceTest { - - @Test - public void whenCalledgetMessage_thenCorrect() throws Exception { - ExecutorService executorService = Executors.newFixedThreadPool(2); - MessageService messageService = new MessageService("Welcome to Baeldung!"); - Future future1 = (Future) executorService.submit(new MessageServiceCallable(messageService)); - Future future2 = (Future) executorService.submit(new MessageServiceCallable(messageService)); - - assertThat(future1.get()).isEqualTo("Welcome to Baeldung!"); - assertThat(future2.get()).isEqualTo("Welcome to Baeldung!"); - } -} +package com.baeldung.concurrent.threadsafety.tests; + +import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; +import com.baeldung.concurrent.threadsafety.callables.MessageServiceCallable; +import com.baeldung.concurrent.threadsafety.services.MessageService; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +public class MessageServiceTest { + + @Test + public void whenCalledgetMessage_thenCorrect() throws Exception { + ExecutorService executorService = Executors.newFixedThreadPool(2); + MessageService messageService = new MessageService("Welcome to Baeldung!"); + Future future1 = (Future) executorService.submit(new MessageServiceCallable(messageService)); + Future future2 = (Future) executorService.submit(new MessageServiceCallable(messageService)); + + assertThat(future1.get()).isEqualTo("Welcome to Baeldung!"); + assertThat(future2.get()).isEqualTo("Welcome to Baeldung!"); + } +} diff --git a/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ReentrantLockCounterTest.java b/core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ReentrantLockCounterTest.java similarity index 97% rename from core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ReentrantLockCounterTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ReentrantLockCounterTest.java index 05c721ab26..20fa2c74da 100644 --- a/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ReentrantLockCounterTest.java +++ b/core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ReentrantLockCounterTest.java @@ -1,23 +1,23 @@ -package com.baeldung.concurrent.threadsafety.tests; - -import com.baeldung.concurrent.threadsafety.callables.ReentrantLockCounterCallable; -import com.baeldung.concurrent.threadsafety.services.ReentrantLockCounter; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; - -public class ReentrantLockCounterTest { - - @Test - public void whenCalledIncrementCounter_thenCorrect() throws Exception { - ExecutorService executorService = Executors.newFixedThreadPool(2); - ReentrantLockCounter counter = new ReentrantLockCounter(); - Future future1 = (Future) executorService.submit(new ReentrantLockCounterCallable(counter)); - Future future2 = (Future) executorService.submit(new ReentrantLockCounterCallable(counter)); - - assertThat(future1.get()).isEqualTo(1); - assertThat(future2.get()).isEqualTo(2); - } -} +package com.baeldung.concurrent.threadsafety.tests; + +import com.baeldung.concurrent.threadsafety.callables.ReentrantLockCounterCallable; +import com.baeldung.concurrent.threadsafety.services.ReentrantLockCounter; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; + +public class ReentrantLockCounterTest { + + @Test + public void whenCalledIncrementCounter_thenCorrect() throws Exception { + ExecutorService executorService = Executors.newFixedThreadPool(2); + ReentrantLockCounter counter = new ReentrantLockCounter(); + Future future1 = (Future) executorService.submit(new ReentrantLockCounterCallable(counter)); + Future future2 = (Future) executorService.submit(new ReentrantLockCounterCallable(counter)); + + assertThat(future1.get()).isEqualTo(1); + assertThat(future2.get()).isEqualTo(2); + } +} diff --git a/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ReentrantReadWriteLockCounterTest.java b/core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ReentrantReadWriteLockCounterTest.java similarity index 97% rename from core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ReentrantReadWriteLockCounterTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ReentrantReadWriteLockCounterTest.java index c56137ce04..6113473cac 100644 --- a/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ReentrantReadWriteLockCounterTest.java +++ b/core-java-modules/core-java-concurrency-basic/src/test/com/baeldung/concurrent/threadsafety/tests/ReentrantReadWriteLockCounterTest.java @@ -1,24 +1,24 @@ -package com.baeldung.concurrent.threadsafety.tests; - -import com.baeldung.concurrent.threadsafety.callables.ReentranReadWriteLockCounterCallable; -import com.baeldung.concurrent.threadsafety.services.ReentrantReadWriteLockCounter; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; - -public class ReentrantReadWriteLockCounterTest { - - @Test - public void whenCalledIncrementCounter_thenCorrect() throws Exception { - ExecutorService executorService = Executors.newFixedThreadPool(2); - ReentrantReadWriteLockCounter counter = new ReentrantReadWriteLockCounter(); - Future future1 = (Future) executorService.submit(new ReentranReadWriteLockCounterCallable(counter)); - Future future2 = (Future) executorService.submit(new ReentranReadWriteLockCounterCallable(counter)); - - assertThat(future1.get()).isEqualTo(1); - assertThat(future2.get()).isEqualTo(2); - } - -} +package com.baeldung.concurrent.threadsafety.tests; + +import com.baeldung.concurrent.threadsafety.callables.ReentranReadWriteLockCounterCallable; +import com.baeldung.concurrent.threadsafety.services.ReentrantReadWriteLockCounter; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; + +public class ReentrantReadWriteLockCounterTest { + + @Test + public void whenCalledIncrementCounter_thenCorrect() throws Exception { + ExecutorService executorService = Executors.newFixedThreadPool(2); + ReentrantReadWriteLockCounter counter = new ReentrantReadWriteLockCounter(); + Future future1 = (Future) executorService.submit(new ReentranReadWriteLockCounterCallable(counter)); + Future future2 = (Future) executorService.submit(new ReentranReadWriteLockCounterCallable(counter)); + + assertThat(future1.get()).isEqualTo(1); + assertThat(future2.get()).isEqualTo(2); + } + +} diff --git a/core-java-concurrency-basic/src/test/java/com/baeldung/completablefuture/CompletableFutureLongRunningUnitTest.java b/core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/completablefuture/CompletableFutureLongRunningUnitTest.java similarity index 100% rename from core-java-concurrency-basic/src/test/java/com/baeldung/completablefuture/CompletableFutureLongRunningUnitTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/completablefuture/CompletableFutureLongRunningUnitTest.java diff --git a/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/callable/FactorialTaskManualTest.java b/core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/callable/FactorialTaskManualTest.java similarity index 100% rename from core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/callable/FactorialTaskManualTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/callable/FactorialTaskManualTest.java diff --git a/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishManualTest.java b/core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishManualTest.java similarity index 100% rename from core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishManualTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishManualTest.java diff --git a/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/future/FactorialSquareCalculatorUnitTest.java b/core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/future/FactorialSquareCalculatorUnitTest.java similarity index 100% rename from core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/future/FactorialSquareCalculatorUnitTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/future/FactorialSquareCalculatorUnitTest.java diff --git a/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/future/SquareCalculatorIntegrationTest.java b/core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/future/SquareCalculatorIntegrationTest.java similarity index 100% rename from core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/future/SquareCalculatorIntegrationTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/future/SquareCalculatorIntegrationTest.java diff --git a/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/runnable/RunnableVsThreadLiveTest.java b/core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/runnable/RunnableVsThreadLiveTest.java similarity index 100% rename from core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/runnable/RunnableVsThreadLiveTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/runnable/RunnableVsThreadLiveTest.java diff --git a/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/stopping/StopThreadManualTest.java b/core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/stopping/StopThreadManualTest.java similarity index 100% rename from core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/stopping/StopThreadManualTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/stopping/StopThreadManualTest.java diff --git a/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/synchronize/BaeldungSychronizedBlockUnitTest.java b/core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/synchronize/BaeldungSychronizedBlockUnitTest.java similarity index 100% rename from core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/synchronize/BaeldungSychronizedBlockUnitTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/synchronize/BaeldungSychronizedBlockUnitTest.java diff --git a/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/synchronize/BaeldungSynchronizeMethodsUnitTest.java b/core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/synchronize/BaeldungSynchronizeMethodsUnitTest.java similarity index 100% rename from core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/synchronize/BaeldungSynchronizeMethodsUnitTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/synchronize/BaeldungSynchronizeMethodsUnitTest.java diff --git a/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/waitandnotify/NetworkIntegrationTest.java b/core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/waitandnotify/NetworkIntegrationTest.java similarity index 100% rename from core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/waitandnotify/NetworkIntegrationTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/concurrent/waitandnotify/NetworkIntegrationTest.java diff --git a/core-java-concurrency-basic/src/test/java/com/baeldung/java8/Java8ExecutorServiceIntegrationTest.java b/core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/java8/Java8ExecutorServiceIntegrationTest.java similarity index 100% rename from core-java-concurrency-basic/src/test/java/com/baeldung/java8/Java8ExecutorServiceIntegrationTest.java rename to core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/java8/Java8ExecutorServiceIntegrationTest.java diff --git a/core-java-concurrency-basic/src/test/resources/.gitignore b/core-java-modules/core-java-concurrency-basic/src/test/resources/.gitignore similarity index 100% rename from core-java-concurrency-basic/src/test/resources/.gitignore rename to core-java-modules/core-java-concurrency-basic/src/test/resources/.gitignore diff --git a/core-java-concurrency-collections/.gitignore b/core-java-modules/core-java-concurrency-collections/.gitignore similarity index 100% rename from core-java-concurrency-collections/.gitignore rename to core-java-modules/core-java-concurrency-collections/.gitignore diff --git a/core-java-concurrency-collections/README.md b/core-java-modules/core-java-concurrency-collections/README.md similarity index 100% rename from core-java-concurrency-collections/README.md rename to core-java-modules/core-java-concurrency-collections/README.md diff --git a/core-java-concurrency-collections/pom.xml b/core-java-modules/core-java-concurrency-collections/pom.xml similarity index 98% rename from core-java-concurrency-collections/pom.xml rename to core-java-modules/core-java-concurrency-collections/pom.xml index e192bbe46f..27aae4ea6c 100644 --- a/core-java-concurrency-collections/pom.xml +++ b/core-java-modules/core-java-concurrency-collections/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/blockingqueue/BlockingQueueUsage.java b/core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/blockingqueue/BlockingQueueUsage.java similarity index 100% rename from core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/blockingqueue/BlockingQueueUsage.java rename to core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/blockingqueue/BlockingQueueUsage.java diff --git a/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/blockingqueue/NumbersConsumer.java b/core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/blockingqueue/NumbersConsumer.java similarity index 100% rename from core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/blockingqueue/NumbersConsumer.java rename to core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/blockingqueue/NumbersConsumer.java diff --git a/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/blockingqueue/NumbersProducer.java b/core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/blockingqueue/NumbersProducer.java similarity index 100% rename from core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/blockingqueue/NumbersProducer.java rename to core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/blockingqueue/NumbersProducer.java diff --git a/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/delayqueue/DelayObject.java b/core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/delayqueue/DelayObject.java similarity index 100% rename from core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/delayqueue/DelayObject.java rename to core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/delayqueue/DelayObject.java diff --git a/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/delayqueue/DelayQueueConsumer.java b/core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/delayqueue/DelayQueueConsumer.java similarity index 100% rename from core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/delayqueue/DelayQueueConsumer.java rename to core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/delayqueue/DelayQueueConsumer.java diff --git a/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/delayqueue/DelayQueueProducer.java b/core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/delayqueue/DelayQueueProducer.java similarity index 100% rename from core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/delayqueue/DelayQueueProducer.java rename to core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/delayqueue/DelayQueueProducer.java diff --git a/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/skiplist/Event.java b/core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/skiplist/Event.java similarity index 100% rename from core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/skiplist/Event.java rename to core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/skiplist/Event.java diff --git a/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/skiplist/EventWindowSort.java b/core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/skiplist/EventWindowSort.java similarity index 100% rename from core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/skiplist/EventWindowSort.java rename to core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/concurrent/skiplist/EventWindowSort.java diff --git a/core-java-concurrency-collections/src/main/java/com/baeldung/transferqueue/Consumer.java b/core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/transferqueue/Consumer.java similarity index 100% rename from core-java-concurrency-collections/src/main/java/com/baeldung/transferqueue/Consumer.java rename to core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/transferqueue/Consumer.java diff --git a/core-java-concurrency-collections/src/main/java/com/baeldung/transferqueue/Producer.java b/core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/transferqueue/Producer.java similarity index 100% rename from core-java-concurrency-collections/src/main/java/com/baeldung/transferqueue/Producer.java rename to core-java-modules/core-java-concurrency-collections/src/main/java/com/baeldung/transferqueue/Producer.java diff --git a/core-java-concurrency-collections/src/main/resources/logback.xml b/core-java-modules/core-java-concurrency-collections/src/main/resources/logback.xml similarity index 100% rename from core-java-concurrency-collections/src/main/resources/logback.xml rename to core-java-modules/core-java-concurrency-collections/src/main/resources/logback.xml diff --git a/core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/copyonwrite/CopyOnWriteArrayListUnitTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/copyonwrite/CopyOnWriteArrayListUnitTest.java similarity index 100% rename from core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/copyonwrite/CopyOnWriteArrayListUnitTest.java rename to core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/copyonwrite/CopyOnWriteArrayListUnitTest.java diff --git a/core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/delayqueue/DelayQueueIntegrationTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/delayqueue/DelayQueueIntegrationTest.java similarity index 100% rename from core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/delayqueue/DelayQueueIntegrationTest.java rename to core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/delayqueue/DelayQueueIntegrationTest.java diff --git a/core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/priorityblockingqueue/PriorityBlockingQueueIntegrationTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/priorityblockingqueue/PriorityBlockingQueueIntegrationTest.java similarity index 100% rename from core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/priorityblockingqueue/PriorityBlockingQueueIntegrationTest.java rename to core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/priorityblockingqueue/PriorityBlockingQueueIntegrationTest.java diff --git a/core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/skiplist/ConcurrentSkipListSetIntegrationTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/skiplist/ConcurrentSkipListSetIntegrationTest.java similarity index 100% rename from core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/skiplist/ConcurrentSkipListSetIntegrationTest.java rename to core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/concurrent/skiplist/ConcurrentSkipListSetIntegrationTest.java diff --git a/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapAggregateStatusManualTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapAggregateStatusManualTest.java similarity index 100% rename from core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapAggregateStatusManualTest.java rename to core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapAggregateStatusManualTest.java diff --git a/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapNullKeyValueManualTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapNullKeyValueManualTest.java similarity index 100% rename from core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapNullKeyValueManualTest.java rename to core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapNullKeyValueManualTest.java diff --git a/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapPerformanceManualTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapPerformanceManualTest.java similarity index 100% rename from core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapPerformanceManualTest.java rename to core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapPerformanceManualTest.java diff --git a/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentNavigableMapManualTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentNavigableMapManualTest.java similarity index 100% rename from core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentNavigableMapManualTest.java rename to core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurrentNavigableMapManualTest.java diff --git a/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurretMapMemoryConsistencyManualTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurretMapMemoryConsistencyManualTest.java similarity index 100% rename from core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurretMapMemoryConsistencyManualTest.java rename to core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmap/ConcurretMapMemoryConsistencyManualTest.java diff --git a/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmodification/ConcurrentModificationUnitTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmodification/ConcurrentModificationUnitTest.java similarity index 100% rename from core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmodification/ConcurrentModificationUnitTest.java rename to core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/concurrentmodification/ConcurrentModificationUnitTest.java diff --git a/core-java-concurrency-collections/src/test/java/com/baeldung/synchronousqueue/SynchronousQueueIntegrationTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/synchronousqueue/SynchronousQueueIntegrationTest.java similarity index 100% rename from core-java-concurrency-collections/src/test/java/com/baeldung/synchronousqueue/SynchronousQueueIntegrationTest.java rename to core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/synchronousqueue/SynchronousQueueIntegrationTest.java diff --git a/core-java-concurrency-collections/src/test/java/com/baeldung/transferqueue/TransferQueueIntegrationTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/transferqueue/TransferQueueIntegrationTest.java similarity index 100% rename from core-java-concurrency-collections/src/test/java/com/baeldung/transferqueue/TransferQueueIntegrationTest.java rename to core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/transferqueue/TransferQueueIntegrationTest.java diff --git a/core-java-concurrency-collections/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStreamIntegrationTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStreamIntegrationTest.java similarity index 100% rename from core-java-concurrency-collections/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStreamIntegrationTest.java rename to core-java-modules/core-java-concurrency-collections/src/test/java/org/baeldung/java/streams/ThreadPoolInParallelStreamIntegrationTest.java diff --git a/core-java-concurrency-collections/src/test/resources/.gitignore b/core-java-modules/core-java-concurrency-collections/src/test/resources/.gitignore similarity index 100% rename from core-java-concurrency-collections/src/test/resources/.gitignore rename to core-java-modules/core-java-concurrency-collections/src/test/resources/.gitignore diff --git a/core-java-io/.gitignore b/core-java-modules/core-java-io/.gitignore similarity index 100% rename from core-java-io/.gitignore rename to core-java-modules/core-java-io/.gitignore diff --git a/core-java-io/README.md b/core-java-modules/core-java-io/README.md similarity index 100% rename from core-java-io/README.md rename to core-java-modules/core-java-io/README.md diff --git a/core-java-modules/core-java-io/hard_link.txt b/core-java-modules/core-java-io/hard_link.txt new file mode 100644 index 0000000000..931a810b8d --- /dev/null +++ b/core-java-modules/core-java-io/hard_link.txt @@ -0,0 +1,10000 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 +282 +283 +284 +285 +286 +287 +288 +289 +290 +291 +292 +293 +294 +295 +296 +297 +298 +299 +300 +301 +302 +303 +304 +305 +306 +307 +308 +309 +310 +311 +312 +313 +314 +315 +316 +317 +318 +319 +320 +321 +322 +323 +324 +325 +326 +327 +328 +329 +330 +331 +332 +333 +334 +335 +336 +337 +338 +339 +340 +341 +342 +343 +344 +345 +346 +347 +348 +349 +350 +351 +352 +353 +354 +355 +356 +357 +358 +359 +360 +361 +362 +363 +364 +365 +366 +367 +368 +369 +370 +371 +372 +373 +374 +375 +376 +377 +378 +379 +380 +381 +382 +383 +384 +385 +386 +387 +388 +389 +390 +391 +392 +393 +394 +395 +396 +397 +398 +399 +400 +401 +402 +403 +404 +405 +406 +407 +408 +409 +410 +411 +412 +413 +414 +415 +416 +417 +418 +419 +420 +421 +422 +423 +424 +425 +426 +427 +428 +429 +430 +431 +432 +433 +434 +435 +436 +437 +438 +439 +440 +441 +442 +443 +444 +445 +446 +447 +448 +449 +450 +451 +452 +453 +454 +455 +456 +457 +458 +459 +460 +461 +462 +463 +464 +465 +466 +467 +468 +469 +470 +471 +472 +473 +474 +475 +476 +477 +478 +479 +480 +481 +482 +483 +484 +485 +486 +487 +488 +489 +490 +491 +492 +493 +494 +495 +496 +497 +498 +499 +500 +501 +502 +503 +504 +505 +506 +507 +508 +509 +510 +511 +512 +513 +514 +515 +516 +517 +518 +519 +520 +521 +522 +523 +524 +525 +526 +527 +528 +529 +530 +531 +532 +533 +534 +535 +536 +537 +538 +539 +540 +541 +542 +543 +544 +545 +546 +547 +548 +549 +550 +551 +552 +553 +554 +555 +556 +557 +558 +559 +560 +561 +562 +563 +564 +565 +566 +567 +568 +569 +570 +571 +572 +573 +574 +575 +576 +577 +578 +579 +580 +581 +582 +583 +584 +585 +586 +587 +588 +589 +590 +591 +592 +593 +594 +595 +596 +597 +598 +599 +600 +601 +602 +603 +604 +605 +606 +607 +608 +609 +610 +611 +612 +613 +614 +615 +616 +617 +618 +619 +620 +621 +622 +623 +624 +625 +626 +627 +628 +629 +630 +631 +632 +633 +634 +635 +636 +637 +638 +639 +640 +641 +642 +643 +644 +645 +646 +647 +648 +649 +650 +651 +652 +653 +654 +655 +656 +657 +658 +659 +660 +661 +662 +663 +664 +665 +666 +667 +668 +669 +670 +671 +672 +673 +674 +675 +676 +677 +678 +679 +680 +681 +682 +683 +684 +685 +686 +687 +688 +689 +690 +691 +692 +693 +694 +695 +696 +697 +698 +699 +700 +701 +702 +703 +704 +705 +706 +707 +708 +709 +710 +711 +712 +713 +714 +715 +716 +717 +718 +719 +720 +721 +722 +723 +724 +725 +726 +727 +728 +729 +730 +731 +732 +733 +734 +735 +736 +737 +738 +739 +740 +741 +742 +743 +744 +745 +746 +747 +748 +749 +750 +751 +752 +753 +754 +755 +756 +757 +758 +759 +760 +761 +762 +763 +764 +765 +766 +767 +768 +769 +770 +771 +772 +773 +774 +775 +776 +777 +778 +779 +780 +781 +782 +783 +784 +785 +786 +787 +788 +789 +790 +791 +792 +793 +794 +795 +796 +797 +798 +799 +800 +801 +802 +803 +804 +805 +806 +807 +808 +809 +810 +811 +812 +813 +814 +815 +816 +817 +818 +819 +820 +821 +822 +823 +824 +825 +826 +827 +828 +829 +830 +831 +832 +833 +834 +835 +836 +837 +838 +839 +840 +841 +842 +843 +844 +845 +846 +847 +848 +849 +850 +851 +852 +853 +854 +855 +856 +857 +858 +859 +860 +861 +862 +863 +864 +865 +866 +867 +868 +869 +870 +871 +872 +873 +874 +875 +876 +877 +878 +879 +880 +881 +882 +883 +884 +885 +886 +887 +888 +889 +890 +891 +892 +893 +894 +895 +896 +897 +898 +899 +900 +901 +902 +903 +904 +905 +906 +907 +908 +909 +910 +911 +912 +913 +914 +915 +916 +917 +918 +919 +920 +921 +922 +923 +924 +925 +926 +927 +928 +929 +930 +931 +932 +933 +934 +935 +936 +937 +938 +939 +940 +941 +942 +943 +944 +945 +946 +947 +948 +949 +950 +951 +952 +953 +954 +955 +956 +957 +958 +959 +960 +961 +962 +963 +964 +965 +966 +967 +968 +969 +970 +971 +972 +973 +974 +975 +976 +977 +978 +979 +980 +981 +982 +983 +984 +985 +986 +987 +988 +989 +990 +991 +992 +993 +994 +995 +996 +997 +998 +999 +1000 +1001 +1002 +1003 +1004 +1005 +1006 +1007 +1008 +1009 +1010 +1011 +1012 +1013 +1014 +1015 +1016 +1017 +1018 +1019 +1020 +1021 +1022 +1023 +1024 +1025 +1026 +1027 +1028 +1029 +1030 +1031 +1032 +1033 +1034 +1035 +1036 +1037 +1038 +1039 +1040 +1041 +1042 +1043 +1044 +1045 +1046 +1047 +1048 +1049 +1050 +1051 +1052 +1053 +1054 +1055 +1056 +1057 +1058 +1059 +1060 +1061 +1062 +1063 +1064 +1065 +1066 +1067 +1068 +1069 +1070 +1071 +1072 +1073 +1074 +1075 +1076 +1077 +1078 +1079 +1080 +1081 +1082 +1083 +1084 +1085 +1086 +1087 +1088 +1089 +1090 +1091 +1092 +1093 +1094 +1095 +1096 +1097 +1098 +1099 +1100 +1101 +1102 +1103 +1104 +1105 +1106 +1107 +1108 +1109 +1110 +1111 +1112 +1113 +1114 +1115 +1116 +1117 +1118 +1119 +1120 +1121 +1122 +1123 +1124 +1125 +1126 +1127 +1128 +1129 +1130 +1131 +1132 +1133 +1134 +1135 +1136 +1137 +1138 +1139 +1140 +1141 +1142 +1143 +1144 +1145 +1146 +1147 +1148 +1149 +1150 +1151 +1152 +1153 +1154 +1155 +1156 +1157 +1158 +1159 +1160 +1161 +1162 +1163 +1164 +1165 +1166 +1167 +1168 +1169 +1170 +1171 +1172 +1173 +1174 +1175 +1176 +1177 +1178 +1179 +1180 +1181 +1182 +1183 +1184 +1185 +1186 +1187 +1188 +1189 +1190 +1191 +1192 +1193 +1194 +1195 +1196 +1197 +1198 +1199 +1200 +1201 +1202 +1203 +1204 +1205 +1206 +1207 +1208 +1209 +1210 +1211 +1212 +1213 +1214 +1215 +1216 +1217 +1218 +1219 +1220 +1221 +1222 +1223 +1224 +1225 +1226 +1227 +1228 +1229 +1230 +1231 +1232 +1233 +1234 +1235 +1236 +1237 +1238 +1239 +1240 +1241 +1242 +1243 +1244 +1245 +1246 +1247 +1248 +1249 +1250 +1251 +1252 +1253 +1254 +1255 +1256 +1257 +1258 +1259 +1260 +1261 +1262 +1263 +1264 +1265 +1266 +1267 +1268 +1269 +1270 +1271 +1272 +1273 +1274 +1275 +1276 +1277 +1278 +1279 +1280 +1281 +1282 +1283 +1284 +1285 +1286 +1287 +1288 +1289 +1290 +1291 +1292 +1293 +1294 +1295 +1296 +1297 +1298 +1299 +1300 +1301 +1302 +1303 +1304 +1305 +1306 +1307 +1308 +1309 +1310 +1311 +1312 +1313 +1314 +1315 +1316 +1317 +1318 +1319 +1320 +1321 +1322 +1323 +1324 +1325 +1326 +1327 +1328 +1329 +1330 +1331 +1332 +1333 +1334 +1335 +1336 +1337 +1338 +1339 +1340 +1341 +1342 +1343 +1344 +1345 +1346 +1347 +1348 +1349 +1350 +1351 +1352 +1353 +1354 +1355 +1356 +1357 +1358 +1359 +1360 +1361 +1362 +1363 +1364 +1365 +1366 +1367 +1368 +1369 +1370 +1371 +1372 +1373 +1374 +1375 +1376 +1377 +1378 +1379 +1380 +1381 +1382 +1383 +1384 +1385 +1386 +1387 +1388 +1389 +1390 +1391 +1392 +1393 +1394 +1395 +1396 +1397 +1398 +1399 +1400 +1401 +1402 +1403 +1404 +1405 +1406 +1407 +1408 +1409 +1410 +1411 +1412 +1413 +1414 +1415 +1416 +1417 +1418 +1419 +1420 +1421 +1422 +1423 +1424 +1425 +1426 +1427 +1428 +1429 +1430 +1431 +1432 +1433 +1434 +1435 +1436 +1437 +1438 +1439 +1440 +1441 +1442 +1443 +1444 +1445 +1446 +1447 +1448 +1449 +1450 +1451 +1452 +1453 +1454 +1455 +1456 +1457 +1458 +1459 +1460 +1461 +1462 +1463 +1464 +1465 +1466 +1467 +1468 +1469 +1470 +1471 +1472 +1473 +1474 +1475 +1476 +1477 +1478 +1479 +1480 +1481 +1482 +1483 +1484 +1485 +1486 +1487 +1488 +1489 +1490 +1491 +1492 +1493 +1494 +1495 +1496 +1497 +1498 +1499 +1500 +1501 +1502 +1503 +1504 +1505 +1506 +1507 +1508 +1509 +1510 +1511 +1512 +1513 +1514 +1515 +1516 +1517 +1518 +1519 +1520 +1521 +1522 +1523 +1524 +1525 +1526 +1527 +1528 +1529 +1530 +1531 +1532 +1533 +1534 +1535 +1536 +1537 +1538 +1539 +1540 +1541 +1542 +1543 +1544 +1545 +1546 +1547 +1548 +1549 +1550 +1551 +1552 +1553 +1554 +1555 +1556 +1557 +1558 +1559 +1560 +1561 +1562 +1563 +1564 +1565 +1566 +1567 +1568 +1569 +1570 +1571 +1572 +1573 +1574 +1575 +1576 +1577 +1578 +1579 +1580 +1581 +1582 +1583 +1584 +1585 +1586 +1587 +1588 +1589 +1590 +1591 +1592 +1593 +1594 +1595 +1596 +1597 +1598 +1599 +1600 +1601 +1602 +1603 +1604 +1605 +1606 +1607 +1608 +1609 +1610 +1611 +1612 +1613 +1614 +1615 +1616 +1617 +1618 +1619 +1620 +1621 +1622 +1623 +1624 +1625 +1626 +1627 +1628 +1629 +1630 +1631 +1632 +1633 +1634 +1635 +1636 +1637 +1638 +1639 +1640 +1641 +1642 +1643 +1644 +1645 +1646 +1647 +1648 +1649 +1650 +1651 +1652 +1653 +1654 +1655 +1656 +1657 +1658 +1659 +1660 +1661 +1662 +1663 +1664 +1665 +1666 +1667 +1668 +1669 +1670 +1671 +1672 +1673 +1674 +1675 +1676 +1677 +1678 +1679 +1680 +1681 +1682 +1683 +1684 +1685 +1686 +1687 +1688 +1689 +1690 +1691 +1692 +1693 +1694 +1695 +1696 +1697 +1698 +1699 +1700 +1701 +1702 +1703 +1704 +1705 +1706 +1707 +1708 +1709 +1710 +1711 +1712 +1713 +1714 +1715 +1716 +1717 +1718 +1719 +1720 +1721 +1722 +1723 +1724 +1725 +1726 +1727 +1728 +1729 +1730 +1731 +1732 +1733 +1734 +1735 +1736 +1737 +1738 +1739 +1740 +1741 +1742 +1743 +1744 +1745 +1746 +1747 +1748 +1749 +1750 +1751 +1752 +1753 +1754 +1755 +1756 +1757 +1758 +1759 +1760 +1761 +1762 +1763 +1764 +1765 +1766 +1767 +1768 +1769 +1770 +1771 +1772 +1773 +1774 +1775 +1776 +1777 +1778 +1779 +1780 +1781 +1782 +1783 +1784 +1785 +1786 +1787 +1788 +1789 +1790 +1791 +1792 +1793 +1794 +1795 +1796 +1797 +1798 +1799 +1800 +1801 +1802 +1803 +1804 +1805 +1806 +1807 +1808 +1809 +1810 +1811 +1812 +1813 +1814 +1815 +1816 +1817 +1818 +1819 +1820 +1821 +1822 +1823 +1824 +1825 +1826 +1827 +1828 +1829 +1830 +1831 +1832 +1833 +1834 +1835 +1836 +1837 +1838 +1839 +1840 +1841 +1842 +1843 +1844 +1845 +1846 +1847 +1848 +1849 +1850 +1851 +1852 +1853 +1854 +1855 +1856 +1857 +1858 +1859 +1860 +1861 +1862 +1863 +1864 +1865 +1866 +1867 +1868 +1869 +1870 +1871 +1872 +1873 +1874 +1875 +1876 +1877 +1878 +1879 +1880 +1881 +1882 +1883 +1884 +1885 +1886 +1887 +1888 +1889 +1890 +1891 +1892 +1893 +1894 +1895 +1896 +1897 +1898 +1899 +1900 +1901 +1902 +1903 +1904 +1905 +1906 +1907 +1908 +1909 +1910 +1911 +1912 +1913 +1914 +1915 +1916 +1917 +1918 +1919 +1920 +1921 +1922 +1923 +1924 +1925 +1926 +1927 +1928 +1929 +1930 +1931 +1932 +1933 +1934 +1935 +1936 +1937 +1938 +1939 +1940 +1941 +1942 +1943 +1944 +1945 +1946 +1947 +1948 +1949 +1950 +1951 +1952 +1953 +1954 +1955 +1956 +1957 +1958 +1959 +1960 +1961 +1962 +1963 +1964 +1965 +1966 +1967 +1968 +1969 +1970 +1971 +1972 +1973 +1974 +1975 +1976 +1977 +1978 +1979 +1980 +1981 +1982 +1983 +1984 +1985 +1986 +1987 +1988 +1989 +1990 +1991 +1992 +1993 +1994 +1995 +1996 +1997 +1998 +1999 +2000 +2001 +2002 +2003 +2004 +2005 +2006 +2007 +2008 +2009 +2010 +2011 +2012 +2013 +2014 +2015 +2016 +2017 +2018 +2019 +2020 +2021 +2022 +2023 +2024 +2025 +2026 +2027 +2028 +2029 +2030 +2031 +2032 +2033 +2034 +2035 +2036 +2037 +2038 +2039 +2040 +2041 +2042 +2043 +2044 +2045 +2046 +2047 +2048 +2049 +2050 +2051 +2052 +2053 +2054 +2055 +2056 +2057 +2058 +2059 +2060 +2061 +2062 +2063 +2064 +2065 +2066 +2067 +2068 +2069 +2070 +2071 +2072 +2073 +2074 +2075 +2076 +2077 +2078 +2079 +2080 +2081 +2082 +2083 +2084 +2085 +2086 +2087 +2088 +2089 +2090 +2091 +2092 +2093 +2094 +2095 +2096 +2097 +2098 +2099 +2100 +2101 +2102 +2103 +2104 +2105 +2106 +2107 +2108 +2109 +2110 +2111 +2112 +2113 +2114 +2115 +2116 +2117 +2118 +2119 +2120 +2121 +2122 +2123 +2124 +2125 +2126 +2127 +2128 +2129 +2130 +2131 +2132 +2133 +2134 +2135 +2136 +2137 +2138 +2139 +2140 +2141 +2142 +2143 +2144 +2145 +2146 +2147 +2148 +2149 +2150 +2151 +2152 +2153 +2154 +2155 +2156 +2157 +2158 +2159 +2160 +2161 +2162 +2163 +2164 +2165 +2166 +2167 +2168 +2169 +2170 +2171 +2172 +2173 +2174 +2175 +2176 +2177 +2178 +2179 +2180 +2181 +2182 +2183 +2184 +2185 +2186 +2187 +2188 +2189 +2190 +2191 +2192 +2193 +2194 +2195 +2196 +2197 +2198 +2199 +2200 +2201 +2202 +2203 +2204 +2205 +2206 +2207 +2208 +2209 +2210 +2211 +2212 +2213 +2214 +2215 +2216 +2217 +2218 +2219 +2220 +2221 +2222 +2223 +2224 +2225 +2226 +2227 +2228 +2229 +2230 +2231 +2232 +2233 +2234 +2235 +2236 +2237 +2238 +2239 +2240 +2241 +2242 +2243 +2244 +2245 +2246 +2247 +2248 +2249 +2250 +2251 +2252 +2253 +2254 +2255 +2256 +2257 +2258 +2259 +2260 +2261 +2262 +2263 +2264 +2265 +2266 +2267 +2268 +2269 +2270 +2271 +2272 +2273 +2274 +2275 +2276 +2277 +2278 +2279 +2280 +2281 +2282 +2283 +2284 +2285 +2286 +2287 +2288 +2289 +2290 +2291 +2292 +2293 +2294 +2295 +2296 +2297 +2298 +2299 +2300 +2301 +2302 +2303 +2304 +2305 +2306 +2307 +2308 +2309 +2310 +2311 +2312 +2313 +2314 +2315 +2316 +2317 +2318 +2319 +2320 +2321 +2322 +2323 +2324 +2325 +2326 +2327 +2328 +2329 +2330 +2331 +2332 +2333 +2334 +2335 +2336 +2337 +2338 +2339 +2340 +2341 +2342 +2343 +2344 +2345 +2346 +2347 +2348 +2349 +2350 +2351 +2352 +2353 +2354 +2355 +2356 +2357 +2358 +2359 +2360 +2361 +2362 +2363 +2364 +2365 +2366 +2367 +2368 +2369 +2370 +2371 +2372 +2373 +2374 +2375 +2376 +2377 +2378 +2379 +2380 +2381 +2382 +2383 +2384 +2385 +2386 +2387 +2388 +2389 +2390 +2391 +2392 +2393 +2394 +2395 +2396 +2397 +2398 +2399 +2400 +2401 +2402 +2403 +2404 +2405 +2406 +2407 +2408 +2409 +2410 +2411 +2412 +2413 +2414 +2415 +2416 +2417 +2418 +2419 +2420 +2421 +2422 +2423 +2424 +2425 +2426 +2427 +2428 +2429 +2430 +2431 +2432 +2433 +2434 +2435 +2436 +2437 +2438 +2439 +2440 +2441 +2442 +2443 +2444 +2445 +2446 +2447 +2448 +2449 +2450 +2451 +2452 +2453 +2454 +2455 +2456 +2457 +2458 +2459 +2460 +2461 +2462 +2463 +2464 +2465 +2466 +2467 +2468 +2469 +2470 +2471 +2472 +2473 +2474 +2475 +2476 +2477 +2478 +2479 +2480 +2481 +2482 +2483 +2484 +2485 +2486 +2487 +2488 +2489 +2490 +2491 +2492 +2493 +2494 +2495 +2496 +2497 +2498 +2499 +2500 +2501 +2502 +2503 +2504 +2505 +2506 +2507 +2508 +2509 +2510 +2511 +2512 +2513 +2514 +2515 +2516 +2517 +2518 +2519 +2520 +2521 +2522 +2523 +2524 +2525 +2526 +2527 +2528 +2529 +2530 +2531 +2532 +2533 +2534 +2535 +2536 +2537 +2538 +2539 +2540 +2541 +2542 +2543 +2544 +2545 +2546 +2547 +2548 +2549 +2550 +2551 +2552 +2553 +2554 +2555 +2556 +2557 +2558 +2559 +2560 +2561 +2562 +2563 +2564 +2565 +2566 +2567 +2568 +2569 +2570 +2571 +2572 +2573 +2574 +2575 +2576 +2577 +2578 +2579 +2580 +2581 +2582 +2583 +2584 +2585 +2586 +2587 +2588 +2589 +2590 +2591 +2592 +2593 +2594 +2595 +2596 +2597 +2598 +2599 +2600 +2601 +2602 +2603 +2604 +2605 +2606 +2607 +2608 +2609 +2610 +2611 +2612 +2613 +2614 +2615 +2616 +2617 +2618 +2619 +2620 +2621 +2622 +2623 +2624 +2625 +2626 +2627 +2628 +2629 +2630 +2631 +2632 +2633 +2634 +2635 +2636 +2637 +2638 +2639 +2640 +2641 +2642 +2643 +2644 +2645 +2646 +2647 +2648 +2649 +2650 +2651 +2652 +2653 +2654 +2655 +2656 +2657 +2658 +2659 +2660 +2661 +2662 +2663 +2664 +2665 +2666 +2667 +2668 +2669 +2670 +2671 +2672 +2673 +2674 +2675 +2676 +2677 +2678 +2679 +2680 +2681 +2682 +2683 +2684 +2685 +2686 +2687 +2688 +2689 +2690 +2691 +2692 +2693 +2694 +2695 +2696 +2697 +2698 +2699 +2700 +2701 +2702 +2703 +2704 +2705 +2706 +2707 +2708 +2709 +2710 +2711 +2712 +2713 +2714 +2715 +2716 +2717 +2718 +2719 +2720 +2721 +2722 +2723 +2724 +2725 +2726 +2727 +2728 +2729 +2730 +2731 +2732 +2733 +2734 +2735 +2736 +2737 +2738 +2739 +2740 +2741 +2742 +2743 +2744 +2745 +2746 +2747 +2748 +2749 +2750 +2751 +2752 +2753 +2754 +2755 +2756 +2757 +2758 +2759 +2760 +2761 +2762 +2763 +2764 +2765 +2766 +2767 +2768 +2769 +2770 +2771 +2772 +2773 +2774 +2775 +2776 +2777 +2778 +2779 +2780 +2781 +2782 +2783 +2784 +2785 +2786 +2787 +2788 +2789 +2790 +2791 +2792 +2793 +2794 +2795 +2796 +2797 +2798 +2799 +2800 +2801 +2802 +2803 +2804 +2805 +2806 +2807 +2808 +2809 +2810 +2811 +2812 +2813 +2814 +2815 +2816 +2817 +2818 +2819 +2820 +2821 +2822 +2823 +2824 +2825 +2826 +2827 +2828 +2829 +2830 +2831 +2832 +2833 +2834 +2835 +2836 +2837 +2838 +2839 +2840 +2841 +2842 +2843 +2844 +2845 +2846 +2847 +2848 +2849 +2850 +2851 +2852 +2853 +2854 +2855 +2856 +2857 +2858 +2859 +2860 +2861 +2862 +2863 +2864 +2865 +2866 +2867 +2868 +2869 +2870 +2871 +2872 +2873 +2874 +2875 +2876 +2877 +2878 +2879 +2880 +2881 +2882 +2883 +2884 +2885 +2886 +2887 +2888 +2889 +2890 +2891 +2892 +2893 +2894 +2895 +2896 +2897 +2898 +2899 +2900 +2901 +2902 +2903 +2904 +2905 +2906 +2907 +2908 +2909 +2910 +2911 +2912 +2913 +2914 +2915 +2916 +2917 +2918 +2919 +2920 +2921 +2922 +2923 +2924 +2925 +2926 +2927 +2928 +2929 +2930 +2931 +2932 +2933 +2934 +2935 +2936 +2937 +2938 +2939 +2940 +2941 +2942 +2943 +2944 +2945 +2946 +2947 +2948 +2949 +2950 +2951 +2952 +2953 +2954 +2955 +2956 +2957 +2958 +2959 +2960 +2961 +2962 +2963 +2964 +2965 +2966 +2967 +2968 +2969 +2970 +2971 +2972 +2973 +2974 +2975 +2976 +2977 +2978 +2979 +2980 +2981 +2982 +2983 +2984 +2985 +2986 +2987 +2988 +2989 +2990 +2991 +2992 +2993 +2994 +2995 +2996 +2997 +2998 +2999 +3000 +3001 +3002 +3003 +3004 +3005 +3006 +3007 +3008 +3009 +3010 +3011 +3012 +3013 +3014 +3015 +3016 +3017 +3018 +3019 +3020 +3021 +3022 +3023 +3024 +3025 +3026 +3027 +3028 +3029 +3030 +3031 +3032 +3033 +3034 +3035 +3036 +3037 +3038 +3039 +3040 +3041 +3042 +3043 +3044 +3045 +3046 +3047 +3048 +3049 +3050 +3051 +3052 +3053 +3054 +3055 +3056 +3057 +3058 +3059 +3060 +3061 +3062 +3063 +3064 +3065 +3066 +3067 +3068 +3069 +3070 +3071 +3072 +3073 +3074 +3075 +3076 +3077 +3078 +3079 +3080 +3081 +3082 +3083 +3084 +3085 +3086 +3087 +3088 +3089 +3090 +3091 +3092 +3093 +3094 +3095 +3096 +3097 +3098 +3099 +3100 +3101 +3102 +3103 +3104 +3105 +3106 +3107 +3108 +3109 +3110 +3111 +3112 +3113 +3114 +3115 +3116 +3117 +3118 +3119 +3120 +3121 +3122 +3123 +3124 +3125 +3126 +3127 +3128 +3129 +3130 +3131 +3132 +3133 +3134 +3135 +3136 +3137 +3138 +3139 +3140 +3141 +3142 +3143 +3144 +3145 +3146 +3147 +3148 +3149 +3150 +3151 +3152 +3153 +3154 +3155 +3156 +3157 +3158 +3159 +3160 +3161 +3162 +3163 +3164 +3165 +3166 +3167 +3168 +3169 +3170 +3171 +3172 +3173 +3174 +3175 +3176 +3177 +3178 +3179 +3180 +3181 +3182 +3183 +3184 +3185 +3186 +3187 +3188 +3189 +3190 +3191 +3192 +3193 +3194 +3195 +3196 +3197 +3198 +3199 +3200 +3201 +3202 +3203 +3204 +3205 +3206 +3207 +3208 +3209 +3210 +3211 +3212 +3213 +3214 +3215 +3216 +3217 +3218 +3219 +3220 +3221 +3222 +3223 +3224 +3225 +3226 +3227 +3228 +3229 +3230 +3231 +3232 +3233 +3234 +3235 +3236 +3237 +3238 +3239 +3240 +3241 +3242 +3243 +3244 +3245 +3246 +3247 +3248 +3249 +3250 +3251 +3252 +3253 +3254 +3255 +3256 +3257 +3258 +3259 +3260 +3261 +3262 +3263 +3264 +3265 +3266 +3267 +3268 +3269 +3270 +3271 +3272 +3273 +3274 +3275 +3276 +3277 +3278 +3279 +3280 +3281 +3282 +3283 +3284 +3285 +3286 +3287 +3288 +3289 +3290 +3291 +3292 +3293 +3294 +3295 +3296 +3297 +3298 +3299 +3300 +3301 +3302 +3303 +3304 +3305 +3306 +3307 +3308 +3309 +3310 +3311 +3312 +3313 +3314 +3315 +3316 +3317 +3318 +3319 +3320 +3321 +3322 +3323 +3324 +3325 +3326 +3327 +3328 +3329 +3330 +3331 +3332 +3333 +3334 +3335 +3336 +3337 +3338 +3339 +3340 +3341 +3342 +3343 +3344 +3345 +3346 +3347 +3348 +3349 +3350 +3351 +3352 +3353 +3354 +3355 +3356 +3357 +3358 +3359 +3360 +3361 +3362 +3363 +3364 +3365 +3366 +3367 +3368 +3369 +3370 +3371 +3372 +3373 +3374 +3375 +3376 +3377 +3378 +3379 +3380 +3381 +3382 +3383 +3384 +3385 +3386 +3387 +3388 +3389 +3390 +3391 +3392 +3393 +3394 +3395 +3396 +3397 +3398 +3399 +3400 +3401 +3402 +3403 +3404 +3405 +3406 +3407 +3408 +3409 +3410 +3411 +3412 +3413 +3414 +3415 +3416 +3417 +3418 +3419 +3420 +3421 +3422 +3423 +3424 +3425 +3426 +3427 +3428 +3429 +3430 +3431 +3432 +3433 +3434 +3435 +3436 +3437 +3438 +3439 +3440 +3441 +3442 +3443 +3444 +3445 +3446 +3447 +3448 +3449 +3450 +3451 +3452 +3453 +3454 +3455 +3456 +3457 +3458 +3459 +3460 +3461 +3462 +3463 +3464 +3465 +3466 +3467 +3468 +3469 +3470 +3471 +3472 +3473 +3474 +3475 +3476 +3477 +3478 +3479 +3480 +3481 +3482 +3483 +3484 +3485 +3486 +3487 +3488 +3489 +3490 +3491 +3492 +3493 +3494 +3495 +3496 +3497 +3498 +3499 +3500 +3501 +3502 +3503 +3504 +3505 +3506 +3507 +3508 +3509 +3510 +3511 +3512 +3513 +3514 +3515 +3516 +3517 +3518 +3519 +3520 +3521 +3522 +3523 +3524 +3525 +3526 +3527 +3528 +3529 +3530 +3531 +3532 +3533 +3534 +3535 +3536 +3537 +3538 +3539 +3540 +3541 +3542 +3543 +3544 +3545 +3546 +3547 +3548 +3549 +3550 +3551 +3552 +3553 +3554 +3555 +3556 +3557 +3558 +3559 +3560 +3561 +3562 +3563 +3564 +3565 +3566 +3567 +3568 +3569 +3570 +3571 +3572 +3573 +3574 +3575 +3576 +3577 +3578 +3579 +3580 +3581 +3582 +3583 +3584 +3585 +3586 +3587 +3588 +3589 +3590 +3591 +3592 +3593 +3594 +3595 +3596 +3597 +3598 +3599 +3600 +3601 +3602 +3603 +3604 +3605 +3606 +3607 +3608 +3609 +3610 +3611 +3612 +3613 +3614 +3615 +3616 +3617 +3618 +3619 +3620 +3621 +3622 +3623 +3624 +3625 +3626 +3627 +3628 +3629 +3630 +3631 +3632 +3633 +3634 +3635 +3636 +3637 +3638 +3639 +3640 +3641 +3642 +3643 +3644 +3645 +3646 +3647 +3648 +3649 +3650 +3651 +3652 +3653 +3654 +3655 +3656 +3657 +3658 +3659 +3660 +3661 +3662 +3663 +3664 +3665 +3666 +3667 +3668 +3669 +3670 +3671 +3672 +3673 +3674 +3675 +3676 +3677 +3678 +3679 +3680 +3681 +3682 +3683 +3684 +3685 +3686 +3687 +3688 +3689 +3690 +3691 +3692 +3693 +3694 +3695 +3696 +3697 +3698 +3699 +3700 +3701 +3702 +3703 +3704 +3705 +3706 +3707 +3708 +3709 +3710 +3711 +3712 +3713 +3714 +3715 +3716 +3717 +3718 +3719 +3720 +3721 +3722 +3723 +3724 +3725 +3726 +3727 +3728 +3729 +3730 +3731 +3732 +3733 +3734 +3735 +3736 +3737 +3738 +3739 +3740 +3741 +3742 +3743 +3744 +3745 +3746 +3747 +3748 +3749 +3750 +3751 +3752 +3753 +3754 +3755 +3756 +3757 +3758 +3759 +3760 +3761 +3762 +3763 +3764 +3765 +3766 +3767 +3768 +3769 +3770 +3771 +3772 +3773 +3774 +3775 +3776 +3777 +3778 +3779 +3780 +3781 +3782 +3783 +3784 +3785 +3786 +3787 +3788 +3789 +3790 +3791 +3792 +3793 +3794 +3795 +3796 +3797 +3798 +3799 +3800 +3801 +3802 +3803 +3804 +3805 +3806 +3807 +3808 +3809 +3810 +3811 +3812 +3813 +3814 +3815 +3816 +3817 +3818 +3819 +3820 +3821 +3822 +3823 +3824 +3825 +3826 +3827 +3828 +3829 +3830 +3831 +3832 +3833 +3834 +3835 +3836 +3837 +3838 +3839 +3840 +3841 +3842 +3843 +3844 +3845 +3846 +3847 +3848 +3849 +3850 +3851 +3852 +3853 +3854 +3855 +3856 +3857 +3858 +3859 +3860 +3861 +3862 +3863 +3864 +3865 +3866 +3867 +3868 +3869 +3870 +3871 +3872 +3873 +3874 +3875 +3876 +3877 +3878 +3879 +3880 +3881 +3882 +3883 +3884 +3885 +3886 +3887 +3888 +3889 +3890 +3891 +3892 +3893 +3894 +3895 +3896 +3897 +3898 +3899 +3900 +3901 +3902 +3903 +3904 +3905 +3906 +3907 +3908 +3909 +3910 +3911 +3912 +3913 +3914 +3915 +3916 +3917 +3918 +3919 +3920 +3921 +3922 +3923 +3924 +3925 +3926 +3927 +3928 +3929 +3930 +3931 +3932 +3933 +3934 +3935 +3936 +3937 +3938 +3939 +3940 +3941 +3942 +3943 +3944 +3945 +3946 +3947 +3948 +3949 +3950 +3951 +3952 +3953 +3954 +3955 +3956 +3957 +3958 +3959 +3960 +3961 +3962 +3963 +3964 +3965 +3966 +3967 +3968 +3969 +3970 +3971 +3972 +3973 +3974 +3975 +3976 +3977 +3978 +3979 +3980 +3981 +3982 +3983 +3984 +3985 +3986 +3987 +3988 +3989 +3990 +3991 +3992 +3993 +3994 +3995 +3996 +3997 +3998 +3999 +4000 +4001 +4002 +4003 +4004 +4005 +4006 +4007 +4008 +4009 +4010 +4011 +4012 +4013 +4014 +4015 +4016 +4017 +4018 +4019 +4020 +4021 +4022 +4023 +4024 +4025 +4026 +4027 +4028 +4029 +4030 +4031 +4032 +4033 +4034 +4035 +4036 +4037 +4038 +4039 +4040 +4041 +4042 +4043 +4044 +4045 +4046 +4047 +4048 +4049 +4050 +4051 +4052 +4053 +4054 +4055 +4056 +4057 +4058 +4059 +4060 +4061 +4062 +4063 +4064 +4065 +4066 +4067 +4068 +4069 +4070 +4071 +4072 +4073 +4074 +4075 +4076 +4077 +4078 +4079 +4080 +4081 +4082 +4083 +4084 +4085 +4086 +4087 +4088 +4089 +4090 +4091 +4092 +4093 +4094 +4095 +4096 +4097 +4098 +4099 +4100 +4101 +4102 +4103 +4104 +4105 +4106 +4107 +4108 +4109 +4110 +4111 +4112 +4113 +4114 +4115 +4116 +4117 +4118 +4119 +4120 +4121 +4122 +4123 +4124 +4125 +4126 +4127 +4128 +4129 +4130 +4131 +4132 +4133 +4134 +4135 +4136 +4137 +4138 +4139 +4140 +4141 +4142 +4143 +4144 +4145 +4146 +4147 +4148 +4149 +4150 +4151 +4152 +4153 +4154 +4155 +4156 +4157 +4158 +4159 +4160 +4161 +4162 +4163 +4164 +4165 +4166 +4167 +4168 +4169 +4170 +4171 +4172 +4173 +4174 +4175 +4176 +4177 +4178 +4179 +4180 +4181 +4182 +4183 +4184 +4185 +4186 +4187 +4188 +4189 +4190 +4191 +4192 +4193 +4194 +4195 +4196 +4197 +4198 +4199 +4200 +4201 +4202 +4203 +4204 +4205 +4206 +4207 +4208 +4209 +4210 +4211 +4212 +4213 +4214 +4215 +4216 +4217 +4218 +4219 +4220 +4221 +4222 +4223 +4224 +4225 +4226 +4227 +4228 +4229 +4230 +4231 +4232 +4233 +4234 +4235 +4236 +4237 +4238 +4239 +4240 +4241 +4242 +4243 +4244 +4245 +4246 +4247 +4248 +4249 +4250 +4251 +4252 +4253 +4254 +4255 +4256 +4257 +4258 +4259 +4260 +4261 +4262 +4263 +4264 +4265 +4266 +4267 +4268 +4269 +4270 +4271 +4272 +4273 +4274 +4275 +4276 +4277 +4278 +4279 +4280 +4281 +4282 +4283 +4284 +4285 +4286 +4287 +4288 +4289 +4290 +4291 +4292 +4293 +4294 +4295 +4296 +4297 +4298 +4299 +4300 +4301 +4302 +4303 +4304 +4305 +4306 +4307 +4308 +4309 +4310 +4311 +4312 +4313 +4314 +4315 +4316 +4317 +4318 +4319 +4320 +4321 +4322 +4323 +4324 +4325 +4326 +4327 +4328 +4329 +4330 +4331 +4332 +4333 +4334 +4335 +4336 +4337 +4338 +4339 +4340 +4341 +4342 +4343 +4344 +4345 +4346 +4347 +4348 +4349 +4350 +4351 +4352 +4353 +4354 +4355 +4356 +4357 +4358 +4359 +4360 +4361 +4362 +4363 +4364 +4365 +4366 +4367 +4368 +4369 +4370 +4371 +4372 +4373 +4374 +4375 +4376 +4377 +4378 +4379 +4380 +4381 +4382 +4383 +4384 +4385 +4386 +4387 +4388 +4389 +4390 +4391 +4392 +4393 +4394 +4395 +4396 +4397 +4398 +4399 +4400 +4401 +4402 +4403 +4404 +4405 +4406 +4407 +4408 +4409 +4410 +4411 +4412 +4413 +4414 +4415 +4416 +4417 +4418 +4419 +4420 +4421 +4422 +4423 +4424 +4425 +4426 +4427 +4428 +4429 +4430 +4431 +4432 +4433 +4434 +4435 +4436 +4437 +4438 +4439 +4440 +4441 +4442 +4443 +4444 +4445 +4446 +4447 +4448 +4449 +4450 +4451 +4452 +4453 +4454 +4455 +4456 +4457 +4458 +4459 +4460 +4461 +4462 +4463 +4464 +4465 +4466 +4467 +4468 +4469 +4470 +4471 +4472 +4473 +4474 +4475 +4476 +4477 +4478 +4479 +4480 +4481 +4482 +4483 +4484 +4485 +4486 +4487 +4488 +4489 +4490 +4491 +4492 +4493 +4494 +4495 +4496 +4497 +4498 +4499 +4500 +4501 +4502 +4503 +4504 +4505 +4506 +4507 +4508 +4509 +4510 +4511 +4512 +4513 +4514 +4515 +4516 +4517 +4518 +4519 +4520 +4521 +4522 +4523 +4524 +4525 +4526 +4527 +4528 +4529 +4530 +4531 +4532 +4533 +4534 +4535 +4536 +4537 +4538 +4539 +4540 +4541 +4542 +4543 +4544 +4545 +4546 +4547 +4548 +4549 +4550 +4551 +4552 +4553 +4554 +4555 +4556 +4557 +4558 +4559 +4560 +4561 +4562 +4563 +4564 +4565 +4566 +4567 +4568 +4569 +4570 +4571 +4572 +4573 +4574 +4575 +4576 +4577 +4578 +4579 +4580 +4581 +4582 +4583 +4584 +4585 +4586 +4587 +4588 +4589 +4590 +4591 +4592 +4593 +4594 +4595 +4596 +4597 +4598 +4599 +4600 +4601 +4602 +4603 +4604 +4605 +4606 +4607 +4608 +4609 +4610 +4611 +4612 +4613 +4614 +4615 +4616 +4617 +4618 +4619 +4620 +4621 +4622 +4623 +4624 +4625 +4626 +4627 +4628 +4629 +4630 +4631 +4632 +4633 +4634 +4635 +4636 +4637 +4638 +4639 +4640 +4641 +4642 +4643 +4644 +4645 +4646 +4647 +4648 +4649 +4650 +4651 +4652 +4653 +4654 +4655 +4656 +4657 +4658 +4659 +4660 +4661 +4662 +4663 +4664 +4665 +4666 +4667 +4668 +4669 +4670 +4671 +4672 +4673 +4674 +4675 +4676 +4677 +4678 +4679 +4680 +4681 +4682 +4683 +4684 +4685 +4686 +4687 +4688 +4689 +4690 +4691 +4692 +4693 +4694 +4695 +4696 +4697 +4698 +4699 +4700 +4701 +4702 +4703 +4704 +4705 +4706 +4707 +4708 +4709 +4710 +4711 +4712 +4713 +4714 +4715 +4716 +4717 +4718 +4719 +4720 +4721 +4722 +4723 +4724 +4725 +4726 +4727 +4728 +4729 +4730 +4731 +4732 +4733 +4734 +4735 +4736 +4737 +4738 +4739 +4740 +4741 +4742 +4743 +4744 +4745 +4746 +4747 +4748 +4749 +4750 +4751 +4752 +4753 +4754 +4755 +4756 +4757 +4758 +4759 +4760 +4761 +4762 +4763 +4764 +4765 +4766 +4767 +4768 +4769 +4770 +4771 +4772 +4773 +4774 +4775 +4776 +4777 +4778 +4779 +4780 +4781 +4782 +4783 +4784 +4785 +4786 +4787 +4788 +4789 +4790 +4791 +4792 +4793 +4794 +4795 +4796 +4797 +4798 +4799 +4800 +4801 +4802 +4803 +4804 +4805 +4806 +4807 +4808 +4809 +4810 +4811 +4812 +4813 +4814 +4815 +4816 +4817 +4818 +4819 +4820 +4821 +4822 +4823 +4824 +4825 +4826 +4827 +4828 +4829 +4830 +4831 +4832 +4833 +4834 +4835 +4836 +4837 +4838 +4839 +4840 +4841 +4842 +4843 +4844 +4845 +4846 +4847 +4848 +4849 +4850 +4851 +4852 +4853 +4854 +4855 +4856 +4857 +4858 +4859 +4860 +4861 +4862 +4863 +4864 +4865 +4866 +4867 +4868 +4869 +4870 +4871 +4872 +4873 +4874 +4875 +4876 +4877 +4878 +4879 +4880 +4881 +4882 +4883 +4884 +4885 +4886 +4887 +4888 +4889 +4890 +4891 +4892 +4893 +4894 +4895 +4896 +4897 +4898 +4899 +4900 +4901 +4902 +4903 +4904 +4905 +4906 +4907 +4908 +4909 +4910 +4911 +4912 +4913 +4914 +4915 +4916 +4917 +4918 +4919 +4920 +4921 +4922 +4923 +4924 +4925 +4926 +4927 +4928 +4929 +4930 +4931 +4932 +4933 +4934 +4935 +4936 +4937 +4938 +4939 +4940 +4941 +4942 +4943 +4944 +4945 +4946 +4947 +4948 +4949 +4950 +4951 +4952 +4953 +4954 +4955 +4956 +4957 +4958 +4959 +4960 +4961 +4962 +4963 +4964 +4965 +4966 +4967 +4968 +4969 +4970 +4971 +4972 +4973 +4974 +4975 +4976 +4977 +4978 +4979 +4980 +4981 +4982 +4983 +4984 +4985 +4986 +4987 +4988 +4989 +4990 +4991 +4992 +4993 +4994 +4995 +4996 +4997 +4998 +4999 +5000 +5001 +5002 +5003 +5004 +5005 +5006 +5007 +5008 +5009 +5010 +5011 +5012 +5013 +5014 +5015 +5016 +5017 +5018 +5019 +5020 +5021 +5022 +5023 +5024 +5025 +5026 +5027 +5028 +5029 +5030 +5031 +5032 +5033 +5034 +5035 +5036 +5037 +5038 +5039 +5040 +5041 +5042 +5043 +5044 +5045 +5046 +5047 +5048 +5049 +5050 +5051 +5052 +5053 +5054 +5055 +5056 +5057 +5058 +5059 +5060 +5061 +5062 +5063 +5064 +5065 +5066 +5067 +5068 +5069 +5070 +5071 +5072 +5073 +5074 +5075 +5076 +5077 +5078 +5079 +5080 +5081 +5082 +5083 +5084 +5085 +5086 +5087 +5088 +5089 +5090 +5091 +5092 +5093 +5094 +5095 +5096 +5097 +5098 +5099 +5100 +5101 +5102 +5103 +5104 +5105 +5106 +5107 +5108 +5109 +5110 +5111 +5112 +5113 +5114 +5115 +5116 +5117 +5118 +5119 +5120 +5121 +5122 +5123 +5124 +5125 +5126 +5127 +5128 +5129 +5130 +5131 +5132 +5133 +5134 +5135 +5136 +5137 +5138 +5139 +5140 +5141 +5142 +5143 +5144 +5145 +5146 +5147 +5148 +5149 +5150 +5151 +5152 +5153 +5154 +5155 +5156 +5157 +5158 +5159 +5160 +5161 +5162 +5163 +5164 +5165 +5166 +5167 +5168 +5169 +5170 +5171 +5172 +5173 +5174 +5175 +5176 +5177 +5178 +5179 +5180 +5181 +5182 +5183 +5184 +5185 +5186 +5187 +5188 +5189 +5190 +5191 +5192 +5193 +5194 +5195 +5196 +5197 +5198 +5199 +5200 +5201 +5202 +5203 +5204 +5205 +5206 +5207 +5208 +5209 +5210 +5211 +5212 +5213 +5214 +5215 +5216 +5217 +5218 +5219 +5220 +5221 +5222 +5223 +5224 +5225 +5226 +5227 +5228 +5229 +5230 +5231 +5232 +5233 +5234 +5235 +5236 +5237 +5238 +5239 +5240 +5241 +5242 +5243 +5244 +5245 +5246 +5247 +5248 +5249 +5250 +5251 +5252 +5253 +5254 +5255 +5256 +5257 +5258 +5259 +5260 +5261 +5262 +5263 +5264 +5265 +5266 +5267 +5268 +5269 +5270 +5271 +5272 +5273 +5274 +5275 +5276 +5277 +5278 +5279 +5280 +5281 +5282 +5283 +5284 +5285 +5286 +5287 +5288 +5289 +5290 +5291 +5292 +5293 +5294 +5295 +5296 +5297 +5298 +5299 +5300 +5301 +5302 +5303 +5304 +5305 +5306 +5307 +5308 +5309 +5310 +5311 +5312 +5313 +5314 +5315 +5316 +5317 +5318 +5319 +5320 +5321 +5322 +5323 +5324 +5325 +5326 +5327 +5328 +5329 +5330 +5331 +5332 +5333 +5334 +5335 +5336 +5337 +5338 +5339 +5340 +5341 +5342 +5343 +5344 +5345 +5346 +5347 +5348 +5349 +5350 +5351 +5352 +5353 +5354 +5355 +5356 +5357 +5358 +5359 +5360 +5361 +5362 +5363 +5364 +5365 +5366 +5367 +5368 +5369 +5370 +5371 +5372 +5373 +5374 +5375 +5376 +5377 +5378 +5379 +5380 +5381 +5382 +5383 +5384 +5385 +5386 +5387 +5388 +5389 +5390 +5391 +5392 +5393 +5394 +5395 +5396 +5397 +5398 +5399 +5400 +5401 +5402 +5403 +5404 +5405 +5406 +5407 +5408 +5409 +5410 +5411 +5412 +5413 +5414 +5415 +5416 +5417 +5418 +5419 +5420 +5421 +5422 +5423 +5424 +5425 +5426 +5427 +5428 +5429 +5430 +5431 +5432 +5433 +5434 +5435 +5436 +5437 +5438 +5439 +5440 +5441 +5442 +5443 +5444 +5445 +5446 +5447 +5448 +5449 +5450 +5451 +5452 +5453 +5454 +5455 +5456 +5457 +5458 +5459 +5460 +5461 +5462 +5463 +5464 +5465 +5466 +5467 +5468 +5469 +5470 +5471 +5472 +5473 +5474 +5475 +5476 +5477 +5478 +5479 +5480 +5481 +5482 +5483 +5484 +5485 +5486 +5487 +5488 +5489 +5490 +5491 +5492 +5493 +5494 +5495 +5496 +5497 +5498 +5499 +5500 +5501 +5502 +5503 +5504 +5505 +5506 +5507 +5508 +5509 +5510 +5511 +5512 +5513 +5514 +5515 +5516 +5517 +5518 +5519 +5520 +5521 +5522 +5523 +5524 +5525 +5526 +5527 +5528 +5529 +5530 +5531 +5532 +5533 +5534 +5535 +5536 +5537 +5538 +5539 +5540 +5541 +5542 +5543 +5544 +5545 +5546 +5547 +5548 +5549 +5550 +5551 +5552 +5553 +5554 +5555 +5556 +5557 +5558 +5559 +5560 +5561 +5562 +5563 +5564 +5565 +5566 +5567 +5568 +5569 +5570 +5571 +5572 +5573 +5574 +5575 +5576 +5577 +5578 +5579 +5580 +5581 +5582 +5583 +5584 +5585 +5586 +5587 +5588 +5589 +5590 +5591 +5592 +5593 +5594 +5595 +5596 +5597 +5598 +5599 +5600 +5601 +5602 +5603 +5604 +5605 +5606 +5607 +5608 +5609 +5610 +5611 +5612 +5613 +5614 +5615 +5616 +5617 +5618 +5619 +5620 +5621 +5622 +5623 +5624 +5625 +5626 +5627 +5628 +5629 +5630 +5631 +5632 +5633 +5634 +5635 +5636 +5637 +5638 +5639 +5640 +5641 +5642 +5643 +5644 +5645 +5646 +5647 +5648 +5649 +5650 +5651 +5652 +5653 +5654 +5655 +5656 +5657 +5658 +5659 +5660 +5661 +5662 +5663 +5664 +5665 +5666 +5667 +5668 +5669 +5670 +5671 +5672 +5673 +5674 +5675 +5676 +5677 +5678 +5679 +5680 +5681 +5682 +5683 +5684 +5685 +5686 +5687 +5688 +5689 +5690 +5691 +5692 +5693 +5694 +5695 +5696 +5697 +5698 +5699 +5700 +5701 +5702 +5703 +5704 +5705 +5706 +5707 +5708 +5709 +5710 +5711 +5712 +5713 +5714 +5715 +5716 +5717 +5718 +5719 +5720 +5721 +5722 +5723 +5724 +5725 +5726 +5727 +5728 +5729 +5730 +5731 +5732 +5733 +5734 +5735 +5736 +5737 +5738 +5739 +5740 +5741 +5742 +5743 +5744 +5745 +5746 +5747 +5748 +5749 +5750 +5751 +5752 +5753 +5754 +5755 +5756 +5757 +5758 +5759 +5760 +5761 +5762 +5763 +5764 +5765 +5766 +5767 +5768 +5769 +5770 +5771 +5772 +5773 +5774 +5775 +5776 +5777 +5778 +5779 +5780 +5781 +5782 +5783 +5784 +5785 +5786 +5787 +5788 +5789 +5790 +5791 +5792 +5793 +5794 +5795 +5796 +5797 +5798 +5799 +5800 +5801 +5802 +5803 +5804 +5805 +5806 +5807 +5808 +5809 +5810 +5811 +5812 +5813 +5814 +5815 +5816 +5817 +5818 +5819 +5820 +5821 +5822 +5823 +5824 +5825 +5826 +5827 +5828 +5829 +5830 +5831 +5832 +5833 +5834 +5835 +5836 +5837 +5838 +5839 +5840 +5841 +5842 +5843 +5844 +5845 +5846 +5847 +5848 +5849 +5850 +5851 +5852 +5853 +5854 +5855 +5856 +5857 +5858 +5859 +5860 +5861 +5862 +5863 +5864 +5865 +5866 +5867 +5868 +5869 +5870 +5871 +5872 +5873 +5874 +5875 +5876 +5877 +5878 +5879 +5880 +5881 +5882 +5883 +5884 +5885 +5886 +5887 +5888 +5889 +5890 +5891 +5892 +5893 +5894 +5895 +5896 +5897 +5898 +5899 +5900 +5901 +5902 +5903 +5904 +5905 +5906 +5907 +5908 +5909 +5910 +5911 +5912 +5913 +5914 +5915 +5916 +5917 +5918 +5919 +5920 +5921 +5922 +5923 +5924 +5925 +5926 +5927 +5928 +5929 +5930 +5931 +5932 +5933 +5934 +5935 +5936 +5937 +5938 +5939 +5940 +5941 +5942 +5943 +5944 +5945 +5946 +5947 +5948 +5949 +5950 +5951 +5952 +5953 +5954 +5955 +5956 +5957 +5958 +5959 +5960 +5961 +5962 +5963 +5964 +5965 +5966 +5967 +5968 +5969 +5970 +5971 +5972 +5973 +5974 +5975 +5976 +5977 +5978 +5979 +5980 +5981 +5982 +5983 +5984 +5985 +5986 +5987 +5988 +5989 +5990 +5991 +5992 +5993 +5994 +5995 +5996 +5997 +5998 +5999 +6000 +6001 +6002 +6003 +6004 +6005 +6006 +6007 +6008 +6009 +6010 +6011 +6012 +6013 +6014 +6015 +6016 +6017 +6018 +6019 +6020 +6021 +6022 +6023 +6024 +6025 +6026 +6027 +6028 +6029 +6030 +6031 +6032 +6033 +6034 +6035 +6036 +6037 +6038 +6039 +6040 +6041 +6042 +6043 +6044 +6045 +6046 +6047 +6048 +6049 +6050 +6051 +6052 +6053 +6054 +6055 +6056 +6057 +6058 +6059 +6060 +6061 +6062 +6063 +6064 +6065 +6066 +6067 +6068 +6069 +6070 +6071 +6072 +6073 +6074 +6075 +6076 +6077 +6078 +6079 +6080 +6081 +6082 +6083 +6084 +6085 +6086 +6087 +6088 +6089 +6090 +6091 +6092 +6093 +6094 +6095 +6096 +6097 +6098 +6099 +6100 +6101 +6102 +6103 +6104 +6105 +6106 +6107 +6108 +6109 +6110 +6111 +6112 +6113 +6114 +6115 +6116 +6117 +6118 +6119 +6120 +6121 +6122 +6123 +6124 +6125 +6126 +6127 +6128 +6129 +6130 +6131 +6132 +6133 +6134 +6135 +6136 +6137 +6138 +6139 +6140 +6141 +6142 +6143 +6144 +6145 +6146 +6147 +6148 +6149 +6150 +6151 +6152 +6153 +6154 +6155 +6156 +6157 +6158 +6159 +6160 +6161 +6162 +6163 +6164 +6165 +6166 +6167 +6168 +6169 +6170 +6171 +6172 +6173 +6174 +6175 +6176 +6177 +6178 +6179 +6180 +6181 +6182 +6183 +6184 +6185 +6186 +6187 +6188 +6189 +6190 +6191 +6192 +6193 +6194 +6195 +6196 +6197 +6198 +6199 +6200 +6201 +6202 +6203 +6204 +6205 +6206 +6207 +6208 +6209 +6210 +6211 +6212 +6213 +6214 +6215 +6216 +6217 +6218 +6219 +6220 +6221 +6222 +6223 +6224 +6225 +6226 +6227 +6228 +6229 +6230 +6231 +6232 +6233 +6234 +6235 +6236 +6237 +6238 +6239 +6240 +6241 +6242 +6243 +6244 +6245 +6246 +6247 +6248 +6249 +6250 +6251 +6252 +6253 +6254 +6255 +6256 +6257 +6258 +6259 +6260 +6261 +6262 +6263 +6264 +6265 +6266 +6267 +6268 +6269 +6270 +6271 +6272 +6273 +6274 +6275 +6276 +6277 +6278 +6279 +6280 +6281 +6282 +6283 +6284 +6285 +6286 +6287 +6288 +6289 +6290 +6291 +6292 +6293 +6294 +6295 +6296 +6297 +6298 +6299 +6300 +6301 +6302 +6303 +6304 +6305 +6306 +6307 +6308 +6309 +6310 +6311 +6312 +6313 +6314 +6315 +6316 +6317 +6318 +6319 +6320 +6321 +6322 +6323 +6324 +6325 +6326 +6327 +6328 +6329 +6330 +6331 +6332 +6333 +6334 +6335 +6336 +6337 +6338 +6339 +6340 +6341 +6342 +6343 +6344 +6345 +6346 +6347 +6348 +6349 +6350 +6351 +6352 +6353 +6354 +6355 +6356 +6357 +6358 +6359 +6360 +6361 +6362 +6363 +6364 +6365 +6366 +6367 +6368 +6369 +6370 +6371 +6372 +6373 +6374 +6375 +6376 +6377 +6378 +6379 +6380 +6381 +6382 +6383 +6384 +6385 +6386 +6387 +6388 +6389 +6390 +6391 +6392 +6393 +6394 +6395 +6396 +6397 +6398 +6399 +6400 +6401 +6402 +6403 +6404 +6405 +6406 +6407 +6408 +6409 +6410 +6411 +6412 +6413 +6414 +6415 +6416 +6417 +6418 +6419 +6420 +6421 +6422 +6423 +6424 +6425 +6426 +6427 +6428 +6429 +6430 +6431 +6432 +6433 +6434 +6435 +6436 +6437 +6438 +6439 +6440 +6441 +6442 +6443 +6444 +6445 +6446 +6447 +6448 +6449 +6450 +6451 +6452 +6453 +6454 +6455 +6456 +6457 +6458 +6459 +6460 +6461 +6462 +6463 +6464 +6465 +6466 +6467 +6468 +6469 +6470 +6471 +6472 +6473 +6474 +6475 +6476 +6477 +6478 +6479 +6480 +6481 +6482 +6483 +6484 +6485 +6486 +6487 +6488 +6489 +6490 +6491 +6492 +6493 +6494 +6495 +6496 +6497 +6498 +6499 +6500 +6501 +6502 +6503 +6504 +6505 +6506 +6507 +6508 +6509 +6510 +6511 +6512 +6513 +6514 +6515 +6516 +6517 +6518 +6519 +6520 +6521 +6522 +6523 +6524 +6525 +6526 +6527 +6528 +6529 +6530 +6531 +6532 +6533 +6534 +6535 +6536 +6537 +6538 +6539 +6540 +6541 +6542 +6543 +6544 +6545 +6546 +6547 +6548 +6549 +6550 +6551 +6552 +6553 +6554 +6555 +6556 +6557 +6558 +6559 +6560 +6561 +6562 +6563 +6564 +6565 +6566 +6567 +6568 +6569 +6570 +6571 +6572 +6573 +6574 +6575 +6576 +6577 +6578 +6579 +6580 +6581 +6582 +6583 +6584 +6585 +6586 +6587 +6588 +6589 +6590 +6591 +6592 +6593 +6594 +6595 +6596 +6597 +6598 +6599 +6600 +6601 +6602 +6603 +6604 +6605 +6606 +6607 +6608 +6609 +6610 +6611 +6612 +6613 +6614 +6615 +6616 +6617 +6618 +6619 +6620 +6621 +6622 +6623 +6624 +6625 +6626 +6627 +6628 +6629 +6630 +6631 +6632 +6633 +6634 +6635 +6636 +6637 +6638 +6639 +6640 +6641 +6642 +6643 +6644 +6645 +6646 +6647 +6648 +6649 +6650 +6651 +6652 +6653 +6654 +6655 +6656 +6657 +6658 +6659 +6660 +6661 +6662 +6663 +6664 +6665 +6666 +6667 +6668 +6669 +6670 +6671 +6672 +6673 +6674 +6675 +6676 +6677 +6678 +6679 +6680 +6681 +6682 +6683 +6684 +6685 +6686 +6687 +6688 +6689 +6690 +6691 +6692 +6693 +6694 +6695 +6696 +6697 +6698 +6699 +6700 +6701 +6702 +6703 +6704 +6705 +6706 +6707 +6708 +6709 +6710 +6711 +6712 +6713 +6714 +6715 +6716 +6717 +6718 +6719 +6720 +6721 +6722 +6723 +6724 +6725 +6726 +6727 +6728 +6729 +6730 +6731 +6732 +6733 +6734 +6735 +6736 +6737 +6738 +6739 +6740 +6741 +6742 +6743 +6744 +6745 +6746 +6747 +6748 +6749 +6750 +6751 +6752 +6753 +6754 +6755 +6756 +6757 +6758 +6759 +6760 +6761 +6762 +6763 +6764 +6765 +6766 +6767 +6768 +6769 +6770 +6771 +6772 +6773 +6774 +6775 +6776 +6777 +6778 +6779 +6780 +6781 +6782 +6783 +6784 +6785 +6786 +6787 +6788 +6789 +6790 +6791 +6792 +6793 +6794 +6795 +6796 +6797 +6798 +6799 +6800 +6801 +6802 +6803 +6804 +6805 +6806 +6807 +6808 +6809 +6810 +6811 +6812 +6813 +6814 +6815 +6816 +6817 +6818 +6819 +6820 +6821 +6822 +6823 +6824 +6825 +6826 +6827 +6828 +6829 +6830 +6831 +6832 +6833 +6834 +6835 +6836 +6837 +6838 +6839 +6840 +6841 +6842 +6843 +6844 +6845 +6846 +6847 +6848 +6849 +6850 +6851 +6852 +6853 +6854 +6855 +6856 +6857 +6858 +6859 +6860 +6861 +6862 +6863 +6864 +6865 +6866 +6867 +6868 +6869 +6870 +6871 +6872 +6873 +6874 +6875 +6876 +6877 +6878 +6879 +6880 +6881 +6882 +6883 +6884 +6885 +6886 +6887 +6888 +6889 +6890 +6891 +6892 +6893 +6894 +6895 +6896 +6897 +6898 +6899 +6900 +6901 +6902 +6903 +6904 +6905 +6906 +6907 +6908 +6909 +6910 +6911 +6912 +6913 +6914 +6915 +6916 +6917 +6918 +6919 +6920 +6921 +6922 +6923 +6924 +6925 +6926 +6927 +6928 +6929 +6930 +6931 +6932 +6933 +6934 +6935 +6936 +6937 +6938 +6939 +6940 +6941 +6942 +6943 +6944 +6945 +6946 +6947 +6948 +6949 +6950 +6951 +6952 +6953 +6954 +6955 +6956 +6957 +6958 +6959 +6960 +6961 +6962 +6963 +6964 +6965 +6966 +6967 +6968 +6969 +6970 +6971 +6972 +6973 +6974 +6975 +6976 +6977 +6978 +6979 +6980 +6981 +6982 +6983 +6984 +6985 +6986 +6987 +6988 +6989 +6990 +6991 +6992 +6993 +6994 +6995 +6996 +6997 +6998 +6999 +7000 +7001 +7002 +7003 +7004 +7005 +7006 +7007 +7008 +7009 +7010 +7011 +7012 +7013 +7014 +7015 +7016 +7017 +7018 +7019 +7020 +7021 +7022 +7023 +7024 +7025 +7026 +7027 +7028 +7029 +7030 +7031 +7032 +7033 +7034 +7035 +7036 +7037 +7038 +7039 +7040 +7041 +7042 +7043 +7044 +7045 +7046 +7047 +7048 +7049 +7050 +7051 +7052 +7053 +7054 +7055 +7056 +7057 +7058 +7059 +7060 +7061 +7062 +7063 +7064 +7065 +7066 +7067 +7068 +7069 +7070 +7071 +7072 +7073 +7074 +7075 +7076 +7077 +7078 +7079 +7080 +7081 +7082 +7083 +7084 +7085 +7086 +7087 +7088 +7089 +7090 +7091 +7092 +7093 +7094 +7095 +7096 +7097 +7098 +7099 +7100 +7101 +7102 +7103 +7104 +7105 +7106 +7107 +7108 +7109 +7110 +7111 +7112 +7113 +7114 +7115 +7116 +7117 +7118 +7119 +7120 +7121 +7122 +7123 +7124 +7125 +7126 +7127 +7128 +7129 +7130 +7131 +7132 +7133 +7134 +7135 +7136 +7137 +7138 +7139 +7140 +7141 +7142 +7143 +7144 +7145 +7146 +7147 +7148 +7149 +7150 +7151 +7152 +7153 +7154 +7155 +7156 +7157 +7158 +7159 +7160 +7161 +7162 +7163 +7164 +7165 +7166 +7167 +7168 +7169 +7170 +7171 +7172 +7173 +7174 +7175 +7176 +7177 +7178 +7179 +7180 +7181 +7182 +7183 +7184 +7185 +7186 +7187 +7188 +7189 +7190 +7191 +7192 +7193 +7194 +7195 +7196 +7197 +7198 +7199 +7200 +7201 +7202 +7203 +7204 +7205 +7206 +7207 +7208 +7209 +7210 +7211 +7212 +7213 +7214 +7215 +7216 +7217 +7218 +7219 +7220 +7221 +7222 +7223 +7224 +7225 +7226 +7227 +7228 +7229 +7230 +7231 +7232 +7233 +7234 +7235 +7236 +7237 +7238 +7239 +7240 +7241 +7242 +7243 +7244 +7245 +7246 +7247 +7248 +7249 +7250 +7251 +7252 +7253 +7254 +7255 +7256 +7257 +7258 +7259 +7260 +7261 +7262 +7263 +7264 +7265 +7266 +7267 +7268 +7269 +7270 +7271 +7272 +7273 +7274 +7275 +7276 +7277 +7278 +7279 +7280 +7281 +7282 +7283 +7284 +7285 +7286 +7287 +7288 +7289 +7290 +7291 +7292 +7293 +7294 +7295 +7296 +7297 +7298 +7299 +7300 +7301 +7302 +7303 +7304 +7305 +7306 +7307 +7308 +7309 +7310 +7311 +7312 +7313 +7314 +7315 +7316 +7317 +7318 +7319 +7320 +7321 +7322 +7323 +7324 +7325 +7326 +7327 +7328 +7329 +7330 +7331 +7332 +7333 +7334 +7335 +7336 +7337 +7338 +7339 +7340 +7341 +7342 +7343 +7344 +7345 +7346 +7347 +7348 +7349 +7350 +7351 +7352 +7353 +7354 +7355 +7356 +7357 +7358 +7359 +7360 +7361 +7362 +7363 +7364 +7365 +7366 +7367 +7368 +7369 +7370 +7371 +7372 +7373 +7374 +7375 +7376 +7377 +7378 +7379 +7380 +7381 +7382 +7383 +7384 +7385 +7386 +7387 +7388 +7389 +7390 +7391 +7392 +7393 +7394 +7395 +7396 +7397 +7398 +7399 +7400 +7401 +7402 +7403 +7404 +7405 +7406 +7407 +7408 +7409 +7410 +7411 +7412 +7413 +7414 +7415 +7416 +7417 +7418 +7419 +7420 +7421 +7422 +7423 +7424 +7425 +7426 +7427 +7428 +7429 +7430 +7431 +7432 +7433 +7434 +7435 +7436 +7437 +7438 +7439 +7440 +7441 +7442 +7443 +7444 +7445 +7446 +7447 +7448 +7449 +7450 +7451 +7452 +7453 +7454 +7455 +7456 +7457 +7458 +7459 +7460 +7461 +7462 +7463 +7464 +7465 +7466 +7467 +7468 +7469 +7470 +7471 +7472 +7473 +7474 +7475 +7476 +7477 +7478 +7479 +7480 +7481 +7482 +7483 +7484 +7485 +7486 +7487 +7488 +7489 +7490 +7491 +7492 +7493 +7494 +7495 +7496 +7497 +7498 +7499 +7500 +7501 +7502 +7503 +7504 +7505 +7506 +7507 +7508 +7509 +7510 +7511 +7512 +7513 +7514 +7515 +7516 +7517 +7518 +7519 +7520 +7521 +7522 +7523 +7524 +7525 +7526 +7527 +7528 +7529 +7530 +7531 +7532 +7533 +7534 +7535 +7536 +7537 +7538 +7539 +7540 +7541 +7542 +7543 +7544 +7545 +7546 +7547 +7548 +7549 +7550 +7551 +7552 +7553 +7554 +7555 +7556 +7557 +7558 +7559 +7560 +7561 +7562 +7563 +7564 +7565 +7566 +7567 +7568 +7569 +7570 +7571 +7572 +7573 +7574 +7575 +7576 +7577 +7578 +7579 +7580 +7581 +7582 +7583 +7584 +7585 +7586 +7587 +7588 +7589 +7590 +7591 +7592 +7593 +7594 +7595 +7596 +7597 +7598 +7599 +7600 +7601 +7602 +7603 +7604 +7605 +7606 +7607 +7608 +7609 +7610 +7611 +7612 +7613 +7614 +7615 +7616 +7617 +7618 +7619 +7620 +7621 +7622 +7623 +7624 +7625 +7626 +7627 +7628 +7629 +7630 +7631 +7632 +7633 +7634 +7635 +7636 +7637 +7638 +7639 +7640 +7641 +7642 +7643 +7644 +7645 +7646 +7647 +7648 +7649 +7650 +7651 +7652 +7653 +7654 +7655 +7656 +7657 +7658 +7659 +7660 +7661 +7662 +7663 +7664 +7665 +7666 +7667 +7668 +7669 +7670 +7671 +7672 +7673 +7674 +7675 +7676 +7677 +7678 +7679 +7680 +7681 +7682 +7683 +7684 +7685 +7686 +7687 +7688 +7689 +7690 +7691 +7692 +7693 +7694 +7695 +7696 +7697 +7698 +7699 +7700 +7701 +7702 +7703 +7704 +7705 +7706 +7707 +7708 +7709 +7710 +7711 +7712 +7713 +7714 +7715 +7716 +7717 +7718 +7719 +7720 +7721 +7722 +7723 +7724 +7725 +7726 +7727 +7728 +7729 +7730 +7731 +7732 +7733 +7734 +7735 +7736 +7737 +7738 +7739 +7740 +7741 +7742 +7743 +7744 +7745 +7746 +7747 +7748 +7749 +7750 +7751 +7752 +7753 +7754 +7755 +7756 +7757 +7758 +7759 +7760 +7761 +7762 +7763 +7764 +7765 +7766 +7767 +7768 +7769 +7770 +7771 +7772 +7773 +7774 +7775 +7776 +7777 +7778 +7779 +7780 +7781 +7782 +7783 +7784 +7785 +7786 +7787 +7788 +7789 +7790 +7791 +7792 +7793 +7794 +7795 +7796 +7797 +7798 +7799 +7800 +7801 +7802 +7803 +7804 +7805 +7806 +7807 +7808 +7809 +7810 +7811 +7812 +7813 +7814 +7815 +7816 +7817 +7818 +7819 +7820 +7821 +7822 +7823 +7824 +7825 +7826 +7827 +7828 +7829 +7830 +7831 +7832 +7833 +7834 +7835 +7836 +7837 +7838 +7839 +7840 +7841 +7842 +7843 +7844 +7845 +7846 +7847 +7848 +7849 +7850 +7851 +7852 +7853 +7854 +7855 +7856 +7857 +7858 +7859 +7860 +7861 +7862 +7863 +7864 +7865 +7866 +7867 +7868 +7869 +7870 +7871 +7872 +7873 +7874 +7875 +7876 +7877 +7878 +7879 +7880 +7881 +7882 +7883 +7884 +7885 +7886 +7887 +7888 +7889 +7890 +7891 +7892 +7893 +7894 +7895 +7896 +7897 +7898 +7899 +7900 +7901 +7902 +7903 +7904 +7905 +7906 +7907 +7908 +7909 +7910 +7911 +7912 +7913 +7914 +7915 +7916 +7917 +7918 +7919 +7920 +7921 +7922 +7923 +7924 +7925 +7926 +7927 +7928 +7929 +7930 +7931 +7932 +7933 +7934 +7935 +7936 +7937 +7938 +7939 +7940 +7941 +7942 +7943 +7944 +7945 +7946 +7947 +7948 +7949 +7950 +7951 +7952 +7953 +7954 +7955 +7956 +7957 +7958 +7959 +7960 +7961 +7962 +7963 +7964 +7965 +7966 +7967 +7968 +7969 +7970 +7971 +7972 +7973 +7974 +7975 +7976 +7977 +7978 +7979 +7980 +7981 +7982 +7983 +7984 +7985 +7986 +7987 +7988 +7989 +7990 +7991 +7992 +7993 +7994 +7995 +7996 +7997 +7998 +7999 +8000 +8001 +8002 +8003 +8004 +8005 +8006 +8007 +8008 +8009 +8010 +8011 +8012 +8013 +8014 +8015 +8016 +8017 +8018 +8019 +8020 +8021 +8022 +8023 +8024 +8025 +8026 +8027 +8028 +8029 +8030 +8031 +8032 +8033 +8034 +8035 +8036 +8037 +8038 +8039 +8040 +8041 +8042 +8043 +8044 +8045 +8046 +8047 +8048 +8049 +8050 +8051 +8052 +8053 +8054 +8055 +8056 +8057 +8058 +8059 +8060 +8061 +8062 +8063 +8064 +8065 +8066 +8067 +8068 +8069 +8070 +8071 +8072 +8073 +8074 +8075 +8076 +8077 +8078 +8079 +8080 +8081 +8082 +8083 +8084 +8085 +8086 +8087 +8088 +8089 +8090 +8091 +8092 +8093 +8094 +8095 +8096 +8097 +8098 +8099 +8100 +8101 +8102 +8103 +8104 +8105 +8106 +8107 +8108 +8109 +8110 +8111 +8112 +8113 +8114 +8115 +8116 +8117 +8118 +8119 +8120 +8121 +8122 +8123 +8124 +8125 +8126 +8127 +8128 +8129 +8130 +8131 +8132 +8133 +8134 +8135 +8136 +8137 +8138 +8139 +8140 +8141 +8142 +8143 +8144 +8145 +8146 +8147 +8148 +8149 +8150 +8151 +8152 +8153 +8154 +8155 +8156 +8157 +8158 +8159 +8160 +8161 +8162 +8163 +8164 +8165 +8166 +8167 +8168 +8169 +8170 +8171 +8172 +8173 +8174 +8175 +8176 +8177 +8178 +8179 +8180 +8181 +8182 +8183 +8184 +8185 +8186 +8187 +8188 +8189 +8190 +8191 +8192 +8193 +8194 +8195 +8196 +8197 +8198 +8199 +8200 +8201 +8202 +8203 +8204 +8205 +8206 +8207 +8208 +8209 +8210 +8211 +8212 +8213 +8214 +8215 +8216 +8217 +8218 +8219 +8220 +8221 +8222 +8223 +8224 +8225 +8226 +8227 +8228 +8229 +8230 +8231 +8232 +8233 +8234 +8235 +8236 +8237 +8238 +8239 +8240 +8241 +8242 +8243 +8244 +8245 +8246 +8247 +8248 +8249 +8250 +8251 +8252 +8253 +8254 +8255 +8256 +8257 +8258 +8259 +8260 +8261 +8262 +8263 +8264 +8265 +8266 +8267 +8268 +8269 +8270 +8271 +8272 +8273 +8274 +8275 +8276 +8277 +8278 +8279 +8280 +8281 +8282 +8283 +8284 +8285 +8286 +8287 +8288 +8289 +8290 +8291 +8292 +8293 +8294 +8295 +8296 +8297 +8298 +8299 +8300 +8301 +8302 +8303 +8304 +8305 +8306 +8307 +8308 +8309 +8310 +8311 +8312 +8313 +8314 +8315 +8316 +8317 +8318 +8319 +8320 +8321 +8322 +8323 +8324 +8325 +8326 +8327 +8328 +8329 +8330 +8331 +8332 +8333 +8334 +8335 +8336 +8337 +8338 +8339 +8340 +8341 +8342 +8343 +8344 +8345 +8346 +8347 +8348 +8349 +8350 +8351 +8352 +8353 +8354 +8355 +8356 +8357 +8358 +8359 +8360 +8361 +8362 +8363 +8364 +8365 +8366 +8367 +8368 +8369 +8370 +8371 +8372 +8373 +8374 +8375 +8376 +8377 +8378 +8379 +8380 +8381 +8382 +8383 +8384 +8385 +8386 +8387 +8388 +8389 +8390 +8391 +8392 +8393 +8394 +8395 +8396 +8397 +8398 +8399 +8400 +8401 +8402 +8403 +8404 +8405 +8406 +8407 +8408 +8409 +8410 +8411 +8412 +8413 +8414 +8415 +8416 +8417 +8418 +8419 +8420 +8421 +8422 +8423 +8424 +8425 +8426 +8427 +8428 +8429 +8430 +8431 +8432 +8433 +8434 +8435 +8436 +8437 +8438 +8439 +8440 +8441 +8442 +8443 +8444 +8445 +8446 +8447 +8448 +8449 +8450 +8451 +8452 +8453 +8454 +8455 +8456 +8457 +8458 +8459 +8460 +8461 +8462 +8463 +8464 +8465 +8466 +8467 +8468 +8469 +8470 +8471 +8472 +8473 +8474 +8475 +8476 +8477 +8478 +8479 +8480 +8481 +8482 +8483 +8484 +8485 +8486 +8487 +8488 +8489 +8490 +8491 +8492 +8493 +8494 +8495 +8496 +8497 +8498 +8499 +8500 +8501 +8502 +8503 +8504 +8505 +8506 +8507 +8508 +8509 +8510 +8511 +8512 +8513 +8514 +8515 +8516 +8517 +8518 +8519 +8520 +8521 +8522 +8523 +8524 +8525 +8526 +8527 +8528 +8529 +8530 +8531 +8532 +8533 +8534 +8535 +8536 +8537 +8538 +8539 +8540 +8541 +8542 +8543 +8544 +8545 +8546 +8547 +8548 +8549 +8550 +8551 +8552 +8553 +8554 +8555 +8556 +8557 +8558 +8559 +8560 +8561 +8562 +8563 +8564 +8565 +8566 +8567 +8568 +8569 +8570 +8571 +8572 +8573 +8574 +8575 +8576 +8577 +8578 +8579 +8580 +8581 +8582 +8583 +8584 +8585 +8586 +8587 +8588 +8589 +8590 +8591 +8592 +8593 +8594 +8595 +8596 +8597 +8598 +8599 +8600 +8601 +8602 +8603 +8604 +8605 +8606 +8607 +8608 +8609 +8610 +8611 +8612 +8613 +8614 +8615 +8616 +8617 +8618 +8619 +8620 +8621 +8622 +8623 +8624 +8625 +8626 +8627 +8628 +8629 +8630 +8631 +8632 +8633 +8634 +8635 +8636 +8637 +8638 +8639 +8640 +8641 +8642 +8643 +8644 +8645 +8646 +8647 +8648 +8649 +8650 +8651 +8652 +8653 +8654 +8655 +8656 +8657 +8658 +8659 +8660 +8661 +8662 +8663 +8664 +8665 +8666 +8667 +8668 +8669 +8670 +8671 +8672 +8673 +8674 +8675 +8676 +8677 +8678 +8679 +8680 +8681 +8682 +8683 +8684 +8685 +8686 +8687 +8688 +8689 +8690 +8691 +8692 +8693 +8694 +8695 +8696 +8697 +8698 +8699 +8700 +8701 +8702 +8703 +8704 +8705 +8706 +8707 +8708 +8709 +8710 +8711 +8712 +8713 +8714 +8715 +8716 +8717 +8718 +8719 +8720 +8721 +8722 +8723 +8724 +8725 +8726 +8727 +8728 +8729 +8730 +8731 +8732 +8733 +8734 +8735 +8736 +8737 +8738 +8739 +8740 +8741 +8742 +8743 +8744 +8745 +8746 +8747 +8748 +8749 +8750 +8751 +8752 +8753 +8754 +8755 +8756 +8757 +8758 +8759 +8760 +8761 +8762 +8763 +8764 +8765 +8766 +8767 +8768 +8769 +8770 +8771 +8772 +8773 +8774 +8775 +8776 +8777 +8778 +8779 +8780 +8781 +8782 +8783 +8784 +8785 +8786 +8787 +8788 +8789 +8790 +8791 +8792 +8793 +8794 +8795 +8796 +8797 +8798 +8799 +8800 +8801 +8802 +8803 +8804 +8805 +8806 +8807 +8808 +8809 +8810 +8811 +8812 +8813 +8814 +8815 +8816 +8817 +8818 +8819 +8820 +8821 +8822 +8823 +8824 +8825 +8826 +8827 +8828 +8829 +8830 +8831 +8832 +8833 +8834 +8835 +8836 +8837 +8838 +8839 +8840 +8841 +8842 +8843 +8844 +8845 +8846 +8847 +8848 +8849 +8850 +8851 +8852 +8853 +8854 +8855 +8856 +8857 +8858 +8859 +8860 +8861 +8862 +8863 +8864 +8865 +8866 +8867 +8868 +8869 +8870 +8871 +8872 +8873 +8874 +8875 +8876 +8877 +8878 +8879 +8880 +8881 +8882 +8883 +8884 +8885 +8886 +8887 +8888 +8889 +8890 +8891 +8892 +8893 +8894 +8895 +8896 +8897 +8898 +8899 +8900 +8901 +8902 +8903 +8904 +8905 +8906 +8907 +8908 +8909 +8910 +8911 +8912 +8913 +8914 +8915 +8916 +8917 +8918 +8919 +8920 +8921 +8922 +8923 +8924 +8925 +8926 +8927 +8928 +8929 +8930 +8931 +8932 +8933 +8934 +8935 +8936 +8937 +8938 +8939 +8940 +8941 +8942 +8943 +8944 +8945 +8946 +8947 +8948 +8949 +8950 +8951 +8952 +8953 +8954 +8955 +8956 +8957 +8958 +8959 +8960 +8961 +8962 +8963 +8964 +8965 +8966 +8967 +8968 +8969 +8970 +8971 +8972 +8973 +8974 +8975 +8976 +8977 +8978 +8979 +8980 +8981 +8982 +8983 +8984 +8985 +8986 +8987 +8988 +8989 +8990 +8991 +8992 +8993 +8994 +8995 +8996 +8997 +8998 +8999 +9000 +9001 +9002 +9003 +9004 +9005 +9006 +9007 +9008 +9009 +9010 +9011 +9012 +9013 +9014 +9015 +9016 +9017 +9018 +9019 +9020 +9021 +9022 +9023 +9024 +9025 +9026 +9027 +9028 +9029 +9030 +9031 +9032 +9033 +9034 +9035 +9036 +9037 +9038 +9039 +9040 +9041 +9042 +9043 +9044 +9045 +9046 +9047 +9048 +9049 +9050 +9051 +9052 +9053 +9054 +9055 +9056 +9057 +9058 +9059 +9060 +9061 +9062 +9063 +9064 +9065 +9066 +9067 +9068 +9069 +9070 +9071 +9072 +9073 +9074 +9075 +9076 +9077 +9078 +9079 +9080 +9081 +9082 +9083 +9084 +9085 +9086 +9087 +9088 +9089 +9090 +9091 +9092 +9093 +9094 +9095 +9096 +9097 +9098 +9099 +9100 +9101 +9102 +9103 +9104 +9105 +9106 +9107 +9108 +9109 +9110 +9111 +9112 +9113 +9114 +9115 +9116 +9117 +9118 +9119 +9120 +9121 +9122 +9123 +9124 +9125 +9126 +9127 +9128 +9129 +9130 +9131 +9132 +9133 +9134 +9135 +9136 +9137 +9138 +9139 +9140 +9141 +9142 +9143 +9144 +9145 +9146 +9147 +9148 +9149 +9150 +9151 +9152 +9153 +9154 +9155 +9156 +9157 +9158 +9159 +9160 +9161 +9162 +9163 +9164 +9165 +9166 +9167 +9168 +9169 +9170 +9171 +9172 +9173 +9174 +9175 +9176 +9177 +9178 +9179 +9180 +9181 +9182 +9183 +9184 +9185 +9186 +9187 +9188 +9189 +9190 +9191 +9192 +9193 +9194 +9195 +9196 +9197 +9198 +9199 +9200 +9201 +9202 +9203 +9204 +9205 +9206 +9207 +9208 +9209 +9210 +9211 +9212 +9213 +9214 +9215 +9216 +9217 +9218 +9219 +9220 +9221 +9222 +9223 +9224 +9225 +9226 +9227 +9228 +9229 +9230 +9231 +9232 +9233 +9234 +9235 +9236 +9237 +9238 +9239 +9240 +9241 +9242 +9243 +9244 +9245 +9246 +9247 +9248 +9249 +9250 +9251 +9252 +9253 +9254 +9255 +9256 +9257 +9258 +9259 +9260 +9261 +9262 +9263 +9264 +9265 +9266 +9267 +9268 +9269 +9270 +9271 +9272 +9273 +9274 +9275 +9276 +9277 +9278 +9279 +9280 +9281 +9282 +9283 +9284 +9285 +9286 +9287 +9288 +9289 +9290 +9291 +9292 +9293 +9294 +9295 +9296 +9297 +9298 +9299 +9300 +9301 +9302 +9303 +9304 +9305 +9306 +9307 +9308 +9309 +9310 +9311 +9312 +9313 +9314 +9315 +9316 +9317 +9318 +9319 +9320 +9321 +9322 +9323 +9324 +9325 +9326 +9327 +9328 +9329 +9330 +9331 +9332 +9333 +9334 +9335 +9336 +9337 +9338 +9339 +9340 +9341 +9342 +9343 +9344 +9345 +9346 +9347 +9348 +9349 +9350 +9351 +9352 +9353 +9354 +9355 +9356 +9357 +9358 +9359 +9360 +9361 +9362 +9363 +9364 +9365 +9366 +9367 +9368 +9369 +9370 +9371 +9372 +9373 +9374 +9375 +9376 +9377 +9378 +9379 +9380 +9381 +9382 +9383 +9384 +9385 +9386 +9387 +9388 +9389 +9390 +9391 +9392 +9393 +9394 +9395 +9396 +9397 +9398 +9399 +9400 +9401 +9402 +9403 +9404 +9405 +9406 +9407 +9408 +9409 +9410 +9411 +9412 +9413 +9414 +9415 +9416 +9417 +9418 +9419 +9420 +9421 +9422 +9423 +9424 +9425 +9426 +9427 +9428 +9429 +9430 +9431 +9432 +9433 +9434 +9435 +9436 +9437 +9438 +9439 +9440 +9441 +9442 +9443 +9444 +9445 +9446 +9447 +9448 +9449 +9450 +9451 +9452 +9453 +9454 +9455 +9456 +9457 +9458 +9459 +9460 +9461 +9462 +9463 +9464 +9465 +9466 +9467 +9468 +9469 +9470 +9471 +9472 +9473 +9474 +9475 +9476 +9477 +9478 +9479 +9480 +9481 +9482 +9483 +9484 +9485 +9486 +9487 +9488 +9489 +9490 +9491 +9492 +9493 +9494 +9495 +9496 +9497 +9498 +9499 +9500 +9501 +9502 +9503 +9504 +9505 +9506 +9507 +9508 +9509 +9510 +9511 +9512 +9513 +9514 +9515 +9516 +9517 +9518 +9519 +9520 +9521 +9522 +9523 +9524 +9525 +9526 +9527 +9528 +9529 +9530 +9531 +9532 +9533 +9534 +9535 +9536 +9537 +9538 +9539 +9540 +9541 +9542 +9543 +9544 +9545 +9546 +9547 +9548 +9549 +9550 +9551 +9552 +9553 +9554 +9555 +9556 +9557 +9558 +9559 +9560 +9561 +9562 +9563 +9564 +9565 +9566 +9567 +9568 +9569 +9570 +9571 +9572 +9573 +9574 +9575 +9576 +9577 +9578 +9579 +9580 +9581 +9582 +9583 +9584 +9585 +9586 +9587 +9588 +9589 +9590 +9591 +9592 +9593 +9594 +9595 +9596 +9597 +9598 +9599 +9600 +9601 +9602 +9603 +9604 +9605 +9606 +9607 +9608 +9609 +9610 +9611 +9612 +9613 +9614 +9615 +9616 +9617 +9618 +9619 +9620 +9621 +9622 +9623 +9624 +9625 +9626 +9627 +9628 +9629 +9630 +9631 +9632 +9633 +9634 +9635 +9636 +9637 +9638 +9639 +9640 +9641 +9642 +9643 +9644 +9645 +9646 +9647 +9648 +9649 +9650 +9651 +9652 +9653 +9654 +9655 +9656 +9657 +9658 +9659 +9660 +9661 +9662 +9663 +9664 +9665 +9666 +9667 +9668 +9669 +9670 +9671 +9672 +9673 +9674 +9675 +9676 +9677 +9678 +9679 +9680 +9681 +9682 +9683 +9684 +9685 +9686 +9687 +9688 +9689 +9690 +9691 +9692 +9693 +9694 +9695 +9696 +9697 +9698 +9699 +9700 +9701 +9702 +9703 +9704 +9705 +9706 +9707 +9708 +9709 +9710 +9711 +9712 +9713 +9714 +9715 +9716 +9717 +9718 +9719 +9720 +9721 +9722 +9723 +9724 +9725 +9726 +9727 +9728 +9729 +9730 +9731 +9732 +9733 +9734 +9735 +9736 +9737 +9738 +9739 +9740 +9741 +9742 +9743 +9744 +9745 +9746 +9747 +9748 +9749 +9750 +9751 +9752 +9753 +9754 +9755 +9756 +9757 +9758 +9759 +9760 +9761 +9762 +9763 +9764 +9765 +9766 +9767 +9768 +9769 +9770 +9771 +9772 +9773 +9774 +9775 +9776 +9777 +9778 +9779 +9780 +9781 +9782 +9783 +9784 +9785 +9786 +9787 +9788 +9789 +9790 +9791 +9792 +9793 +9794 +9795 +9796 +9797 +9798 +9799 +9800 +9801 +9802 +9803 +9804 +9805 +9806 +9807 +9808 +9809 +9810 +9811 +9812 +9813 +9814 +9815 +9816 +9817 +9818 +9819 +9820 +9821 +9822 +9823 +9824 +9825 +9826 +9827 +9828 +9829 +9830 +9831 +9832 +9833 +9834 +9835 +9836 +9837 +9838 +9839 +9840 +9841 +9842 +9843 +9844 +9845 +9846 +9847 +9848 +9849 +9850 +9851 +9852 +9853 +9854 +9855 +9856 +9857 +9858 +9859 +9860 +9861 +9862 +9863 +9864 +9865 +9866 +9867 +9868 +9869 +9870 +9871 +9872 +9873 +9874 +9875 +9876 +9877 +9878 +9879 +9880 +9881 +9882 +9883 +9884 +9885 +9886 +9887 +9888 +9889 +9890 +9891 +9892 +9893 +9894 +9895 +9896 +9897 +9898 +9899 +9900 +9901 +9902 +9903 +9904 +9905 +9906 +9907 +9908 +9909 +9910 +9911 +9912 +9913 +9914 +9915 +9916 +9917 +9918 +9919 +9920 +9921 +9922 +9923 +9924 +9925 +9926 +9927 +9928 +9929 +9930 +9931 +9932 +9933 +9934 +9935 +9936 +9937 +9938 +9939 +9940 +9941 +9942 +9943 +9944 +9945 +9946 +9947 +9948 +9949 +9950 +9951 +9952 +9953 +9954 +9955 +9956 +9957 +9958 +9959 +9960 +9961 +9962 +9963 +9964 +9965 +9966 +9967 +9968 +9969 +9970 +9971 +9972 +9973 +9974 +9975 +9976 +9977 +9978 +9979 +9980 +9981 +9982 +9983 +9984 +9985 +9986 +9987 +9988 +9989 +9990 +9991 +9992 +9993 +9994 +9995 +9996 +9997 +9998 +9999 diff --git a/core-java-io/pom.xml b/core-java-modules/core-java-io/pom.xml similarity index 99% rename from core-java-io/pom.xml rename to core-java-modules/core-java-io/pom.xml index b6f8a317f6..44c703ee68 100644 --- a/core-java-io/pom.xml +++ b/core-java-modules/core-java-io/pom.xml @@ -10,7 +10,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-io/src/main/java/com/baeldung/bufferedreader/BufferedReaderExample.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/bufferedreader/BufferedReaderExample.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/bufferedreader/BufferedReaderExample.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/bufferedreader/BufferedReaderExample.java diff --git a/core-java-io/src/main/java/com/baeldung/csv/WriteCsvFileExample.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/csv/WriteCsvFileExample.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/csv/WriteCsvFileExample.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/csv/WriteCsvFileExample.java diff --git a/core-java-io/src/main/java/com/baeldung/dirmonitoring/DirectoryMonitoringExample.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/dirmonitoring/DirectoryMonitoringExample.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/dirmonitoring/DirectoryMonitoringExample.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/dirmonitoring/DirectoryMonitoringExample.java diff --git a/core-java-io/src/main/java/com/baeldung/download/FileDownload.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/download/FileDownload.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/download/FileDownload.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/download/FileDownload.java diff --git a/core-java-io/src/main/java/com/baeldung/download/ResumableDownload.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/download/ResumableDownload.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/download/ResumableDownload.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/download/ResumableDownload.java diff --git a/core-java-io/src/main/java/com/baeldung/extension/Extension.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/extension/Extension.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/extension/Extension.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/extension/Extension.java diff --git a/core-java-io/src/main/java/com/baeldung/fileparser/BufferedReaderExample.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/fileparser/BufferedReaderExample.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/fileparser/BufferedReaderExample.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/fileparser/BufferedReaderExample.java diff --git a/core-java-io/src/main/java/com/baeldung/fileparser/FileReaderExample.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/fileparser/FileReaderExample.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/fileparser/FileReaderExample.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/fileparser/FileReaderExample.java diff --git a/core-java-io/src/main/java/com/baeldung/fileparser/FilesReadLinesExample.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/fileparser/FilesReadLinesExample.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/fileparser/FilesReadLinesExample.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/fileparser/FilesReadLinesExample.java diff --git a/core-java-io/src/main/java/com/baeldung/fileparser/ScannerIntExample.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/fileparser/ScannerIntExample.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/fileparser/ScannerIntExample.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/fileparser/ScannerIntExample.java diff --git a/core-java-io/src/main/java/com/baeldung/fileparser/ScannerStringExample.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/fileparser/ScannerStringExample.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/fileparser/ScannerStringExample.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/fileparser/ScannerStringExample.java diff --git a/core-java-io/src/main/java/com/baeldung/files/ListFiles.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/files/ListFiles.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/files/ListFiles.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/files/ListFiles.java diff --git a/core-java-io/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java diff --git a/core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoClient.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoClient.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoClient.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoClient.java diff --git a/core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoServer.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoServer.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoServer.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoServer.java diff --git a/core-java-io/src/main/java/com/baeldung/java/nio/selector/README.md b/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/README.md similarity index 100% rename from core-java-io/src/main/java/com/baeldung/java/nio/selector/README.md rename to core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/README.md diff --git a/core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileSearchExample.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileSearchExample.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileSearchExample.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileSearchExample.java diff --git a/core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileVisitorImpl.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileVisitorImpl.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileVisitorImpl.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileVisitorImpl.java diff --git a/core-java-io/src/main/java/com/baeldung/java/nio2/watcher/DirectoryWatcherExample.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/watcher/DirectoryWatcherExample.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/java/nio2/watcher/DirectoryWatcherExample.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/watcher/DirectoryWatcherExample.java diff --git a/core-java-io/src/main/java/com/baeldung/stream/FileCopy.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/stream/FileCopy.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/stream/FileCopy.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/stream/FileCopy.java diff --git a/core-java-io/src/main/java/com/baeldung/stream/OutputStreamExamples.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/stream/OutputStreamExamples.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/stream/OutputStreamExamples.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/stream/OutputStreamExamples.java diff --git a/core-java-io/src/main/java/com/baeldung/symlink/SymLinkExample.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/symlink/SymLinkExample.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/symlink/SymLinkExample.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/symlink/SymLinkExample.java diff --git a/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java diff --git a/core-java-io/src/main/java/com/baeldung/util/StreamUtils.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/util/StreamUtils.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/util/StreamUtils.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/util/StreamUtils.java diff --git a/core-java-io/src/main/java/com/baeldung/zip/ZipDirectory.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/zip/ZipDirectory.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/zip/ZipDirectory.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/zip/ZipDirectory.java diff --git a/core-java-io/src/main/java/com/baeldung/zip/ZipFile.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/zip/ZipFile.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/zip/ZipFile.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/zip/ZipFile.java diff --git a/core-java-io/src/main/java/com/baeldung/zip/ZipMultipleFiles.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/zip/ZipMultipleFiles.java similarity index 100% rename from core-java-io/src/main/java/com/baeldung/zip/ZipMultipleFiles.java rename to core-java-modules/core-java-io/src/main/java/com/baeldung/zip/ZipMultipleFiles.java diff --git a/core-java-io/src/main/resources/ESAPI.properties b/core-java-modules/core-java-io/src/main/resources/ESAPI.properties similarity index 100% rename from core-java-io/src/main/resources/ESAPI.properties rename to core-java-modules/core-java-io/src/main/resources/ESAPI.properties diff --git a/core-java-io/src/main/resources/META-INF/BenchmarkList b/core-java-modules/core-java-io/src/main/resources/META-INF/BenchmarkList old mode 100755 new mode 100644 similarity index 100% rename from core-java-io/src/main/resources/META-INF/BenchmarkList rename to core-java-modules/core-java-io/src/main/resources/META-INF/BenchmarkList diff --git a/core-java-io/src/main/resources/META-INF/persistence.xml b/core-java-modules/core-java-io/src/main/resources/META-INF/persistence.xml similarity index 100% rename from core-java-io/src/main/resources/META-INF/persistence.xml rename to core-java-modules/core-java-io/src/main/resources/META-INF/persistence.xml diff --git a/core-java-io/src/main/resources/META-INF/services/com.sun.source.util.Plugin b/core-java-modules/core-java-io/src/main/resources/META-INF/services/com.sun.source.util.Plugin similarity index 100% rename from core-java-io/src/main/resources/META-INF/services/com.sun.source.util.Plugin rename to core-java-modules/core-java-io/src/main/resources/META-INF/services/com.sun.source.util.Plugin diff --git a/core-java-io/src/main/resources/countries.properties b/core-java-modules/core-java-io/src/main/resources/countries.properties similarity index 82% rename from core-java-io/src/main/resources/countries.properties rename to core-java-modules/core-java-io/src/main/resources/countries.properties index e743b5a40b..3c1f53aded 100644 --- a/core-java-io/src/main/resources/countries.properties +++ b/core-java-modules/core-java-io/src/main/resources/countries.properties @@ -1,3 +1,3 @@ -UK -US -Germany +UK +US +Germany diff --git a/core-java-io/src/main/resources/data.csv b/core-java-modules/core-java-io/src/main/resources/data.csv similarity index 100% rename from core-java-io/src/main/resources/data.csv rename to core-java-modules/core-java-io/src/main/resources/data.csv diff --git a/core-java-io/src/main/resources/datasource.properties b/core-java-modules/core-java-io/src/main/resources/datasource.properties similarity index 100% rename from core-java-io/src/main/resources/datasource.properties rename to core-java-modules/core-java-io/src/main/resources/datasource.properties diff --git a/core-java-io/src/main/resources/dirCompressed.zip b/core-java-modules/core-java-io/src/main/resources/dirCompressed.zip similarity index 100% rename from core-java-io/src/main/resources/dirCompressed.zip rename to core-java-modules/core-java-io/src/main/resources/dirCompressed.zip diff --git a/core-java-io/src/main/resources/input.txt b/core-java-modules/core-java-io/src/main/resources/input.txt similarity index 100% rename from core-java-io/src/main/resources/input.txt rename to core-java-modules/core-java-io/src/main/resources/input.txt diff --git a/core-java-io/src/main/resources/js/bind.js b/core-java-modules/core-java-io/src/main/resources/js/bind.js similarity index 100% rename from core-java-io/src/main/resources/js/bind.js rename to core-java-modules/core-java-io/src/main/resources/js/bind.js diff --git a/core-java-io/src/main/resources/js/locations.js b/core-java-modules/core-java-io/src/main/resources/js/locations.js similarity index 100% rename from core-java-io/src/main/resources/js/locations.js rename to core-java-modules/core-java-io/src/main/resources/js/locations.js diff --git a/core-java-io/src/main/resources/js/math_module.js b/core-java-modules/core-java-io/src/main/resources/js/math_module.js similarity index 100% rename from core-java-io/src/main/resources/js/math_module.js rename to core-java-modules/core-java-io/src/main/resources/js/math_module.js diff --git a/core-java-io/src/main/resources/js/no_such.js b/core-java-modules/core-java-io/src/main/resources/js/no_such.js similarity index 100% rename from core-java-io/src/main/resources/js/no_such.js rename to core-java-modules/core-java-io/src/main/resources/js/no_such.js diff --git a/core-java-io/src/main/resources/js/script.js b/core-java-modules/core-java-io/src/main/resources/js/script.js similarity index 100% rename from core-java-io/src/main/resources/js/script.js rename to core-java-modules/core-java-io/src/main/resources/js/script.js diff --git a/core-java-io/src/main/resources/js/trim.js b/core-java-modules/core-java-io/src/main/resources/js/trim.js similarity index 100% rename from core-java-io/src/main/resources/js/trim.js rename to core-java-modules/core-java-io/src/main/resources/js/trim.js diff --git a/core-java-io/src/main/resources/js/typed_arrays.js b/core-java-modules/core-java-io/src/main/resources/js/typed_arrays.js similarity index 100% rename from core-java-io/src/main/resources/js/typed_arrays.js rename to core-java-modules/core-java-io/src/main/resources/js/typed_arrays.js diff --git a/core-java-io/src/main/resources/log4j.properties b/core-java-modules/core-java-io/src/main/resources/log4j.properties similarity index 100% rename from core-java-io/src/main/resources/log4j.properties rename to core-java-modules/core-java-io/src/main/resources/log4j.properties diff --git a/core-java-io/src/main/resources/log4jstructuraldp.properties b/core-java-modules/core-java-io/src/main/resources/log4jstructuraldp.properties similarity index 100% rename from core-java-io/src/main/resources/log4jstructuraldp.properties rename to core-java-modules/core-java-io/src/main/resources/log4jstructuraldp.properties diff --git a/core-java-io/src/main/resources/logback.xml b/core-java-modules/core-java-io/src/main/resources/logback.xml similarity index 100% rename from core-java-io/src/main/resources/logback.xml rename to core-java-modules/core-java-io/src/main/resources/logback.xml diff --git a/core-java-io/src/main/resources/multiCompressed.zip b/core-java-modules/core-java-io/src/main/resources/multiCompressed.zip similarity index 100% rename from core-java-io/src/main/resources/multiCompressed.zip rename to core-java-modules/core-java-io/src/main/resources/multiCompressed.zip diff --git a/core-java-io/src/main/resources/unzipTest/compressed.zip b/core-java-modules/core-java-io/src/main/resources/unzipTest/compressed.zip similarity index 100% rename from core-java-io/src/main/resources/unzipTest/compressed.zip rename to core-java-modules/core-java-io/src/main/resources/unzipTest/compressed.zip diff --git a/core-java-io/src/main/resources/zipTest/test1.txt b/core-java-modules/core-java-io/src/main/resources/zipTest/test1.txt similarity index 100% rename from core-java-io/src/main/resources/zipTest/test1.txt rename to core-java-modules/core-java-io/src/main/resources/zipTest/test1.txt diff --git a/core-java-io/src/main/resources/zipTest/test2.txt b/core-java-modules/core-java-io/src/main/resources/zipTest/test2.txt similarity index 100% rename from core-java-io/src/main/resources/zipTest/test2.txt rename to core-java-modules/core-java-io/src/main/resources/zipTest/test2.txt diff --git a/core-java-io/src/test/java/com/baeldung/bufferedreader/BufferedReaderExampleUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/bufferedreader/BufferedReaderExampleUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/bufferedreader/BufferedReaderExampleUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/bufferedreader/BufferedReaderExampleUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/bufferedreader/BufferedReaderUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/bufferedreader/BufferedReaderUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/bufferedreader/BufferedReaderUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/bufferedreader/BufferedReaderUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/copyfiles/FileCopierIntegrationTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/copyfiles/FileCopierIntegrationTest.java similarity index 97% rename from core-java-io/src/test/java/com/baeldung/copyfiles/FileCopierIntegrationTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/copyfiles/FileCopierIntegrationTest.java index 4603644bf5..2b4a15ed59 100644 --- a/core-java-io/src/test/java/com/baeldung/copyfiles/FileCopierIntegrationTest.java +++ b/core-java-modules/core-java-io/src/test/java/com/baeldung/copyfiles/FileCopierIntegrationTest.java @@ -1,69 +1,69 @@ -package com.baeldung.copyfiles; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; - -import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Test; -import static org.assertj.core.api.Assertions.*; - -public class FileCopierIntegrationTest { - File original = new File("src/test/resources/original.txt"); - - @Before - public void init() throws IOException { - if (!original.exists()) - Files.createFile(original.toPath()); - } - - @Test - public void givenIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException { - File copied = new File("src/test/resources/copiedWithIo.txt"); - try (InputStream in = new BufferedInputStream(new FileInputStream(original)); OutputStream out = new BufferedOutputStream(new FileOutputStream(copied))) { - byte[] buffer = new byte[1024]; - int lengthRead; - while ((lengthRead = in.read(buffer)) > 0) { - out.write(buffer, 0, lengthRead); - out.flush(); - } - } - assertThat(copied).exists(); - assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); - } - - @Test - public void givenCommonsIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException { - File copied = new File("src/test/resources/copiedWithApacheCommons.txt"); - FileUtils.copyFile(original, copied); - assertThat(copied).exists(); - assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); - } - - @Test - public void givenNIO2_whenCopied_thenCopyExistsWithSameContents() throws IOException { - Path copied = Paths.get("src/test/resources/copiedWithNio.txt"); - Path originalPath = original.toPath(); - Files.copy(originalPath, copied, StandardCopyOption.REPLACE_EXISTING); - assertThat(copied).exists(); - assertThat(Files.readAllLines(originalPath).equals(Files.readAllLines(copied))); - } - - @Test - public void givenGuava_whenCopied_thenCopyExistsWithSameContents() throws IOException { - File copied = new File("src/test/resources/copiedWithApacheCommons.txt"); - com.google.common.io.Files.copy(original, copied); - assertThat(copied).exists(); - assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); - } -} +package com.baeldung.copyfiles; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + +import org.apache.commons.io.FileUtils; +import org.junit.Before; +import org.junit.Test; +import static org.assertj.core.api.Assertions.*; + +public class FileCopierIntegrationTest { + File original = new File("src/test/resources/original.txt"); + + @Before + public void init() throws IOException { + if (!original.exists()) + Files.createFile(original.toPath()); + } + + @Test + public void givenIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException { + File copied = new File("src/test/resources/copiedWithIo.txt"); + try (InputStream in = new BufferedInputStream(new FileInputStream(original)); OutputStream out = new BufferedOutputStream(new FileOutputStream(copied))) { + byte[] buffer = new byte[1024]; + int lengthRead; + while ((lengthRead = in.read(buffer)) > 0) { + out.write(buffer, 0, lengthRead); + out.flush(); + } + } + assertThat(copied).exists(); + assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); + } + + @Test + public void givenCommonsIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException { + File copied = new File("src/test/resources/copiedWithApacheCommons.txt"); + FileUtils.copyFile(original, copied); + assertThat(copied).exists(); + assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); + } + + @Test + public void givenNIO2_whenCopied_thenCopyExistsWithSameContents() throws IOException { + Path copied = Paths.get("src/test/resources/copiedWithNio.txt"); + Path originalPath = original.toPath(); + Files.copy(originalPath, copied, StandardCopyOption.REPLACE_EXISTING); + assertThat(copied).exists(); + assertThat(Files.readAllLines(originalPath).equals(Files.readAllLines(copied))); + } + + @Test + public void givenGuava_whenCopied_thenCopyExistsWithSameContents() throws IOException { + File copied = new File("src/test/resources/copiedWithApacheCommons.txt"); + com.google.common.io.Files.copy(original, copied); + assertThat(copied).exists(); + assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); + } +} diff --git a/core-java-io/src/test/java/com/baeldung/csv/ReadCSVInArrayUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/csv/ReadCSVInArrayUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/csv/ReadCSVInArrayUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/csv/ReadCSVInArrayUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/csv/WriteCsvFileExampleUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/csv/WriteCsvFileExampleUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/csv/WriteCsvFileExampleUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/csv/WriteCsvFileExampleUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/directories/NewDirectoryUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/directories/NewDirectoryUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/directories/NewDirectoryUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/directories/NewDirectoryUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java diff --git a/core-java-io/src/test/java/com/baeldung/extension/ExtensionUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/extension/ExtensionUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/file/FileOperationsManualTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/file/FileOperationsManualTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/file/FileOperationsManualTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/file/FileOperationsManualTest.java diff --git a/core-java-io/src/test/java/com/baeldung/file/FilenameFilterManualTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/file/FilenameFilterManualTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/file/FilenameFilterManualTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/file/FilenameFilterManualTest.java diff --git a/core-java-io/src/test/java/com/baeldung/file/FilesClearDataUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/file/FilesClearDataUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/file/FilesClearDataUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/file/FilesClearDataUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/file/FilesManualTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/file/FilesManualTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/file/FilesManualTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/file/FilesManualTest.java diff --git a/core-java-io/src/test/java/com/baeldung/file/ListFilesUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/file/ListFilesUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/file/ListFilesUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/file/ListFilesUnitTest.java diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/filechannel/FileChannelUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/filechannel/FileChannelUnitTest.java new file mode 100644 index 0000000000..6964ba80e3 --- /dev/null +++ b/core-java-modules/core-java-io/src/test/java/com/baeldung/filechannel/FileChannelUnitTest.java @@ -0,0 +1,165 @@ +package com.baeldung.filechannel; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.nio.charset.StandardCharsets; + +import org.junit.Test; + +public class FileChannelUnitTest { + + @Test + public void givenFile_whenReadWithFileChannelUsingRandomAccessFile_thenCorrect() throws IOException { + + try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r"); + FileChannel channel = reader.getChannel(); + ByteArrayOutputStream out = new ByteArrayOutputStream();) { + + int bufferSize = 1024; + if (bufferSize > channel.size()) { + bufferSize = (int) channel.size(); + } + ByteBuffer buff = ByteBuffer.allocate(bufferSize); + + while (channel.read(buff) > 0) { + out.write(buff.array(), 0, buff.position()); + buff.clear(); + } + + String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8); + + assertEquals("Hello world", fileContent); + } + } + + @Test + public void givenFile_whenReadWithFileChannelUsingFileInputStream_thenCorrect() throws IOException { + + try (ByteArrayOutputStream out = new ByteArrayOutputStream(); + FileInputStream fin = new FileInputStream("src/test/resources/test_read.in"); + FileChannel channel = fin.getChannel();) { + + int bufferSize = 1024; + if (bufferSize > channel.size()) { + bufferSize = (int) channel.size(); + } + ByteBuffer buff = ByteBuffer.allocate(bufferSize); + + while (channel.read(buff) > 0) { + out.write(buff.array(), 0, buff.position()); + buff.clear(); + } + String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8); + + assertEquals("Hello world", fileContent); + } + } + + @Test + public void givenFile_whenReadAFileSectionIntoMemoryWithFileChannel_thenCorrect() throws IOException { + + try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r"); + FileChannel channel = reader.getChannel(); + ByteArrayOutputStream out = new ByteArrayOutputStream();) { + + MappedByteBuffer buff = channel.map(FileChannel.MapMode.READ_ONLY, 6, 5); + + if (buff.hasRemaining()) { + byte[] data = new byte[buff.remaining()]; + buff.get(data); + assertEquals("world", new String(data, StandardCharsets.UTF_8)); + } + } + } + + @Test + public void whenWriteWithFileChannelUsingRandomAccessFile_thenCorrect() throws IOException { + String file = "src/test/resources/test_write_using_filechannel.txt"; + try (RandomAccessFile writer = new RandomAccessFile(file, "rw"); + FileChannel channel = writer.getChannel();) { + ByteBuffer buff = ByteBuffer.wrap("Hello world".getBytes(StandardCharsets.UTF_8)); + + channel.write(buff); + + // now we verify whether the file was written correctly + RandomAccessFile reader = new RandomAccessFile(file, "r"); + assertEquals("Hello world", reader.readLine()); + reader.close(); + } + } + + @Test + public void givenFile_whenWriteAFileUsingLockAFileSectionWithFileChannel_thenCorrect() throws IOException { + try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "rw"); + FileChannel channel = reader.getChannel(); + FileLock fileLock = channel.tryLock(6, 5, Boolean.FALSE);) { + + assertNotNull(fileLock); + } + } + + @Test + public void givenFile_whenReadWithFileChannelGetPosition_thenCorrect() throws IOException { + + try (ByteArrayOutputStream out = new ByteArrayOutputStream(); + RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r"); + FileChannel channel = reader.getChannel();) { + + int bufferSize = 1024; + if (bufferSize > channel.size()) { + bufferSize = (int) channel.size(); + } + ByteBuffer buff = ByteBuffer.allocate(bufferSize); + + while (channel.read(buff) > 0) { + out.write(buff.array(), 0, buff.position()); + buff.clear(); + } + + // the original file is 11 bytes long, so that's where the position pointer should be + assertEquals(11, channel.position()); + + channel.position(4); + assertEquals(4, channel.position()); + } + } + + @Test + public void whenGetFileSize_thenCorrect() throws IOException { + + try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r"); + FileChannel channel = reader.getChannel();) { + + // the original file is 11 bytes long, so that's where the position pointer should be + assertEquals(11, channel.size()); + } + } + + @Test + public void whenTruncateFile_thenCorrect() throws IOException { + String input = "this is a test input"; + + FileOutputStream fout = new FileOutputStream("src/test/resources/test_truncate.txt"); + FileChannel channel = fout.getChannel(); + + ByteBuffer buff = ByteBuffer.wrap(input.getBytes()); + channel.write(buff); + buff.flip(); + + channel = channel.truncate(5); + assertEquals(5, channel.size()); + + fout.close(); + channel.close(); + } +} diff --git a/core-java-io/src/test/java/com/baeldung/fileparser/BufferedReaderUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/fileparser/BufferedReaderUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/fileparser/BufferedReaderUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/fileparser/BufferedReaderUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/fileparser/FileReaderUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/fileparser/FileReaderUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/fileparser/FileReaderUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/fileparser/FileReaderUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/fileparser/FilesReadAllLinesUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/fileparser/FilesReadAllLinesUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/fileparser/FilesReadAllLinesUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/fileparser/FilesReadAllLinesUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/fileparser/ScannerIntUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/fileparser/ScannerIntUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/fileparser/ScannerIntUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/fileparser/ScannerIntUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/fileparser/ScannerStringUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/fileparser/ScannerStringUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/fileparser/ScannerStringUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/fileparser/ScannerStringUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/filesystem/jndi/test/LookupFSJNDIIntegrationTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/filesystem/jndi/test/LookupFSJNDIIntegrationTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/filesystem/jndi/test/LookupFSJNDIIntegrationTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/filesystem/jndi/test/LookupFSJNDIIntegrationTest.java diff --git a/core-java-io/src/test/java/com/baeldung/java/mimetype/MimeTypeUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/java/mimetype/MimeTypeUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/java/mimetype/MimeTypeUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/java/mimetype/MimeTypeUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/java/nio/selector/NioEchoLiveTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio/selector/NioEchoLiveTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/java/nio/selector/NioEchoLiveTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio/selector/NioEchoLiveTest.java diff --git a/core-java-io/src/test/java/com/baeldung/java/nio2/FileIntegrationTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/FileIntegrationTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/java/nio2/FileIntegrationTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/FileIntegrationTest.java diff --git a/core-java-io/src/test/java/com/baeldung/java/nio2/PathManualTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/PathManualTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/java/nio2/PathManualTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/PathManualTest.java diff --git a/core-java-io/src/test/java/com/baeldung/java/nio2/README.md b/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/README.md similarity index 100% rename from core-java-io/src/test/java/com/baeldung/java/nio2/README.md rename to core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/README.md diff --git a/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoClient.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoClient.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoClient.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoClient.java diff --git a/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoIntegrationTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoIntegrationTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoIntegrationTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoIntegrationTest.java diff --git a/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer.java diff --git a/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer2.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer2.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer2.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer2.java diff --git a/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncFileIntegrationTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncFileIntegrationTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncFileIntegrationTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncFileIntegrationTest.java diff --git a/core-java-io/src/test/java/com/baeldung/java/nio2/attributes/BasicAttribsIntegrationTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/attributes/BasicAttribsIntegrationTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/java/nio2/attributes/BasicAttribsIntegrationTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/attributes/BasicAttribsIntegrationTest.java diff --git a/core-java-io/src/test/java/com/baeldung/java8/JavaFileSizeUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/java8/JavaFileSizeUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/java8/JavaFileSizeUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/java8/JavaFileSizeUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/java8/JavaFolderSizeUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/java8/JavaFolderSizeUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/java8/JavaFolderSizeUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/java8/JavaFolderSizeUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/mappedbytebuffer/MappedByteBufferUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/mappedbytebuffer/MappedByteBufferUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/mappedbytebuffer/MappedByteBufferUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/mappedbytebuffer/MappedByteBufferUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/stream/FileCopyUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/stream/FileCopyUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/stream/FileCopyUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/stream/FileCopyUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/stream/OutputStreamExamplesUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/stream/OutputStreamExamplesUnitTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/stream/OutputStreamExamplesUnitTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/stream/OutputStreamExamplesUnitTest.java diff --git a/core-java-io/src/test/java/com/baeldung/symlink/SymLinkExampleManualTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/symlink/SymLinkExampleManualTest.java similarity index 100% rename from core-java-io/src/test/java/com/baeldung/symlink/SymLinkExampleManualTest.java rename to core-java-modules/core-java-io/src/test/java/com/baeldung/symlink/SymLinkExampleManualTest.java diff --git a/core-java-io/src/test/java/org/baeldung/core/exceptions/FileNotFoundExceptionUnitTest.java b/core-java-modules/core-java-io/src/test/java/org/baeldung/core/exceptions/FileNotFoundExceptionUnitTest.java similarity index 100% rename from core-java-io/src/test/java/org/baeldung/core/exceptions/FileNotFoundExceptionUnitTest.java rename to core-java-modules/core-java-io/src/test/java/org/baeldung/core/exceptions/FileNotFoundExceptionUnitTest.java diff --git a/core-java-io/src/test/java/org/baeldung/java/io/InputStreamToByteBufferUnitTest.java b/core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/InputStreamToByteBufferUnitTest.java similarity index 100% rename from core-java-io/src/test/java/org/baeldung/java/io/InputStreamToByteBufferUnitTest.java rename to core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/InputStreamToByteBufferUnitTest.java diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaFilePathUnitTest.java b/core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaFilePathUnitTest.java similarity index 100% rename from core-java-io/src/test/java/org/baeldung/java/io/JavaFilePathUnitTest.java rename to core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaFilePathUnitTest.java diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaFileUnitTest.java b/core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaFileUnitTest.java similarity index 100% rename from core-java-io/src/test/java/org/baeldung/java/io/JavaFileUnitTest.java rename to core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaFileUnitTest.java diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaInputStreamToXUnitTest.java b/core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaInputStreamToXUnitTest.java similarity index 100% rename from core-java-io/src/test/java/org/baeldung/java/io/JavaInputStreamToXUnitTest.java rename to core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaInputStreamToXUnitTest.java diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java b/core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java similarity index 100% rename from core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java rename to core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaReaderToXUnitTest.java b/core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaReaderToXUnitTest.java similarity index 100% rename from core-java-io/src/test/java/org/baeldung/java/io/JavaReaderToXUnitTest.java rename to core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaReaderToXUnitTest.java diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaScannerUnitTest.java b/core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaScannerUnitTest.java similarity index 100% rename from core-java-io/src/test/java/org/baeldung/java/io/JavaScannerUnitTest.java rename to core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaScannerUnitTest.java diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaWriteToFileUnitTest.java b/core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaWriteToFileUnitTest.java similarity index 100% rename from core-java-io/src/test/java/org/baeldung/java/io/JavaWriteToFileUnitTest.java rename to core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaWriteToFileUnitTest.java diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaXToByteArrayUnitTest.java b/core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaXToByteArrayUnitTest.java similarity index 100% rename from core-java-io/src/test/java/org/baeldung/java/io/JavaXToByteArrayUnitTest.java rename to core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaXToByteArrayUnitTest.java diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaXToInputStreamUnitTest.java b/core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaXToInputStreamUnitTest.java similarity index 100% rename from core-java-io/src/test/java/org/baeldung/java/io/JavaXToInputStreamUnitTest.java rename to core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaXToInputStreamUnitTest.java diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaXToReaderUnitTest.java b/core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaXToReaderUnitTest.java similarity index 100% rename from core-java-io/src/test/java/org/baeldung/java/io/JavaXToReaderUnitTest.java rename to core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaXToReaderUnitTest.java diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaXToWriterUnitTest.java b/core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaXToWriterUnitTest.java similarity index 100% rename from core-java-io/src/test/java/org/baeldung/java/io/JavaXToWriterUnitTest.java rename to core-java-modules/core-java-io/src/test/java/org/baeldung/java/io/JavaXToWriterUnitTest.java diff --git a/core-java-io/src/test/resources/.gitignore b/core-java-modules/core-java-io/src/test/resources/.gitignore similarity index 100% rename from core-java-io/src/test/resources/.gitignore rename to core-java-modules/core-java-io/src/test/resources/.gitignore diff --git a/core-java-io/src/test/resources/META-INF/mime.types b/core-java-modules/core-java-io/src/test/resources/META-INF/mime.types similarity index 100% rename from core-java-io/src/test/resources/META-INF/mime.types rename to core-java-modules/core-java-io/src/test/resources/META-INF/mime.types diff --git a/core-java-io/src/test/resources/anothersample.txt b/core-java-modules/core-java-io/src/test/resources/anothersample.txt similarity index 100% rename from core-java-io/src/test/resources/anothersample.txt rename to core-java-modules/core-java-io/src/test/resources/anothersample.txt diff --git a/core-java-io/src/test/resources/book.csv b/core-java-modules/core-java-io/src/test/resources/book.csv similarity index 100% rename from core-java-io/src/test/resources/book.csv rename to core-java-modules/core-java-io/src/test/resources/book.csv diff --git a/core-java-io/src/test/resources/configuration.properties b/core-java-modules/core-java-io/src/test/resources/configuration.properties similarity index 100% rename from core-java-io/src/test/resources/configuration.properties rename to core-java-modules/core-java-io/src/test/resources/configuration.properties diff --git a/core-java-io/src/test/resources/copiedWithApacheCommons.txt b/core-java-modules/core-java-io/src/test/resources/copiedWithApacheCommons.txt similarity index 100% rename from core-java-io/src/test/resources/copiedWithApacheCommons.txt rename to core-java-modules/core-java-io/src/test/resources/copiedWithApacheCommons.txt diff --git a/core-java-io/src/test/resources/copiedWithIo.txt b/core-java-modules/core-java-io/src/test/resources/copiedWithIo.txt similarity index 100% rename from core-java-io/src/test/resources/copiedWithIo.txt rename to core-java-modules/core-java-io/src/test/resources/copiedWithIo.txt diff --git a/core-java-io/src/test/resources/copiedWithNio.txt b/core-java-modules/core-java-io/src/test/resources/copiedWithNio.txt similarity index 100% rename from core-java-io/src/test/resources/copiedWithNio.txt rename to core-java-modules/core-java-io/src/test/resources/copiedWithNio.txt diff --git a/core-java-io/src/test/resources/copyTest/dest/readme.txt b/core-java-modules/core-java-io/src/test/resources/copyTest/dest/readme.txt similarity index 100% rename from core-java-io/src/test/resources/copyTest/dest/readme.txt rename to core-java-modules/core-java-io/src/test/resources/copyTest/dest/readme.txt diff --git a/core-java-io/src/test/resources/copyTest/src/test_apache.txt b/core-java-modules/core-java-io/src/test/resources/copyTest/src/test_apache.txt similarity index 100% rename from core-java-io/src/test/resources/copyTest/src/test_apache.txt rename to core-java-modules/core-java-io/src/test/resources/copyTest/src/test_apache.txt diff --git a/core-java-io/src/test/resources/copyTest/src/test_channel.txt b/core-java-modules/core-java-io/src/test/resources/copyTest/src/test_channel.txt similarity index 100% rename from core-java-io/src/test/resources/copyTest/src/test_channel.txt rename to core-java-modules/core-java-io/src/test/resources/copyTest/src/test_channel.txt diff --git a/core-java-io/src/test/resources/copyTest/src/test_files.txt b/core-java-modules/core-java-io/src/test/resources/copyTest/src/test_files.txt similarity index 100% rename from core-java-io/src/test/resources/copyTest/src/test_files.txt rename to core-java-modules/core-java-io/src/test/resources/copyTest/src/test_files.txt diff --git a/core-java-io/src/test/resources/copyTest/src/test_stream.txt b/core-java-modules/core-java-io/src/test/resources/copyTest/src/test_stream.txt similarity index 100% rename from core-java-io/src/test/resources/copyTest/src/test_stream.txt rename to core-java-modules/core-java-io/src/test/resources/copyTest/src/test_stream.txt diff --git a/core-java-io/src/test/resources/dictionary.in b/core-java-modules/core-java-io/src/test/resources/dictionary.in similarity index 100% rename from core-java-io/src/test/resources/dictionary.in rename to core-java-modules/core-java-io/src/test/resources/dictionary.in diff --git a/core-java-io/src/test/resources/file.txt b/core-java-modules/core-java-io/src/test/resources/file.txt similarity index 100% rename from core-java-io/src/test/resources/file.txt rename to core-java-modules/core-java-io/src/test/resources/file.txt diff --git a/core-java-io/src/test/resources/fileNameFilterManualTestFolder/people.json b/core-java-modules/core-java-io/src/test/resources/fileNameFilterManualTestFolder/people.json similarity index 100% rename from core-java-io/src/test/resources/fileNameFilterManualTestFolder/people.json rename to core-java-modules/core-java-io/src/test/resources/fileNameFilterManualTestFolder/people.json diff --git a/core-java-io/src/test/resources/fileNameFilterManualTestFolder/students.json b/core-java-modules/core-java-io/src/test/resources/fileNameFilterManualTestFolder/students.json similarity index 100% rename from core-java-io/src/test/resources/fileNameFilterManualTestFolder/students.json rename to core-java-modules/core-java-io/src/test/resources/fileNameFilterManualTestFolder/students.json diff --git a/core-java-io/src/test/resources/fileNameFilterManualTestFolder/teachers.xml b/core-java-modules/core-java-io/src/test/resources/fileNameFilterManualTestFolder/teachers.xml similarity index 100% rename from core-java-io/src/test/resources/fileNameFilterManualTestFolder/teachers.xml rename to core-java-modules/core-java-io/src/test/resources/fileNameFilterManualTestFolder/teachers.xml diff --git a/core-java-io/src/test/resources/fileNameFilterManualTestFolder/workers.xml b/core-java-modules/core-java-io/src/test/resources/fileNameFilterManualTestFolder/workers.xml similarity index 100% rename from core-java-io/src/test/resources/fileNameFilterManualTestFolder/workers.xml rename to core-java-modules/core-java-io/src/test/resources/fileNameFilterManualTestFolder/workers.xml diff --git a/core-java-io/src/test/resources/fileTest.txt b/core-java-modules/core-java-io/src/test/resources/fileTest.txt similarity index 100% rename from core-java-io/src/test/resources/fileTest.txt rename to core-java-modules/core-java-io/src/test/resources/fileTest.txt diff --git a/core-java-io/src/test/resources/fileToRead.txt b/core-java-modules/core-java-io/src/test/resources/fileToRead.txt similarity index 100% rename from core-java-io/src/test/resources/fileToRead.txt rename to core-java-modules/core-java-io/src/test/resources/fileToRead.txt diff --git a/core-java-io/src/test/resources/fileToWriteTo.txt b/core-java-modules/core-java-io/src/test/resources/fileToWriteTo.txt similarity index 100% rename from core-java-io/src/test/resources/fileToWriteTo.txt rename to core-java-modules/core-java-io/src/test/resources/fileToWriteTo.txt diff --git a/core-java-io/src/test/resources/fileexample.txt b/core-java-modules/core-java-io/src/test/resources/fileexample.txt similarity index 100% rename from core-java-io/src/test/resources/fileexample.txt rename to core-java-modules/core-java-io/src/test/resources/fileexample.txt diff --git a/core-java-io/src/test/resources/frontenac-2257154_960_720.jpg b/core-java-modules/core-java-io/src/test/resources/frontenac-2257154_960_720.jpg similarity index 100% rename from core-java-io/src/test/resources/frontenac-2257154_960_720.jpg rename to core-java-modules/core-java-io/src/test/resources/frontenac-2257154_960_720.jpg diff --git a/core-java-io/src/test/resources/initialFile.txt b/core-java-modules/core-java-io/src/test/resources/initialFile.txt similarity index 100% rename from core-java-io/src/test/resources/initialFile.txt rename to core-java-modules/core-java-io/src/test/resources/initialFile.txt diff --git a/core-java-io/src/test/resources/listFilesUnitTestFolder/country.txt b/core-java-modules/core-java-io/src/test/resources/listFilesUnitTestFolder/country.txt similarity index 100% rename from core-java-io/src/test/resources/listFilesUnitTestFolder/country.txt rename to core-java-modules/core-java-io/src/test/resources/listFilesUnitTestFolder/country.txt diff --git a/core-java-io/src/test/resources/listFilesUnitTestFolder/employee.json b/core-java-modules/core-java-io/src/test/resources/listFilesUnitTestFolder/employee.json similarity index 100% rename from core-java-io/src/test/resources/listFilesUnitTestFolder/employee.json rename to core-java-modules/core-java-io/src/test/resources/listFilesUnitTestFolder/employee.json diff --git a/core-java-io/src/test/resources/listFilesUnitTestFolder/students.json b/core-java-modules/core-java-io/src/test/resources/listFilesUnitTestFolder/students.json similarity index 100% rename from core-java-io/src/test/resources/listFilesUnitTestFolder/students.json rename to core-java-modules/core-java-io/src/test/resources/listFilesUnitTestFolder/students.json diff --git a/core-java-io/src/test/resources/listFilesUnitTestFolder/test.xml b/core-java-modules/core-java-io/src/test/resources/listFilesUnitTestFolder/test.xml similarity index 100% rename from core-java-io/src/test/resources/listFilesUnitTestFolder/test.xml rename to core-java-modules/core-java-io/src/test/resources/listFilesUnitTestFolder/test.xml diff --git a/core-java-io/src/test/resources/original.txt b/core-java-modules/core-java-io/src/test/resources/original.txt similarity index 100% rename from core-java-io/src/test/resources/original.txt rename to core-java-modules/core-java-io/src/test/resources/original.txt diff --git a/core-java-io/src/test/resources/product.png b/core-java-modules/core-java-io/src/test/resources/product.png similarity index 100% rename from core-java-io/src/test/resources/product.png rename to core-java-modules/core-java-io/src/test/resources/product.png diff --git a/core-java-io/src/test/resources/sample.txt b/core-java-modules/core-java-io/src/test/resources/sample.txt similarity index 100% rename from core-java-io/src/test/resources/sample.txt rename to core-java-modules/core-java-io/src/test/resources/sample.txt diff --git a/core-java-io/src/test/resources/sampleNumberFile.txt b/core-java-modules/core-java-io/src/test/resources/sampleNumberFile.txt similarity index 100% rename from core-java-io/src/test/resources/sampleNumberFile.txt rename to core-java-modules/core-java-io/src/test/resources/sampleNumberFile.txt diff --git a/core-java-io/src/test/resources/sampleTextFile.txt b/core-java-modules/core-java-io/src/test/resources/sampleTextFile.txt similarity index 100% rename from core-java-io/src/test/resources/sampleTextFile.txt rename to core-java-modules/core-java-io/src/test/resources/sampleTextFile.txt diff --git a/core-java-io/src/test/resources/targetFile.tmp b/core-java-modules/core-java-io/src/test/resources/targetFile.tmp similarity index 100% rename from core-java-io/src/test/resources/targetFile.tmp rename to core-java-modules/core-java-io/src/test/resources/targetFile.tmp diff --git a/core-java-io/src/test/resources/targetFile.txt b/core-java-modules/core-java-io/src/test/resources/targetFile.txt similarity index 100% rename from core-java-io/src/test/resources/targetFile.txt rename to core-java-modules/core-java-io/src/test/resources/targetFile.txt diff --git a/core-java-io/src/test/resources/test.find b/core-java-modules/core-java-io/src/test/resources/test.find similarity index 100% rename from core-java-io/src/test/resources/test.find rename to core-java-modules/core-java-io/src/test/resources/test.find diff --git a/core-java-io/src/test/resources/testFolder/sample_file_1.in b/core-java-modules/core-java-io/src/test/resources/testFolder/sample_file_1.in similarity index 100% rename from core-java-io/src/test/resources/testFolder/sample_file_1.in rename to core-java-modules/core-java-io/src/test/resources/testFolder/sample_file_1.in diff --git a/core-java-io/src/test/resources/testFolder/sample_file_2.in b/core-java-modules/core-java-io/src/test/resources/testFolder/sample_file_2.in similarity index 100% rename from core-java-io/src/test/resources/testFolder/sample_file_2.in rename to core-java-modules/core-java-io/src/test/resources/testFolder/sample_file_2.in diff --git a/core-java-io/src/test/resources/test_read.in b/core-java-modules/core-java-io/src/test/resources/test_read.in similarity index 100% rename from core-java-io/src/test/resources/test_read.in rename to core-java-modules/core-java-io/src/test/resources/test_read.in diff --git a/core-java-io/src/test/resources/test_read1.in b/core-java-modules/core-java-io/src/test/resources/test_read1.in similarity index 100% rename from core-java-io/src/test/resources/test_read1.in rename to core-java-modules/core-java-io/src/test/resources/test_read1.in diff --git a/core-java-io/src/test/resources/test_read2.in b/core-java-modules/core-java-io/src/test/resources/test_read2.in similarity index 100% rename from core-java-io/src/test/resources/test_read2.in rename to core-java-modules/core-java-io/src/test/resources/test_read2.in diff --git a/core-java-io/src/test/resources/test_read3.in b/core-java-modules/core-java-io/src/test/resources/test_read3.in similarity index 100% rename from core-java-io/src/test/resources/test_read3.in rename to core-java-modules/core-java-io/src/test/resources/test_read3.in diff --git a/core-java-io/src/test/resources/test_read4.in b/core-java-modules/core-java-io/src/test/resources/test_read4.in similarity index 100% rename from core-java-io/src/test/resources/test_read4.in rename to core-java-modules/core-java-io/src/test/resources/test_read4.in diff --git a/core-java-io/src/test/resources/test_read7.in b/core-java-modules/core-java-io/src/test/resources/test_read7.in similarity index 100% rename from core-java-io/src/test/resources/test_read7.in rename to core-java-modules/core-java-io/src/test/resources/test_read7.in diff --git a/core-java-io/src/test/resources/test_read8.in b/core-java-modules/core-java-io/src/test/resources/test_read8.in similarity index 100% rename from core-java-io/src/test/resources/test_read8.in rename to core-java-modules/core-java-io/src/test/resources/test_read8.in diff --git a/core-java-io/src/test/resources/test_read_d.in b/core-java-modules/core-java-io/src/test/resources/test_read_d.in similarity index 100% rename from core-java-io/src/test/resources/test_read_d.in rename to core-java-modules/core-java-io/src/test/resources/test_read_d.in diff --git a/core-java-io/src/test/resources/test_read_multiple.in b/core-java-modules/core-java-io/src/test/resources/test_read_multiple.in similarity index 100% rename from core-java-io/src/test/resources/test_read_multiple.in rename to core-java-modules/core-java-io/src/test/resources/test_read_multiple.in diff --git a/core-java-modules/core-java-io/src/test/resources/test_truncate.txt b/core-java-modules/core-java-io/src/test/resources/test_truncate.txt new file mode 100644 index 0000000000..26d3b38cdd --- /dev/null +++ b/core-java-modules/core-java-io/src/test/resources/test_truncate.txt @@ -0,0 +1 @@ +this \ No newline at end of file diff --git a/core-java-io/src/test/resources/test_write.txt b/core-java-modules/core-java-io/src/test/resources/test_write.txt similarity index 100% rename from core-java-io/src/test/resources/test_write.txt rename to core-java-modules/core-java-io/src/test/resources/test_write.txt diff --git a/core-java-io/src/test/resources/test_write_1.txt b/core-java-modules/core-java-io/src/test/resources/test_write_1.txt similarity index 100% rename from core-java-io/src/test/resources/test_write_1.txt rename to core-java-modules/core-java-io/src/test/resources/test_write_1.txt diff --git a/core-java-io/src/test/resources/test_write_2.txt b/core-java-modules/core-java-io/src/test/resources/test_write_2.txt similarity index 100% rename from core-java-io/src/test/resources/test_write_2.txt rename to core-java-modules/core-java-io/src/test/resources/test_write_2.txt diff --git a/core-java-io/src/test/resources/test_write_3.txt b/core-java-modules/core-java-io/src/test/resources/test_write_3.txt similarity index 100% rename from core-java-io/src/test/resources/test_write_3.txt rename to core-java-modules/core-java-io/src/test/resources/test_write_3.txt diff --git a/core-java-io/src/test/resources/test_write_4.txt b/core-java-modules/core-java-io/src/test/resources/test_write_4.txt similarity index 100% rename from core-java-io/src/test/resources/test_write_4.txt rename to core-java-modules/core-java-io/src/test/resources/test_write_4.txt diff --git a/core-java-io/src/test/resources/test_write_5.txt b/core-java-modules/core-java-io/src/test/resources/test_write_5.txt similarity index 100% rename from core-java-io/src/test/resources/test_write_5.txt rename to core-java-modules/core-java-io/src/test/resources/test_write_5.txt diff --git a/core-java/src/test/resources/test_read.in b/core-java-modules/core-java-io/src/test/resources/test_write_using_filechannel.txt similarity index 100% rename from core-java/src/test/resources/test_read.in rename to core-java-modules/core-java-io/src/test/resources/test_write_using_filechannel.txt diff --git a/core-java-modules/core-java-io/target_link.txt b/core-java-modules/core-java-io/target_link.txt new file mode 100644 index 0000000000..931a810b8d --- /dev/null +++ b/core-java-modules/core-java-io/target_link.txt @@ -0,0 +1,10000 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 +282 +283 +284 +285 +286 +287 +288 +289 +290 +291 +292 +293 +294 +295 +296 +297 +298 +299 +300 +301 +302 +303 +304 +305 +306 +307 +308 +309 +310 +311 +312 +313 +314 +315 +316 +317 +318 +319 +320 +321 +322 +323 +324 +325 +326 +327 +328 +329 +330 +331 +332 +333 +334 +335 +336 +337 +338 +339 +340 +341 +342 +343 +344 +345 +346 +347 +348 +349 +350 +351 +352 +353 +354 +355 +356 +357 +358 +359 +360 +361 +362 +363 +364 +365 +366 +367 +368 +369 +370 +371 +372 +373 +374 +375 +376 +377 +378 +379 +380 +381 +382 +383 +384 +385 +386 +387 +388 +389 +390 +391 +392 +393 +394 +395 +396 +397 +398 +399 +400 +401 +402 +403 +404 +405 +406 +407 +408 +409 +410 +411 +412 +413 +414 +415 +416 +417 +418 +419 +420 +421 +422 +423 +424 +425 +426 +427 +428 +429 +430 +431 +432 +433 +434 +435 +436 +437 +438 +439 +440 +441 +442 +443 +444 +445 +446 +447 +448 +449 +450 +451 +452 +453 +454 +455 +456 +457 +458 +459 +460 +461 +462 +463 +464 +465 +466 +467 +468 +469 +470 +471 +472 +473 +474 +475 +476 +477 +478 +479 +480 +481 +482 +483 +484 +485 +486 +487 +488 +489 +490 +491 +492 +493 +494 +495 +496 +497 +498 +499 +500 +501 +502 +503 +504 +505 +506 +507 +508 +509 +510 +511 +512 +513 +514 +515 +516 +517 +518 +519 +520 +521 +522 +523 +524 +525 +526 +527 +528 +529 +530 +531 +532 +533 +534 +535 +536 +537 +538 +539 +540 +541 +542 +543 +544 +545 +546 +547 +548 +549 +550 +551 +552 +553 +554 +555 +556 +557 +558 +559 +560 +561 +562 +563 +564 +565 +566 +567 +568 +569 +570 +571 +572 +573 +574 +575 +576 +577 +578 +579 +580 +581 +582 +583 +584 +585 +586 +587 +588 +589 +590 +591 +592 +593 +594 +595 +596 +597 +598 +599 +600 +601 +602 +603 +604 +605 +606 +607 +608 +609 +610 +611 +612 +613 +614 +615 +616 +617 +618 +619 +620 +621 +622 +623 +624 +625 +626 +627 +628 +629 +630 +631 +632 +633 +634 +635 +636 +637 +638 +639 +640 +641 +642 +643 +644 +645 +646 +647 +648 +649 +650 +651 +652 +653 +654 +655 +656 +657 +658 +659 +660 +661 +662 +663 +664 +665 +666 +667 +668 +669 +670 +671 +672 +673 +674 +675 +676 +677 +678 +679 +680 +681 +682 +683 +684 +685 +686 +687 +688 +689 +690 +691 +692 +693 +694 +695 +696 +697 +698 +699 +700 +701 +702 +703 +704 +705 +706 +707 +708 +709 +710 +711 +712 +713 +714 +715 +716 +717 +718 +719 +720 +721 +722 +723 +724 +725 +726 +727 +728 +729 +730 +731 +732 +733 +734 +735 +736 +737 +738 +739 +740 +741 +742 +743 +744 +745 +746 +747 +748 +749 +750 +751 +752 +753 +754 +755 +756 +757 +758 +759 +760 +761 +762 +763 +764 +765 +766 +767 +768 +769 +770 +771 +772 +773 +774 +775 +776 +777 +778 +779 +780 +781 +782 +783 +784 +785 +786 +787 +788 +789 +790 +791 +792 +793 +794 +795 +796 +797 +798 +799 +800 +801 +802 +803 +804 +805 +806 +807 +808 +809 +810 +811 +812 +813 +814 +815 +816 +817 +818 +819 +820 +821 +822 +823 +824 +825 +826 +827 +828 +829 +830 +831 +832 +833 +834 +835 +836 +837 +838 +839 +840 +841 +842 +843 +844 +845 +846 +847 +848 +849 +850 +851 +852 +853 +854 +855 +856 +857 +858 +859 +860 +861 +862 +863 +864 +865 +866 +867 +868 +869 +870 +871 +872 +873 +874 +875 +876 +877 +878 +879 +880 +881 +882 +883 +884 +885 +886 +887 +888 +889 +890 +891 +892 +893 +894 +895 +896 +897 +898 +899 +900 +901 +902 +903 +904 +905 +906 +907 +908 +909 +910 +911 +912 +913 +914 +915 +916 +917 +918 +919 +920 +921 +922 +923 +924 +925 +926 +927 +928 +929 +930 +931 +932 +933 +934 +935 +936 +937 +938 +939 +940 +941 +942 +943 +944 +945 +946 +947 +948 +949 +950 +951 +952 +953 +954 +955 +956 +957 +958 +959 +960 +961 +962 +963 +964 +965 +966 +967 +968 +969 +970 +971 +972 +973 +974 +975 +976 +977 +978 +979 +980 +981 +982 +983 +984 +985 +986 +987 +988 +989 +990 +991 +992 +993 +994 +995 +996 +997 +998 +999 +1000 +1001 +1002 +1003 +1004 +1005 +1006 +1007 +1008 +1009 +1010 +1011 +1012 +1013 +1014 +1015 +1016 +1017 +1018 +1019 +1020 +1021 +1022 +1023 +1024 +1025 +1026 +1027 +1028 +1029 +1030 +1031 +1032 +1033 +1034 +1035 +1036 +1037 +1038 +1039 +1040 +1041 +1042 +1043 +1044 +1045 +1046 +1047 +1048 +1049 +1050 +1051 +1052 +1053 +1054 +1055 +1056 +1057 +1058 +1059 +1060 +1061 +1062 +1063 +1064 +1065 +1066 +1067 +1068 +1069 +1070 +1071 +1072 +1073 +1074 +1075 +1076 +1077 +1078 +1079 +1080 +1081 +1082 +1083 +1084 +1085 +1086 +1087 +1088 +1089 +1090 +1091 +1092 +1093 +1094 +1095 +1096 +1097 +1098 +1099 +1100 +1101 +1102 +1103 +1104 +1105 +1106 +1107 +1108 +1109 +1110 +1111 +1112 +1113 +1114 +1115 +1116 +1117 +1118 +1119 +1120 +1121 +1122 +1123 +1124 +1125 +1126 +1127 +1128 +1129 +1130 +1131 +1132 +1133 +1134 +1135 +1136 +1137 +1138 +1139 +1140 +1141 +1142 +1143 +1144 +1145 +1146 +1147 +1148 +1149 +1150 +1151 +1152 +1153 +1154 +1155 +1156 +1157 +1158 +1159 +1160 +1161 +1162 +1163 +1164 +1165 +1166 +1167 +1168 +1169 +1170 +1171 +1172 +1173 +1174 +1175 +1176 +1177 +1178 +1179 +1180 +1181 +1182 +1183 +1184 +1185 +1186 +1187 +1188 +1189 +1190 +1191 +1192 +1193 +1194 +1195 +1196 +1197 +1198 +1199 +1200 +1201 +1202 +1203 +1204 +1205 +1206 +1207 +1208 +1209 +1210 +1211 +1212 +1213 +1214 +1215 +1216 +1217 +1218 +1219 +1220 +1221 +1222 +1223 +1224 +1225 +1226 +1227 +1228 +1229 +1230 +1231 +1232 +1233 +1234 +1235 +1236 +1237 +1238 +1239 +1240 +1241 +1242 +1243 +1244 +1245 +1246 +1247 +1248 +1249 +1250 +1251 +1252 +1253 +1254 +1255 +1256 +1257 +1258 +1259 +1260 +1261 +1262 +1263 +1264 +1265 +1266 +1267 +1268 +1269 +1270 +1271 +1272 +1273 +1274 +1275 +1276 +1277 +1278 +1279 +1280 +1281 +1282 +1283 +1284 +1285 +1286 +1287 +1288 +1289 +1290 +1291 +1292 +1293 +1294 +1295 +1296 +1297 +1298 +1299 +1300 +1301 +1302 +1303 +1304 +1305 +1306 +1307 +1308 +1309 +1310 +1311 +1312 +1313 +1314 +1315 +1316 +1317 +1318 +1319 +1320 +1321 +1322 +1323 +1324 +1325 +1326 +1327 +1328 +1329 +1330 +1331 +1332 +1333 +1334 +1335 +1336 +1337 +1338 +1339 +1340 +1341 +1342 +1343 +1344 +1345 +1346 +1347 +1348 +1349 +1350 +1351 +1352 +1353 +1354 +1355 +1356 +1357 +1358 +1359 +1360 +1361 +1362 +1363 +1364 +1365 +1366 +1367 +1368 +1369 +1370 +1371 +1372 +1373 +1374 +1375 +1376 +1377 +1378 +1379 +1380 +1381 +1382 +1383 +1384 +1385 +1386 +1387 +1388 +1389 +1390 +1391 +1392 +1393 +1394 +1395 +1396 +1397 +1398 +1399 +1400 +1401 +1402 +1403 +1404 +1405 +1406 +1407 +1408 +1409 +1410 +1411 +1412 +1413 +1414 +1415 +1416 +1417 +1418 +1419 +1420 +1421 +1422 +1423 +1424 +1425 +1426 +1427 +1428 +1429 +1430 +1431 +1432 +1433 +1434 +1435 +1436 +1437 +1438 +1439 +1440 +1441 +1442 +1443 +1444 +1445 +1446 +1447 +1448 +1449 +1450 +1451 +1452 +1453 +1454 +1455 +1456 +1457 +1458 +1459 +1460 +1461 +1462 +1463 +1464 +1465 +1466 +1467 +1468 +1469 +1470 +1471 +1472 +1473 +1474 +1475 +1476 +1477 +1478 +1479 +1480 +1481 +1482 +1483 +1484 +1485 +1486 +1487 +1488 +1489 +1490 +1491 +1492 +1493 +1494 +1495 +1496 +1497 +1498 +1499 +1500 +1501 +1502 +1503 +1504 +1505 +1506 +1507 +1508 +1509 +1510 +1511 +1512 +1513 +1514 +1515 +1516 +1517 +1518 +1519 +1520 +1521 +1522 +1523 +1524 +1525 +1526 +1527 +1528 +1529 +1530 +1531 +1532 +1533 +1534 +1535 +1536 +1537 +1538 +1539 +1540 +1541 +1542 +1543 +1544 +1545 +1546 +1547 +1548 +1549 +1550 +1551 +1552 +1553 +1554 +1555 +1556 +1557 +1558 +1559 +1560 +1561 +1562 +1563 +1564 +1565 +1566 +1567 +1568 +1569 +1570 +1571 +1572 +1573 +1574 +1575 +1576 +1577 +1578 +1579 +1580 +1581 +1582 +1583 +1584 +1585 +1586 +1587 +1588 +1589 +1590 +1591 +1592 +1593 +1594 +1595 +1596 +1597 +1598 +1599 +1600 +1601 +1602 +1603 +1604 +1605 +1606 +1607 +1608 +1609 +1610 +1611 +1612 +1613 +1614 +1615 +1616 +1617 +1618 +1619 +1620 +1621 +1622 +1623 +1624 +1625 +1626 +1627 +1628 +1629 +1630 +1631 +1632 +1633 +1634 +1635 +1636 +1637 +1638 +1639 +1640 +1641 +1642 +1643 +1644 +1645 +1646 +1647 +1648 +1649 +1650 +1651 +1652 +1653 +1654 +1655 +1656 +1657 +1658 +1659 +1660 +1661 +1662 +1663 +1664 +1665 +1666 +1667 +1668 +1669 +1670 +1671 +1672 +1673 +1674 +1675 +1676 +1677 +1678 +1679 +1680 +1681 +1682 +1683 +1684 +1685 +1686 +1687 +1688 +1689 +1690 +1691 +1692 +1693 +1694 +1695 +1696 +1697 +1698 +1699 +1700 +1701 +1702 +1703 +1704 +1705 +1706 +1707 +1708 +1709 +1710 +1711 +1712 +1713 +1714 +1715 +1716 +1717 +1718 +1719 +1720 +1721 +1722 +1723 +1724 +1725 +1726 +1727 +1728 +1729 +1730 +1731 +1732 +1733 +1734 +1735 +1736 +1737 +1738 +1739 +1740 +1741 +1742 +1743 +1744 +1745 +1746 +1747 +1748 +1749 +1750 +1751 +1752 +1753 +1754 +1755 +1756 +1757 +1758 +1759 +1760 +1761 +1762 +1763 +1764 +1765 +1766 +1767 +1768 +1769 +1770 +1771 +1772 +1773 +1774 +1775 +1776 +1777 +1778 +1779 +1780 +1781 +1782 +1783 +1784 +1785 +1786 +1787 +1788 +1789 +1790 +1791 +1792 +1793 +1794 +1795 +1796 +1797 +1798 +1799 +1800 +1801 +1802 +1803 +1804 +1805 +1806 +1807 +1808 +1809 +1810 +1811 +1812 +1813 +1814 +1815 +1816 +1817 +1818 +1819 +1820 +1821 +1822 +1823 +1824 +1825 +1826 +1827 +1828 +1829 +1830 +1831 +1832 +1833 +1834 +1835 +1836 +1837 +1838 +1839 +1840 +1841 +1842 +1843 +1844 +1845 +1846 +1847 +1848 +1849 +1850 +1851 +1852 +1853 +1854 +1855 +1856 +1857 +1858 +1859 +1860 +1861 +1862 +1863 +1864 +1865 +1866 +1867 +1868 +1869 +1870 +1871 +1872 +1873 +1874 +1875 +1876 +1877 +1878 +1879 +1880 +1881 +1882 +1883 +1884 +1885 +1886 +1887 +1888 +1889 +1890 +1891 +1892 +1893 +1894 +1895 +1896 +1897 +1898 +1899 +1900 +1901 +1902 +1903 +1904 +1905 +1906 +1907 +1908 +1909 +1910 +1911 +1912 +1913 +1914 +1915 +1916 +1917 +1918 +1919 +1920 +1921 +1922 +1923 +1924 +1925 +1926 +1927 +1928 +1929 +1930 +1931 +1932 +1933 +1934 +1935 +1936 +1937 +1938 +1939 +1940 +1941 +1942 +1943 +1944 +1945 +1946 +1947 +1948 +1949 +1950 +1951 +1952 +1953 +1954 +1955 +1956 +1957 +1958 +1959 +1960 +1961 +1962 +1963 +1964 +1965 +1966 +1967 +1968 +1969 +1970 +1971 +1972 +1973 +1974 +1975 +1976 +1977 +1978 +1979 +1980 +1981 +1982 +1983 +1984 +1985 +1986 +1987 +1988 +1989 +1990 +1991 +1992 +1993 +1994 +1995 +1996 +1997 +1998 +1999 +2000 +2001 +2002 +2003 +2004 +2005 +2006 +2007 +2008 +2009 +2010 +2011 +2012 +2013 +2014 +2015 +2016 +2017 +2018 +2019 +2020 +2021 +2022 +2023 +2024 +2025 +2026 +2027 +2028 +2029 +2030 +2031 +2032 +2033 +2034 +2035 +2036 +2037 +2038 +2039 +2040 +2041 +2042 +2043 +2044 +2045 +2046 +2047 +2048 +2049 +2050 +2051 +2052 +2053 +2054 +2055 +2056 +2057 +2058 +2059 +2060 +2061 +2062 +2063 +2064 +2065 +2066 +2067 +2068 +2069 +2070 +2071 +2072 +2073 +2074 +2075 +2076 +2077 +2078 +2079 +2080 +2081 +2082 +2083 +2084 +2085 +2086 +2087 +2088 +2089 +2090 +2091 +2092 +2093 +2094 +2095 +2096 +2097 +2098 +2099 +2100 +2101 +2102 +2103 +2104 +2105 +2106 +2107 +2108 +2109 +2110 +2111 +2112 +2113 +2114 +2115 +2116 +2117 +2118 +2119 +2120 +2121 +2122 +2123 +2124 +2125 +2126 +2127 +2128 +2129 +2130 +2131 +2132 +2133 +2134 +2135 +2136 +2137 +2138 +2139 +2140 +2141 +2142 +2143 +2144 +2145 +2146 +2147 +2148 +2149 +2150 +2151 +2152 +2153 +2154 +2155 +2156 +2157 +2158 +2159 +2160 +2161 +2162 +2163 +2164 +2165 +2166 +2167 +2168 +2169 +2170 +2171 +2172 +2173 +2174 +2175 +2176 +2177 +2178 +2179 +2180 +2181 +2182 +2183 +2184 +2185 +2186 +2187 +2188 +2189 +2190 +2191 +2192 +2193 +2194 +2195 +2196 +2197 +2198 +2199 +2200 +2201 +2202 +2203 +2204 +2205 +2206 +2207 +2208 +2209 +2210 +2211 +2212 +2213 +2214 +2215 +2216 +2217 +2218 +2219 +2220 +2221 +2222 +2223 +2224 +2225 +2226 +2227 +2228 +2229 +2230 +2231 +2232 +2233 +2234 +2235 +2236 +2237 +2238 +2239 +2240 +2241 +2242 +2243 +2244 +2245 +2246 +2247 +2248 +2249 +2250 +2251 +2252 +2253 +2254 +2255 +2256 +2257 +2258 +2259 +2260 +2261 +2262 +2263 +2264 +2265 +2266 +2267 +2268 +2269 +2270 +2271 +2272 +2273 +2274 +2275 +2276 +2277 +2278 +2279 +2280 +2281 +2282 +2283 +2284 +2285 +2286 +2287 +2288 +2289 +2290 +2291 +2292 +2293 +2294 +2295 +2296 +2297 +2298 +2299 +2300 +2301 +2302 +2303 +2304 +2305 +2306 +2307 +2308 +2309 +2310 +2311 +2312 +2313 +2314 +2315 +2316 +2317 +2318 +2319 +2320 +2321 +2322 +2323 +2324 +2325 +2326 +2327 +2328 +2329 +2330 +2331 +2332 +2333 +2334 +2335 +2336 +2337 +2338 +2339 +2340 +2341 +2342 +2343 +2344 +2345 +2346 +2347 +2348 +2349 +2350 +2351 +2352 +2353 +2354 +2355 +2356 +2357 +2358 +2359 +2360 +2361 +2362 +2363 +2364 +2365 +2366 +2367 +2368 +2369 +2370 +2371 +2372 +2373 +2374 +2375 +2376 +2377 +2378 +2379 +2380 +2381 +2382 +2383 +2384 +2385 +2386 +2387 +2388 +2389 +2390 +2391 +2392 +2393 +2394 +2395 +2396 +2397 +2398 +2399 +2400 +2401 +2402 +2403 +2404 +2405 +2406 +2407 +2408 +2409 +2410 +2411 +2412 +2413 +2414 +2415 +2416 +2417 +2418 +2419 +2420 +2421 +2422 +2423 +2424 +2425 +2426 +2427 +2428 +2429 +2430 +2431 +2432 +2433 +2434 +2435 +2436 +2437 +2438 +2439 +2440 +2441 +2442 +2443 +2444 +2445 +2446 +2447 +2448 +2449 +2450 +2451 +2452 +2453 +2454 +2455 +2456 +2457 +2458 +2459 +2460 +2461 +2462 +2463 +2464 +2465 +2466 +2467 +2468 +2469 +2470 +2471 +2472 +2473 +2474 +2475 +2476 +2477 +2478 +2479 +2480 +2481 +2482 +2483 +2484 +2485 +2486 +2487 +2488 +2489 +2490 +2491 +2492 +2493 +2494 +2495 +2496 +2497 +2498 +2499 +2500 +2501 +2502 +2503 +2504 +2505 +2506 +2507 +2508 +2509 +2510 +2511 +2512 +2513 +2514 +2515 +2516 +2517 +2518 +2519 +2520 +2521 +2522 +2523 +2524 +2525 +2526 +2527 +2528 +2529 +2530 +2531 +2532 +2533 +2534 +2535 +2536 +2537 +2538 +2539 +2540 +2541 +2542 +2543 +2544 +2545 +2546 +2547 +2548 +2549 +2550 +2551 +2552 +2553 +2554 +2555 +2556 +2557 +2558 +2559 +2560 +2561 +2562 +2563 +2564 +2565 +2566 +2567 +2568 +2569 +2570 +2571 +2572 +2573 +2574 +2575 +2576 +2577 +2578 +2579 +2580 +2581 +2582 +2583 +2584 +2585 +2586 +2587 +2588 +2589 +2590 +2591 +2592 +2593 +2594 +2595 +2596 +2597 +2598 +2599 +2600 +2601 +2602 +2603 +2604 +2605 +2606 +2607 +2608 +2609 +2610 +2611 +2612 +2613 +2614 +2615 +2616 +2617 +2618 +2619 +2620 +2621 +2622 +2623 +2624 +2625 +2626 +2627 +2628 +2629 +2630 +2631 +2632 +2633 +2634 +2635 +2636 +2637 +2638 +2639 +2640 +2641 +2642 +2643 +2644 +2645 +2646 +2647 +2648 +2649 +2650 +2651 +2652 +2653 +2654 +2655 +2656 +2657 +2658 +2659 +2660 +2661 +2662 +2663 +2664 +2665 +2666 +2667 +2668 +2669 +2670 +2671 +2672 +2673 +2674 +2675 +2676 +2677 +2678 +2679 +2680 +2681 +2682 +2683 +2684 +2685 +2686 +2687 +2688 +2689 +2690 +2691 +2692 +2693 +2694 +2695 +2696 +2697 +2698 +2699 +2700 +2701 +2702 +2703 +2704 +2705 +2706 +2707 +2708 +2709 +2710 +2711 +2712 +2713 +2714 +2715 +2716 +2717 +2718 +2719 +2720 +2721 +2722 +2723 +2724 +2725 +2726 +2727 +2728 +2729 +2730 +2731 +2732 +2733 +2734 +2735 +2736 +2737 +2738 +2739 +2740 +2741 +2742 +2743 +2744 +2745 +2746 +2747 +2748 +2749 +2750 +2751 +2752 +2753 +2754 +2755 +2756 +2757 +2758 +2759 +2760 +2761 +2762 +2763 +2764 +2765 +2766 +2767 +2768 +2769 +2770 +2771 +2772 +2773 +2774 +2775 +2776 +2777 +2778 +2779 +2780 +2781 +2782 +2783 +2784 +2785 +2786 +2787 +2788 +2789 +2790 +2791 +2792 +2793 +2794 +2795 +2796 +2797 +2798 +2799 +2800 +2801 +2802 +2803 +2804 +2805 +2806 +2807 +2808 +2809 +2810 +2811 +2812 +2813 +2814 +2815 +2816 +2817 +2818 +2819 +2820 +2821 +2822 +2823 +2824 +2825 +2826 +2827 +2828 +2829 +2830 +2831 +2832 +2833 +2834 +2835 +2836 +2837 +2838 +2839 +2840 +2841 +2842 +2843 +2844 +2845 +2846 +2847 +2848 +2849 +2850 +2851 +2852 +2853 +2854 +2855 +2856 +2857 +2858 +2859 +2860 +2861 +2862 +2863 +2864 +2865 +2866 +2867 +2868 +2869 +2870 +2871 +2872 +2873 +2874 +2875 +2876 +2877 +2878 +2879 +2880 +2881 +2882 +2883 +2884 +2885 +2886 +2887 +2888 +2889 +2890 +2891 +2892 +2893 +2894 +2895 +2896 +2897 +2898 +2899 +2900 +2901 +2902 +2903 +2904 +2905 +2906 +2907 +2908 +2909 +2910 +2911 +2912 +2913 +2914 +2915 +2916 +2917 +2918 +2919 +2920 +2921 +2922 +2923 +2924 +2925 +2926 +2927 +2928 +2929 +2930 +2931 +2932 +2933 +2934 +2935 +2936 +2937 +2938 +2939 +2940 +2941 +2942 +2943 +2944 +2945 +2946 +2947 +2948 +2949 +2950 +2951 +2952 +2953 +2954 +2955 +2956 +2957 +2958 +2959 +2960 +2961 +2962 +2963 +2964 +2965 +2966 +2967 +2968 +2969 +2970 +2971 +2972 +2973 +2974 +2975 +2976 +2977 +2978 +2979 +2980 +2981 +2982 +2983 +2984 +2985 +2986 +2987 +2988 +2989 +2990 +2991 +2992 +2993 +2994 +2995 +2996 +2997 +2998 +2999 +3000 +3001 +3002 +3003 +3004 +3005 +3006 +3007 +3008 +3009 +3010 +3011 +3012 +3013 +3014 +3015 +3016 +3017 +3018 +3019 +3020 +3021 +3022 +3023 +3024 +3025 +3026 +3027 +3028 +3029 +3030 +3031 +3032 +3033 +3034 +3035 +3036 +3037 +3038 +3039 +3040 +3041 +3042 +3043 +3044 +3045 +3046 +3047 +3048 +3049 +3050 +3051 +3052 +3053 +3054 +3055 +3056 +3057 +3058 +3059 +3060 +3061 +3062 +3063 +3064 +3065 +3066 +3067 +3068 +3069 +3070 +3071 +3072 +3073 +3074 +3075 +3076 +3077 +3078 +3079 +3080 +3081 +3082 +3083 +3084 +3085 +3086 +3087 +3088 +3089 +3090 +3091 +3092 +3093 +3094 +3095 +3096 +3097 +3098 +3099 +3100 +3101 +3102 +3103 +3104 +3105 +3106 +3107 +3108 +3109 +3110 +3111 +3112 +3113 +3114 +3115 +3116 +3117 +3118 +3119 +3120 +3121 +3122 +3123 +3124 +3125 +3126 +3127 +3128 +3129 +3130 +3131 +3132 +3133 +3134 +3135 +3136 +3137 +3138 +3139 +3140 +3141 +3142 +3143 +3144 +3145 +3146 +3147 +3148 +3149 +3150 +3151 +3152 +3153 +3154 +3155 +3156 +3157 +3158 +3159 +3160 +3161 +3162 +3163 +3164 +3165 +3166 +3167 +3168 +3169 +3170 +3171 +3172 +3173 +3174 +3175 +3176 +3177 +3178 +3179 +3180 +3181 +3182 +3183 +3184 +3185 +3186 +3187 +3188 +3189 +3190 +3191 +3192 +3193 +3194 +3195 +3196 +3197 +3198 +3199 +3200 +3201 +3202 +3203 +3204 +3205 +3206 +3207 +3208 +3209 +3210 +3211 +3212 +3213 +3214 +3215 +3216 +3217 +3218 +3219 +3220 +3221 +3222 +3223 +3224 +3225 +3226 +3227 +3228 +3229 +3230 +3231 +3232 +3233 +3234 +3235 +3236 +3237 +3238 +3239 +3240 +3241 +3242 +3243 +3244 +3245 +3246 +3247 +3248 +3249 +3250 +3251 +3252 +3253 +3254 +3255 +3256 +3257 +3258 +3259 +3260 +3261 +3262 +3263 +3264 +3265 +3266 +3267 +3268 +3269 +3270 +3271 +3272 +3273 +3274 +3275 +3276 +3277 +3278 +3279 +3280 +3281 +3282 +3283 +3284 +3285 +3286 +3287 +3288 +3289 +3290 +3291 +3292 +3293 +3294 +3295 +3296 +3297 +3298 +3299 +3300 +3301 +3302 +3303 +3304 +3305 +3306 +3307 +3308 +3309 +3310 +3311 +3312 +3313 +3314 +3315 +3316 +3317 +3318 +3319 +3320 +3321 +3322 +3323 +3324 +3325 +3326 +3327 +3328 +3329 +3330 +3331 +3332 +3333 +3334 +3335 +3336 +3337 +3338 +3339 +3340 +3341 +3342 +3343 +3344 +3345 +3346 +3347 +3348 +3349 +3350 +3351 +3352 +3353 +3354 +3355 +3356 +3357 +3358 +3359 +3360 +3361 +3362 +3363 +3364 +3365 +3366 +3367 +3368 +3369 +3370 +3371 +3372 +3373 +3374 +3375 +3376 +3377 +3378 +3379 +3380 +3381 +3382 +3383 +3384 +3385 +3386 +3387 +3388 +3389 +3390 +3391 +3392 +3393 +3394 +3395 +3396 +3397 +3398 +3399 +3400 +3401 +3402 +3403 +3404 +3405 +3406 +3407 +3408 +3409 +3410 +3411 +3412 +3413 +3414 +3415 +3416 +3417 +3418 +3419 +3420 +3421 +3422 +3423 +3424 +3425 +3426 +3427 +3428 +3429 +3430 +3431 +3432 +3433 +3434 +3435 +3436 +3437 +3438 +3439 +3440 +3441 +3442 +3443 +3444 +3445 +3446 +3447 +3448 +3449 +3450 +3451 +3452 +3453 +3454 +3455 +3456 +3457 +3458 +3459 +3460 +3461 +3462 +3463 +3464 +3465 +3466 +3467 +3468 +3469 +3470 +3471 +3472 +3473 +3474 +3475 +3476 +3477 +3478 +3479 +3480 +3481 +3482 +3483 +3484 +3485 +3486 +3487 +3488 +3489 +3490 +3491 +3492 +3493 +3494 +3495 +3496 +3497 +3498 +3499 +3500 +3501 +3502 +3503 +3504 +3505 +3506 +3507 +3508 +3509 +3510 +3511 +3512 +3513 +3514 +3515 +3516 +3517 +3518 +3519 +3520 +3521 +3522 +3523 +3524 +3525 +3526 +3527 +3528 +3529 +3530 +3531 +3532 +3533 +3534 +3535 +3536 +3537 +3538 +3539 +3540 +3541 +3542 +3543 +3544 +3545 +3546 +3547 +3548 +3549 +3550 +3551 +3552 +3553 +3554 +3555 +3556 +3557 +3558 +3559 +3560 +3561 +3562 +3563 +3564 +3565 +3566 +3567 +3568 +3569 +3570 +3571 +3572 +3573 +3574 +3575 +3576 +3577 +3578 +3579 +3580 +3581 +3582 +3583 +3584 +3585 +3586 +3587 +3588 +3589 +3590 +3591 +3592 +3593 +3594 +3595 +3596 +3597 +3598 +3599 +3600 +3601 +3602 +3603 +3604 +3605 +3606 +3607 +3608 +3609 +3610 +3611 +3612 +3613 +3614 +3615 +3616 +3617 +3618 +3619 +3620 +3621 +3622 +3623 +3624 +3625 +3626 +3627 +3628 +3629 +3630 +3631 +3632 +3633 +3634 +3635 +3636 +3637 +3638 +3639 +3640 +3641 +3642 +3643 +3644 +3645 +3646 +3647 +3648 +3649 +3650 +3651 +3652 +3653 +3654 +3655 +3656 +3657 +3658 +3659 +3660 +3661 +3662 +3663 +3664 +3665 +3666 +3667 +3668 +3669 +3670 +3671 +3672 +3673 +3674 +3675 +3676 +3677 +3678 +3679 +3680 +3681 +3682 +3683 +3684 +3685 +3686 +3687 +3688 +3689 +3690 +3691 +3692 +3693 +3694 +3695 +3696 +3697 +3698 +3699 +3700 +3701 +3702 +3703 +3704 +3705 +3706 +3707 +3708 +3709 +3710 +3711 +3712 +3713 +3714 +3715 +3716 +3717 +3718 +3719 +3720 +3721 +3722 +3723 +3724 +3725 +3726 +3727 +3728 +3729 +3730 +3731 +3732 +3733 +3734 +3735 +3736 +3737 +3738 +3739 +3740 +3741 +3742 +3743 +3744 +3745 +3746 +3747 +3748 +3749 +3750 +3751 +3752 +3753 +3754 +3755 +3756 +3757 +3758 +3759 +3760 +3761 +3762 +3763 +3764 +3765 +3766 +3767 +3768 +3769 +3770 +3771 +3772 +3773 +3774 +3775 +3776 +3777 +3778 +3779 +3780 +3781 +3782 +3783 +3784 +3785 +3786 +3787 +3788 +3789 +3790 +3791 +3792 +3793 +3794 +3795 +3796 +3797 +3798 +3799 +3800 +3801 +3802 +3803 +3804 +3805 +3806 +3807 +3808 +3809 +3810 +3811 +3812 +3813 +3814 +3815 +3816 +3817 +3818 +3819 +3820 +3821 +3822 +3823 +3824 +3825 +3826 +3827 +3828 +3829 +3830 +3831 +3832 +3833 +3834 +3835 +3836 +3837 +3838 +3839 +3840 +3841 +3842 +3843 +3844 +3845 +3846 +3847 +3848 +3849 +3850 +3851 +3852 +3853 +3854 +3855 +3856 +3857 +3858 +3859 +3860 +3861 +3862 +3863 +3864 +3865 +3866 +3867 +3868 +3869 +3870 +3871 +3872 +3873 +3874 +3875 +3876 +3877 +3878 +3879 +3880 +3881 +3882 +3883 +3884 +3885 +3886 +3887 +3888 +3889 +3890 +3891 +3892 +3893 +3894 +3895 +3896 +3897 +3898 +3899 +3900 +3901 +3902 +3903 +3904 +3905 +3906 +3907 +3908 +3909 +3910 +3911 +3912 +3913 +3914 +3915 +3916 +3917 +3918 +3919 +3920 +3921 +3922 +3923 +3924 +3925 +3926 +3927 +3928 +3929 +3930 +3931 +3932 +3933 +3934 +3935 +3936 +3937 +3938 +3939 +3940 +3941 +3942 +3943 +3944 +3945 +3946 +3947 +3948 +3949 +3950 +3951 +3952 +3953 +3954 +3955 +3956 +3957 +3958 +3959 +3960 +3961 +3962 +3963 +3964 +3965 +3966 +3967 +3968 +3969 +3970 +3971 +3972 +3973 +3974 +3975 +3976 +3977 +3978 +3979 +3980 +3981 +3982 +3983 +3984 +3985 +3986 +3987 +3988 +3989 +3990 +3991 +3992 +3993 +3994 +3995 +3996 +3997 +3998 +3999 +4000 +4001 +4002 +4003 +4004 +4005 +4006 +4007 +4008 +4009 +4010 +4011 +4012 +4013 +4014 +4015 +4016 +4017 +4018 +4019 +4020 +4021 +4022 +4023 +4024 +4025 +4026 +4027 +4028 +4029 +4030 +4031 +4032 +4033 +4034 +4035 +4036 +4037 +4038 +4039 +4040 +4041 +4042 +4043 +4044 +4045 +4046 +4047 +4048 +4049 +4050 +4051 +4052 +4053 +4054 +4055 +4056 +4057 +4058 +4059 +4060 +4061 +4062 +4063 +4064 +4065 +4066 +4067 +4068 +4069 +4070 +4071 +4072 +4073 +4074 +4075 +4076 +4077 +4078 +4079 +4080 +4081 +4082 +4083 +4084 +4085 +4086 +4087 +4088 +4089 +4090 +4091 +4092 +4093 +4094 +4095 +4096 +4097 +4098 +4099 +4100 +4101 +4102 +4103 +4104 +4105 +4106 +4107 +4108 +4109 +4110 +4111 +4112 +4113 +4114 +4115 +4116 +4117 +4118 +4119 +4120 +4121 +4122 +4123 +4124 +4125 +4126 +4127 +4128 +4129 +4130 +4131 +4132 +4133 +4134 +4135 +4136 +4137 +4138 +4139 +4140 +4141 +4142 +4143 +4144 +4145 +4146 +4147 +4148 +4149 +4150 +4151 +4152 +4153 +4154 +4155 +4156 +4157 +4158 +4159 +4160 +4161 +4162 +4163 +4164 +4165 +4166 +4167 +4168 +4169 +4170 +4171 +4172 +4173 +4174 +4175 +4176 +4177 +4178 +4179 +4180 +4181 +4182 +4183 +4184 +4185 +4186 +4187 +4188 +4189 +4190 +4191 +4192 +4193 +4194 +4195 +4196 +4197 +4198 +4199 +4200 +4201 +4202 +4203 +4204 +4205 +4206 +4207 +4208 +4209 +4210 +4211 +4212 +4213 +4214 +4215 +4216 +4217 +4218 +4219 +4220 +4221 +4222 +4223 +4224 +4225 +4226 +4227 +4228 +4229 +4230 +4231 +4232 +4233 +4234 +4235 +4236 +4237 +4238 +4239 +4240 +4241 +4242 +4243 +4244 +4245 +4246 +4247 +4248 +4249 +4250 +4251 +4252 +4253 +4254 +4255 +4256 +4257 +4258 +4259 +4260 +4261 +4262 +4263 +4264 +4265 +4266 +4267 +4268 +4269 +4270 +4271 +4272 +4273 +4274 +4275 +4276 +4277 +4278 +4279 +4280 +4281 +4282 +4283 +4284 +4285 +4286 +4287 +4288 +4289 +4290 +4291 +4292 +4293 +4294 +4295 +4296 +4297 +4298 +4299 +4300 +4301 +4302 +4303 +4304 +4305 +4306 +4307 +4308 +4309 +4310 +4311 +4312 +4313 +4314 +4315 +4316 +4317 +4318 +4319 +4320 +4321 +4322 +4323 +4324 +4325 +4326 +4327 +4328 +4329 +4330 +4331 +4332 +4333 +4334 +4335 +4336 +4337 +4338 +4339 +4340 +4341 +4342 +4343 +4344 +4345 +4346 +4347 +4348 +4349 +4350 +4351 +4352 +4353 +4354 +4355 +4356 +4357 +4358 +4359 +4360 +4361 +4362 +4363 +4364 +4365 +4366 +4367 +4368 +4369 +4370 +4371 +4372 +4373 +4374 +4375 +4376 +4377 +4378 +4379 +4380 +4381 +4382 +4383 +4384 +4385 +4386 +4387 +4388 +4389 +4390 +4391 +4392 +4393 +4394 +4395 +4396 +4397 +4398 +4399 +4400 +4401 +4402 +4403 +4404 +4405 +4406 +4407 +4408 +4409 +4410 +4411 +4412 +4413 +4414 +4415 +4416 +4417 +4418 +4419 +4420 +4421 +4422 +4423 +4424 +4425 +4426 +4427 +4428 +4429 +4430 +4431 +4432 +4433 +4434 +4435 +4436 +4437 +4438 +4439 +4440 +4441 +4442 +4443 +4444 +4445 +4446 +4447 +4448 +4449 +4450 +4451 +4452 +4453 +4454 +4455 +4456 +4457 +4458 +4459 +4460 +4461 +4462 +4463 +4464 +4465 +4466 +4467 +4468 +4469 +4470 +4471 +4472 +4473 +4474 +4475 +4476 +4477 +4478 +4479 +4480 +4481 +4482 +4483 +4484 +4485 +4486 +4487 +4488 +4489 +4490 +4491 +4492 +4493 +4494 +4495 +4496 +4497 +4498 +4499 +4500 +4501 +4502 +4503 +4504 +4505 +4506 +4507 +4508 +4509 +4510 +4511 +4512 +4513 +4514 +4515 +4516 +4517 +4518 +4519 +4520 +4521 +4522 +4523 +4524 +4525 +4526 +4527 +4528 +4529 +4530 +4531 +4532 +4533 +4534 +4535 +4536 +4537 +4538 +4539 +4540 +4541 +4542 +4543 +4544 +4545 +4546 +4547 +4548 +4549 +4550 +4551 +4552 +4553 +4554 +4555 +4556 +4557 +4558 +4559 +4560 +4561 +4562 +4563 +4564 +4565 +4566 +4567 +4568 +4569 +4570 +4571 +4572 +4573 +4574 +4575 +4576 +4577 +4578 +4579 +4580 +4581 +4582 +4583 +4584 +4585 +4586 +4587 +4588 +4589 +4590 +4591 +4592 +4593 +4594 +4595 +4596 +4597 +4598 +4599 +4600 +4601 +4602 +4603 +4604 +4605 +4606 +4607 +4608 +4609 +4610 +4611 +4612 +4613 +4614 +4615 +4616 +4617 +4618 +4619 +4620 +4621 +4622 +4623 +4624 +4625 +4626 +4627 +4628 +4629 +4630 +4631 +4632 +4633 +4634 +4635 +4636 +4637 +4638 +4639 +4640 +4641 +4642 +4643 +4644 +4645 +4646 +4647 +4648 +4649 +4650 +4651 +4652 +4653 +4654 +4655 +4656 +4657 +4658 +4659 +4660 +4661 +4662 +4663 +4664 +4665 +4666 +4667 +4668 +4669 +4670 +4671 +4672 +4673 +4674 +4675 +4676 +4677 +4678 +4679 +4680 +4681 +4682 +4683 +4684 +4685 +4686 +4687 +4688 +4689 +4690 +4691 +4692 +4693 +4694 +4695 +4696 +4697 +4698 +4699 +4700 +4701 +4702 +4703 +4704 +4705 +4706 +4707 +4708 +4709 +4710 +4711 +4712 +4713 +4714 +4715 +4716 +4717 +4718 +4719 +4720 +4721 +4722 +4723 +4724 +4725 +4726 +4727 +4728 +4729 +4730 +4731 +4732 +4733 +4734 +4735 +4736 +4737 +4738 +4739 +4740 +4741 +4742 +4743 +4744 +4745 +4746 +4747 +4748 +4749 +4750 +4751 +4752 +4753 +4754 +4755 +4756 +4757 +4758 +4759 +4760 +4761 +4762 +4763 +4764 +4765 +4766 +4767 +4768 +4769 +4770 +4771 +4772 +4773 +4774 +4775 +4776 +4777 +4778 +4779 +4780 +4781 +4782 +4783 +4784 +4785 +4786 +4787 +4788 +4789 +4790 +4791 +4792 +4793 +4794 +4795 +4796 +4797 +4798 +4799 +4800 +4801 +4802 +4803 +4804 +4805 +4806 +4807 +4808 +4809 +4810 +4811 +4812 +4813 +4814 +4815 +4816 +4817 +4818 +4819 +4820 +4821 +4822 +4823 +4824 +4825 +4826 +4827 +4828 +4829 +4830 +4831 +4832 +4833 +4834 +4835 +4836 +4837 +4838 +4839 +4840 +4841 +4842 +4843 +4844 +4845 +4846 +4847 +4848 +4849 +4850 +4851 +4852 +4853 +4854 +4855 +4856 +4857 +4858 +4859 +4860 +4861 +4862 +4863 +4864 +4865 +4866 +4867 +4868 +4869 +4870 +4871 +4872 +4873 +4874 +4875 +4876 +4877 +4878 +4879 +4880 +4881 +4882 +4883 +4884 +4885 +4886 +4887 +4888 +4889 +4890 +4891 +4892 +4893 +4894 +4895 +4896 +4897 +4898 +4899 +4900 +4901 +4902 +4903 +4904 +4905 +4906 +4907 +4908 +4909 +4910 +4911 +4912 +4913 +4914 +4915 +4916 +4917 +4918 +4919 +4920 +4921 +4922 +4923 +4924 +4925 +4926 +4927 +4928 +4929 +4930 +4931 +4932 +4933 +4934 +4935 +4936 +4937 +4938 +4939 +4940 +4941 +4942 +4943 +4944 +4945 +4946 +4947 +4948 +4949 +4950 +4951 +4952 +4953 +4954 +4955 +4956 +4957 +4958 +4959 +4960 +4961 +4962 +4963 +4964 +4965 +4966 +4967 +4968 +4969 +4970 +4971 +4972 +4973 +4974 +4975 +4976 +4977 +4978 +4979 +4980 +4981 +4982 +4983 +4984 +4985 +4986 +4987 +4988 +4989 +4990 +4991 +4992 +4993 +4994 +4995 +4996 +4997 +4998 +4999 +5000 +5001 +5002 +5003 +5004 +5005 +5006 +5007 +5008 +5009 +5010 +5011 +5012 +5013 +5014 +5015 +5016 +5017 +5018 +5019 +5020 +5021 +5022 +5023 +5024 +5025 +5026 +5027 +5028 +5029 +5030 +5031 +5032 +5033 +5034 +5035 +5036 +5037 +5038 +5039 +5040 +5041 +5042 +5043 +5044 +5045 +5046 +5047 +5048 +5049 +5050 +5051 +5052 +5053 +5054 +5055 +5056 +5057 +5058 +5059 +5060 +5061 +5062 +5063 +5064 +5065 +5066 +5067 +5068 +5069 +5070 +5071 +5072 +5073 +5074 +5075 +5076 +5077 +5078 +5079 +5080 +5081 +5082 +5083 +5084 +5085 +5086 +5087 +5088 +5089 +5090 +5091 +5092 +5093 +5094 +5095 +5096 +5097 +5098 +5099 +5100 +5101 +5102 +5103 +5104 +5105 +5106 +5107 +5108 +5109 +5110 +5111 +5112 +5113 +5114 +5115 +5116 +5117 +5118 +5119 +5120 +5121 +5122 +5123 +5124 +5125 +5126 +5127 +5128 +5129 +5130 +5131 +5132 +5133 +5134 +5135 +5136 +5137 +5138 +5139 +5140 +5141 +5142 +5143 +5144 +5145 +5146 +5147 +5148 +5149 +5150 +5151 +5152 +5153 +5154 +5155 +5156 +5157 +5158 +5159 +5160 +5161 +5162 +5163 +5164 +5165 +5166 +5167 +5168 +5169 +5170 +5171 +5172 +5173 +5174 +5175 +5176 +5177 +5178 +5179 +5180 +5181 +5182 +5183 +5184 +5185 +5186 +5187 +5188 +5189 +5190 +5191 +5192 +5193 +5194 +5195 +5196 +5197 +5198 +5199 +5200 +5201 +5202 +5203 +5204 +5205 +5206 +5207 +5208 +5209 +5210 +5211 +5212 +5213 +5214 +5215 +5216 +5217 +5218 +5219 +5220 +5221 +5222 +5223 +5224 +5225 +5226 +5227 +5228 +5229 +5230 +5231 +5232 +5233 +5234 +5235 +5236 +5237 +5238 +5239 +5240 +5241 +5242 +5243 +5244 +5245 +5246 +5247 +5248 +5249 +5250 +5251 +5252 +5253 +5254 +5255 +5256 +5257 +5258 +5259 +5260 +5261 +5262 +5263 +5264 +5265 +5266 +5267 +5268 +5269 +5270 +5271 +5272 +5273 +5274 +5275 +5276 +5277 +5278 +5279 +5280 +5281 +5282 +5283 +5284 +5285 +5286 +5287 +5288 +5289 +5290 +5291 +5292 +5293 +5294 +5295 +5296 +5297 +5298 +5299 +5300 +5301 +5302 +5303 +5304 +5305 +5306 +5307 +5308 +5309 +5310 +5311 +5312 +5313 +5314 +5315 +5316 +5317 +5318 +5319 +5320 +5321 +5322 +5323 +5324 +5325 +5326 +5327 +5328 +5329 +5330 +5331 +5332 +5333 +5334 +5335 +5336 +5337 +5338 +5339 +5340 +5341 +5342 +5343 +5344 +5345 +5346 +5347 +5348 +5349 +5350 +5351 +5352 +5353 +5354 +5355 +5356 +5357 +5358 +5359 +5360 +5361 +5362 +5363 +5364 +5365 +5366 +5367 +5368 +5369 +5370 +5371 +5372 +5373 +5374 +5375 +5376 +5377 +5378 +5379 +5380 +5381 +5382 +5383 +5384 +5385 +5386 +5387 +5388 +5389 +5390 +5391 +5392 +5393 +5394 +5395 +5396 +5397 +5398 +5399 +5400 +5401 +5402 +5403 +5404 +5405 +5406 +5407 +5408 +5409 +5410 +5411 +5412 +5413 +5414 +5415 +5416 +5417 +5418 +5419 +5420 +5421 +5422 +5423 +5424 +5425 +5426 +5427 +5428 +5429 +5430 +5431 +5432 +5433 +5434 +5435 +5436 +5437 +5438 +5439 +5440 +5441 +5442 +5443 +5444 +5445 +5446 +5447 +5448 +5449 +5450 +5451 +5452 +5453 +5454 +5455 +5456 +5457 +5458 +5459 +5460 +5461 +5462 +5463 +5464 +5465 +5466 +5467 +5468 +5469 +5470 +5471 +5472 +5473 +5474 +5475 +5476 +5477 +5478 +5479 +5480 +5481 +5482 +5483 +5484 +5485 +5486 +5487 +5488 +5489 +5490 +5491 +5492 +5493 +5494 +5495 +5496 +5497 +5498 +5499 +5500 +5501 +5502 +5503 +5504 +5505 +5506 +5507 +5508 +5509 +5510 +5511 +5512 +5513 +5514 +5515 +5516 +5517 +5518 +5519 +5520 +5521 +5522 +5523 +5524 +5525 +5526 +5527 +5528 +5529 +5530 +5531 +5532 +5533 +5534 +5535 +5536 +5537 +5538 +5539 +5540 +5541 +5542 +5543 +5544 +5545 +5546 +5547 +5548 +5549 +5550 +5551 +5552 +5553 +5554 +5555 +5556 +5557 +5558 +5559 +5560 +5561 +5562 +5563 +5564 +5565 +5566 +5567 +5568 +5569 +5570 +5571 +5572 +5573 +5574 +5575 +5576 +5577 +5578 +5579 +5580 +5581 +5582 +5583 +5584 +5585 +5586 +5587 +5588 +5589 +5590 +5591 +5592 +5593 +5594 +5595 +5596 +5597 +5598 +5599 +5600 +5601 +5602 +5603 +5604 +5605 +5606 +5607 +5608 +5609 +5610 +5611 +5612 +5613 +5614 +5615 +5616 +5617 +5618 +5619 +5620 +5621 +5622 +5623 +5624 +5625 +5626 +5627 +5628 +5629 +5630 +5631 +5632 +5633 +5634 +5635 +5636 +5637 +5638 +5639 +5640 +5641 +5642 +5643 +5644 +5645 +5646 +5647 +5648 +5649 +5650 +5651 +5652 +5653 +5654 +5655 +5656 +5657 +5658 +5659 +5660 +5661 +5662 +5663 +5664 +5665 +5666 +5667 +5668 +5669 +5670 +5671 +5672 +5673 +5674 +5675 +5676 +5677 +5678 +5679 +5680 +5681 +5682 +5683 +5684 +5685 +5686 +5687 +5688 +5689 +5690 +5691 +5692 +5693 +5694 +5695 +5696 +5697 +5698 +5699 +5700 +5701 +5702 +5703 +5704 +5705 +5706 +5707 +5708 +5709 +5710 +5711 +5712 +5713 +5714 +5715 +5716 +5717 +5718 +5719 +5720 +5721 +5722 +5723 +5724 +5725 +5726 +5727 +5728 +5729 +5730 +5731 +5732 +5733 +5734 +5735 +5736 +5737 +5738 +5739 +5740 +5741 +5742 +5743 +5744 +5745 +5746 +5747 +5748 +5749 +5750 +5751 +5752 +5753 +5754 +5755 +5756 +5757 +5758 +5759 +5760 +5761 +5762 +5763 +5764 +5765 +5766 +5767 +5768 +5769 +5770 +5771 +5772 +5773 +5774 +5775 +5776 +5777 +5778 +5779 +5780 +5781 +5782 +5783 +5784 +5785 +5786 +5787 +5788 +5789 +5790 +5791 +5792 +5793 +5794 +5795 +5796 +5797 +5798 +5799 +5800 +5801 +5802 +5803 +5804 +5805 +5806 +5807 +5808 +5809 +5810 +5811 +5812 +5813 +5814 +5815 +5816 +5817 +5818 +5819 +5820 +5821 +5822 +5823 +5824 +5825 +5826 +5827 +5828 +5829 +5830 +5831 +5832 +5833 +5834 +5835 +5836 +5837 +5838 +5839 +5840 +5841 +5842 +5843 +5844 +5845 +5846 +5847 +5848 +5849 +5850 +5851 +5852 +5853 +5854 +5855 +5856 +5857 +5858 +5859 +5860 +5861 +5862 +5863 +5864 +5865 +5866 +5867 +5868 +5869 +5870 +5871 +5872 +5873 +5874 +5875 +5876 +5877 +5878 +5879 +5880 +5881 +5882 +5883 +5884 +5885 +5886 +5887 +5888 +5889 +5890 +5891 +5892 +5893 +5894 +5895 +5896 +5897 +5898 +5899 +5900 +5901 +5902 +5903 +5904 +5905 +5906 +5907 +5908 +5909 +5910 +5911 +5912 +5913 +5914 +5915 +5916 +5917 +5918 +5919 +5920 +5921 +5922 +5923 +5924 +5925 +5926 +5927 +5928 +5929 +5930 +5931 +5932 +5933 +5934 +5935 +5936 +5937 +5938 +5939 +5940 +5941 +5942 +5943 +5944 +5945 +5946 +5947 +5948 +5949 +5950 +5951 +5952 +5953 +5954 +5955 +5956 +5957 +5958 +5959 +5960 +5961 +5962 +5963 +5964 +5965 +5966 +5967 +5968 +5969 +5970 +5971 +5972 +5973 +5974 +5975 +5976 +5977 +5978 +5979 +5980 +5981 +5982 +5983 +5984 +5985 +5986 +5987 +5988 +5989 +5990 +5991 +5992 +5993 +5994 +5995 +5996 +5997 +5998 +5999 +6000 +6001 +6002 +6003 +6004 +6005 +6006 +6007 +6008 +6009 +6010 +6011 +6012 +6013 +6014 +6015 +6016 +6017 +6018 +6019 +6020 +6021 +6022 +6023 +6024 +6025 +6026 +6027 +6028 +6029 +6030 +6031 +6032 +6033 +6034 +6035 +6036 +6037 +6038 +6039 +6040 +6041 +6042 +6043 +6044 +6045 +6046 +6047 +6048 +6049 +6050 +6051 +6052 +6053 +6054 +6055 +6056 +6057 +6058 +6059 +6060 +6061 +6062 +6063 +6064 +6065 +6066 +6067 +6068 +6069 +6070 +6071 +6072 +6073 +6074 +6075 +6076 +6077 +6078 +6079 +6080 +6081 +6082 +6083 +6084 +6085 +6086 +6087 +6088 +6089 +6090 +6091 +6092 +6093 +6094 +6095 +6096 +6097 +6098 +6099 +6100 +6101 +6102 +6103 +6104 +6105 +6106 +6107 +6108 +6109 +6110 +6111 +6112 +6113 +6114 +6115 +6116 +6117 +6118 +6119 +6120 +6121 +6122 +6123 +6124 +6125 +6126 +6127 +6128 +6129 +6130 +6131 +6132 +6133 +6134 +6135 +6136 +6137 +6138 +6139 +6140 +6141 +6142 +6143 +6144 +6145 +6146 +6147 +6148 +6149 +6150 +6151 +6152 +6153 +6154 +6155 +6156 +6157 +6158 +6159 +6160 +6161 +6162 +6163 +6164 +6165 +6166 +6167 +6168 +6169 +6170 +6171 +6172 +6173 +6174 +6175 +6176 +6177 +6178 +6179 +6180 +6181 +6182 +6183 +6184 +6185 +6186 +6187 +6188 +6189 +6190 +6191 +6192 +6193 +6194 +6195 +6196 +6197 +6198 +6199 +6200 +6201 +6202 +6203 +6204 +6205 +6206 +6207 +6208 +6209 +6210 +6211 +6212 +6213 +6214 +6215 +6216 +6217 +6218 +6219 +6220 +6221 +6222 +6223 +6224 +6225 +6226 +6227 +6228 +6229 +6230 +6231 +6232 +6233 +6234 +6235 +6236 +6237 +6238 +6239 +6240 +6241 +6242 +6243 +6244 +6245 +6246 +6247 +6248 +6249 +6250 +6251 +6252 +6253 +6254 +6255 +6256 +6257 +6258 +6259 +6260 +6261 +6262 +6263 +6264 +6265 +6266 +6267 +6268 +6269 +6270 +6271 +6272 +6273 +6274 +6275 +6276 +6277 +6278 +6279 +6280 +6281 +6282 +6283 +6284 +6285 +6286 +6287 +6288 +6289 +6290 +6291 +6292 +6293 +6294 +6295 +6296 +6297 +6298 +6299 +6300 +6301 +6302 +6303 +6304 +6305 +6306 +6307 +6308 +6309 +6310 +6311 +6312 +6313 +6314 +6315 +6316 +6317 +6318 +6319 +6320 +6321 +6322 +6323 +6324 +6325 +6326 +6327 +6328 +6329 +6330 +6331 +6332 +6333 +6334 +6335 +6336 +6337 +6338 +6339 +6340 +6341 +6342 +6343 +6344 +6345 +6346 +6347 +6348 +6349 +6350 +6351 +6352 +6353 +6354 +6355 +6356 +6357 +6358 +6359 +6360 +6361 +6362 +6363 +6364 +6365 +6366 +6367 +6368 +6369 +6370 +6371 +6372 +6373 +6374 +6375 +6376 +6377 +6378 +6379 +6380 +6381 +6382 +6383 +6384 +6385 +6386 +6387 +6388 +6389 +6390 +6391 +6392 +6393 +6394 +6395 +6396 +6397 +6398 +6399 +6400 +6401 +6402 +6403 +6404 +6405 +6406 +6407 +6408 +6409 +6410 +6411 +6412 +6413 +6414 +6415 +6416 +6417 +6418 +6419 +6420 +6421 +6422 +6423 +6424 +6425 +6426 +6427 +6428 +6429 +6430 +6431 +6432 +6433 +6434 +6435 +6436 +6437 +6438 +6439 +6440 +6441 +6442 +6443 +6444 +6445 +6446 +6447 +6448 +6449 +6450 +6451 +6452 +6453 +6454 +6455 +6456 +6457 +6458 +6459 +6460 +6461 +6462 +6463 +6464 +6465 +6466 +6467 +6468 +6469 +6470 +6471 +6472 +6473 +6474 +6475 +6476 +6477 +6478 +6479 +6480 +6481 +6482 +6483 +6484 +6485 +6486 +6487 +6488 +6489 +6490 +6491 +6492 +6493 +6494 +6495 +6496 +6497 +6498 +6499 +6500 +6501 +6502 +6503 +6504 +6505 +6506 +6507 +6508 +6509 +6510 +6511 +6512 +6513 +6514 +6515 +6516 +6517 +6518 +6519 +6520 +6521 +6522 +6523 +6524 +6525 +6526 +6527 +6528 +6529 +6530 +6531 +6532 +6533 +6534 +6535 +6536 +6537 +6538 +6539 +6540 +6541 +6542 +6543 +6544 +6545 +6546 +6547 +6548 +6549 +6550 +6551 +6552 +6553 +6554 +6555 +6556 +6557 +6558 +6559 +6560 +6561 +6562 +6563 +6564 +6565 +6566 +6567 +6568 +6569 +6570 +6571 +6572 +6573 +6574 +6575 +6576 +6577 +6578 +6579 +6580 +6581 +6582 +6583 +6584 +6585 +6586 +6587 +6588 +6589 +6590 +6591 +6592 +6593 +6594 +6595 +6596 +6597 +6598 +6599 +6600 +6601 +6602 +6603 +6604 +6605 +6606 +6607 +6608 +6609 +6610 +6611 +6612 +6613 +6614 +6615 +6616 +6617 +6618 +6619 +6620 +6621 +6622 +6623 +6624 +6625 +6626 +6627 +6628 +6629 +6630 +6631 +6632 +6633 +6634 +6635 +6636 +6637 +6638 +6639 +6640 +6641 +6642 +6643 +6644 +6645 +6646 +6647 +6648 +6649 +6650 +6651 +6652 +6653 +6654 +6655 +6656 +6657 +6658 +6659 +6660 +6661 +6662 +6663 +6664 +6665 +6666 +6667 +6668 +6669 +6670 +6671 +6672 +6673 +6674 +6675 +6676 +6677 +6678 +6679 +6680 +6681 +6682 +6683 +6684 +6685 +6686 +6687 +6688 +6689 +6690 +6691 +6692 +6693 +6694 +6695 +6696 +6697 +6698 +6699 +6700 +6701 +6702 +6703 +6704 +6705 +6706 +6707 +6708 +6709 +6710 +6711 +6712 +6713 +6714 +6715 +6716 +6717 +6718 +6719 +6720 +6721 +6722 +6723 +6724 +6725 +6726 +6727 +6728 +6729 +6730 +6731 +6732 +6733 +6734 +6735 +6736 +6737 +6738 +6739 +6740 +6741 +6742 +6743 +6744 +6745 +6746 +6747 +6748 +6749 +6750 +6751 +6752 +6753 +6754 +6755 +6756 +6757 +6758 +6759 +6760 +6761 +6762 +6763 +6764 +6765 +6766 +6767 +6768 +6769 +6770 +6771 +6772 +6773 +6774 +6775 +6776 +6777 +6778 +6779 +6780 +6781 +6782 +6783 +6784 +6785 +6786 +6787 +6788 +6789 +6790 +6791 +6792 +6793 +6794 +6795 +6796 +6797 +6798 +6799 +6800 +6801 +6802 +6803 +6804 +6805 +6806 +6807 +6808 +6809 +6810 +6811 +6812 +6813 +6814 +6815 +6816 +6817 +6818 +6819 +6820 +6821 +6822 +6823 +6824 +6825 +6826 +6827 +6828 +6829 +6830 +6831 +6832 +6833 +6834 +6835 +6836 +6837 +6838 +6839 +6840 +6841 +6842 +6843 +6844 +6845 +6846 +6847 +6848 +6849 +6850 +6851 +6852 +6853 +6854 +6855 +6856 +6857 +6858 +6859 +6860 +6861 +6862 +6863 +6864 +6865 +6866 +6867 +6868 +6869 +6870 +6871 +6872 +6873 +6874 +6875 +6876 +6877 +6878 +6879 +6880 +6881 +6882 +6883 +6884 +6885 +6886 +6887 +6888 +6889 +6890 +6891 +6892 +6893 +6894 +6895 +6896 +6897 +6898 +6899 +6900 +6901 +6902 +6903 +6904 +6905 +6906 +6907 +6908 +6909 +6910 +6911 +6912 +6913 +6914 +6915 +6916 +6917 +6918 +6919 +6920 +6921 +6922 +6923 +6924 +6925 +6926 +6927 +6928 +6929 +6930 +6931 +6932 +6933 +6934 +6935 +6936 +6937 +6938 +6939 +6940 +6941 +6942 +6943 +6944 +6945 +6946 +6947 +6948 +6949 +6950 +6951 +6952 +6953 +6954 +6955 +6956 +6957 +6958 +6959 +6960 +6961 +6962 +6963 +6964 +6965 +6966 +6967 +6968 +6969 +6970 +6971 +6972 +6973 +6974 +6975 +6976 +6977 +6978 +6979 +6980 +6981 +6982 +6983 +6984 +6985 +6986 +6987 +6988 +6989 +6990 +6991 +6992 +6993 +6994 +6995 +6996 +6997 +6998 +6999 +7000 +7001 +7002 +7003 +7004 +7005 +7006 +7007 +7008 +7009 +7010 +7011 +7012 +7013 +7014 +7015 +7016 +7017 +7018 +7019 +7020 +7021 +7022 +7023 +7024 +7025 +7026 +7027 +7028 +7029 +7030 +7031 +7032 +7033 +7034 +7035 +7036 +7037 +7038 +7039 +7040 +7041 +7042 +7043 +7044 +7045 +7046 +7047 +7048 +7049 +7050 +7051 +7052 +7053 +7054 +7055 +7056 +7057 +7058 +7059 +7060 +7061 +7062 +7063 +7064 +7065 +7066 +7067 +7068 +7069 +7070 +7071 +7072 +7073 +7074 +7075 +7076 +7077 +7078 +7079 +7080 +7081 +7082 +7083 +7084 +7085 +7086 +7087 +7088 +7089 +7090 +7091 +7092 +7093 +7094 +7095 +7096 +7097 +7098 +7099 +7100 +7101 +7102 +7103 +7104 +7105 +7106 +7107 +7108 +7109 +7110 +7111 +7112 +7113 +7114 +7115 +7116 +7117 +7118 +7119 +7120 +7121 +7122 +7123 +7124 +7125 +7126 +7127 +7128 +7129 +7130 +7131 +7132 +7133 +7134 +7135 +7136 +7137 +7138 +7139 +7140 +7141 +7142 +7143 +7144 +7145 +7146 +7147 +7148 +7149 +7150 +7151 +7152 +7153 +7154 +7155 +7156 +7157 +7158 +7159 +7160 +7161 +7162 +7163 +7164 +7165 +7166 +7167 +7168 +7169 +7170 +7171 +7172 +7173 +7174 +7175 +7176 +7177 +7178 +7179 +7180 +7181 +7182 +7183 +7184 +7185 +7186 +7187 +7188 +7189 +7190 +7191 +7192 +7193 +7194 +7195 +7196 +7197 +7198 +7199 +7200 +7201 +7202 +7203 +7204 +7205 +7206 +7207 +7208 +7209 +7210 +7211 +7212 +7213 +7214 +7215 +7216 +7217 +7218 +7219 +7220 +7221 +7222 +7223 +7224 +7225 +7226 +7227 +7228 +7229 +7230 +7231 +7232 +7233 +7234 +7235 +7236 +7237 +7238 +7239 +7240 +7241 +7242 +7243 +7244 +7245 +7246 +7247 +7248 +7249 +7250 +7251 +7252 +7253 +7254 +7255 +7256 +7257 +7258 +7259 +7260 +7261 +7262 +7263 +7264 +7265 +7266 +7267 +7268 +7269 +7270 +7271 +7272 +7273 +7274 +7275 +7276 +7277 +7278 +7279 +7280 +7281 +7282 +7283 +7284 +7285 +7286 +7287 +7288 +7289 +7290 +7291 +7292 +7293 +7294 +7295 +7296 +7297 +7298 +7299 +7300 +7301 +7302 +7303 +7304 +7305 +7306 +7307 +7308 +7309 +7310 +7311 +7312 +7313 +7314 +7315 +7316 +7317 +7318 +7319 +7320 +7321 +7322 +7323 +7324 +7325 +7326 +7327 +7328 +7329 +7330 +7331 +7332 +7333 +7334 +7335 +7336 +7337 +7338 +7339 +7340 +7341 +7342 +7343 +7344 +7345 +7346 +7347 +7348 +7349 +7350 +7351 +7352 +7353 +7354 +7355 +7356 +7357 +7358 +7359 +7360 +7361 +7362 +7363 +7364 +7365 +7366 +7367 +7368 +7369 +7370 +7371 +7372 +7373 +7374 +7375 +7376 +7377 +7378 +7379 +7380 +7381 +7382 +7383 +7384 +7385 +7386 +7387 +7388 +7389 +7390 +7391 +7392 +7393 +7394 +7395 +7396 +7397 +7398 +7399 +7400 +7401 +7402 +7403 +7404 +7405 +7406 +7407 +7408 +7409 +7410 +7411 +7412 +7413 +7414 +7415 +7416 +7417 +7418 +7419 +7420 +7421 +7422 +7423 +7424 +7425 +7426 +7427 +7428 +7429 +7430 +7431 +7432 +7433 +7434 +7435 +7436 +7437 +7438 +7439 +7440 +7441 +7442 +7443 +7444 +7445 +7446 +7447 +7448 +7449 +7450 +7451 +7452 +7453 +7454 +7455 +7456 +7457 +7458 +7459 +7460 +7461 +7462 +7463 +7464 +7465 +7466 +7467 +7468 +7469 +7470 +7471 +7472 +7473 +7474 +7475 +7476 +7477 +7478 +7479 +7480 +7481 +7482 +7483 +7484 +7485 +7486 +7487 +7488 +7489 +7490 +7491 +7492 +7493 +7494 +7495 +7496 +7497 +7498 +7499 +7500 +7501 +7502 +7503 +7504 +7505 +7506 +7507 +7508 +7509 +7510 +7511 +7512 +7513 +7514 +7515 +7516 +7517 +7518 +7519 +7520 +7521 +7522 +7523 +7524 +7525 +7526 +7527 +7528 +7529 +7530 +7531 +7532 +7533 +7534 +7535 +7536 +7537 +7538 +7539 +7540 +7541 +7542 +7543 +7544 +7545 +7546 +7547 +7548 +7549 +7550 +7551 +7552 +7553 +7554 +7555 +7556 +7557 +7558 +7559 +7560 +7561 +7562 +7563 +7564 +7565 +7566 +7567 +7568 +7569 +7570 +7571 +7572 +7573 +7574 +7575 +7576 +7577 +7578 +7579 +7580 +7581 +7582 +7583 +7584 +7585 +7586 +7587 +7588 +7589 +7590 +7591 +7592 +7593 +7594 +7595 +7596 +7597 +7598 +7599 +7600 +7601 +7602 +7603 +7604 +7605 +7606 +7607 +7608 +7609 +7610 +7611 +7612 +7613 +7614 +7615 +7616 +7617 +7618 +7619 +7620 +7621 +7622 +7623 +7624 +7625 +7626 +7627 +7628 +7629 +7630 +7631 +7632 +7633 +7634 +7635 +7636 +7637 +7638 +7639 +7640 +7641 +7642 +7643 +7644 +7645 +7646 +7647 +7648 +7649 +7650 +7651 +7652 +7653 +7654 +7655 +7656 +7657 +7658 +7659 +7660 +7661 +7662 +7663 +7664 +7665 +7666 +7667 +7668 +7669 +7670 +7671 +7672 +7673 +7674 +7675 +7676 +7677 +7678 +7679 +7680 +7681 +7682 +7683 +7684 +7685 +7686 +7687 +7688 +7689 +7690 +7691 +7692 +7693 +7694 +7695 +7696 +7697 +7698 +7699 +7700 +7701 +7702 +7703 +7704 +7705 +7706 +7707 +7708 +7709 +7710 +7711 +7712 +7713 +7714 +7715 +7716 +7717 +7718 +7719 +7720 +7721 +7722 +7723 +7724 +7725 +7726 +7727 +7728 +7729 +7730 +7731 +7732 +7733 +7734 +7735 +7736 +7737 +7738 +7739 +7740 +7741 +7742 +7743 +7744 +7745 +7746 +7747 +7748 +7749 +7750 +7751 +7752 +7753 +7754 +7755 +7756 +7757 +7758 +7759 +7760 +7761 +7762 +7763 +7764 +7765 +7766 +7767 +7768 +7769 +7770 +7771 +7772 +7773 +7774 +7775 +7776 +7777 +7778 +7779 +7780 +7781 +7782 +7783 +7784 +7785 +7786 +7787 +7788 +7789 +7790 +7791 +7792 +7793 +7794 +7795 +7796 +7797 +7798 +7799 +7800 +7801 +7802 +7803 +7804 +7805 +7806 +7807 +7808 +7809 +7810 +7811 +7812 +7813 +7814 +7815 +7816 +7817 +7818 +7819 +7820 +7821 +7822 +7823 +7824 +7825 +7826 +7827 +7828 +7829 +7830 +7831 +7832 +7833 +7834 +7835 +7836 +7837 +7838 +7839 +7840 +7841 +7842 +7843 +7844 +7845 +7846 +7847 +7848 +7849 +7850 +7851 +7852 +7853 +7854 +7855 +7856 +7857 +7858 +7859 +7860 +7861 +7862 +7863 +7864 +7865 +7866 +7867 +7868 +7869 +7870 +7871 +7872 +7873 +7874 +7875 +7876 +7877 +7878 +7879 +7880 +7881 +7882 +7883 +7884 +7885 +7886 +7887 +7888 +7889 +7890 +7891 +7892 +7893 +7894 +7895 +7896 +7897 +7898 +7899 +7900 +7901 +7902 +7903 +7904 +7905 +7906 +7907 +7908 +7909 +7910 +7911 +7912 +7913 +7914 +7915 +7916 +7917 +7918 +7919 +7920 +7921 +7922 +7923 +7924 +7925 +7926 +7927 +7928 +7929 +7930 +7931 +7932 +7933 +7934 +7935 +7936 +7937 +7938 +7939 +7940 +7941 +7942 +7943 +7944 +7945 +7946 +7947 +7948 +7949 +7950 +7951 +7952 +7953 +7954 +7955 +7956 +7957 +7958 +7959 +7960 +7961 +7962 +7963 +7964 +7965 +7966 +7967 +7968 +7969 +7970 +7971 +7972 +7973 +7974 +7975 +7976 +7977 +7978 +7979 +7980 +7981 +7982 +7983 +7984 +7985 +7986 +7987 +7988 +7989 +7990 +7991 +7992 +7993 +7994 +7995 +7996 +7997 +7998 +7999 +8000 +8001 +8002 +8003 +8004 +8005 +8006 +8007 +8008 +8009 +8010 +8011 +8012 +8013 +8014 +8015 +8016 +8017 +8018 +8019 +8020 +8021 +8022 +8023 +8024 +8025 +8026 +8027 +8028 +8029 +8030 +8031 +8032 +8033 +8034 +8035 +8036 +8037 +8038 +8039 +8040 +8041 +8042 +8043 +8044 +8045 +8046 +8047 +8048 +8049 +8050 +8051 +8052 +8053 +8054 +8055 +8056 +8057 +8058 +8059 +8060 +8061 +8062 +8063 +8064 +8065 +8066 +8067 +8068 +8069 +8070 +8071 +8072 +8073 +8074 +8075 +8076 +8077 +8078 +8079 +8080 +8081 +8082 +8083 +8084 +8085 +8086 +8087 +8088 +8089 +8090 +8091 +8092 +8093 +8094 +8095 +8096 +8097 +8098 +8099 +8100 +8101 +8102 +8103 +8104 +8105 +8106 +8107 +8108 +8109 +8110 +8111 +8112 +8113 +8114 +8115 +8116 +8117 +8118 +8119 +8120 +8121 +8122 +8123 +8124 +8125 +8126 +8127 +8128 +8129 +8130 +8131 +8132 +8133 +8134 +8135 +8136 +8137 +8138 +8139 +8140 +8141 +8142 +8143 +8144 +8145 +8146 +8147 +8148 +8149 +8150 +8151 +8152 +8153 +8154 +8155 +8156 +8157 +8158 +8159 +8160 +8161 +8162 +8163 +8164 +8165 +8166 +8167 +8168 +8169 +8170 +8171 +8172 +8173 +8174 +8175 +8176 +8177 +8178 +8179 +8180 +8181 +8182 +8183 +8184 +8185 +8186 +8187 +8188 +8189 +8190 +8191 +8192 +8193 +8194 +8195 +8196 +8197 +8198 +8199 +8200 +8201 +8202 +8203 +8204 +8205 +8206 +8207 +8208 +8209 +8210 +8211 +8212 +8213 +8214 +8215 +8216 +8217 +8218 +8219 +8220 +8221 +8222 +8223 +8224 +8225 +8226 +8227 +8228 +8229 +8230 +8231 +8232 +8233 +8234 +8235 +8236 +8237 +8238 +8239 +8240 +8241 +8242 +8243 +8244 +8245 +8246 +8247 +8248 +8249 +8250 +8251 +8252 +8253 +8254 +8255 +8256 +8257 +8258 +8259 +8260 +8261 +8262 +8263 +8264 +8265 +8266 +8267 +8268 +8269 +8270 +8271 +8272 +8273 +8274 +8275 +8276 +8277 +8278 +8279 +8280 +8281 +8282 +8283 +8284 +8285 +8286 +8287 +8288 +8289 +8290 +8291 +8292 +8293 +8294 +8295 +8296 +8297 +8298 +8299 +8300 +8301 +8302 +8303 +8304 +8305 +8306 +8307 +8308 +8309 +8310 +8311 +8312 +8313 +8314 +8315 +8316 +8317 +8318 +8319 +8320 +8321 +8322 +8323 +8324 +8325 +8326 +8327 +8328 +8329 +8330 +8331 +8332 +8333 +8334 +8335 +8336 +8337 +8338 +8339 +8340 +8341 +8342 +8343 +8344 +8345 +8346 +8347 +8348 +8349 +8350 +8351 +8352 +8353 +8354 +8355 +8356 +8357 +8358 +8359 +8360 +8361 +8362 +8363 +8364 +8365 +8366 +8367 +8368 +8369 +8370 +8371 +8372 +8373 +8374 +8375 +8376 +8377 +8378 +8379 +8380 +8381 +8382 +8383 +8384 +8385 +8386 +8387 +8388 +8389 +8390 +8391 +8392 +8393 +8394 +8395 +8396 +8397 +8398 +8399 +8400 +8401 +8402 +8403 +8404 +8405 +8406 +8407 +8408 +8409 +8410 +8411 +8412 +8413 +8414 +8415 +8416 +8417 +8418 +8419 +8420 +8421 +8422 +8423 +8424 +8425 +8426 +8427 +8428 +8429 +8430 +8431 +8432 +8433 +8434 +8435 +8436 +8437 +8438 +8439 +8440 +8441 +8442 +8443 +8444 +8445 +8446 +8447 +8448 +8449 +8450 +8451 +8452 +8453 +8454 +8455 +8456 +8457 +8458 +8459 +8460 +8461 +8462 +8463 +8464 +8465 +8466 +8467 +8468 +8469 +8470 +8471 +8472 +8473 +8474 +8475 +8476 +8477 +8478 +8479 +8480 +8481 +8482 +8483 +8484 +8485 +8486 +8487 +8488 +8489 +8490 +8491 +8492 +8493 +8494 +8495 +8496 +8497 +8498 +8499 +8500 +8501 +8502 +8503 +8504 +8505 +8506 +8507 +8508 +8509 +8510 +8511 +8512 +8513 +8514 +8515 +8516 +8517 +8518 +8519 +8520 +8521 +8522 +8523 +8524 +8525 +8526 +8527 +8528 +8529 +8530 +8531 +8532 +8533 +8534 +8535 +8536 +8537 +8538 +8539 +8540 +8541 +8542 +8543 +8544 +8545 +8546 +8547 +8548 +8549 +8550 +8551 +8552 +8553 +8554 +8555 +8556 +8557 +8558 +8559 +8560 +8561 +8562 +8563 +8564 +8565 +8566 +8567 +8568 +8569 +8570 +8571 +8572 +8573 +8574 +8575 +8576 +8577 +8578 +8579 +8580 +8581 +8582 +8583 +8584 +8585 +8586 +8587 +8588 +8589 +8590 +8591 +8592 +8593 +8594 +8595 +8596 +8597 +8598 +8599 +8600 +8601 +8602 +8603 +8604 +8605 +8606 +8607 +8608 +8609 +8610 +8611 +8612 +8613 +8614 +8615 +8616 +8617 +8618 +8619 +8620 +8621 +8622 +8623 +8624 +8625 +8626 +8627 +8628 +8629 +8630 +8631 +8632 +8633 +8634 +8635 +8636 +8637 +8638 +8639 +8640 +8641 +8642 +8643 +8644 +8645 +8646 +8647 +8648 +8649 +8650 +8651 +8652 +8653 +8654 +8655 +8656 +8657 +8658 +8659 +8660 +8661 +8662 +8663 +8664 +8665 +8666 +8667 +8668 +8669 +8670 +8671 +8672 +8673 +8674 +8675 +8676 +8677 +8678 +8679 +8680 +8681 +8682 +8683 +8684 +8685 +8686 +8687 +8688 +8689 +8690 +8691 +8692 +8693 +8694 +8695 +8696 +8697 +8698 +8699 +8700 +8701 +8702 +8703 +8704 +8705 +8706 +8707 +8708 +8709 +8710 +8711 +8712 +8713 +8714 +8715 +8716 +8717 +8718 +8719 +8720 +8721 +8722 +8723 +8724 +8725 +8726 +8727 +8728 +8729 +8730 +8731 +8732 +8733 +8734 +8735 +8736 +8737 +8738 +8739 +8740 +8741 +8742 +8743 +8744 +8745 +8746 +8747 +8748 +8749 +8750 +8751 +8752 +8753 +8754 +8755 +8756 +8757 +8758 +8759 +8760 +8761 +8762 +8763 +8764 +8765 +8766 +8767 +8768 +8769 +8770 +8771 +8772 +8773 +8774 +8775 +8776 +8777 +8778 +8779 +8780 +8781 +8782 +8783 +8784 +8785 +8786 +8787 +8788 +8789 +8790 +8791 +8792 +8793 +8794 +8795 +8796 +8797 +8798 +8799 +8800 +8801 +8802 +8803 +8804 +8805 +8806 +8807 +8808 +8809 +8810 +8811 +8812 +8813 +8814 +8815 +8816 +8817 +8818 +8819 +8820 +8821 +8822 +8823 +8824 +8825 +8826 +8827 +8828 +8829 +8830 +8831 +8832 +8833 +8834 +8835 +8836 +8837 +8838 +8839 +8840 +8841 +8842 +8843 +8844 +8845 +8846 +8847 +8848 +8849 +8850 +8851 +8852 +8853 +8854 +8855 +8856 +8857 +8858 +8859 +8860 +8861 +8862 +8863 +8864 +8865 +8866 +8867 +8868 +8869 +8870 +8871 +8872 +8873 +8874 +8875 +8876 +8877 +8878 +8879 +8880 +8881 +8882 +8883 +8884 +8885 +8886 +8887 +8888 +8889 +8890 +8891 +8892 +8893 +8894 +8895 +8896 +8897 +8898 +8899 +8900 +8901 +8902 +8903 +8904 +8905 +8906 +8907 +8908 +8909 +8910 +8911 +8912 +8913 +8914 +8915 +8916 +8917 +8918 +8919 +8920 +8921 +8922 +8923 +8924 +8925 +8926 +8927 +8928 +8929 +8930 +8931 +8932 +8933 +8934 +8935 +8936 +8937 +8938 +8939 +8940 +8941 +8942 +8943 +8944 +8945 +8946 +8947 +8948 +8949 +8950 +8951 +8952 +8953 +8954 +8955 +8956 +8957 +8958 +8959 +8960 +8961 +8962 +8963 +8964 +8965 +8966 +8967 +8968 +8969 +8970 +8971 +8972 +8973 +8974 +8975 +8976 +8977 +8978 +8979 +8980 +8981 +8982 +8983 +8984 +8985 +8986 +8987 +8988 +8989 +8990 +8991 +8992 +8993 +8994 +8995 +8996 +8997 +8998 +8999 +9000 +9001 +9002 +9003 +9004 +9005 +9006 +9007 +9008 +9009 +9010 +9011 +9012 +9013 +9014 +9015 +9016 +9017 +9018 +9019 +9020 +9021 +9022 +9023 +9024 +9025 +9026 +9027 +9028 +9029 +9030 +9031 +9032 +9033 +9034 +9035 +9036 +9037 +9038 +9039 +9040 +9041 +9042 +9043 +9044 +9045 +9046 +9047 +9048 +9049 +9050 +9051 +9052 +9053 +9054 +9055 +9056 +9057 +9058 +9059 +9060 +9061 +9062 +9063 +9064 +9065 +9066 +9067 +9068 +9069 +9070 +9071 +9072 +9073 +9074 +9075 +9076 +9077 +9078 +9079 +9080 +9081 +9082 +9083 +9084 +9085 +9086 +9087 +9088 +9089 +9090 +9091 +9092 +9093 +9094 +9095 +9096 +9097 +9098 +9099 +9100 +9101 +9102 +9103 +9104 +9105 +9106 +9107 +9108 +9109 +9110 +9111 +9112 +9113 +9114 +9115 +9116 +9117 +9118 +9119 +9120 +9121 +9122 +9123 +9124 +9125 +9126 +9127 +9128 +9129 +9130 +9131 +9132 +9133 +9134 +9135 +9136 +9137 +9138 +9139 +9140 +9141 +9142 +9143 +9144 +9145 +9146 +9147 +9148 +9149 +9150 +9151 +9152 +9153 +9154 +9155 +9156 +9157 +9158 +9159 +9160 +9161 +9162 +9163 +9164 +9165 +9166 +9167 +9168 +9169 +9170 +9171 +9172 +9173 +9174 +9175 +9176 +9177 +9178 +9179 +9180 +9181 +9182 +9183 +9184 +9185 +9186 +9187 +9188 +9189 +9190 +9191 +9192 +9193 +9194 +9195 +9196 +9197 +9198 +9199 +9200 +9201 +9202 +9203 +9204 +9205 +9206 +9207 +9208 +9209 +9210 +9211 +9212 +9213 +9214 +9215 +9216 +9217 +9218 +9219 +9220 +9221 +9222 +9223 +9224 +9225 +9226 +9227 +9228 +9229 +9230 +9231 +9232 +9233 +9234 +9235 +9236 +9237 +9238 +9239 +9240 +9241 +9242 +9243 +9244 +9245 +9246 +9247 +9248 +9249 +9250 +9251 +9252 +9253 +9254 +9255 +9256 +9257 +9258 +9259 +9260 +9261 +9262 +9263 +9264 +9265 +9266 +9267 +9268 +9269 +9270 +9271 +9272 +9273 +9274 +9275 +9276 +9277 +9278 +9279 +9280 +9281 +9282 +9283 +9284 +9285 +9286 +9287 +9288 +9289 +9290 +9291 +9292 +9293 +9294 +9295 +9296 +9297 +9298 +9299 +9300 +9301 +9302 +9303 +9304 +9305 +9306 +9307 +9308 +9309 +9310 +9311 +9312 +9313 +9314 +9315 +9316 +9317 +9318 +9319 +9320 +9321 +9322 +9323 +9324 +9325 +9326 +9327 +9328 +9329 +9330 +9331 +9332 +9333 +9334 +9335 +9336 +9337 +9338 +9339 +9340 +9341 +9342 +9343 +9344 +9345 +9346 +9347 +9348 +9349 +9350 +9351 +9352 +9353 +9354 +9355 +9356 +9357 +9358 +9359 +9360 +9361 +9362 +9363 +9364 +9365 +9366 +9367 +9368 +9369 +9370 +9371 +9372 +9373 +9374 +9375 +9376 +9377 +9378 +9379 +9380 +9381 +9382 +9383 +9384 +9385 +9386 +9387 +9388 +9389 +9390 +9391 +9392 +9393 +9394 +9395 +9396 +9397 +9398 +9399 +9400 +9401 +9402 +9403 +9404 +9405 +9406 +9407 +9408 +9409 +9410 +9411 +9412 +9413 +9414 +9415 +9416 +9417 +9418 +9419 +9420 +9421 +9422 +9423 +9424 +9425 +9426 +9427 +9428 +9429 +9430 +9431 +9432 +9433 +9434 +9435 +9436 +9437 +9438 +9439 +9440 +9441 +9442 +9443 +9444 +9445 +9446 +9447 +9448 +9449 +9450 +9451 +9452 +9453 +9454 +9455 +9456 +9457 +9458 +9459 +9460 +9461 +9462 +9463 +9464 +9465 +9466 +9467 +9468 +9469 +9470 +9471 +9472 +9473 +9474 +9475 +9476 +9477 +9478 +9479 +9480 +9481 +9482 +9483 +9484 +9485 +9486 +9487 +9488 +9489 +9490 +9491 +9492 +9493 +9494 +9495 +9496 +9497 +9498 +9499 +9500 +9501 +9502 +9503 +9504 +9505 +9506 +9507 +9508 +9509 +9510 +9511 +9512 +9513 +9514 +9515 +9516 +9517 +9518 +9519 +9520 +9521 +9522 +9523 +9524 +9525 +9526 +9527 +9528 +9529 +9530 +9531 +9532 +9533 +9534 +9535 +9536 +9537 +9538 +9539 +9540 +9541 +9542 +9543 +9544 +9545 +9546 +9547 +9548 +9549 +9550 +9551 +9552 +9553 +9554 +9555 +9556 +9557 +9558 +9559 +9560 +9561 +9562 +9563 +9564 +9565 +9566 +9567 +9568 +9569 +9570 +9571 +9572 +9573 +9574 +9575 +9576 +9577 +9578 +9579 +9580 +9581 +9582 +9583 +9584 +9585 +9586 +9587 +9588 +9589 +9590 +9591 +9592 +9593 +9594 +9595 +9596 +9597 +9598 +9599 +9600 +9601 +9602 +9603 +9604 +9605 +9606 +9607 +9608 +9609 +9610 +9611 +9612 +9613 +9614 +9615 +9616 +9617 +9618 +9619 +9620 +9621 +9622 +9623 +9624 +9625 +9626 +9627 +9628 +9629 +9630 +9631 +9632 +9633 +9634 +9635 +9636 +9637 +9638 +9639 +9640 +9641 +9642 +9643 +9644 +9645 +9646 +9647 +9648 +9649 +9650 +9651 +9652 +9653 +9654 +9655 +9656 +9657 +9658 +9659 +9660 +9661 +9662 +9663 +9664 +9665 +9666 +9667 +9668 +9669 +9670 +9671 +9672 +9673 +9674 +9675 +9676 +9677 +9678 +9679 +9680 +9681 +9682 +9683 +9684 +9685 +9686 +9687 +9688 +9689 +9690 +9691 +9692 +9693 +9694 +9695 +9696 +9697 +9698 +9699 +9700 +9701 +9702 +9703 +9704 +9705 +9706 +9707 +9708 +9709 +9710 +9711 +9712 +9713 +9714 +9715 +9716 +9717 +9718 +9719 +9720 +9721 +9722 +9723 +9724 +9725 +9726 +9727 +9728 +9729 +9730 +9731 +9732 +9733 +9734 +9735 +9736 +9737 +9738 +9739 +9740 +9741 +9742 +9743 +9744 +9745 +9746 +9747 +9748 +9749 +9750 +9751 +9752 +9753 +9754 +9755 +9756 +9757 +9758 +9759 +9760 +9761 +9762 +9763 +9764 +9765 +9766 +9767 +9768 +9769 +9770 +9771 +9772 +9773 +9774 +9775 +9776 +9777 +9778 +9779 +9780 +9781 +9782 +9783 +9784 +9785 +9786 +9787 +9788 +9789 +9790 +9791 +9792 +9793 +9794 +9795 +9796 +9797 +9798 +9799 +9800 +9801 +9802 +9803 +9804 +9805 +9806 +9807 +9808 +9809 +9810 +9811 +9812 +9813 +9814 +9815 +9816 +9817 +9818 +9819 +9820 +9821 +9822 +9823 +9824 +9825 +9826 +9827 +9828 +9829 +9830 +9831 +9832 +9833 +9834 +9835 +9836 +9837 +9838 +9839 +9840 +9841 +9842 +9843 +9844 +9845 +9846 +9847 +9848 +9849 +9850 +9851 +9852 +9853 +9854 +9855 +9856 +9857 +9858 +9859 +9860 +9861 +9862 +9863 +9864 +9865 +9866 +9867 +9868 +9869 +9870 +9871 +9872 +9873 +9874 +9875 +9876 +9877 +9878 +9879 +9880 +9881 +9882 +9883 +9884 +9885 +9886 +9887 +9888 +9889 +9890 +9891 +9892 +9893 +9894 +9895 +9896 +9897 +9898 +9899 +9900 +9901 +9902 +9903 +9904 +9905 +9906 +9907 +9908 +9909 +9910 +9911 +9912 +9913 +9914 +9915 +9916 +9917 +9918 +9919 +9920 +9921 +9922 +9923 +9924 +9925 +9926 +9927 +9928 +9929 +9930 +9931 +9932 +9933 +9934 +9935 +9936 +9937 +9938 +9939 +9940 +9941 +9942 +9943 +9944 +9945 +9946 +9947 +9948 +9949 +9950 +9951 +9952 +9953 +9954 +9955 +9956 +9957 +9958 +9959 +9960 +9961 +9962 +9963 +9964 +9965 +9966 +9967 +9968 +9969 +9970 +9971 +9972 +9973 +9974 +9975 +9976 +9977 +9978 +9979 +9980 +9981 +9982 +9983 +9984 +9985 +9986 +9987 +9988 +9989 +9990 +9991 +9992 +9993 +9994 +9995 +9996 +9997 +9998 +9999 diff --git a/core-java-jvm/README.md b/core-java-modules/core-java-jvm/README.md similarity index 100% rename from core-java-jvm/README.md rename to core-java-modules/core-java-jvm/README.md diff --git a/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml similarity index 96% rename from core-java-jvm/pom.xml rename to core-java-modules/core-java-jvm/pom.xml index 752b26f03f..6c700cd005 100644 --- a/core-java-jvm/pom.xml +++ b/core-java-modules/core-java-jvm/pom.xml @@ -11,6 +11,7 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT + ../../ diff --git a/core-java-jvm/src/main/java/com/baeldung/inlining/ConsecutiveNumbersSum.java b/core-java-modules/core-java-jvm/src/main/java/com/baeldung/inlining/ConsecutiveNumbersSum.java similarity index 100% rename from core-java-jvm/src/main/java/com/baeldung/inlining/ConsecutiveNumbersSum.java rename to core-java-modules/core-java-jvm/src/main/java/com/baeldung/inlining/ConsecutiveNumbersSum.java diff --git a/core-java-jvm/src/main/java/com/baeldung/inlining/InliningExample.java b/core-java-modules/core-java-jvm/src/main/java/com/baeldung/inlining/InliningExample.java similarity index 100% rename from core-java-jvm/src/main/java/com/baeldung/inlining/InliningExample.java rename to core-java-modules/core-java-jvm/src/main/java/com/baeldung/inlining/InliningExample.java diff --git a/core-java-jvm/src/test/java/com/baeldung/inlining/ConsecutiveNumbersSumUnitTest.java b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/inlining/ConsecutiveNumbersSumUnitTest.java similarity index 100% rename from core-java-jvm/src/test/java/com/baeldung/inlining/ConsecutiveNumbersSumUnitTest.java rename to core-java-modules/core-java-jvm/src/test/java/com/baeldung/inlining/ConsecutiveNumbersSumUnitTest.java diff --git a/core-java-lambdas/pom.xml b/core-java-modules/core-java-lambdas/pom.xml similarity index 91% rename from core-java-lambdas/pom.xml rename to core-java-modules/core-java-lambdas/pom.xml index 25538a3524..d6158c2946 100644 --- a/core-java-lambdas/pom.xml +++ b/core-java-modules/core-java-lambdas/pom.xml @@ -12,7 +12,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-lambdas/src/main/java/com/baeldung/lambdas/LambdaVariables.java b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/lambdas/LambdaVariables.java similarity index 100% rename from core-java-lambdas/src/main/java/com/baeldung/lambdas/LambdaVariables.java rename to core-java-modules/core-java-lambdas/src/main/java/com/baeldung/lambdas/LambdaVariables.java diff --git a/core-java-lang-oop-2/.gitignore b/core-java-modules/core-java-lang-oop-2/.gitignore similarity index 100% rename from core-java-lang-oop-2/.gitignore rename to core-java-modules/core-java-lang-oop-2/.gitignore diff --git a/core-java-modules/core-java-lang-oop-2/README.md b/core-java-modules/core-java-lang-oop-2/README.md new file mode 100644 index 0000000000..af0aed5af3 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-2/README.md @@ -0,0 +1,6 @@ +========= + +## Core Java Lang OOP 2 Cookbooks and Examples + +### Relevant Articles: +- [Generic Constructors in Java](https://www.baeldung.com/java-generic-constructors) diff --git a/core-java-lang-oop-2/pom.xml b/core-java-modules/core-java-lang-oop-2/pom.xml similarity index 94% rename from core-java-lang-oop-2/pom.xml rename to core-java-modules/core-java-lang-oop-2/pom.xml index 3faf9fe6ee..669a37b0f5 100644 --- a/core-java-lang-oop-2/pom.xml +++ b/core-java-modules/core-java-lang-oop-2/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-8-2/src/main/java/com/baeldung/anonymous/Book.java b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/anonymous/Book.java similarity index 100% rename from core-java-8-2/src/main/java/com/baeldung/anonymous/Book.java rename to core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/anonymous/Book.java diff --git a/core-java-8-2/src/main/java/com/baeldung/anonymous/Main.java b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/anonymous/Main.java similarity index 100% rename from core-java-8-2/src/main/java/com/baeldung/anonymous/Main.java rename to core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/anonymous/Main.java diff --git a/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Entry.java b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Entry.java new file mode 100644 index 0000000000..07759ca9ba --- /dev/null +++ b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Entry.java @@ -0,0 +1,38 @@ +package com.baeldung.generics; + +import java.io.Serializable; + +public class Entry { + private String data; + private int rank; + + // non-generic constructor + public Entry(String data, int rank) { + this.data = data; + this.rank = rank; + } + + // generic constructor + public Entry(E element) { + this.data = element.toString(); + this.rank = element.getRank(); + } + + // getters and setters + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public int getRank() { + return rank; + } + + public void setRank(int rank) { + this.rank = rank; + } + +} diff --git a/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/GenericEntry.java b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/GenericEntry.java new file mode 100644 index 0000000000..27d3a44069 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/GenericEntry.java @@ -0,0 +1,53 @@ +package com.baeldung.generics; + +import java.io.Serializable; +import java.util.Optional; + +public class GenericEntry { + private T data; + private int rank; + + // non-generic constructor + public GenericEntry(int rank) { + this.rank = rank; + } + + // generic constructor + public GenericEntry(T data, int rank) { + this.data = data; + this.rank = rank; + } + + // generic constructor with different type + public GenericEntry(E element) { + this.data = (T) element; + this.rank = element.getRank(); + } + + // generic constructor with different type and wild card + public GenericEntry(Optional optional) { + if (optional.isPresent()) { + this.data = (T) optional.get(); + this.rank = optional.get() + .getRank(); + } + } + + // getters and setters + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } + + public int getRank() { + return rank; + } + + public void setRank(int rank) { + this.rank = rank; + } + +} diff --git a/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/MapEntry.java b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/MapEntry.java new file mode 100644 index 0000000000..3d626b2fa5 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/MapEntry.java @@ -0,0 +1,34 @@ +package com.baeldung.generics; + +public class MapEntry { + private K key; + private V value; + + public MapEntry() { + super(); + } + + // generic constructor with two parameters + public MapEntry(K key, V value) { + this.key = key; + this.value = value; + } + + // getters and setters + public K getKey() { + return key; + } + + public void setKey(K key) { + this.key = key; + } + + public V getValue() { + return value; + } + + public void setValue(V value) { + this.value = value; + } + +} diff --git a/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Product.java b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Product.java new file mode 100644 index 0000000000..bfc9f63071 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Product.java @@ -0,0 +1,50 @@ +package com.baeldung.generics; + +import java.io.Serializable; + +public class Product implements Rankable, Serializable { + private String name; + private double price; + private int sales; + + public Product(String name, double price) { + this.name = name; + this.price = price; + } + + @Override + public int getRank() { + return sales; + } + + @Override + public String toString() { + return "Product [name=" + name + ", price=" + price + ", sales=" + sales + "]"; + } + + // getters and setters + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public int getSales() { + return sales; + } + + public void setSales(int sales) { + this.sales = sales; + } + +} diff --git a/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Rankable.java b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Rankable.java new file mode 100644 index 0000000000..72bda67d9d --- /dev/null +++ b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Rankable.java @@ -0,0 +1,5 @@ +package com.baeldung.generics; + +public interface Rankable { + public int getRank(); +} diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClass.java b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClass.java similarity index 100% rename from core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClass.java rename to core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClass.java diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution1.java b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution1.java similarity index 100% rename from core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution1.java rename to core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution1.java diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution2.java b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution2.java similarity index 100% rename from core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution2.java rename to core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution2.java diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution3.java b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution3.java similarity index 100% rename from core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution3.java rename to core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution3.java diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyException.java b/core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyException.java similarity index 100% rename from core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyException.java rename to core-java-modules/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyException.java diff --git a/core-java-modules/core-java-lang-oop-2/src/test/java/com/baeldung/generics/GenericConstructorUnitTest.java b/core-java-modules/core-java-lang-oop-2/src/test/java/com/baeldung/generics/GenericConstructorUnitTest.java new file mode 100644 index 0000000000..60907bbfd3 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-2/src/test/java/com/baeldung/generics/GenericConstructorUnitTest.java @@ -0,0 +1,76 @@ +package com.baeldung.generics; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.io.Serializable; +import java.util.Optional; + +import org.junit.Test; + +public class GenericConstructorUnitTest { + + @Test + public void givenNonGenericConstructor_whenCreateNonGenericEntry_thenOK() { + Entry entry = new Entry("sample", 1); + + assertEquals("sample", entry.getData()); + assertEquals(1, entry.getRank()); + } + + @Test + public void givenGenericConstructor_whenCreateNonGenericEntry_thenOK() { + Product product = new Product("milk", 2.5); + product.setSales(30); + Entry entry = new Entry(product); + + assertEquals(product.toString(), entry.getData()); + assertEquals(30, entry.getRank()); + } + + @Test + public void givenNonGenericConstructor_whenCreateGenericEntry_thenOK() { + GenericEntry entry = new GenericEntry(1); + + assertNull(entry.getData()); + assertEquals(1, entry.getRank()); + } + + @Test + public void givenGenericConstructor_whenCreateGenericEntry_thenOK() { + GenericEntry entry = new GenericEntry("sample", 1); + + assertEquals("sample", entry.getData()); + assertEquals(1, entry.getRank()); + } + + @Test + public void givenGenericConstructorWithDifferentType_whenCreateGenericEntry_thenOK() { + Product product = new Product("milk", 2.5); + product.setSales(30); + GenericEntry entry = new GenericEntry(product); + + assertEquals(product, entry.getData()); + assertEquals(30, entry.getRank()); + } + + @Test + public void givenGenericConstructorWithWildCard_whenCreateGenericEntry_thenOK() { + Product product = new Product("milk", 2.5); + product.setSales(30); + Optional optional = Optional.of(product); + GenericEntry entry = new GenericEntry(optional); + + assertEquals(product, entry.getData()); + assertEquals(30, entry.getRank()); + } + + @Test + public void givenGenericConstructor_whenCreateGenericEntryWithTwoTypes_thenOK() { + MapEntry entry = new MapEntry("sample", 1); + + assertEquals("sample", entry.getKey()); + assertEquals(1, entry.getValue() + .intValue()); + } +} diff --git a/core-java-lang-oop/.gitignore b/core-java-modules/core-java-lang-oop/.gitignore similarity index 100% rename from core-java-lang-oop/.gitignore rename to core-java-modules/core-java-lang-oop/.gitignore diff --git a/core-java-lang-oop/README.md b/core-java-modules/core-java-lang-oop/README.md similarity index 100% rename from core-java-lang-oop/README.md rename to core-java-modules/core-java-lang-oop/README.md diff --git a/core-java-lang-oop/pom.xml b/core-java-modules/core-java-lang-oop/pom.xml similarity index 98% rename from core-java-lang-oop/pom.xml rename to core-java-modules/core-java-lang-oop/pom.xml index 6763bbb26d..c9bb3b3e5a 100644 --- a/core-java-lang-oop/pom.xml +++ b/core-java-modules/core-java-lang-oop/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/Public.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/Public.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/Public.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/Public.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/SubClass.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/SubClass.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/SubClass.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/SubClass.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/SuperPublic.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/SuperPublic.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/SuperPublic.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/SuperPublic.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/another/AnotherPublic.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/another/AnotherPublic.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/another/AnotherPublic.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/another/AnotherPublic.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/another/AnotherSubClass.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/another/AnotherSubClass.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/another/AnotherSubClass.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/another/AnotherSubClass.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/another/AnotherSuperPublic.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/another/AnotherSuperPublic.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/another/AnotherSuperPublic.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/accessmodifiers/another/AnotherSuperPublic.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/casting/Animal.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/casting/Animal.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/casting/Animal.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/casting/Animal.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/casting/AnimalFeeder.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/casting/AnimalFeeder.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/casting/AnimalFeeder.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/casting/AnimalFeeder.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/casting/AnimalFeederGeneric.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/casting/AnimalFeederGeneric.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/casting/AnimalFeederGeneric.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/casting/AnimalFeederGeneric.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/casting/Cat.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/casting/Cat.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/casting/Cat.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/casting/Cat.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/casting/Dog.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/casting/Dog.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/casting/Dog.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/casting/Dog.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/casting/Mew.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/casting/Mew.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/casting/Mew.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/casting/Mew.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/constructors/BankAccount.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/constructors/BankAccount.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/constructors/BankAccount.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/constructors/BankAccount.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/constructors/Transaction.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/constructors/Transaction.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/constructors/Transaction.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/constructors/Transaction.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/deepcopy/Address.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/deepcopy/Address.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/deepcopy/Address.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/deepcopy/Address.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/deepcopy/User.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/deepcopy/User.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/deepcopy/User.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/deepcopy/User.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/Money.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/Money.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/Money.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/Money.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/Team.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/Team.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/Team.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/Team.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/Voucher.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/Voucher.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/Voucher.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/Voucher.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/WrongTeam.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/WrongTeam.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/WrongTeam.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/WrongTeam.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/WrongVoucher.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/WrongVoucher.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/WrongVoucher.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/WrongVoucher.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/ComplexClass.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/ComplexClass.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/ComplexClass.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/ComplexClass.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/PrimitiveClass.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/PrimitiveClass.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/PrimitiveClass.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/PrimitiveClass.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/Rectangle.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/Rectangle.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/Rectangle.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/Rectangle.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/Shape.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/Shape.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/Shape.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/Shape.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/Square.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/Square.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/Square.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/equalshashcode/entities/Square.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/BlackCat.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/BlackCat.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/BlackCat.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/BlackCat.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/BlackDog.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/BlackDog.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/BlackDog.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/BlackDog.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/Cat.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/Cat.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/Cat.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/Cat.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/Dog.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/Dog.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/Dog.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/finalkeyword/Dog.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/hashcode/entities/User.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/hashcode/entities/User.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/hashcode/entities/User.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/hashcode/entities/User.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/immutableobjects/Currency.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/immutableobjects/Currency.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/immutableobjects/Currency.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/immutableobjects/Currency.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/immutableobjects/Money.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/immutableobjects/Money.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/immutableobjects/Money.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/immutableobjects/Money.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/ArmoredCar.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/ArmoredCar.java similarity index 96% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritance/ArmoredCar.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/ArmoredCar.java index b6bb5181b8..ad654ba31a 100644 --- a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/ArmoredCar.java +++ b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/ArmoredCar.java @@ -1,43 +1,43 @@ -package com.baeldung.inheritance; - -public class ArmoredCar extends Car implements Floatable, Flyable{ - private int bulletProofWindows; - private String model; - - public void remoteStartCar() { - // this vehicle can be started by using a remote control - } - - public String registerModel() { - return model; - } - - public String getAValue() { - return super.model; // returns value of model defined in base class Car - // return this.model; // will return value of model defined in ArmoredCar - // return model; // will return value of model defined in ArmoredCar - } - - public static String msg() { - // return super.msg(); // this won't compile. - return "ArmoredCar"; - } - - @Override - public void floatOnWater() { - System.out.println("I can float!"); - } - - @Override - public void fly() { - System.out.println("I can fly!"); - } - - public void aMethod() { - // System.out.println(duration); // Won't compile - System.out.println(Floatable.duration); // outputs 10 - System.out.println(Flyable.duration); // outputs 20 - } - - -} +package com.baeldung.inheritance; + +public class ArmoredCar extends Car implements Floatable, Flyable{ + private int bulletProofWindows; + private String model; + + public void remoteStartCar() { + // this vehicle can be started by using a remote control + } + + public String registerModel() { + return model; + } + + public String getAValue() { + return super.model; // returns value of model defined in base class Car + // return this.model; // will return value of model defined in ArmoredCar + // return model; // will return value of model defined in ArmoredCar + } + + public static String msg() { + // return super.msg(); // this won't compile. + return "ArmoredCar"; + } + + @Override + public void floatOnWater() { + System.out.println("I can float!"); + } + + @Override + public void fly() { + System.out.println("I can fly!"); + } + + public void aMethod() { + // System.out.println(duration); // Won't compile + System.out.println(Floatable.duration); // outputs 10 + System.out.println(Flyable.duration); // outputs 20 + } + + +} diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/BMW.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/BMW.java similarity index 93% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritance/BMW.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/BMW.java index 8ad3bb683f..8eb6198203 100644 --- a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/BMW.java +++ b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/BMW.java @@ -1,12 +1,12 @@ -package com.baeldung.inheritance; - -public class BMW extends Car { - public BMW() { - super(5, "BMW"); - } - - @Override - public String toString() { - return model; - } -} +package com.baeldung.inheritance; + +public class BMW extends Car { + public BMW() { + super(5, "BMW"); + } + + @Override + public String toString() { + return model; + } +} diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Car.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Car.java similarity index 95% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritance/Car.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Car.java index 21ea9ea569..ddb06dcf08 100644 --- a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Car.java +++ b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Car.java @@ -1,32 +1,32 @@ -package com.baeldung.inheritance; - -public class Car { - private final int DEFAULT_WHEEL_COUNT = 5; - private final String DEFAULT_MODEL = "Basic"; - - protected int wheels; - protected String model; - - public Car() { - this.wheels = DEFAULT_WHEEL_COUNT; - this.model = DEFAULT_MODEL; - } - - public Car(int wheels, String model) { - this.wheels = wheels; - this.model = model; - } - - public void start() { - // Check essential parts - // If okay, start. - } - public static int count = 10; - public static String msg() { - return "Car"; - } - - public String toString() { - return model; - } +package com.baeldung.inheritance; + +public class Car { + private final int DEFAULT_WHEEL_COUNT = 5; + private final String DEFAULT_MODEL = "Basic"; + + protected int wheels; + protected String model; + + public Car() { + this.wheels = DEFAULT_WHEEL_COUNT; + this.model = DEFAULT_MODEL; + } + + public Car(int wheels, String model) { + this.wheels = wheels; + this.model = model; + } + + public void start() { + // Check essential parts + // If okay, start. + } + public static int count = 10; + public static String msg() { + return "Car"; + } + + public String toString() { + return model; + } } \ No newline at end of file diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Employee.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Employee.java similarity index 94% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritance/Employee.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Employee.java index 599a1d7331..9018382087 100644 --- a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Employee.java +++ b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Employee.java @@ -1,15 +1,15 @@ -package com.baeldung.inheritance; - -public class Employee { - private String name; - private Car car; - - public Employee(String name, Car car) { - this.name = name; - this.car = car; - } - - public Car getCar() { - return car; - } +package com.baeldung.inheritance; + +public class Employee { + private String name; + private Car car; + + public Employee(String name, Car car) { + this.name = name; + this.car = car; + } + + public Car getCar() { + return car; + } } \ No newline at end of file diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Floatable.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Floatable.java similarity index 95% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritance/Floatable.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Floatable.java index c0b456dffb..b90163487a 100644 --- a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Floatable.java +++ b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Floatable.java @@ -1,10 +1,10 @@ -package com.baeldung.inheritance; - -public interface Floatable { - int duration = 10; - void floatOnWater(); - - default void repair() { - System.out.println("Repairing Floatable object"); - } -} +package com.baeldung.inheritance; + +public interface Floatable { + int duration = 10; + void floatOnWater(); + + default void repair() { + System.out.println("Repairing Floatable object"); + } +} diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Flyable.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Flyable.java similarity index 94% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritance/Flyable.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Flyable.java index cb8244cf5b..a25ce6f91b 100644 --- a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Flyable.java +++ b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/Flyable.java @@ -1,13 +1,13 @@ -package com.baeldung.inheritance; - -public interface Flyable { - int duration = 10; - void fly(); - - /* - * Commented - */ - //default void repair() { - // System.out.println("Repairing Flyable object"); - //} -} +package com.baeldung.inheritance; + +public interface Flyable { + int duration = 10; + void fly(); + + /* + * Commented + */ + //default void repair() { + // System.out.println("Repairing Flyable object"); + //} +} diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/SpaceCar.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/SpaceCar.java similarity index 95% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritance/SpaceCar.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/SpaceCar.java index 8c23b26da9..76a44411db 100644 --- a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/SpaceCar.java +++ b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/SpaceCar.java @@ -1,18 +1,18 @@ -package com.baeldung.inheritance; - -public class SpaceCar extends Car implements SpaceTraveller { - @Override - public void floatOnWater() { - System.out.println("SpaceCar floating!"); - } - - @Override - public void fly() { - System.out.println("SpaceCar flying!"); - } - - @Override - public void remoteControl() { - System.out.println("SpaceCar being controlled remotely!"); - } -} +package com.baeldung.inheritance; + +public class SpaceCar extends Car implements SpaceTraveller { + @Override + public void floatOnWater() { + System.out.println("SpaceCar floating!"); + } + + @Override + public void fly() { + System.out.println("SpaceCar flying!"); + } + + @Override + public void remoteControl() { + System.out.println("SpaceCar being controlled remotely!"); + } +} diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/SpaceTraveller.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/SpaceTraveller.java similarity index 96% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritance/SpaceTraveller.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/SpaceTraveller.java index 9b66441791..3a473af093 100644 --- a/core-java-lang-oop/src/main/java/com/baeldung/inheritance/SpaceTraveller.java +++ b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritance/SpaceTraveller.java @@ -1,6 +1,6 @@ -package com.baeldung.inheritance; - -public interface SpaceTraveller extends Floatable, Flyable { - int duration = 10; - void remoteControl(); +package com.baeldung.inheritance; + +public interface SpaceTraveller extends Floatable, Flyable { + int duration = 10; + void remoteControl(); } \ No newline at end of file diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/application/Application.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/application/Application.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/application/Application.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/application/Application.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Actress.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Actress.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Actress.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Actress.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Computer.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Computer.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Computer.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Computer.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Memory.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Memory.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Memory.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Memory.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Person.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Person.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Person.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Person.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Processor.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Processor.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Processor.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Processor.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/SoundCard.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/SoundCard.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/SoundCard.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/SoundCard.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/StandardMemory.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/StandardMemory.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/StandardMemory.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/StandardMemory.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/StandardProcessor.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/StandardProcessor.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/StandardProcessor.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/StandardProcessor.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/StandardSoundCard.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/StandardSoundCard.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/StandardSoundCard.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/StandardSoundCard.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Waitress.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Waitress.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Waitress.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/inheritancecomposition/model/Waitress.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/initializationguide/User.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/initializationguide/User.java similarity index 94% rename from core-java-lang-oop/src/main/java/com/baeldung/initializationguide/User.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/initializationguide/User.java index e2e3f051dd..1d9a872d69 100644 --- a/core-java-lang-oop/src/main/java/com/baeldung/initializationguide/User.java +++ b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/initializationguide/User.java @@ -1,53 +1,53 @@ -package com.baeldung.initializationguide; - -import java.io.Serializable; - -public class User implements Serializable, Cloneable { - private static final long serialVersionUID = 1L; - static String forum; - private String name; - private int id; - - { - id = 0; - System.out.println("Instance Initializer"); - } - - static { - forum = "Java"; - System.out.println("Static Initializer"); - } - - public User(String name, int id) { - super(); - this.name = name; - this.id = id; - } - - public User() { - System.out.println("Constructor"); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - @Override - protected Object clone() throws CloneNotSupportedException { - return this; - } - -} - +package com.baeldung.initializationguide; + +import java.io.Serializable; + +public class User implements Serializable, Cloneable { + private static final long serialVersionUID = 1L; + static String forum; + private String name; + private int id; + + { + id = 0; + System.out.println("Instance Initializer"); + } + + static { + forum = "Java"; + System.out.println("Static Initializer"); + } + + public User(String name, int id) { + super(); + this.name = name; + this.id = id; + } + + public User() { + System.out.println("Constructor"); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Override + protected Object clone() throws CloneNotSupportedException { + return this; + } + +} + diff --git a/core-java-lang-oop/src/main/java/com/baeldung/keyword/KeywordDemo.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/keyword/KeywordDemo.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/keyword/KeywordDemo.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/keyword/KeywordDemo.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/keyword/superkeyword/SuperBase.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/keyword/superkeyword/SuperBase.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/keyword/superkeyword/SuperBase.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/keyword/superkeyword/SuperBase.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/keyword/superkeyword/SuperSub.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/keyword/superkeyword/SuperSub.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/keyword/superkeyword/SuperSub.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/keyword/superkeyword/SuperSub.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/keyword/thiskeyword/KeywordUnitTest.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/keyword/thiskeyword/KeywordUnitTest.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/keyword/thiskeyword/KeywordUnitTest.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/keyword/thiskeyword/KeywordUnitTest.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/DeletableShape.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/DeletableShape.java similarity index 94% rename from core-java-lang-oop/src/main/java/com/baeldung/markerinterface/DeletableShape.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/DeletableShape.java index 7674407da8..800ba6f46c 100644 --- a/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/DeletableShape.java +++ b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/DeletableShape.java @@ -1,5 +1,5 @@ -package com.baeldung.markerinterface; - -public interface DeletableShape extends Shape { - -} +package com.baeldung.markerinterface; + +public interface DeletableShape extends Shape { + +} diff --git a/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/Rectangle.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/Rectangle.java similarity index 95% rename from core-java-lang-oop/src/main/java/com/baeldung/markerinterface/Rectangle.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/Rectangle.java index d64ffad0a2..659f2af2ee 100644 --- a/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/Rectangle.java +++ b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/Rectangle.java @@ -1,22 +1,22 @@ -package com.baeldung.markerinterface; - -public class Rectangle implements DeletableShape { - - private double width; - private double height; - - public Rectangle(double width, double height) { - this.width = width; - this.height = height; - } - - @Override - public double getArea() { - return width * height; - } - - @Override - public double getCircumference() { - return 2 * (width + height); - } -} +package com.baeldung.markerinterface; + +public class Rectangle implements DeletableShape { + + private double width; + private double height; + + public Rectangle(double width, double height) { + this.width = width; + this.height = height; + } + + @Override + public double getArea() { + return width * height; + } + + @Override + public double getCircumference() { + return 2 * (width + height); + } +} diff --git a/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/Shape.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/Shape.java similarity index 95% rename from core-java-lang-oop/src/main/java/com/baeldung/markerinterface/Shape.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/Shape.java index 2e53aefc03..b1db906087 100644 --- a/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/Shape.java +++ b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/Shape.java @@ -1,6 +1,6 @@ -package com.baeldung.markerinterface; - -public interface Shape { - double getArea(); - double getCircumference(); +package com.baeldung.markerinterface; + +public interface Shape { + double getArea(); + double getCircumference(); } \ No newline at end of file diff --git a/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/ShapeDao.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/ShapeDao.java similarity index 95% rename from core-java-lang-oop/src/main/java/com/baeldung/markerinterface/ShapeDao.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/ShapeDao.java index bc988a793d..1b95c7b307 100644 --- a/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/ShapeDao.java +++ b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/markerinterface/ShapeDao.java @@ -1,14 +1,14 @@ -package com.baeldung.markerinterface; - -public class ShapeDao { - - public boolean delete(Object object) { - if (!(object instanceof DeletableShape)) { - return false; - } - // Calling the code that deletes the entity from the database - - return true; - } - -} +package com.baeldung.markerinterface; + +public class ShapeDao { + + public boolean delete(Object object) { + if (!(object instanceof DeletableShape)) { + return false; + } + // Calling the code that deletes the entity from the database + + return true; + } + +} diff --git a/core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/application/Application.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/application/Application.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/application/Application.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/application/Application.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/model/Car.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/model/Car.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/model/Car.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/model/Car.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/model/Vehicle.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/model/Vehicle.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/model/Vehicle.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/model/Vehicle.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/util/Multiplier.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/util/Multiplier.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/util/Multiplier.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/methodoverloadingoverriding/util/Multiplier.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/polymorphism/FileManager.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/polymorphism/FileManager.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/polymorphism/FileManager.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/polymorphism/FileManager.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/polymorphism/GenericFile.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/polymorphism/GenericFile.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/polymorphism/GenericFile.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/polymorphism/GenericFile.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/polymorphism/ImageFile.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/polymorphism/ImageFile.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/polymorphism/ImageFile.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/polymorphism/ImageFile.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/polymorphism/TextFile.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/polymorphism/TextFile.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/polymorphism/TextFile.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/polymorphism/TextFile.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/scope/method/BaseMethodClass.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/method/BaseMethodClass.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/scope/method/BaseMethodClass.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/method/BaseMethodClass.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/scope/method/ChildMethodClass.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/method/ChildMethodClass.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/scope/method/ChildMethodClass.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/method/ChildMethodClass.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/scope/method/MethodHidingDemo.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/method/MethodHidingDemo.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/scope/method/MethodHidingDemo.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/method/MethodHidingDemo.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/scope/variable/ChildVariable.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/variable/ChildVariable.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/scope/variable/ChildVariable.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/variable/ChildVariable.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/scope/variable/HideVariable.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/variable/HideVariable.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/scope/variable/HideVariable.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/variable/HideVariable.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/scope/variable/ParentVariable.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/variable/ParentVariable.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/scope/variable/ParentVariable.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/variable/ParentVariable.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/scope/variable/VariableHidingDemo.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/variable/VariableHidingDemo.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/scope/variable/VariableHidingDemo.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/scope/variable/VariableHidingDemo.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/staticdemo/Car.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/staticdemo/Car.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/staticdemo/Car.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/staticdemo/Car.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/staticdemo/Singleton.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/staticdemo/Singleton.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/staticdemo/Singleton.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/staticdemo/Singleton.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/staticdemo/StaticBlock.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/staticdemo/StaticBlock.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/staticdemo/StaticBlock.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/staticdemo/StaticBlock.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/typeerasure/ArrayContentPrintUtil.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/typeerasure/ArrayContentPrintUtil.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/typeerasure/ArrayContentPrintUtil.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/typeerasure/ArrayContentPrintUtil.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/typeerasure/BoundStack.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/typeerasure/BoundStack.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/typeerasure/BoundStack.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/typeerasure/BoundStack.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/typeerasure/IntegerStack.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/typeerasure/IntegerStack.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/typeerasure/IntegerStack.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/typeerasure/IntegerStack.java diff --git a/core-java-lang-oop/src/main/java/com/baeldung/typeerasure/Stack.java b/core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/typeerasure/Stack.java similarity index 100% rename from core-java-lang-oop/src/main/java/com/baeldung/typeerasure/Stack.java rename to core-java-modules/core-java-lang-oop/src/main/java/com/baeldung/typeerasure/Stack.java diff --git a/core-java-lang-oop/src/main/resources/logback.xml b/core-java-modules/core-java-lang-oop/src/main/resources/logback.xml similarity index 100% rename from core-java-lang-oop/src/main/resources/logback.xml rename to core-java-modules/core-java-lang-oop/src/main/resources/logback.xml diff --git a/core-java-lang-oop/src/test/java/com/baeldung/casting/CastingUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/casting/CastingUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/casting/CastingUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/casting/CastingUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/deepcopy/DeepCopyUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/deepcopy/DeepCopyUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/deepcopy/DeepCopyUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/deepcopy/DeepCopyUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/deepcopy/ShallowCopyUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/deepcopy/ShallowCopyUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/deepcopy/ShallowCopyUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/deepcopy/ShallowCopyUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/MoneyUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/MoneyUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/MoneyUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/MoneyUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/TeamUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/TeamUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/TeamUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/TeamUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/entities/ComplexClassUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/entities/ComplexClassUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/entities/ComplexClassUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/entities/ComplexClassUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/entities/PrimitiveClassUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/entities/PrimitiveClassUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/entities/PrimitiveClassUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/entities/PrimitiveClassUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/entities/SquareClassUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/entities/SquareClassUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/entities/SquareClassUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/equalshashcode/entities/SquareClassUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/finalkeyword/FinalUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/finalkeyword/FinalUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/finalkeyword/FinalUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/finalkeyword/FinalUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/hashcode/application/ApplicationUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/hashcode/application/ApplicationUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/hashcode/application/ApplicationUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/hashcode/application/ApplicationUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/hashcode/entities/UserUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/hashcode/entities/UserUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/hashcode/entities/UserUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/hashcode/entities/UserUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/immutableobjects/ImmutableObjectsUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/immutableobjects/ImmutableObjectsUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/immutableobjects/ImmutableObjectsUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/immutableobjects/ImmutableObjectsUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/inheritance/AppUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/inheritance/AppUnitTest.java similarity index 96% rename from core-java-lang-oop/src/test/java/com/baeldung/inheritance/AppUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/inheritance/AppUnitTest.java index 1c3c2fff35..0d9dfed27a 100644 --- a/core-java-lang-oop/src/test/java/com/baeldung/inheritance/AppUnitTest.java +++ b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/inheritance/AppUnitTest.java @@ -1,46 +1,46 @@ -package com.baeldung.inheritance; - -import com.baeldung.inheritance.*; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class AppUnitTest extends TestCase { - - public AppUnitTest(String testName) { - super( testName ); - } - - public static Test suite() { - return new TestSuite(AppUnitTest.class); - } - - @SuppressWarnings("static-access") - public void testStaticMethodUsingBaseClassVariable() { - Car first = new ArmoredCar(); - assertEquals("Car", first.msg()); - } - - @SuppressWarnings("static-access") - public void testStaticMethodUsingDerivedClassVariable() { - ArmoredCar second = new ArmoredCar(); - assertEquals("ArmoredCar", second.msg()); - } - - public void testAssignArmoredCarToCar() { - Employee e1 = new Employee("Shreya", new ArmoredCar()); - assertNotNull(e1.getCar()); - } - - public void testAssignSpaceCarToCar() { - Employee e2 = new Employee("Paul", new SpaceCar()); - assertNotNull(e2.getCar()); - } - - public void testBMWToCar() { - Employee e3 = new Employee("Pavni", new BMW()); - assertNotNull(e3.getCar()); - } - -} +package com.baeldung.inheritance; + +import com.baeldung.inheritance.*; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class AppUnitTest extends TestCase { + + public AppUnitTest(String testName) { + super( testName ); + } + + public static Test suite() { + return new TestSuite(AppUnitTest.class); + } + + @SuppressWarnings("static-access") + public void testStaticMethodUsingBaseClassVariable() { + Car first = new ArmoredCar(); + assertEquals("Car", first.msg()); + } + + @SuppressWarnings("static-access") + public void testStaticMethodUsingDerivedClassVariable() { + ArmoredCar second = new ArmoredCar(); + assertEquals("ArmoredCar", second.msg()); + } + + public void testAssignArmoredCarToCar() { + Employee e1 = new Employee("Shreya", new ArmoredCar()); + assertNotNull(e1.getCar()); + } + + public void testAssignSpaceCarToCar() { + Employee e2 = new Employee("Paul", new SpaceCar()); + assertNotNull(e2.getCar()); + } + + public void testBMWToCar() { + Employee e3 = new Employee("Pavni", new BMW()); + assertNotNull(e3.getCar()); + } + +} diff --git a/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/ActressUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/ActressUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/ActressUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/ActressUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/CompositionUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/CompositionUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/CompositionUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/CompositionUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/InheritanceUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/InheritanceUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/InheritanceUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/InheritanceUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/PersonUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/PersonUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/PersonUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/PersonUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/WaitressUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/WaitressUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/WaitressUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/inheritancecomposition/test/WaitressUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/initializationguide/UserUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/initializationguide/UserUnitTest.java similarity index 97% rename from core-java-lang-oop/src/test/java/com/baeldung/initializationguide/UserUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/initializationguide/UserUnitTest.java index f74384e6f7..a26b602609 100644 --- a/core-java-lang-oop/src/test/java/com/baeldung/initializationguide/UserUnitTest.java +++ b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/initializationguide/UserUnitTest.java @@ -1,37 +1,37 @@ -package com.baeldung.initializationguide; -import org.junit.Before; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.*; - -import java.lang.reflect.InvocationTargetException; - -public class UserUnitTest { - - @Test - public void givenUserInstance_whenIntializedWithNew_thenInstanceIsNotNull() { - User user = new User("Alice", 1); - assertThat(user).isNotNull(); - } - - @Test - public void givenUserInstance_whenInitializedWithReflection_thenInstanceIsNotNull() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - User user = User.class.getConstructor(String.class, int.class) - .newInstance("Alice", 2); - assertThat(user).isNotNull(); - } - - @Test - public void givenUserInstance_whenCopiedWithClone_thenExactMatchIsCreated() throws CloneNotSupportedException { - User user = new User("Alice", 3); - User clonedUser = (User) user.clone(); - assertThat(clonedUser).isEqualTo(user); - } - - @Test - public void givenUserInstance_whenValuesAreNotInitialized_thenUserNameAndIdReturnDefault() { - User user = new User(); - assertThat(user.getName()).isNull(); - assertThat(user.getId() == 0); - } -} +package com.baeldung.initializationguide; +import org.junit.Before; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.*; + +import java.lang.reflect.InvocationTargetException; + +public class UserUnitTest { + + @Test + public void givenUserInstance_whenIntializedWithNew_thenInstanceIsNotNull() { + User user = new User("Alice", 1); + assertThat(user).isNotNull(); + } + + @Test + public void givenUserInstance_whenInitializedWithReflection_thenInstanceIsNotNull() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + User user = User.class.getConstructor(String.class, int.class) + .newInstance("Alice", 2); + assertThat(user).isNotNull(); + } + + @Test + public void givenUserInstance_whenCopiedWithClone_thenExactMatchIsCreated() throws CloneNotSupportedException { + User user = new User("Alice", 3); + User clonedUser = (User) user.clone(); + assertThat(clonedUser).isEqualTo(user); + } + + @Test + public void givenUserInstance_whenValuesAreNotInitialized_thenUserNameAndIdReturnDefault() { + User user = new User(); + assertThat(user.getName()).isNull(); + assertThat(user.getId() == 0); + } +} diff --git a/core-java-lang-oop/src/test/java/com/baeldung/markerinterface/MarkerInterfaceUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/markerinterface/MarkerInterfaceUnitTest.java similarity index 96% rename from core-java-lang-oop/src/test/java/com/baeldung/markerinterface/MarkerInterfaceUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/markerinterface/MarkerInterfaceUnitTest.java index 70d32ba253..81cd51ce51 100644 --- a/core-java-lang-oop/src/test/java/com/baeldung/markerinterface/MarkerInterfaceUnitTest.java +++ b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/markerinterface/MarkerInterfaceUnitTest.java @@ -1,26 +1,26 @@ -package com.baeldung.markerinterface; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - -public class MarkerInterfaceUnitTest { - - @Test - public void givenDeletableObjectThenTrueReturned() { - ShapeDao shapeDao = new ShapeDao(); - Object rectangle = new Rectangle(2, 3); - - boolean result = shapeDao.delete(rectangle); - assertEquals(true, result); - } - - @Test - public void givenNonDeletableObjectThenFalseReturned() { - ShapeDao shapeDao = new ShapeDao(); - Object object = new Object(); - - boolean result = shapeDao.delete(object); - assertEquals(false, result); - } -} +package com.baeldung.markerinterface; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class MarkerInterfaceUnitTest { + + @Test + public void givenDeletableObjectThenTrueReturned() { + ShapeDao shapeDao = new ShapeDao(); + Object rectangle = new Rectangle(2, 3); + + boolean result = shapeDao.delete(rectangle); + assertEquals(true, result); + } + + @Test + public void givenNonDeletableObjectThenFalseReturned() { + ShapeDao shapeDao = new ShapeDao(); + Object object = new Object(); + + boolean result = shapeDao.delete(object); + assertEquals(false, result); + } +} diff --git a/core-java-lang-oop/src/test/java/com/baeldung/methodoverloadingoverriding/test/MethodOverloadingUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/methodoverloadingoverriding/test/MethodOverloadingUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/methodoverloadingoverriding/test/MethodOverloadingUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/methodoverloadingoverriding/test/MethodOverloadingUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/methodoverloadingoverriding/test/MethodOverridingUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/methodoverloadingoverriding/test/MethodOverridingUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/methodoverloadingoverriding/test/MethodOverridingUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/methodoverloadingoverriding/test/MethodOverridingUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/parameterpassing/NonPrimitivesUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/parameterpassing/NonPrimitivesUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/parameterpassing/NonPrimitivesUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/parameterpassing/NonPrimitivesUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/parameterpassing/PrimitivesUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/parameterpassing/PrimitivesUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/parameterpassing/PrimitivesUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/parameterpassing/PrimitivesUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/polymorphism/PolymorphismUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/polymorphism/PolymorphismUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/polymorphism/PolymorphismUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/polymorphism/PolymorphismUnitTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/staticdemo/CarIntegrationTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/staticdemo/CarIntegrationTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/staticdemo/CarIntegrationTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/staticdemo/CarIntegrationTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/staticdemo/SingletonIntegrationTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/staticdemo/SingletonIntegrationTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/staticdemo/SingletonIntegrationTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/staticdemo/SingletonIntegrationTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/staticdemo/StaticBlockIntegrationTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/staticdemo/StaticBlockIntegrationTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/staticdemo/StaticBlockIntegrationTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/staticdemo/StaticBlockIntegrationTest.java diff --git a/core-java-lang-oop/src/test/java/com/baeldung/typeerasure/TypeErasureUnitTest.java b/core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/typeerasure/TypeErasureUnitTest.java similarity index 100% rename from core-java-lang-oop/src/test/java/com/baeldung/typeerasure/TypeErasureUnitTest.java rename to core-java-modules/core-java-lang-oop/src/test/java/com/baeldung/typeerasure/TypeErasureUnitTest.java diff --git a/core-java-lang-oop/src/test/resources/.gitignore b/core-java-modules/core-java-lang-oop/src/test/resources/.gitignore similarity index 100% rename from core-java-lang-oop/src/test/resources/.gitignore rename to core-java-modules/core-java-lang-oop/src/test/resources/.gitignore diff --git a/core-java-lang/.gitignore b/core-java-modules/core-java-lang-syntax/.gitignore similarity index 100% rename from core-java-lang/.gitignore rename to core-java-modules/core-java-lang-syntax/.gitignore diff --git a/core-java-lang-syntax/README.md b/core-java-modules/core-java-lang-syntax/README.md similarity index 100% rename from core-java-lang-syntax/README.md rename to core-java-modules/core-java-lang-syntax/README.md diff --git a/core-java-lang-syntax/pom.xml b/core-java-modules/core-java-lang-syntax/pom.xml similarity index 96% rename from core-java-lang-syntax/pom.xml rename to core-java-modules/core-java-lang-syntax/pom.xml index 9a9df01057..46fa8d1206 100644 --- a/core-java-lang-syntax/pom.xml +++ b/core-java-modules/core-java-lang-syntax/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/breakcontinue/BreakContinue.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/breakcontinue/BreakContinue.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/breakcontinue/BreakContinue.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/breakcontinue/BreakContinue.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/enums/Pizza.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/enums/Pizza.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/enums/Pizza.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/enums/Pizza.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/enums/PizzaDeliveryStrategy.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/enums/PizzaDeliveryStrategy.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/enums/PizzaDeliveryStrategy.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/enums/PizzaDeliveryStrategy.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/enums/PizzaDeliverySystemConfiguration.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/enums/PizzaDeliverySystemConfiguration.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/enums/PizzaDeliverySystemConfiguration.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/enums/PizzaDeliverySystemConfiguration.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/generics/Building.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/Building.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/generics/Building.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/Building.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/generics/Generics.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/Generics.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/generics/Generics.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/Generics.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/generics/House.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/House.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/generics/House.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/House.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/initializationguide/User.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/initializationguide/User.java similarity index 94% rename from core-java-lang-syntax/src/main/java/com/baeldung/initializationguide/User.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/initializationguide/User.java index e2e3f051dd..1d9a872d69 100644 --- a/core-java-lang-syntax/src/main/java/com/baeldung/initializationguide/User.java +++ b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/initializationguide/User.java @@ -1,53 +1,53 @@ -package com.baeldung.initializationguide; - -import java.io.Serializable; - -public class User implements Serializable, Cloneable { - private static final long serialVersionUID = 1L; - static String forum; - private String name; - private int id; - - { - id = 0; - System.out.println("Instance Initializer"); - } - - static { - forum = "Java"; - System.out.println("Static Initializer"); - } - - public User(String name, int id) { - super(); - this.name = name; - this.id = id; - } - - public User() { - System.out.println("Constructor"); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - @Override - protected Object clone() throws CloneNotSupportedException { - return this; - } - -} - +package com.baeldung.initializationguide; + +import java.io.Serializable; + +public class User implements Serializable, Cloneable { + private static final long serialVersionUID = 1L; + static String forum; + private String name; + private int id; + + { + id = 0; + System.out.println("Instance Initializer"); + } + + static { + forum = "Java"; + System.out.println("Static Initializer"); + } + + public User(String name, int id) { + super(); + this.name = name; + this.id = id; + } + + public User() { + System.out.println("Constructor"); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Override + protected Object clone() throws CloneNotSupportedException { + return this; + } + +} + diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Circle.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Circle.java similarity index 94% rename from core-java-lang-syntax/src/main/java/com/baeldung/keyword/Circle.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Circle.java index 231b2f5a59..807020d267 100644 --- a/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Circle.java +++ b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Circle.java @@ -1,5 +1,5 @@ -package com.baeldung.keyword; - -public class Circle extends Round implements Shape { - -} +package com.baeldung.keyword; + +public class Circle extends Round implements Shape { + +} diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Ring.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Ring.java similarity index 94% rename from core-java-lang-syntax/src/main/java/com/baeldung/keyword/Ring.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Ring.java index 99873f9640..64274cbb6b 100644 --- a/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Ring.java +++ b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Ring.java @@ -1,4 +1,4 @@ -package com.baeldung.keyword; - -public class Ring extends Round { -} +package com.baeldung.keyword; + +public class Ring extends Round { +} diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Round.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Round.java similarity index 93% rename from core-java-lang-syntax/src/main/java/com/baeldung/keyword/Round.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Round.java index 0e2cc2c8c7..37008de09c 100644 --- a/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Round.java +++ b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Round.java @@ -1,4 +1,4 @@ -package com.baeldung.keyword; - -public class Round { -} +package com.baeldung.keyword; + +public class Round { +} diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Shape.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Shape.java similarity index 93% rename from core-java-lang-syntax/src/main/java/com/baeldung/keyword/Shape.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Shape.java index 8d00c165a3..437917c29e 100644 --- a/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Shape.java +++ b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Shape.java @@ -1,4 +1,4 @@ -package com.baeldung.keyword; - -public interface Shape { -} +package com.baeldung.keyword; + +public interface Shape { +} diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Triangle.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Triangle.java similarity index 94% rename from core-java-lang-syntax/src/main/java/com/baeldung/keyword/Triangle.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Triangle.java index 406b8f23e5..4cb6ed72ba 100644 --- a/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Triangle.java +++ b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/keyword/Triangle.java @@ -1,4 +1,4 @@ -package com.baeldung.keyword; - -public class Triangle implements Shape { -} +package com.baeldung.keyword; + +public class Triangle implements Shape { +} diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/loops/InfiniteLoops.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/loops/InfiniteLoops.java similarity index 95% rename from core-java-lang-syntax/src/main/java/com/baeldung/loops/InfiniteLoops.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/loops/InfiniteLoops.java index 0706c85db8..4952fd7b35 100644 --- a/core-java-lang-syntax/src/main/java/com/baeldung/loops/InfiniteLoops.java +++ b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/loops/InfiniteLoops.java @@ -1,23 +1,23 @@ -package com.baeldung.loops; - -public class InfiniteLoops { - - public void infiniteLoopUsingWhile() { - while (true) { - System.out.println("Infinite loop using while"); - } - } - - public void infiniteLoopUsingFor() { - for (;;) { - System.out.println("Infinite loop using for"); - } - } - - public void infiniteLoopUsingDoWhile() { - do { - System.out.println("Infinite loop using do-while"); - } while (true); - } - -} +package com.baeldung.loops; + +public class InfiniteLoops { + + public void infiniteLoopUsingWhile() { + while (true) { + System.out.println("Infinite loop using while"); + } + } + + public void infiniteLoopUsingFor() { + for (;;) { + System.out.println("Infinite loop using for"); + } + } + + public void infiniteLoopUsingDoWhile() { + do { + System.out.println("Infinite loop using do-while"); + } while (true); + } + +} diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/loops/LoopsInJava.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/loops/LoopsInJava.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/loops/LoopsInJava.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/loops/LoopsInJava.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/switchstatement/SwitchStatement.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/switchstatement/SwitchStatement.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/switchstatement/SwitchStatement.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/switchstatement/SwitchStatement.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/system/ChatWindow.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/ChatWindow.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/system/ChatWindow.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/ChatWindow.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/system/DateTimeService.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/DateTimeService.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/system/DateTimeService.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/DateTimeService.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/system/EnvironmentVariables.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/EnvironmentVariables.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/system/EnvironmentVariables.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/EnvironmentVariables.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/system/SystemErrDemo.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/SystemErrDemo.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/system/SystemErrDemo.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/SystemErrDemo.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/system/SystemExitDemo.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/SystemExitDemo.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/system/SystemExitDemo.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/SystemExitDemo.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/system/SystemOutDemo.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/SystemOutDemo.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/system/SystemOutDemo.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/SystemOutDemo.java diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/system/UserCredentials.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/UserCredentials.java similarity index 100% rename from core-java-lang-syntax/src/main/java/com/baeldung/system/UserCredentials.java rename to core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/system/UserCredentials.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/breakcontinue/BreakContinueUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/breakcontinue/BreakContinueUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/breakcontinue/BreakContinueUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/breakcontinue/BreakContinueUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/enums/PizzaUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/enums/PizzaUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/enums/PizzaUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/enums/PizzaUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/generics/GenericsUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/generics/GenericsUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/generics/GenericsUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/generics/GenericsUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/initializationguide/UserUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/initializationguide/UserUnitTest.java similarity index 97% rename from core-java-lang-syntax/src/test/java/com/baeldung/initializationguide/UserUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/initializationguide/UserUnitTest.java index f74384e6f7..a26b602609 100644 --- a/core-java-lang-syntax/src/test/java/com/baeldung/initializationguide/UserUnitTest.java +++ b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/initializationguide/UserUnitTest.java @@ -1,37 +1,37 @@ -package com.baeldung.initializationguide; -import org.junit.Before; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.*; - -import java.lang.reflect.InvocationTargetException; - -public class UserUnitTest { - - @Test - public void givenUserInstance_whenIntializedWithNew_thenInstanceIsNotNull() { - User user = new User("Alice", 1); - assertThat(user).isNotNull(); - } - - @Test - public void givenUserInstance_whenInitializedWithReflection_thenInstanceIsNotNull() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - User user = User.class.getConstructor(String.class, int.class) - .newInstance("Alice", 2); - assertThat(user).isNotNull(); - } - - @Test - public void givenUserInstance_whenCopiedWithClone_thenExactMatchIsCreated() throws CloneNotSupportedException { - User user = new User("Alice", 3); - User clonedUser = (User) user.clone(); - assertThat(clonedUser).isEqualTo(user); - } - - @Test - public void givenUserInstance_whenValuesAreNotInitialized_thenUserNameAndIdReturnDefault() { - User user = new User(); - assertThat(user.getName()).isNull(); - assertThat(user.getId() == 0); - } -} +package com.baeldung.initializationguide; +import org.junit.Before; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.*; + +import java.lang.reflect.InvocationTargetException; + +public class UserUnitTest { + + @Test + public void givenUserInstance_whenIntializedWithNew_thenInstanceIsNotNull() { + User user = new User("Alice", 1); + assertThat(user).isNotNull(); + } + + @Test + public void givenUserInstance_whenInitializedWithReflection_thenInstanceIsNotNull() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + User user = User.class.getConstructor(String.class, int.class) + .newInstance("Alice", 2); + assertThat(user).isNotNull(); + } + + @Test + public void givenUserInstance_whenCopiedWithClone_thenExactMatchIsCreated() throws CloneNotSupportedException { + User user = new User("Alice", 3); + User clonedUser = (User) user.clone(); + assertThat(clonedUser).isEqualTo(user); + } + + @Test + public void givenUserInstance_whenValuesAreNotInitialized_thenUserNameAndIdReturnDefault() { + User user = new User(); + assertThat(user.getName()).isNull(); + assertThat(user.getId() == 0); + } +} diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Car.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Car.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Car.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Car.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/DiamondOperatorUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/DiamondOperatorUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/DiamondOperatorUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/DiamondOperatorUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Diesel.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Diesel.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Diesel.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Diesel.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Engine.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Engine.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Engine.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Engine.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Vehicle.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Vehicle.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Vehicle.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/java/diamond/Vehicle.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/java/doublebrace/DoubleBraceUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/java/doublebrace/DoubleBraceUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/java/doublebrace/DoubleBraceUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/java/doublebrace/DoubleBraceUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/keyword/test/InstanceOfUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/keyword/test/InstanceOfUnitTest.java similarity index 96% rename from core-java-lang-syntax/src/test/java/com/baeldung/keyword/test/InstanceOfUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/keyword/test/InstanceOfUnitTest.java index 4c010e3a16..6966fa3944 100644 --- a/core-java-lang-syntax/src/test/java/com/baeldung/keyword/test/InstanceOfUnitTest.java +++ b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/keyword/test/InstanceOfUnitTest.java @@ -1,55 +1,55 @@ -package com.baeldung.keyword.test; - -import org.junit.Assert; -import org.junit.jupiter.api.Test; - -import com.baeldung.keyword.Circle; -import com.baeldung.keyword.Ring; -import com.baeldung.keyword.Round; -import com.baeldung.keyword.Shape; -import com.baeldung.keyword.Triangle; - -public class InstanceOfUnitTest { - - @Test - public void giveWhenInstanceIsCorrect_thenReturnTrue() { - Ring ring = new Ring(); - Assert.assertTrue("ring is instance of Round ", ring instanceof Round); - } - - @Test - public void giveWhenObjectIsInstanceOfType_thenReturnTrue() { - Circle circle = new Circle(); - Assert.assertTrue("circle is instance of Circle ", circle instanceof Circle); - } - - - @Test - public void giveWhenInstanceIsOfSubtype_thenReturnTrue() { - Circle circle = new Circle(); - Assert.assertTrue("circle is instance of Round", circle instanceof Round); - } - - @Test - public void giveWhenTypeIsInterface_thenReturnTrue() { - Circle circle = new Circle(); - Assert.assertTrue("circle is instance of Shape", circle instanceof Shape); - } - - @Test - public void giveWhenTypeIsOfObjectType_thenReturnTrue() { - Thread thread = new Thread(); - Assert.assertTrue("thread is instance of Object", thread instanceof Object); - } - - @Test - public void giveWhenInstanceValueIsNull_thenReturnFalse() { - Circle circle = null; - Assert.assertFalse("circle is instance of Round", circle instanceof Round); - } - - @Test - public void giveWhenComparingClassInDiffHierarchy_thenCompilationError() { - // Assert.assertFalse("circle is instance of Triangle", circle instanceof Triangle); - } -} +package com.baeldung.keyword.test; + +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +import com.baeldung.keyword.Circle; +import com.baeldung.keyword.Ring; +import com.baeldung.keyword.Round; +import com.baeldung.keyword.Shape; +import com.baeldung.keyword.Triangle; + +public class InstanceOfUnitTest { + + @Test + public void giveWhenInstanceIsCorrect_thenReturnTrue() { + Ring ring = new Ring(); + Assert.assertTrue("ring is instance of Round ", ring instanceof Round); + } + + @Test + public void giveWhenObjectIsInstanceOfType_thenReturnTrue() { + Circle circle = new Circle(); + Assert.assertTrue("circle is instance of Circle ", circle instanceof Circle); + } + + + @Test + public void giveWhenInstanceIsOfSubtype_thenReturnTrue() { + Circle circle = new Circle(); + Assert.assertTrue("circle is instance of Round", circle instanceof Round); + } + + @Test + public void giveWhenTypeIsInterface_thenReturnTrue() { + Circle circle = new Circle(); + Assert.assertTrue("circle is instance of Shape", circle instanceof Shape); + } + + @Test + public void giveWhenTypeIsOfObjectType_thenReturnTrue() { + Thread thread = new Thread(); + Assert.assertTrue("thread is instance of Object", thread instanceof Object); + } + + @Test + public void giveWhenInstanceValueIsNull_thenReturnFalse() { + Circle circle = null; + Assert.assertFalse("circle is instance of Round", circle instanceof Round); + } + + @Test + public void giveWhenComparingClassInDiffHierarchy_thenCompilationError() { + // Assert.assertFalse("circle is instance of Triangle", circle instanceof Triangle); + } +} diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/loops/WhenUsingLoops.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/loops/WhenUsingLoops.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/loops/WhenUsingLoops.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/loops/WhenUsingLoops.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/modulo/ModuloUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/modulo/ModuloUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/modulo/ModuloUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/modulo/ModuloUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/primitiveconversion/PrimitiveConversionsJUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/primitiveconversion/PrimitiveConversionsJUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/primitiveconversion/PrimitiveConversionsJUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/primitiveconversion/PrimitiveConversionsJUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/switchstatement/SwitchStatementUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/switchstatement/SwitchStatementUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/switchstatement/SwitchStatementUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/switchstatement/SwitchStatementUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/system/DateTimeServiceUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/system/DateTimeServiceUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/system/DateTimeServiceUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/system/DateTimeServiceUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/system/EnvironmentVariablesUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/system/EnvironmentVariablesUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/system/EnvironmentVariablesUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/system/EnvironmentVariablesUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/system/SystemArrayCopyUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/system/SystemArrayCopyUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/system/SystemArrayCopyUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/system/SystemArrayCopyUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/system/SystemNanoUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/system/SystemNanoUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/system/SystemNanoUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/system/SystemNanoUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/system/SystemPropertiesUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/system/SystemPropertiesUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/system/SystemPropertiesUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/system/SystemPropertiesUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/ternaryoperator/TernaryOperatorUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/ternaryoperator/TernaryOperatorUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/ternaryoperator/TernaryOperatorUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/ternaryoperator/TernaryOperatorUnitTest.java diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/varargs/FormatterUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/varargs/FormatterUnitTest.java similarity index 100% rename from core-java-lang-syntax/src/test/java/com/baeldung/varargs/FormatterUnitTest.java rename to core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/varargs/FormatterUnitTest.java diff --git a/core-java-networking/.gitignore b/core-java-modules/core-java-lang/.gitignore similarity index 100% rename from core-java-networking/.gitignore rename to core-java-modules/core-java-lang/.gitignore diff --git a/core-java-lang/README.md b/core-java-modules/core-java-lang/README.md similarity index 100% rename from core-java-lang/README.md rename to core-java-modules/core-java-lang/README.md diff --git a/core-java-lang/pom.xml b/core-java-modules/core-java-lang/pom.xml similarity index 98% rename from core-java-lang/pom.xml rename to core-java-modules/core-java-lang/pom.xml index 551c8e8505..45ccc8d0f5 100644 --- a/core-java-lang/pom.xml +++ b/core-java-modules/core-java-lang/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-lang/src/main/java/com/baeldung/assertion/Assertion.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/assertion/Assertion.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/assertion/Assertion.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/assertion/Assertion.java diff --git a/core-java-lang/src/main/java/com/baeldung/binding/Animal.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/binding/Animal.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/binding/Animal.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/binding/Animal.java diff --git a/core-java-lang/src/main/java/com/baeldung/binding/AnimalActivity.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/binding/AnimalActivity.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/binding/AnimalActivity.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/binding/AnimalActivity.java diff --git a/core-java-lang/src/main/java/com/baeldung/binding/Cat.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/binding/Cat.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/binding/Cat.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/binding/Cat.java diff --git a/core-java-lang/src/main/java/com/baeldung/chainedexception/LogWithChain.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/chainedexception/LogWithChain.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/chainedexception/LogWithChain.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/chainedexception/LogWithChain.java diff --git a/core-java-lang/src/main/java/com/baeldung/chainedexception/LogWithoutChain.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/chainedexception/LogWithoutChain.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/chainedexception/LogWithoutChain.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/chainedexception/LogWithoutChain.java diff --git a/core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/GirlFriendOfManagerUpsetException.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/GirlFriendOfManagerUpsetException.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/GirlFriendOfManagerUpsetException.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/GirlFriendOfManagerUpsetException.java diff --git a/core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/ManagerUpsetException.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/ManagerUpsetException.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/ManagerUpsetException.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/ManagerUpsetException.java diff --git a/core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/NoLeaveGrantedException.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/NoLeaveGrantedException.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/NoLeaveGrantedException.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/NoLeaveGrantedException.java diff --git a/core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/TeamLeadUpsetException.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/TeamLeadUpsetException.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/TeamLeadUpsetException.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/chainedexception/exceptions/TeamLeadUpsetException.java diff --git a/core-java-lang/src/main/java/com/baeldung/className/RetrievingClassName.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/className/RetrievingClassName.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/className/RetrievingClassName.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/className/RetrievingClassName.java diff --git a/core-java-lang/src/main/java/com/baeldung/comparable/Player.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparable/Player.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/comparable/Player.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/comparable/Player.java diff --git a/core-java-lang/src/main/java/com/baeldung/comparable/PlayerSorter.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparable/PlayerSorter.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/comparable/PlayerSorter.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/comparable/PlayerSorter.java diff --git a/core-java-lang/src/main/java/com/baeldung/comparator/Player.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/Player.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/comparator/Player.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/Player.java diff --git a/core-java-lang/src/main/java/com/baeldung/comparator/PlayerAgeComparator.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerAgeComparator.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/comparator/PlayerAgeComparator.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerAgeComparator.java diff --git a/core-java-lang/src/main/java/com/baeldung/comparator/PlayerAgeSorter.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerAgeSorter.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/comparator/PlayerAgeSorter.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerAgeSorter.java diff --git a/core-java-lang/src/main/java/com/baeldung/comparator/PlayerRankingComparator.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerRankingComparator.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/comparator/PlayerRankingComparator.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerRankingComparator.java diff --git a/core-java-lang/src/main/java/com/baeldung/comparator/PlayerRankingSorter.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerRankingSorter.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/comparator/PlayerRankingSorter.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerRankingSorter.java diff --git a/core-java-lang/src/main/java/com/baeldung/controlstructures/ConditionalBranches.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/controlstructures/ConditionalBranches.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/controlstructures/ConditionalBranches.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/controlstructures/ConditionalBranches.java diff --git a/core-java-lang/src/main/java/com/baeldung/controlstructures/Loops.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/controlstructures/Loops.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/controlstructures/Loops.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/controlstructures/Loops.java diff --git a/core-java-lang/src/main/java/com/baeldung/customexception/FileManager.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/customexception/FileManager.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/customexception/FileManager.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/customexception/FileManager.java diff --git a/core-java-lang/src/main/java/com/baeldung/customexception/IncorrectFileExtensionException.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/customexception/IncorrectFileExtensionException.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/customexception/IncorrectFileExtensionException.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/customexception/IncorrectFileExtensionException.java diff --git a/core-java-lang/src/main/java/com/baeldung/customexception/IncorrectFileNameException.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/customexception/IncorrectFileNameException.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/customexception/IncorrectFileNameException.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/customexception/IncorrectFileNameException.java diff --git a/core-java-lang/src/main/java/com/baeldung/doubles/SplitFloatingPointNumbers.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/doubles/SplitFloatingPointNumbers.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/doubles/SplitFloatingPointNumbers.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/doubles/SplitFloatingPointNumbers.java diff --git a/core-java-lang/src/main/java/com/baeldung/dynamicproxy/DynamicInvocationHandler.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/dynamicproxy/DynamicInvocationHandler.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/dynamicproxy/DynamicInvocationHandler.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/dynamicproxy/DynamicInvocationHandler.java diff --git a/core-java-lang/src/main/java/com/baeldung/dynamicproxy/TimingDynamicInvocationHandler.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/dynamicproxy/TimingDynamicInvocationHandler.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/dynamicproxy/TimingDynamicInvocationHandler.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/dynamicproxy/TimingDynamicInvocationHandler.java diff --git a/core-java-lang/src/main/java/com/baeldung/enums/values/Element1.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element1.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/enums/values/Element1.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element1.java diff --git a/core-java-lang/src/main/java/com/baeldung/enums/values/Element2.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element2.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/enums/values/Element2.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element2.java diff --git a/core-java-lang/src/main/java/com/baeldung/enums/values/Element3.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element3.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/enums/values/Element3.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element3.java diff --git a/core-java-lang/src/main/java/com/baeldung/enums/values/Element4.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element4.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/enums/values/Element4.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element4.java diff --git a/core-java-lang/src/main/java/com/baeldung/enums/values/Labeled.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Labeled.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/enums/values/Labeled.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Labeled.java diff --git a/core-java-lang/src/main/java/com/baeldung/exceptionhandling/Exceptions.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/Exceptions.java similarity index 96% rename from core-java-lang/src/main/java/com/baeldung/exceptionhandling/Exceptions.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/Exceptions.java index 9690648386..32d88cfd12 100644 --- a/core-java-lang/src/main/java/com/baeldung/exceptionhandling/Exceptions.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/Exceptions.java @@ -1,212 +1,212 @@ -package com.baeldung.exceptionhandling; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import java.util.Scanner; -import java.util.logging.Logger; -import java.util.stream.Collectors; - -public class Exceptions { - - private final static Logger logger = Logger.getLogger("ExceptionLogging"); - - public static List getPlayers() throws IOException { - Path path = Paths.get("players.dat"); - List players = Files.readAllLines(path); - - return players.stream() - .map(Player::new) - .collect(Collectors.toList()); - } - - public List loadAllPlayers(String playersFile) throws IOException{ - try { - throw new IOException(); - } catch(IOException ex) { - throw new IllegalStateException(); - } - } - - public int getPlayerScoreThrows(String playerFile) throws FileNotFoundException { - Scanner contents = new Scanner(new File(playerFile)); - return Integer.parseInt(contents.nextLine()); - } - - public int getPlayerScoreTryCatch(String playerFile) { - try { - Scanner contents = new Scanner(new File(playerFile)); - return Integer.parseInt(contents.nextLine()); - } catch (FileNotFoundException noFile) { - throw new IllegalArgumentException("File not found"); - } - } - - public int getPlayerScoreTryCatchRecovery(String playerFile) { - try { - Scanner contents = new Scanner(new File(playerFile)); - return Integer.parseInt(contents.nextLine()); - } catch ( FileNotFoundException noFile ) { - logger.warning("File not found, resetting score."); - return 0; - } - } - - public int getPlayerScoreFinally(String playerFile) throws FileNotFoundException { - Scanner contents = null; - try { - contents = new Scanner(new File(playerFile)); - return Integer.parseInt(contents.nextLine()); - } finally { - if (contents != null) { - contents.close(); - } - } - } - - public int getPlayerScoreTryWithResources(String playerFile) { - try (Scanner contents = new Scanner(new File(playerFile))) { - return Integer.parseInt(contents.nextLine()); - } catch (FileNotFoundException e ) { - logger.warning("File not found, resetting score."); - return 0; - } - } - - public int getPlayerScoreMultipleCatchBlocks(String playerFile) { - try (Scanner contents = new Scanner(new File(playerFile))) { - return Integer.parseInt(contents.nextLine()); - } catch (IOException e) { - logger.warning("Player file wouldn't load!"); - return 0; - } catch (NumberFormatException e) { - logger.warning("Player file was corrupted!"); - return 0; - } - } - - public int getPlayerScoreMultipleCatchBlocksAlternative(String playerFile) { - try (Scanner contents = new Scanner(new File(playerFile)) ) { - return Integer.parseInt(contents.nextLine()); - } catch (FileNotFoundException e) { - logger.warning("Player file not found!"); - return 0; - } catch (IOException e) { - logger.warning("Player file wouldn't load!"); - return 0; - } catch (NumberFormatException e) { - logger.warning("Player file was corrupted!"); - return 0; - } - } - - public int getPlayerScoreUnionCatchBlocks(String playerFile) { - try (Scanner contents = new Scanner(new File(playerFile))) { - return Integer.parseInt(contents.nextLine()); - } catch (IOException | NumberFormatException e) { - logger.warning("Failed to load score!"); - return 0; - } - } - - public List loadAllPlayersThrowingChecked(String playersFile) throws TimeoutException { - boolean tooLong = true; - - while (!tooLong) { - // ... potentially long operation - } - throw new TimeoutException("This operation took too long"); - } - - public List loadAllPlayersThrowingUnchecked(String playersFile) throws TimeoutException { - if(!isFilenameValid(playersFile)) { - throw new IllegalArgumentException("Filename isn't valid!"); - } - return null; - - // ... - } - - public List loadAllPlayersWrapping(String playersFile) throws IOException { - try { - throw new IOException(); - } catch (IOException io) { - throw io; - } - } - - public List loadAllPlayersRethrowing(String playersFile) throws PlayerLoadException { - try { - throw new IOException(); - } catch (IOException io) { - throw new PlayerLoadException(io); - } - } - - public List loadAllPlayersThrowable(String playersFile) { - try { - throw new NullPointerException(); - } catch ( Throwable t ) { - throw t; - } - } - - class FewerExceptions extends Exceptions { - @Override - public List loadAllPlayers(String playersFile) { //can't add "throws MyCheckedException - return null; - // overridden - } - } - - public void throwAsGotoAntiPattern() throws MyException { - try { - // bunch of code - throw new MyException(); - // second bunch of code - } catch ( MyException e ) { - // third bunch of code - } - } - - public int getPlayerScoreSwallowingExceptionAntiPattern(String playerFile) { - try { - // ... - } catch (Exception e) {} // <== catch and swallow - return 0; - } - - public int getPlayerScoreSwallowingExceptionAntiPatternAlternative(String playerFile) { - try { - // ... - } catch (Exception e) { - e.printStackTrace(); - } - return 0; - } - - public int getPlayerScoreSwallowingExceptionAntiPatternAlternative2(String playerFile) throws PlayerScoreException { - try { - throw new IOException(); - } catch (IOException e) { - throw new PlayerScoreException(e); - } - } - - public int getPlayerScoreReturnInFinallyAntiPattern(String playerFile) { - int score = 0; - try { - throw new IOException(); - } finally { - return score; // <== the IOException is dropped - } - } - - private boolean isFilenameValid(String name) { - return false; - } -} +package com.baeldung.exceptionhandling; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.Scanner; +import java.util.logging.Logger; +import java.util.stream.Collectors; + +public class Exceptions { + + private final static Logger logger = Logger.getLogger("ExceptionLogging"); + + public static List getPlayers() throws IOException { + Path path = Paths.get("players.dat"); + List players = Files.readAllLines(path); + + return players.stream() + .map(Player::new) + .collect(Collectors.toList()); + } + + public List loadAllPlayers(String playersFile) throws IOException{ + try { + throw new IOException(); + } catch(IOException ex) { + throw new IllegalStateException(); + } + } + + public int getPlayerScoreThrows(String playerFile) throws FileNotFoundException { + Scanner contents = new Scanner(new File(playerFile)); + return Integer.parseInt(contents.nextLine()); + } + + public int getPlayerScoreTryCatch(String playerFile) { + try { + Scanner contents = new Scanner(new File(playerFile)); + return Integer.parseInt(contents.nextLine()); + } catch (FileNotFoundException noFile) { + throw new IllegalArgumentException("File not found"); + } + } + + public int getPlayerScoreTryCatchRecovery(String playerFile) { + try { + Scanner contents = new Scanner(new File(playerFile)); + return Integer.parseInt(contents.nextLine()); + } catch ( FileNotFoundException noFile ) { + logger.warning("File not found, resetting score."); + return 0; + } + } + + public int getPlayerScoreFinally(String playerFile) throws FileNotFoundException { + Scanner contents = null; + try { + contents = new Scanner(new File(playerFile)); + return Integer.parseInt(contents.nextLine()); + } finally { + if (contents != null) { + contents.close(); + } + } + } + + public int getPlayerScoreTryWithResources(String playerFile) { + try (Scanner contents = new Scanner(new File(playerFile))) { + return Integer.parseInt(contents.nextLine()); + } catch (FileNotFoundException e ) { + logger.warning("File not found, resetting score."); + return 0; + } + } + + public int getPlayerScoreMultipleCatchBlocks(String playerFile) { + try (Scanner contents = new Scanner(new File(playerFile))) { + return Integer.parseInt(contents.nextLine()); + } catch (IOException e) { + logger.warning("Player file wouldn't load!"); + return 0; + } catch (NumberFormatException e) { + logger.warning("Player file was corrupted!"); + return 0; + } + } + + public int getPlayerScoreMultipleCatchBlocksAlternative(String playerFile) { + try (Scanner contents = new Scanner(new File(playerFile)) ) { + return Integer.parseInt(contents.nextLine()); + } catch (FileNotFoundException e) { + logger.warning("Player file not found!"); + return 0; + } catch (IOException e) { + logger.warning("Player file wouldn't load!"); + return 0; + } catch (NumberFormatException e) { + logger.warning("Player file was corrupted!"); + return 0; + } + } + + public int getPlayerScoreUnionCatchBlocks(String playerFile) { + try (Scanner contents = new Scanner(new File(playerFile))) { + return Integer.parseInt(contents.nextLine()); + } catch (IOException | NumberFormatException e) { + logger.warning("Failed to load score!"); + return 0; + } + } + + public List loadAllPlayersThrowingChecked(String playersFile) throws TimeoutException { + boolean tooLong = true; + + while (!tooLong) { + // ... potentially long operation + } + throw new TimeoutException("This operation took too long"); + } + + public List loadAllPlayersThrowingUnchecked(String playersFile) throws TimeoutException { + if(!isFilenameValid(playersFile)) { + throw new IllegalArgumentException("Filename isn't valid!"); + } + return null; + + // ... + } + + public List loadAllPlayersWrapping(String playersFile) throws IOException { + try { + throw new IOException(); + } catch (IOException io) { + throw io; + } + } + + public List loadAllPlayersRethrowing(String playersFile) throws PlayerLoadException { + try { + throw new IOException(); + } catch (IOException io) { + throw new PlayerLoadException(io); + } + } + + public List loadAllPlayersThrowable(String playersFile) { + try { + throw new NullPointerException(); + } catch ( Throwable t ) { + throw t; + } + } + + class FewerExceptions extends Exceptions { + @Override + public List loadAllPlayers(String playersFile) { //can't add "throws MyCheckedException + return null; + // overridden + } + } + + public void throwAsGotoAntiPattern() throws MyException { + try { + // bunch of code + throw new MyException(); + // second bunch of code + } catch ( MyException e ) { + // third bunch of code + } + } + + public int getPlayerScoreSwallowingExceptionAntiPattern(String playerFile) { + try { + // ... + } catch (Exception e) {} // <== catch and swallow + return 0; + } + + public int getPlayerScoreSwallowingExceptionAntiPatternAlternative(String playerFile) { + try { + // ... + } catch (Exception e) { + e.printStackTrace(); + } + return 0; + } + + public int getPlayerScoreSwallowingExceptionAntiPatternAlternative2(String playerFile) throws PlayerScoreException { + try { + throw new IOException(); + } catch (IOException e) { + throw new PlayerScoreException(e); + } + } + + public int getPlayerScoreReturnInFinallyAntiPattern(String playerFile) { + int score = 0; + try { + throw new IOException(); + } finally { + return score; // <== the IOException is dropped + } + } + + private boolean isFilenameValid(String name) { + return false; + } +} diff --git a/core-java-lang/src/main/java/com/baeldung/exceptionhandling/MyException.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/MyException.java similarity index 94% rename from core-java-lang/src/main/java/com/baeldung/exceptionhandling/MyException.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/MyException.java index 5a50acc4de..c2908b7278 100644 --- a/core-java-lang/src/main/java/com/baeldung/exceptionhandling/MyException.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/MyException.java @@ -1,5 +1,5 @@ -package com.baeldung.exceptionhandling; - -public class MyException extends Throwable { - -} +package com.baeldung.exceptionhandling; + +public class MyException extends Throwable { + +} diff --git a/core-java-lang/src/main/java/com/baeldung/exceptionhandling/Player.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/Player.java similarity index 93% rename from core-java-lang/src/main/java/com/baeldung/exceptionhandling/Player.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/Player.java index 4efd37134f..e866802fe3 100644 --- a/core-java-lang/src/main/java/com/baeldung/exceptionhandling/Player.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/Player.java @@ -1,12 +1,12 @@ -package com.baeldung.exceptionhandling; - -public class Player { - - public int id; - public String name; - - public Player(String name) { - this.name = name; - } - -} +package com.baeldung.exceptionhandling; + +public class Player { + + public int id; + public String name; + + public Player(String name) { + this.name = name; + } + +} diff --git a/core-java-lang/src/main/java/com/baeldung/exceptionhandling/PlayerLoadException.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/PlayerLoadException.java similarity index 94% rename from core-java-lang/src/main/java/com/baeldung/exceptionhandling/PlayerLoadException.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/PlayerLoadException.java index 5302fd8e7d..d92edeebbd 100644 --- a/core-java-lang/src/main/java/com/baeldung/exceptionhandling/PlayerLoadException.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/PlayerLoadException.java @@ -1,11 +1,11 @@ -package com.baeldung.exceptionhandling; - -import java.io.IOException; - -public class PlayerLoadException extends Exception { - - public PlayerLoadException(IOException io) { - super(io); - } - -} +package com.baeldung.exceptionhandling; + +import java.io.IOException; + +public class PlayerLoadException extends Exception { + + public PlayerLoadException(IOException io) { + super(io); + } + +} diff --git a/core-java-lang/src/main/java/com/baeldung/exceptionhandling/PlayerScoreException.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/PlayerScoreException.java similarity index 95% rename from core-java-lang/src/main/java/com/baeldung/exceptionhandling/PlayerScoreException.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/PlayerScoreException.java index d11159217e..299370ee86 100644 --- a/core-java-lang/src/main/java/com/baeldung/exceptionhandling/PlayerScoreException.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/PlayerScoreException.java @@ -1,8 +1,8 @@ -package com.baeldung.exceptionhandling; - -public class PlayerScoreException extends Exception { - - public PlayerScoreException(Exception e) { - super(e); - } -} +package com.baeldung.exceptionhandling; + +public class PlayerScoreException extends Exception { + + public PlayerScoreException(Exception e) { + super(e); + } +} diff --git a/core-java-lang/src/main/java/com/baeldung/exceptionhandling/TimeoutException.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/TimeoutException.java similarity index 95% rename from core-java-lang/src/main/java/com/baeldung/exceptionhandling/TimeoutException.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/TimeoutException.java index 294ad542d3..0211284e5d 100644 --- a/core-java-lang/src/main/java/com/baeldung/exceptionhandling/TimeoutException.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/exceptionhandling/TimeoutException.java @@ -1,8 +1,8 @@ -package com.baeldung.exceptionhandling; - -public class TimeoutException extends Exception { - - public TimeoutException(String message) { - super(message); - } -} +package com.baeldung.exceptionhandling; + +public class TimeoutException extends Exception { + + public TimeoutException(String message) { + super(message); + } +} diff --git a/core-java-lang/src/main/java/com/baeldung/finalize/CloseableResource.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/finalize/CloseableResource.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/finalize/CloseableResource.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/finalize/CloseableResource.java diff --git a/core-java-lang/src/main/java/com/baeldung/finalize/Finalizable.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/finalize/Finalizable.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/finalize/Finalizable.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/finalize/Finalizable.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/Box.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/Box.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/Box.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/Box.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/CommaSeparatedCustomers.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/CommaSeparatedCustomers.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/CommaSeparatedCustomers.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/CommaSeparatedCustomers.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/Customer.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/Customer.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/Customer.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/Customer.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/Employee.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/Employee.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/Employee.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/Employee.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/EmployeeSalaryComparator.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/EmployeeSalaryComparator.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/EmployeeSalaryComparator.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/EmployeeSalaryComparator.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/HasColor.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/HasColor.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/HasColor.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/HasColor.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Car.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Car.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Car.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Car.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Fly.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Fly.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Fly.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Fly.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Transform.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Transform.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Transform.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Transform.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Vehicle.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Vehicle.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Vehicle.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/multiinheritance/Vehicle.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/Circle.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/Circle.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/Circle.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/Circle.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/MainTestClass.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/MainTestClass.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/MainTestClass.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/MainTestClass.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/Shape.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/Shape.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/Shape.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/Shape.java diff --git a/core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/Square.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/Square.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/Square.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/interfaces/polymorphysim/Square.java diff --git a/core-java-lang/src/main/java/com/baeldung/java/reflection/Animal.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Animal.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/java/reflection/Animal.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Animal.java diff --git a/core-java-lang/src/main/java/com/baeldung/java/reflection/Bird.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Bird.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/java/reflection/Bird.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Bird.java diff --git a/core-java-lang/src/main/java/com/baeldung/java/reflection/DynamicGreeter.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/DynamicGreeter.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/java/reflection/DynamicGreeter.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/DynamicGreeter.java diff --git a/core-java-lang/src/main/java/com/baeldung/java/reflection/Eating.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Eating.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/java/reflection/Eating.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Eating.java diff --git a/core-java-lang/src/main/java/com/baeldung/java/reflection/Goat.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Goat.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/java/reflection/Goat.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Goat.java diff --git a/core-java-lang/src/main/java/com/baeldung/java/reflection/Greeter.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Greeter.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/java/reflection/Greeter.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Greeter.java diff --git a/core-java-lang/src/main/java/com/baeldung/java/reflection/GreetingAnnotation.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/GreetingAnnotation.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/java/reflection/GreetingAnnotation.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/GreetingAnnotation.java diff --git a/core-java-lang/src/main/java/com/baeldung/java/reflection/Greetings.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Greetings.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/java/reflection/Greetings.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Greetings.java diff --git a/core-java-lang/src/main/java/com/baeldung/java/reflection/Locomotion.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Locomotion.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/java/reflection/Locomotion.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Locomotion.java diff --git a/core-java-lang/src/main/java/com/baeldung/java/reflection/Operations.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Operations.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/java/reflection/Operations.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Operations.java diff --git a/core-java-lang/src/main/java/com/baeldung/java/reflection/Person.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Person.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/java/reflection/Person.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/java/reflection/Person.java diff --git a/core-java-lang/src/main/java/com/baeldung/keywords/finalize/FinalizeObject.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/keywords/finalize/FinalizeObject.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/keywords/finalize/FinalizeObject.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/keywords/finalize/FinalizeObject.java diff --git a/core-java-lang/src/main/java/com/baeldung/keywords/finalkeyword/Child.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/keywords/finalkeyword/Child.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/keywords/finalkeyword/Child.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/keywords/finalkeyword/Child.java diff --git a/core-java-lang/src/main/java/com/baeldung/keywords/finalkeyword/GrandChild.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/keywords/finalkeyword/GrandChild.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/keywords/finalkeyword/GrandChild.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/keywords/finalkeyword/GrandChild.java diff --git a/core-java-lang/src/main/java/com/baeldung/keywords/finalkeyword/Parent.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/keywords/finalkeyword/Parent.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/keywords/finalkeyword/Parent.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/keywords/finalkeyword/Parent.java diff --git a/core-java-lang/src/main/java/com/baeldung/keywords/finallykeyword/FinallyExample.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/keywords/finallykeyword/FinallyExample.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/keywords/finallykeyword/FinallyExample.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/keywords/finallykeyword/FinallyExample.java diff --git a/core-java-lang/src/main/java/com/baeldung/nativekeyword/DateTimeUtils.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/nativekeyword/DateTimeUtils.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/nativekeyword/DateTimeUtils.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/nativekeyword/DateTimeUtils.java diff --git a/core-java-lang/src/main/java/com/baeldung/nativekeyword/NativeMainApp.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/nativekeyword/NativeMainApp.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/nativekeyword/NativeMainApp.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/nativekeyword/NativeMainApp.java diff --git a/core-java-lang/src/main/java/com/baeldung/noclassdeffounderror/ClassWithInitErrors.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/noclassdeffounderror/ClassWithInitErrors.java similarity index 95% rename from core-java-lang/src/main/java/com/baeldung/noclassdeffounderror/ClassWithInitErrors.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/noclassdeffounderror/ClassWithInitErrors.java index 2b19f3496d..b5b357a322 100644 --- a/core-java-lang/src/main/java/com/baeldung/noclassdeffounderror/ClassWithInitErrors.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/noclassdeffounderror/ClassWithInitErrors.java @@ -1,5 +1,5 @@ -package com.baeldung.noclassdeffounderror; - -public class ClassWithInitErrors { - static int data = 1 / 0; -} +package com.baeldung.noclassdeffounderror; + +public class ClassWithInitErrors { + static int data = 1 / 0; +} diff --git a/core-java-lang/src/main/java/com/baeldung/noclassdeffounderror/NoClassDefFoundErrorExample.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/noclassdeffounderror/NoClassDefFoundErrorExample.java similarity index 96% rename from core-java-lang/src/main/java/com/baeldung/noclassdeffounderror/NoClassDefFoundErrorExample.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/noclassdeffounderror/NoClassDefFoundErrorExample.java index 0d02391a73..7bcefbdbd3 100644 --- a/core-java-lang/src/main/java/com/baeldung/noclassdeffounderror/NoClassDefFoundErrorExample.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/noclassdeffounderror/NoClassDefFoundErrorExample.java @@ -1,14 +1,14 @@ -package com.baeldung.noclassdeffounderror; - -public class NoClassDefFoundErrorExample { - public ClassWithInitErrors getClassWithInitErrors() { - ClassWithInitErrors test; - try { - test = new ClassWithInitErrors(); - } catch (Throwable t) { - System.out.println(t); - } - test = new ClassWithInitErrors(); - return test; - } +package com.baeldung.noclassdeffounderror; + +public class NoClassDefFoundErrorExample { + public ClassWithInitErrors getClassWithInitErrors() { + ClassWithInitErrors test; + try { + test = new ClassWithInitErrors(); + } catch (Throwable t) { + System.out.println(t); + } + test = new ClassWithInitErrors(); + return test; + } } \ No newline at end of file diff --git a/core-java-lang/src/main/java/com/baeldung/objects/Car.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/objects/Car.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/objects/Car.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/objects/Car.java diff --git a/core-java-lang/src/main/java/com/baeldung/packages/TodoApp.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/packages/TodoApp.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/packages/TodoApp.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/packages/TodoApp.java diff --git a/core-java-lang/src/main/java/com/baeldung/packages/TodoList.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/packages/TodoList.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/packages/TodoList.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/packages/TodoList.java diff --git a/core-java-lang/src/main/java/com/baeldung/packages/domain/TodoItem.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/packages/domain/TodoItem.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/packages/domain/TodoItem.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/packages/domain/TodoItem.java diff --git a/core-java-lang/src/main/java/com/baeldung/parameterpassing/NonPrimitives.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/parameterpassing/NonPrimitives.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/parameterpassing/NonPrimitives.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/parameterpassing/NonPrimitives.java diff --git a/core-java-lang/src/main/java/com/baeldung/parameterpassing/Primitives.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/parameterpassing/Primitives.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/parameterpassing/Primitives.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/parameterpassing/Primitives.java diff --git a/core-java-lang/src/main/java/com/baeldung/recursion/BinaryNode.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/recursion/BinaryNode.java similarity index 95% rename from core-java-lang/src/main/java/com/baeldung/recursion/BinaryNode.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/recursion/BinaryNode.java index 0c3f0ecc40..c5dd746a4c 100644 --- a/core-java-lang/src/main/java/com/baeldung/recursion/BinaryNode.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/recursion/BinaryNode.java @@ -1,31 +1,31 @@ -package com.baeldung.recursion; - -public class BinaryNode { - int value; - BinaryNode left; - BinaryNode right; - - public BinaryNode(int value){ - this.value = value; - } - - public int getValue() { - return value; - } - public void setValue(int value) { - this.value = value; - } - public BinaryNode getLeft() { - return left; - } - public void setLeft(BinaryNode left) { - this.left = left; - } - public BinaryNode getRight() { - return right; - } - public void setRight(BinaryNode right) { - this.right = right; - } - -} +package com.baeldung.recursion; + +public class BinaryNode { + int value; + BinaryNode left; + BinaryNode right; + + public BinaryNode(int value){ + this.value = value; + } + + public int getValue() { + return value; + } + public void setValue(int value) { + this.value = value; + } + public BinaryNode getLeft() { + return left; + } + public void setLeft(BinaryNode left) { + this.left = left; + } + public BinaryNode getRight() { + return right; + } + public void setRight(BinaryNode right) { + this.right = right; + } + +} diff --git a/core-java-lang/src/main/java/com/baeldung/recursion/RecursionExample.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/recursion/RecursionExample.java similarity index 95% rename from core-java-lang/src/main/java/com/baeldung/recursion/RecursionExample.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/recursion/RecursionExample.java index 649c0e0587..b6800d2e7e 100644 --- a/core-java-lang/src/main/java/com/baeldung/recursion/RecursionExample.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/recursion/RecursionExample.java @@ -1,64 +1,64 @@ -package com.baeldung.recursion; - -public class RecursionExample { - - public int sum(int n){ - if (n >= 1){ - return sum(n - 1) + n; - } - return n; - } - - public int tailSum(int currentSum, int n){ - if (n <= 1) { - return currentSum + n; - } - return tailSum(currentSum + n, n - 1); - } - - public int iterativeSum(int n){ - int sum = 0; - if(n < 0){ - return -1; - } - for(int i=0; i<=n; i++){ - sum += i; - } - return sum; - } - - public int powerOf10(int n){ - if (n == 0){ - return 1; - } - return powerOf10(n-1)*10; - } - - public int fibonacci(int n){ - if (n <=1 ){ - return n; - } - return fibonacci(n-1) + fibonacci(n-2); - } - - public String toBinary(int n){ - if (n <= 1 ){ - return String.valueOf(n); - } - return toBinary(n / 2) + String.valueOf(n % 2); - } - - public int calculateTreeHeight(BinaryNode root){ - if (root!= null){ - if (root.getLeft() != null || root.getRight() != null){ - return 1 + max(calculateTreeHeight(root.left) , calculateTreeHeight(root.right)); - } - } - return 0; - } - - public int max(int a,int b){ - return a>b ? a:b; - } - -} +package com.baeldung.recursion; + +public class RecursionExample { + + public int sum(int n){ + if (n >= 1){ + return sum(n - 1) + n; + } + return n; + } + + public int tailSum(int currentSum, int n){ + if (n <= 1) { + return currentSum + n; + } + return tailSum(currentSum + n, n - 1); + } + + public int iterativeSum(int n){ + int sum = 0; + if(n < 0){ + return -1; + } + for(int i=0; i<=n; i++){ + sum += i; + } + return sum; + } + + public int powerOf10(int n){ + if (n == 0){ + return 1; + } + return powerOf10(n-1)*10; + } + + public int fibonacci(int n){ + if (n <=1 ){ + return n; + } + return fibonacci(n-1) + fibonacci(n-2); + } + + public String toBinary(int n){ + if (n <= 1 ){ + return String.valueOf(n); + } + return toBinary(n / 2) + String.valueOf(n % 2); + } + + public int calculateTreeHeight(BinaryNode root){ + if (root!= null){ + if (root.getLeft() != null || root.getRight() != null){ + return 1 + max(calculateTreeHeight(root.left) , calculateTreeHeight(root.right)); + } + } + return 0; + } + + public int max(int a,int b){ + return a>b ? a:b; + } + +} diff --git a/core-java-lang/src/main/java/com/baeldung/scope/BracketScopeExample.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/scope/BracketScopeExample.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/scope/BracketScopeExample.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/scope/BracketScopeExample.java diff --git a/core-java-lang/src/main/java/com/baeldung/scope/ClassScopeExample.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/scope/ClassScopeExample.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/scope/ClassScopeExample.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/scope/ClassScopeExample.java diff --git a/core-java-lang/src/main/java/com/baeldung/scope/LoopScopeExample.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/scope/LoopScopeExample.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/scope/LoopScopeExample.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/scope/LoopScopeExample.java diff --git a/core-java-lang/src/main/java/com/baeldung/scope/MethodScopeExample.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/scope/MethodScopeExample.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/scope/MethodScopeExample.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/scope/MethodScopeExample.java diff --git a/core-java-lang/src/main/java/com/baeldung/scope/NestedScopesExample.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/scope/NestedScopesExample.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/scope/NestedScopesExample.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/scope/NestedScopesExample.java diff --git a/core-java-lang/src/main/java/com/baeldung/sneakythrows/SneakyRunnable.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/sneakythrows/SneakyRunnable.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/sneakythrows/SneakyRunnable.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/sneakythrows/SneakyRunnable.java diff --git a/core-java-lang/src/main/java/com/baeldung/sneakythrows/SneakyThrows.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/sneakythrows/SneakyThrows.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/sneakythrows/SneakyThrows.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/sneakythrows/SneakyThrows.java diff --git a/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/AccountHolder.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/AccountHolder.java similarity index 96% rename from core-java-lang/src/main/java/com/baeldung/stackoverflowerror/AccountHolder.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/AccountHolder.java index 9555433792..91b8a3bbb0 100644 --- a/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/AccountHolder.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/AccountHolder.java @@ -1,8 +1,8 @@ -package com.baeldung.stackoverflowerror; - -public class AccountHolder { - private String firstName; - private String lastName; - - AccountHolder jointAccountHolder = new AccountHolder(); -} +package com.baeldung.stackoverflowerror; + +public class AccountHolder { + private String firstName; + private String lastName; + + AccountHolder jointAccountHolder = new AccountHolder(); +} diff --git a/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/ClassOne.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/ClassOne.java similarity index 95% rename from core-java-lang/src/main/java/com/baeldung/stackoverflowerror/ClassOne.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/ClassOne.java index 99ef2b4f92..3b95fd1368 100644 --- a/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/ClassOne.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/ClassOne.java @@ -1,16 +1,16 @@ -package com.baeldung.stackoverflowerror; - -public class ClassOne { - private int oneValue; - private ClassTwo clsTwoInstance = null; - - public ClassOne() { - oneValue = 0; - clsTwoInstance = new ClassTwo(); - } - - public ClassOne(int oneValue, ClassTwo clsTwoInstance) { - this.oneValue = oneValue; - this.clsTwoInstance = clsTwoInstance; - } -} +package com.baeldung.stackoverflowerror; + +public class ClassOne { + private int oneValue; + private ClassTwo clsTwoInstance = null; + + public ClassOne() { + oneValue = 0; + clsTwoInstance = new ClassTwo(); + } + + public ClassOne(int oneValue, ClassTwo clsTwoInstance) { + this.oneValue = oneValue; + this.clsTwoInstance = clsTwoInstance; + } +} diff --git a/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/ClassTwo.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/ClassTwo.java similarity index 95% rename from core-java-lang/src/main/java/com/baeldung/stackoverflowerror/ClassTwo.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/ClassTwo.java index 0d34ac3c32..0adf075b43 100644 --- a/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/ClassTwo.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/ClassTwo.java @@ -1,16 +1,16 @@ -package com.baeldung.stackoverflowerror; - -public class ClassTwo { - private int twoValue; - private ClassOne clsOneInstance = null; - - public ClassTwo() { - twoValue = 10; - clsOneInstance = new ClassOne(); - } - - public ClassTwo(int twoValue, ClassOne clsOneInstance) { - this.twoValue = twoValue; - this.clsOneInstance = clsOneInstance; - } -} +package com.baeldung.stackoverflowerror; + +public class ClassTwo { + private int twoValue; + private ClassOne clsOneInstance = null; + + public ClassTwo() { + twoValue = 10; + clsOneInstance = new ClassOne(); + } + + public ClassTwo(int twoValue, ClassOne clsOneInstance) { + this.twoValue = twoValue; + this.clsOneInstance = clsOneInstance; + } +} diff --git a/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/InfiniteRecursionWithTerminationCondition.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/InfiniteRecursionWithTerminationCondition.java similarity index 97% rename from core-java-lang/src/main/java/com/baeldung/stackoverflowerror/InfiniteRecursionWithTerminationCondition.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/InfiniteRecursionWithTerminationCondition.java index 9fb00d4b83..c67eeb30d1 100644 --- a/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/InfiniteRecursionWithTerminationCondition.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/InfiniteRecursionWithTerminationCondition.java @@ -1,7 +1,7 @@ -package com.baeldung.stackoverflowerror; - -public class InfiniteRecursionWithTerminationCondition { - public int calculateFactorial(final int number) { - return number == 1 ? 1 : number * calculateFactorial(number - 1); - } -} +package com.baeldung.stackoverflowerror; + +public class InfiniteRecursionWithTerminationCondition { + public int calculateFactorial(final int number) { + return number == 1 ? 1 : number * calculateFactorial(number - 1); + } +} diff --git a/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/RecursionWithCorrectTerminationCondition.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/RecursionWithCorrectTerminationCondition.java similarity index 97% rename from core-java-lang/src/main/java/com/baeldung/stackoverflowerror/RecursionWithCorrectTerminationCondition.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/RecursionWithCorrectTerminationCondition.java index 16d771f389..8d10c65dcc 100644 --- a/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/RecursionWithCorrectTerminationCondition.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/RecursionWithCorrectTerminationCondition.java @@ -1,7 +1,7 @@ -package com.baeldung.stackoverflowerror; - -public class RecursionWithCorrectTerminationCondition { - public int calculateFactorial(final int number) { - return number <= 1 ? 1 : number * calculateFactorial(number - 1); - } -} +package com.baeldung.stackoverflowerror; + +public class RecursionWithCorrectTerminationCondition { + public int calculateFactorial(final int number) { + return number <= 1 ? 1 : number * calculateFactorial(number - 1); + } +} diff --git a/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/UnintendedInfiniteRecursion.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/UnintendedInfiniteRecursion.java similarity index 96% rename from core-java-lang/src/main/java/com/baeldung/stackoverflowerror/UnintendedInfiniteRecursion.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/UnintendedInfiniteRecursion.java index f5160c3eb3..0b7fb3cf94 100644 --- a/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/UnintendedInfiniteRecursion.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/stackoverflowerror/UnintendedInfiniteRecursion.java @@ -1,7 +1,7 @@ -package com.baeldung.stackoverflowerror; - -public class UnintendedInfiniteRecursion { - public int calculateFactorial(int number) { - return number * calculateFactorial(number - 1); - } -} +package com.baeldung.stackoverflowerror; + +public class UnintendedInfiniteRecursion { + public int calculateFactorial(int number) { + return number * calculateFactorial(number - 1); + } +} diff --git a/core-java-lang/src/main/java/com/baeldung/synthetic/BridgeMethodDemo.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/synthetic/BridgeMethodDemo.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/synthetic/BridgeMethodDemo.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/synthetic/BridgeMethodDemo.java diff --git a/core-java-lang/src/main/java/com/baeldung/synthetic/SyntheticConstructorDemo.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/synthetic/SyntheticConstructorDemo.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/synthetic/SyntheticConstructorDemo.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/synthetic/SyntheticConstructorDemo.java diff --git a/core-java-lang/src/main/java/com/baeldung/synthetic/SyntheticFieldDemo.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/synthetic/SyntheticFieldDemo.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/synthetic/SyntheticFieldDemo.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/synthetic/SyntheticFieldDemo.java diff --git a/core-java-lang/src/main/java/com/baeldung/synthetic/SyntheticMethodDemo.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/synthetic/SyntheticMethodDemo.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/synthetic/SyntheticMethodDemo.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/synthetic/SyntheticMethodDemo.java diff --git a/core-java-lang/src/main/java/com/baeldung/throwsexception/DataAccessException.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/throwsexception/DataAccessException.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/throwsexception/DataAccessException.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/throwsexception/DataAccessException.java diff --git a/core-java-lang/src/main/java/com/baeldung/throwsexception/Main.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/throwsexception/Main.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/throwsexception/Main.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/throwsexception/Main.java diff --git a/core-java-lang/src/main/java/com/baeldung/throwsexception/PersonRepository.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/throwsexception/PersonRepository.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/throwsexception/PersonRepository.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/throwsexception/PersonRepository.java diff --git a/core-java-lang/src/main/java/com/baeldung/throwsexception/SimpleService.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/throwsexception/SimpleService.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/throwsexception/SimpleService.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/throwsexception/SimpleService.java diff --git a/core-java-lang/src/main/java/com/baeldung/throwsexception/TryCatch.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/throwsexception/TryCatch.java similarity index 100% rename from core-java-lang/src/main/java/com/baeldung/throwsexception/TryCatch.java rename to core-java-modules/core-java-lang/src/main/java/com/baeldung/throwsexception/TryCatch.java diff --git a/core-java-lang/src/main/resources/file.txt b/core-java-modules/core-java-lang/src/main/resources/file.txt similarity index 100% rename from core-java-lang/src/main/resources/file.txt rename to core-java-modules/core-java-lang/src/main/resources/file.txt diff --git a/core-java-lang/src/test/java/com/baeldung/binding/AnimalActivityUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/binding/AnimalActivityUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/binding/AnimalActivityUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/binding/AnimalActivityUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/binding/AnimalUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/binding/AnimalUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/binding/AnimalUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/binding/AnimalUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/binding/CatUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/binding/CatUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/binding/CatUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/binding/CatUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/classnotfoundexception/ClassNotFoundExceptionUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/classnotfoundexception/ClassNotFoundExceptionUnitTest.java similarity index 97% rename from core-java-lang/src/test/java/com/baeldung/classnotfoundexception/ClassNotFoundExceptionUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/classnotfoundexception/ClassNotFoundExceptionUnitTest.java index b076b0324a..59605fb1c9 100644 --- a/core-java-lang/src/test/java/com/baeldung/classnotfoundexception/ClassNotFoundExceptionUnitTest.java +++ b/core-java-modules/core-java-lang/src/test/java/com/baeldung/classnotfoundexception/ClassNotFoundExceptionUnitTest.java @@ -1,11 +1,11 @@ -package com.baeldung.classnotfoundexception; - -import org.junit.Test; - -public class ClassNotFoundExceptionUnitTest { - - @Test(expected = ClassNotFoundException.class) - public void givenNoDriversInClassPath_whenLoadDrivers_thenClassNotFoundException() throws ClassNotFoundException { - Class.forName("oracle.jdbc.driver.OracleDriver"); - } +package com.baeldung.classnotfoundexception; + +import org.junit.Test; + +public class ClassNotFoundExceptionUnitTest { + + @Test(expected = ClassNotFoundException.class) + public void givenNoDriversInClassPath_whenLoadDrivers_thenClassNotFoundException() throws ClassNotFoundException { + Class.forName("oracle.jdbc.driver.OracleDriver"); + } } \ No newline at end of file diff --git a/core-java-lang/src/test/java/com/baeldung/comparable/ComparableUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/comparable/ComparableUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/comparable/ComparableUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/comparable/ComparableUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/comparator/ComparatorUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/comparator/ComparatorUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/comparator/ComparatorUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/comparator/ComparatorUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/comparator/Java8ComparatorUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/comparator/Java8ComparatorUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/comparator/Java8ComparatorUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/comparator/Java8ComparatorUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/customexception/IncorrectFileExtensionExceptionUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/customexception/IncorrectFileExtensionExceptionUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/customexception/IncorrectFileExtensionExceptionUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/customexception/IncorrectFileExtensionExceptionUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/customexception/IncorrectFileNameExceptionUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/customexception/IncorrectFileNameExceptionUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/customexception/IncorrectFileNameExceptionUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/customexception/IncorrectFileNameExceptionUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/dynamicproxy/DynamicProxyIntegrationTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/dynamicproxy/DynamicProxyIntegrationTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/dynamicproxy/DynamicProxyIntegrationTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/dynamicproxy/DynamicProxyIntegrationTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/enums/values/Element1UnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element1UnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/enums/values/Element1UnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element1UnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/enums/values/Element2UnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element2UnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/enums/values/Element2UnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element2UnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/enums/values/Element3UnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element3UnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/enums/values/Element3UnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element3UnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/enums/values/Element4UnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element4UnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/enums/values/Element4UnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element4UnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/exceptionhandling/ExceptionsUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/exceptionhandling/ExceptionsUnitTest.java similarity index 96% rename from core-java-lang/src/test/java/com/baeldung/exceptionhandling/ExceptionsUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/exceptionhandling/ExceptionsUnitTest.java index b3f585cfe4..29c690133d 100644 --- a/core-java-lang/src/test/java/com/baeldung/exceptionhandling/ExceptionsUnitTest.java +++ b/core-java-modules/core-java-lang/src/test/java/com/baeldung/exceptionhandling/ExceptionsUnitTest.java @@ -1,80 +1,80 @@ -package com.baeldung.exceptionhandling; - -import org.junit.Test; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.NoSuchFileException; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -public class ExceptionsUnitTest { - - Exceptions exceptions = new Exceptions(); - - @Test - public void getPlayers() { - assertThatThrownBy(() -> exceptions.getPlayers()) - .isInstanceOf(NoSuchFileException.class); - } - - @Test - public void loadAllPlayers() { - assertThatThrownBy(() -> exceptions.loadAllPlayers("")) - .isInstanceOf(IllegalStateException.class); - } - - @Test - public void getPlayerScoreThrows() { - assertThatThrownBy(() -> exceptions.getPlayerScoreThrows("")) - .isInstanceOf(FileNotFoundException.class); - } - - @Test - public void getPlayerScoreTryCatch() { - assertThatThrownBy(() -> exceptions.getPlayerScoreTryCatch("")) - .isInstanceOf(IllegalArgumentException.class); - } - - @Test - public void getPlayerScoreFinally() { - assertThatThrownBy(() -> exceptions.getPlayerScoreFinally("")) - .isInstanceOf(FileNotFoundException.class); - } - - @Test - public void loadAllPlayersThrowingChecked() { - assertThatThrownBy(() -> exceptions.loadAllPlayersThrowingChecked("")) - .isInstanceOf(TimeoutException.class); - } - - @Test - public void loadAllPlayersThrowingUnchecked() { - assertThatThrownBy(() -> exceptions.loadAllPlayersThrowingUnchecked("")) - .isInstanceOf(IllegalArgumentException.class); - } - - @Test - public void loadAllPlayersWrapping() { - assertThatThrownBy(() -> exceptions.loadAllPlayersWrapping("")) - .isInstanceOf(IOException.class); - } - - @Test - public void loadAllPlayersRethrowing() { - assertThatThrownBy(() -> exceptions.loadAllPlayersRethrowing("")) - .isInstanceOf(PlayerLoadException.class); - } - - @Test - public void loadAllPlayersThrowable() { - assertThatThrownBy(() -> exceptions.loadAllPlayersThrowable("")) - .isInstanceOf(NullPointerException.class); - } - - @Test - public void getPlayerScoreSwallowingExceptionAntiPatternAlternative2() { - assertThatThrownBy(() -> exceptions.getPlayerScoreSwallowingExceptionAntiPatternAlternative2("")) - .isInstanceOf(PlayerScoreException.class); - } -} +package com.baeldung.exceptionhandling; + +import org.junit.Test; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.NoSuchFileException; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class ExceptionsUnitTest { + + Exceptions exceptions = new Exceptions(); + + @Test + public void getPlayers() { + assertThatThrownBy(() -> exceptions.getPlayers()) + .isInstanceOf(NoSuchFileException.class); + } + + @Test + public void loadAllPlayers() { + assertThatThrownBy(() -> exceptions.loadAllPlayers("")) + .isInstanceOf(IllegalStateException.class); + } + + @Test + public void getPlayerScoreThrows() { + assertThatThrownBy(() -> exceptions.getPlayerScoreThrows("")) + .isInstanceOf(FileNotFoundException.class); + } + + @Test + public void getPlayerScoreTryCatch() { + assertThatThrownBy(() -> exceptions.getPlayerScoreTryCatch("")) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + public void getPlayerScoreFinally() { + assertThatThrownBy(() -> exceptions.getPlayerScoreFinally("")) + .isInstanceOf(FileNotFoundException.class); + } + + @Test + public void loadAllPlayersThrowingChecked() { + assertThatThrownBy(() -> exceptions.loadAllPlayersThrowingChecked("")) + .isInstanceOf(TimeoutException.class); + } + + @Test + public void loadAllPlayersThrowingUnchecked() { + assertThatThrownBy(() -> exceptions.loadAllPlayersThrowingUnchecked("")) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + public void loadAllPlayersWrapping() { + assertThatThrownBy(() -> exceptions.loadAllPlayersWrapping("")) + .isInstanceOf(IOException.class); + } + + @Test + public void loadAllPlayersRethrowing() { + assertThatThrownBy(() -> exceptions.loadAllPlayersRethrowing("")) + .isInstanceOf(PlayerLoadException.class); + } + + @Test + public void loadAllPlayersThrowable() { + assertThatThrownBy(() -> exceptions.loadAllPlayersThrowable("")) + .isInstanceOf(NullPointerException.class); + } + + @Test + public void getPlayerScoreSwallowingExceptionAntiPatternAlternative2() { + assertThatThrownBy(() -> exceptions.getPlayerScoreSwallowingExceptionAntiPatternAlternative2("")) + .isInstanceOf(PlayerScoreException.class); + } +} diff --git a/core-java-lang/src/test/java/com/baeldung/finalize/FinalizeUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/finalize/FinalizeUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/finalize/FinalizeUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/finalize/FinalizeUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/interfaces/InnerInterfaceUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/interfaces/InnerInterfaceUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/interfaces/InnerInterfaceUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/interfaces/InnerInterfaceUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/java/enumiteration/DaysOfWeekEnum.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/java/enumiteration/DaysOfWeekEnum.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/java/enumiteration/DaysOfWeekEnum.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/java/enumiteration/DaysOfWeekEnum.java diff --git a/core-java-lang/src/test/java/com/baeldung/java/enumiteration/EnumIterationExamples.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/java/enumiteration/EnumIterationExamples.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/java/enumiteration/EnumIterationExamples.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/java/enumiteration/EnumIterationExamples.java diff --git a/core-java-lang/src/test/java/com/baeldung/java/reflection/OperationsUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/java/reflection/OperationsUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/java/reflection/OperationsUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/java/reflection/OperationsUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/java/reflection/ReflectionUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/java/reflection/ReflectionUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/java/reflection/ReflectionUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/java/reflection/ReflectionUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/nativekeyword/DateTimeUtilsManualTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/nativekeyword/DateTimeUtilsManualTest.java similarity index 96% rename from core-java-lang/src/test/java/com/baeldung/nativekeyword/DateTimeUtilsManualTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/nativekeyword/DateTimeUtilsManualTest.java index d5003dfc1f..ac27c11c68 100644 --- a/core-java-lang/src/test/java/com/baeldung/nativekeyword/DateTimeUtilsManualTest.java +++ b/core-java-modules/core-java-lang/src/test/java/com/baeldung/nativekeyword/DateTimeUtilsManualTest.java @@ -1,27 +1,27 @@ -package com.baeldung.nativekeyword; - -import static org.junit.Assert.assertNotNull; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.slf4j.Logger; - -public class DateTimeUtilsManualTest { - - private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(DateTimeUtilsManualTest.class); - - @BeforeClass - public static void setUpClass() { - System.loadLibrary("msvcr100"); - System.loadLibrary("libgcc_s_sjlj-1"); - System.loadLibrary("libstdc++-6"); - System.loadLibrary("nativedatetimeutils"); - } - - @Test - public void givenNativeLibsLoaded_thenNativeMethodIsAccessible() { - DateTimeUtils dateTimeUtils = new DateTimeUtils(); - LOG.info("System time is : " + dateTimeUtils.getSystemTime()); - assertNotNull(dateTimeUtils.getSystemTime()); - } -} +package com.baeldung.nativekeyword; + +import static org.junit.Assert.assertNotNull; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; + +public class DateTimeUtilsManualTest { + + private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(DateTimeUtilsManualTest.class); + + @BeforeClass + public static void setUpClass() { + System.loadLibrary("msvcr100"); + System.loadLibrary("libgcc_s_sjlj-1"); + System.loadLibrary("libstdc++-6"); + System.loadLibrary("nativedatetimeutils"); + } + + @Test + public void givenNativeLibsLoaded_thenNativeMethodIsAccessible() { + DateTimeUtils dateTimeUtils = new DateTimeUtils(); + LOG.info("System time is : " + dateTimeUtils.getSystemTime()); + assertNotNull(dateTimeUtils.getSystemTime()); + } +} diff --git a/core-java-lang/src/test/java/com/baeldung/nestedclass/AnonymousInner.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/nestedclass/AnonymousInner.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/nestedclass/AnonymousInner.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/nestedclass/AnonymousInner.java diff --git a/core-java-lang/src/test/java/com/baeldung/nestedclass/Enclosing.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/nestedclass/Enclosing.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/nestedclass/Enclosing.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/nestedclass/Enclosing.java diff --git a/core-java-lang/src/test/java/com/baeldung/nestedclass/NewEnclosing.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/nestedclass/NewEnclosing.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/nestedclass/NewEnclosing.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/nestedclass/NewEnclosing.java diff --git a/core-java-lang/src/test/java/com/baeldung/nestedclass/NewOuter.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/nestedclass/NewOuter.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/nestedclass/NewOuter.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/nestedclass/NewOuter.java diff --git a/core-java-lang/src/test/java/com/baeldung/nestedclass/Outer.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/nestedclass/Outer.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/nestedclass/Outer.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/nestedclass/Outer.java diff --git a/core-java-lang/src/test/java/com/baeldung/noclassdeffounderror/NoClassDefFoundErrorUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/noclassdeffounderror/NoClassDefFoundErrorUnitTest.java similarity index 97% rename from core-java-lang/src/test/java/com/baeldung/noclassdeffounderror/NoClassDefFoundErrorUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/noclassdeffounderror/NoClassDefFoundErrorUnitTest.java index ccc8c1f69c..521c50098a 100644 --- a/core-java-lang/src/test/java/com/baeldung/noclassdeffounderror/NoClassDefFoundErrorUnitTest.java +++ b/core-java-modules/core-java-lang/src/test/java/com/baeldung/noclassdeffounderror/NoClassDefFoundErrorUnitTest.java @@ -1,12 +1,12 @@ -package com.baeldung.noclassdeffounderror; - -import org.junit.Test; - -public class NoClassDefFoundErrorUnitTest { - - @Test(expected = NoClassDefFoundError.class) - public void givenInitErrorInClass_whenloadClass_thenNoClassDefFoundError() { - NoClassDefFoundErrorExample sample = new NoClassDefFoundErrorExample(); - sample.getClassWithInitErrors(); - } +package com.baeldung.noclassdeffounderror; + +import org.junit.Test; + +public class NoClassDefFoundErrorUnitTest { + + @Test(expected = NoClassDefFoundError.class) + public void givenInitErrorInClass_whenloadClass_thenNoClassDefFoundError() { + NoClassDefFoundErrorExample sample = new NoClassDefFoundErrorExample(); + sample.getClassWithInitErrors(); + } } \ No newline at end of file diff --git a/core-java-lang/src/test/java/com/baeldung/objects/CarUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/objects/CarUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/objects/CarUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/objects/CarUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/packages/PackagesUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/packages/PackagesUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/packages/PackagesUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/packages/PackagesUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/recursion/RecursionExampleUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/recursion/RecursionExampleUnitTest.java similarity index 96% rename from core-java-lang/src/test/java/com/baeldung/recursion/RecursionExampleUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/recursion/RecursionExampleUnitTest.java index 6c560c9c37..7b11e968ce 100644 --- a/core-java-lang/src/test/java/com/baeldung/recursion/RecursionExampleUnitTest.java +++ b/core-java-modules/core-java-lang/src/test/java/com/baeldung/recursion/RecursionExampleUnitTest.java @@ -1,61 +1,61 @@ -package com.baeldung.recursion; - -import org.junit.Assert; -import org.junit.Test; - -public class RecursionExampleUnitTest { - - RecursionExample recursion = new RecursionExample(); - - @Test - public void testPowerOf10() { - int p0 = recursion.powerOf10(0); - int p1 = recursion.powerOf10(1); - int p4 = recursion.powerOf10(4); - - Assert.assertEquals(1, p0); - Assert.assertEquals(10, p1); - Assert.assertEquals(10000, p4); - } - - @Test - public void testFibonacci() { - int n0 = recursion.fibonacci(0); - int n1 = recursion.fibonacci(1); - int n7 = recursion.fibonacci(7); - - Assert.assertEquals(0, n0); - Assert.assertEquals(1, n1); - Assert.assertEquals(13, n7); - } - - @Test - public void testToBinary() { - String b0 = recursion.toBinary(0); - String b1 = recursion.toBinary(1); - String b10 = recursion.toBinary(10); - - Assert.assertEquals("0", b0); - Assert.assertEquals("1", b1); - Assert.assertEquals("1010", b10); - } - - @Test - public void testCalculateTreeHeight() { - BinaryNode root = new BinaryNode(1); - root.setLeft(new BinaryNode(1)); - root.setRight(new BinaryNode(1)); - - root.getLeft().setLeft(new BinaryNode(1)); - root.getLeft().getLeft().setRight(new BinaryNode(1)); - root.getLeft().getLeft().getRight().setLeft(new BinaryNode(1)); - - root.getRight().setLeft(new BinaryNode(1)); - root.getRight().getLeft().setRight(new BinaryNode(1)); - - int height = recursion.calculateTreeHeight(root); - - Assert.assertEquals(4, height); - } - -} +package com.baeldung.recursion; + +import org.junit.Assert; +import org.junit.Test; + +public class RecursionExampleUnitTest { + + RecursionExample recursion = new RecursionExample(); + + @Test + public void testPowerOf10() { + int p0 = recursion.powerOf10(0); + int p1 = recursion.powerOf10(1); + int p4 = recursion.powerOf10(4); + + Assert.assertEquals(1, p0); + Assert.assertEquals(10, p1); + Assert.assertEquals(10000, p4); + } + + @Test + public void testFibonacci() { + int n0 = recursion.fibonacci(0); + int n1 = recursion.fibonacci(1); + int n7 = recursion.fibonacci(7); + + Assert.assertEquals(0, n0); + Assert.assertEquals(1, n1); + Assert.assertEquals(13, n7); + } + + @Test + public void testToBinary() { + String b0 = recursion.toBinary(0); + String b1 = recursion.toBinary(1); + String b10 = recursion.toBinary(10); + + Assert.assertEquals("0", b0); + Assert.assertEquals("1", b1); + Assert.assertEquals("1010", b10); + } + + @Test + public void testCalculateTreeHeight() { + BinaryNode root = new BinaryNode(1); + root.setLeft(new BinaryNode(1)); + root.setRight(new BinaryNode(1)); + + root.getLeft().setLeft(new BinaryNode(1)); + root.getLeft().getLeft().setRight(new BinaryNode(1)); + root.getLeft().getLeft().getRight().setLeft(new BinaryNode(1)); + + root.getRight().setLeft(new BinaryNode(1)); + root.getRight().getLeft().setRight(new BinaryNode(1)); + + int height = recursion.calculateTreeHeight(root); + + Assert.assertEquals(4, height); + } + +} diff --git a/core-java-lang/src/test/java/com/baeldung/sneakythrows/SneakyRunnableUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/sneakythrows/SneakyRunnableUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/sneakythrows/SneakyRunnableUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/sneakythrows/SneakyRunnableUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/sneakythrows/SneakyThrowsUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/sneakythrows/SneakyThrowsUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/sneakythrows/SneakyThrowsUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/sneakythrows/SneakyThrowsUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/AccountHolderManualTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/AccountHolderManualTest.java similarity index 96% rename from core-java-lang/src/test/java/com/baeldung/stackoverflowerror/AccountHolderManualTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/AccountHolderManualTest.java index e6a8f89a16..180b7723ac 100644 --- a/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/AccountHolderManualTest.java +++ b/core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/AccountHolderManualTest.java @@ -1,10 +1,10 @@ -package com.baeldung.stackoverflowerror; - -import org.junit.Test; - -public class AccountHolderManualTest { - @Test(expected = StackOverflowError.class) - public void whenInstanciatingAccountHolder_thenThrowsException() { - AccountHolder holder = new AccountHolder(); - } -} +package com.baeldung.stackoverflowerror; + +import org.junit.Test; + +public class AccountHolderManualTest { + @Test(expected = StackOverflowError.class) + public void whenInstanciatingAccountHolder_thenThrowsException() { + AccountHolder holder = new AccountHolder(); + } +} diff --git a/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/CyclicDependancyManualTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/CyclicDependancyManualTest.java similarity index 96% rename from core-java-lang/src/test/java/com/baeldung/stackoverflowerror/CyclicDependancyManualTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/CyclicDependancyManualTest.java index 1f1de9149a..95164ac935 100644 --- a/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/CyclicDependancyManualTest.java +++ b/core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/CyclicDependancyManualTest.java @@ -1,10 +1,10 @@ -package com.baeldung.stackoverflowerror; - -import org.junit.Test; - -public class CyclicDependancyManualTest { - @Test(expected = StackOverflowError.class) - public void whenInstanciatingClassOne_thenThrowsException() { - ClassOne obj = new ClassOne(); - } -} +package com.baeldung.stackoverflowerror; + +import org.junit.Test; + +public class CyclicDependancyManualTest { + @Test(expected = StackOverflowError.class) + public void whenInstanciatingClassOne_thenThrowsException() { + ClassOne obj = new ClassOne(); + } +} diff --git a/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/InfiniteRecursionWithTerminationConditionManualTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/InfiniteRecursionWithTerminationConditionManualTest.java similarity index 97% rename from core-java-lang/src/test/java/com/baeldung/stackoverflowerror/InfiniteRecursionWithTerminationConditionManualTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/InfiniteRecursionWithTerminationConditionManualTest.java index 3530fa1c3e..ccf8c25271 100644 --- a/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/InfiniteRecursionWithTerminationConditionManualTest.java +++ b/core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/InfiniteRecursionWithTerminationConditionManualTest.java @@ -1,31 +1,31 @@ -package com.baeldung.stackoverflowerror; - -import org.junit.Test; - -import static junit.framework.TestCase.assertEquals; - -public class InfiniteRecursionWithTerminationConditionManualTest { - @Test - public void givenPositiveIntNoOne_whenCalcFact_thenCorrectlyCalc() { - int numToCalcFactorial = 1; - InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition(); - - assertEquals(1, irtc.calculateFactorial(numToCalcFactorial)); - } - - @Test - public void givenPositiveIntGtOne_whenCalcFact_thenCorrectlyCalc() { - int numToCalcFactorial = 5; - InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition(); - - assertEquals(120, irtc.calculateFactorial(numToCalcFactorial)); - } - - @Test(expected = StackOverflowError.class) - public void givenNegativeInt_whenCalcFact_thenThrowsException() { - int numToCalcFactorial = -1; - InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition(); - - irtc.calculateFactorial(numToCalcFactorial); - } -} +package com.baeldung.stackoverflowerror; + +import org.junit.Test; + +import static junit.framework.TestCase.assertEquals; + +public class InfiniteRecursionWithTerminationConditionManualTest { + @Test + public void givenPositiveIntNoOne_whenCalcFact_thenCorrectlyCalc() { + int numToCalcFactorial = 1; + InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition(); + + assertEquals(1, irtc.calculateFactorial(numToCalcFactorial)); + } + + @Test + public void givenPositiveIntGtOne_whenCalcFact_thenCorrectlyCalc() { + int numToCalcFactorial = 5; + InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition(); + + assertEquals(120, irtc.calculateFactorial(numToCalcFactorial)); + } + + @Test(expected = StackOverflowError.class) + public void givenNegativeInt_whenCalcFact_thenThrowsException() { + int numToCalcFactorial = -1; + InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition(); + + irtc.calculateFactorial(numToCalcFactorial); + } +} diff --git a/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/RecursionWithCorrectTerminationConditionManualTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/RecursionWithCorrectTerminationConditionManualTest.java similarity index 96% rename from core-java-lang/src/test/java/com/baeldung/stackoverflowerror/RecursionWithCorrectTerminationConditionManualTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/RecursionWithCorrectTerminationConditionManualTest.java index 858cec2ffa..40c2c4799e 100644 --- a/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/RecursionWithCorrectTerminationConditionManualTest.java +++ b/core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/RecursionWithCorrectTerminationConditionManualTest.java @@ -1,15 +1,15 @@ -package com.baeldung.stackoverflowerror; - -import org.junit.Test; - -import static junit.framework.TestCase.assertEquals; - -public class RecursionWithCorrectTerminationConditionManualTest { - @Test - public void givenNegativeInt_whenCalcFact_thenCorrectlyCalc() { - int numToCalcFactorial = -1; - RecursionWithCorrectTerminationCondition rctc = new RecursionWithCorrectTerminationCondition(); - - assertEquals(1, rctc.calculateFactorial(numToCalcFactorial)); - } -} +package com.baeldung.stackoverflowerror; + +import org.junit.Test; + +import static junit.framework.TestCase.assertEquals; + +public class RecursionWithCorrectTerminationConditionManualTest { + @Test + public void givenNegativeInt_whenCalcFact_thenCorrectlyCalc() { + int numToCalcFactorial = -1; + RecursionWithCorrectTerminationCondition rctc = new RecursionWithCorrectTerminationCondition(); + + assertEquals(1, rctc.calculateFactorial(numToCalcFactorial)); + } +} diff --git a/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/UnintendedInfiniteRecursionManualTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/UnintendedInfiniteRecursionManualTest.java similarity index 97% rename from core-java-lang/src/test/java/com/baeldung/stackoverflowerror/UnintendedInfiniteRecursionManualTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/UnintendedInfiniteRecursionManualTest.java index 1e1c245d4d..f4e2e5221a 100644 --- a/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/UnintendedInfiniteRecursionManualTest.java +++ b/core-java-modules/core-java-lang/src/test/java/com/baeldung/stackoverflowerror/UnintendedInfiniteRecursionManualTest.java @@ -1,30 +1,30 @@ -package com.baeldung.stackoverflowerror; - - -import org.junit.Test; - -public class UnintendedInfiniteRecursionManualTest { - @Test(expected = StackOverflowError.class) - public void givenPositiveIntNoOne_whenCalFact_thenThrowsException() { - int numToCalcFactorial = 1; - UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion(); - - uir.calculateFactorial(numToCalcFactorial); - } - - @Test(expected = StackOverflowError.class) - public void givenPositiveIntGtOne_whenCalcFact_thenThrowsException() { - int numToCalcFactorial = 2; - UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion(); - - uir.calculateFactorial(numToCalcFactorial); - } - - @Test(expected = StackOverflowError.class) - public void givenNegativeInt_whenCalcFact_thenThrowsException() { - int numToCalcFactorial = -1; - UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion(); - - uir.calculateFactorial(numToCalcFactorial); - } -} +package com.baeldung.stackoverflowerror; + + +import org.junit.Test; + +public class UnintendedInfiniteRecursionManualTest { + @Test(expected = StackOverflowError.class) + public void givenPositiveIntNoOne_whenCalFact_thenThrowsException() { + int numToCalcFactorial = 1; + UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion(); + + uir.calculateFactorial(numToCalcFactorial); + } + + @Test(expected = StackOverflowError.class) + public void givenPositiveIntGtOne_whenCalcFact_thenThrowsException() { + int numToCalcFactorial = 2; + UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion(); + + uir.calculateFactorial(numToCalcFactorial); + } + + @Test(expected = StackOverflowError.class) + public void givenNegativeInt_whenCalcFact_thenThrowsException() { + int numToCalcFactorial = -1; + UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion(); + + uir.calculateFactorial(numToCalcFactorial); + } +} diff --git a/core-java-lang/src/test/java/com/baeldung/synthetic/SyntheticUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/synthetic/SyntheticUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/synthetic/SyntheticUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/synthetic/SyntheticUnitTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/throwsexception/SimpleServiceUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/throwsexception/SimpleServiceUnitTest.java similarity index 100% rename from core-java-lang/src/test/java/com/baeldung/throwsexception/SimpleServiceUnitTest.java rename to core-java-modules/core-java-lang/src/test/java/com/baeldung/throwsexception/SimpleServiceUnitTest.java diff --git a/core-java-lang/src/test/resources/correctFileNameWithoutProperExtension b/core-java-modules/core-java-lang/src/test/resources/correctFileNameWithoutProperExtension similarity index 100% rename from core-java-lang/src/test/resources/correctFileNameWithoutProperExtension rename to core-java-modules/core-java-lang/src/test/resources/correctFileNameWithoutProperExtension diff --git a/core-java/.gitignore b/core-java-modules/core-java-networking/.gitignore similarity index 100% rename from core-java/.gitignore rename to core-java-modules/core-java-networking/.gitignore diff --git a/core-java-networking/README.md b/core-java-modules/core-java-networking/README.md similarity index 100% rename from core-java-networking/README.md rename to core-java-modules/core-java-networking/README.md diff --git a/core-java-networking/pom.xml b/core-java-modules/core-java-networking/pom.xml similarity index 96% rename from core-java-networking/pom.xml rename to core-java-modules/core-java-networking/pom.xml index 12bb257fcb..550ebdb4ff 100644 --- a/core-java-networking/pom.xml +++ b/core-java-modules/core-java-networking/pom.xml @@ -10,7 +10,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-networking/src/main/java/com/baeldung/http/FullResponseBuilder.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/http/FullResponseBuilder.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/http/FullResponseBuilder.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/http/FullResponseBuilder.java diff --git a/core-java-networking/src/main/java/com/baeldung/http/ParameterStringBuilder.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/http/ParameterStringBuilder.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/http/ParameterStringBuilder.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/http/ParameterStringBuilder.java diff --git a/core-java-networking/src/main/java/com/baeldung/mail/EmailService.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/mail/EmailService.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/mail/EmailService.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/mail/EmailService.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/cookies/PersistentCookieStore.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/cookies/PersistentCookieStore.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/cookies/PersistentCookieStore.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/cookies/PersistentCookieStore.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java similarity index 87% rename from core-java-networking/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java index 0b5f6d7714..9fbbee8501 100644 --- a/core-java-networking/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java +++ b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java @@ -17,8 +17,8 @@ public class ProxyAcceptCookiePolicy implements CookiePolicy { host = uri.getHost(); } - if (!HttpCookie.domainMatches(acceptedProxy, host)) { - return false; + if (HttpCookie.domainMatches(acceptedProxy, host)) { + return true; } return CookiePolicy.ACCEPT_ORIGINAL_SERVER.shouldAccept(uri, cookie); diff --git a/core-java-networking/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/udp/EchoClient.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/EchoClient.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/udp/EchoClient.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/EchoClient.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/udp/EchoServer.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/EchoServer.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/udp/EchoServer.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/EchoServer.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingClient.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingClient.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingClient.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingClient.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingEchoServer.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingEchoServer.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingEchoServer.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingEchoServer.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/udp/multicast/MulticastEchoServer.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/multicast/MulticastEchoServer.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/udp/multicast/MulticastEchoServer.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/multicast/MulticastEchoServer.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/udp/multicast/MulticastingClient.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/multicast/MulticastingClient.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/udp/multicast/MulticastingClient.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/multicast/MulticastingClient.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/uriurl/URIDemo.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/uriurl/URIDemo.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/uriurl/URIDemo.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/uriurl/URIDemo.java diff --git a/core-java-networking/src/main/java/com/baeldung/networking/uriurl/URLDemo.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/uriurl/URLDemo.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/networking/uriurl/URLDemo.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/uriurl/URLDemo.java diff --git a/core-java-networking/src/main/java/com/baeldung/socket/EchoClient.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/EchoClient.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/socket/EchoClient.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/EchoClient.java diff --git a/core-java-networking/src/main/java/com/baeldung/socket/EchoMultiServer.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/EchoMultiServer.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/socket/EchoMultiServer.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/EchoMultiServer.java diff --git a/core-java-networking/src/main/java/com/baeldung/socket/EchoServer.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/EchoServer.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/socket/EchoServer.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/EchoServer.java diff --git a/core-java-networking/src/main/java/com/baeldung/socket/GreetClient.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/GreetClient.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/socket/GreetClient.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/GreetClient.java diff --git a/core-java-networking/src/main/java/com/baeldung/socket/GreetServer.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/GreetServer.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/socket/GreetServer.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/GreetServer.java diff --git a/core-java-networking/src/main/java/com/baeldung/socket/read/Client.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/read/Client.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/socket/read/Client.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/read/Client.java diff --git a/core-java-networking/src/main/java/com/baeldung/socket/read/Server.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/read/Server.java similarity index 100% rename from core-java-networking/src/main/java/com/baeldung/socket/read/Server.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/read/Server.java diff --git a/core-java-networking/src/main/resources/logback.xml b/core-java-modules/core-java-networking/src/main/resources/logback.xml similarity index 100% rename from core-java-networking/src/main/resources/logback.xml rename to core-java-modules/core-java-networking/src/main/resources/logback.xml diff --git a/core-java-networking/src/test/java/com/baeldung/encoderdecoder/EncoderDecoderUnitTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/encoderdecoder/EncoderDecoderUnitTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/encoderdecoder/EncoderDecoderUnitTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/encoderdecoder/EncoderDecoderUnitTest.java diff --git a/core-java-networking/src/test/java/com/baeldung/http/HttpRequestLiveTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/http/HttpRequestLiveTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/http/HttpRequestLiveTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/http/HttpRequestLiveTest.java diff --git a/core-java-networking/src/test/java/com/baeldung/networking/interfaces/NetworkInterfaceManualTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/interfaces/NetworkInterfaceManualTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/networking/interfaces/NetworkInterfaceManualTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/interfaces/NetworkInterfaceManualTest.java diff --git a/core-java-networking/src/test/java/com/baeldung/networking/udp/UDPLiveTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/UDPLiveTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/networking/udp/UDPLiveTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/UDPLiveTest.java diff --git a/core-java-networking/src/test/java/com/baeldung/networking/udp/broadcast/BroadcastLiveTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/broadcast/BroadcastLiveTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/networking/udp/broadcast/BroadcastLiveTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/broadcast/BroadcastLiveTest.java diff --git a/core-java-networking/src/test/java/com/baeldung/networking/udp/multicast/MulticastLiveTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/multicast/MulticastLiveTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/networking/udp/multicast/MulticastLiveTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/multicast/MulticastLiveTest.java diff --git a/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIDemoLiveTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIDemoLiveTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIDemoLiveTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIDemoLiveTest.java diff --git a/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIvsURLUnitTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIvsURLUnitTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIvsURLUnitTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIvsURLUnitTest.java diff --git a/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URLDemoLiveTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URLDemoLiveTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/networking/uriurl/URLDemoLiveTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URLDemoLiveTest.java diff --git a/core-java-networking/src/test/java/com/baeldung/networking/url/UrlUnitTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/url/UrlUnitTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/networking/url/UrlUnitTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/url/UrlUnitTest.java diff --git a/core-java-networking/src/test/java/com/baeldung/socket/EchoIntegrationTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/EchoIntegrationTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/socket/EchoIntegrationTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/EchoIntegrationTest.java diff --git a/core-java-networking/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java diff --git a/core-java-networking/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java diff --git a/core-java-networking/src/test/java/com/baeldung/socket/read/SocketReadAllDataLiveTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/read/SocketReadAllDataLiveTest.java similarity index 100% rename from core-java-networking/src/test/java/com/baeldung/socket/read/SocketReadAllDataLiveTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/read/SocketReadAllDataLiveTest.java diff --git a/core-java-networking/src/test/resources/.gitignore b/core-java-modules/core-java-networking/src/test/resources/.gitignore similarity index 100% rename from core-java-networking/src/test/resources/.gitignore rename to core-java-modules/core-java-networking/src/test/resources/.gitignore diff --git a/core-java-os/.gitignore b/core-java-modules/core-java-os/.gitignore similarity index 100% rename from core-java-os/.gitignore rename to core-java-modules/core-java-os/.gitignore diff --git a/core-java-os/README.md b/core-java-modules/core-java-os/README.md similarity index 100% rename from core-java-os/README.md rename to core-java-modules/core-java-os/README.md diff --git a/core-java-os/pom.xml b/core-java-modules/core-java-os/pom.xml similarity index 95% rename from core-java-os/pom.xml rename to core-java-modules/core-java-os/pom.xml index c9097cb554..85194b176e 100644 --- a/core-java-os/pom.xml +++ b/core-java-modules/core-java-os/pom.xml @@ -1,82 +1,82 @@ - - 4.0.0 - com.baeldung - core-java-os - 0.1.0-SNAPSHOT - core-java-os - jar - - - com.baeldung - parent-java - 0.0.1-SNAPSHOT - ../parent-java - - - - - org.apache.commons - commons-collections4 - ${commons-collections4.version} - - - commons-io - commons-io - ${commons-io.version} - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - log4j - log4j - ${log4j.version} - - - - org.assertj - assertj-core - ${assertj.version} - test - - - - - core-java-os - - - src/main/resources - true - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${maven.compiler.source} - ${maven.compiler.target} - - - - - - - - 3.5 - 4.1 - 4.01 - - - 3.6.1 - 1.8.9 - 1.9 - 1.9 - 25.1-jre - - + + 4.0.0 + com.baeldung + core-java-os + 0.1.0-SNAPSHOT + core-java-os + jar + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + + + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + + + commons-io + commons-io + ${commons-io.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + log4j + log4j + ${log4j.version} + + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + core-java-os + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + + 3.5 + 4.1 + 4.01 + + + 3.6.1 + 1.8.9 + 1.9 + 1.9 + 25.1-jre + + diff --git a/core-java-os/src/main/java/com/baeldung/java9/process/ChildProcess.java b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/ChildProcess.java similarity index 100% rename from core-java-os/src/main/java/com/baeldung/java9/process/ChildProcess.java rename to core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/ChildProcess.java diff --git a/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java similarity index 96% rename from core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java rename to core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java index 443847916a..37378f9d6c 100644 --- a/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java +++ b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java @@ -1,16 +1,16 @@ -package com.baeldung.java9.process; - -import java.util.logging.Level; -import java.util.logging.Logger; - -public class OutputStreamExample { - - public static void main(String[] args) { - Logger log = Logger.getLogger(OutputStreamExample.class.getName()); - log.log(Level.INFO, Integer.toString(sum(1,2))); - } - - public static int sum(int a, int b) { - return a + b; - } -} +package com.baeldung.java9.process; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class OutputStreamExample { + + public static void main(String[] args) { + Logger log = Logger.getLogger(OutputStreamExample.class.getName()); + log.log(Level.INFO, Integer.toString(sum(1,2))); + } + + public static int sum(int a, int b) { + return a + b; + } +} diff --git a/core-java-os/src/main/java/com/baeldung/java9/process/ProcessCompilationError.java b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/ProcessCompilationError.java similarity index 100% rename from core-java-os/src/main/java/com/baeldung/java9/process/ProcessCompilationError.java rename to core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/ProcessCompilationError.java diff --git a/core-java-os/src/main/java/com/baeldung/java9/process/ProcessUnderstanding.java b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/ProcessUnderstanding.java similarity index 100% rename from core-java-os/src/main/java/com/baeldung/java9/process/ProcessUnderstanding.java rename to core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/ProcessUnderstanding.java diff --git a/core-java-os/src/main/java/com/baeldung/java9/process/ProcessUtils.java b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/ProcessUtils.java similarity index 96% rename from core-java-os/src/main/java/com/baeldung/java9/process/ProcessUtils.java rename to core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/ProcessUtils.java index 5cd2567fb3..1b952f0c3c 100644 --- a/core-java-os/src/main/java/com/baeldung/java9/process/ProcessUtils.java +++ b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/ProcessUtils.java @@ -1,43 +1,43 @@ -package com.baeldung.java9.process; - -import java.io.File; -import java.io.IOException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.time.Duration; -import java.time.Instant; -import java.util.stream.Stream; - -public class ProcessUtils { - - public static String getClassPath() { - String cp = System.getProperty("java.class.path"); - System.out.println("ClassPath is " + cp); - return cp; - } - - public static File getJavaCmd() throws IOException { - String javaHome = System.getProperty("java.home"); - File javaCmd; - if (System.getProperty("os.name").startsWith("Win")) { - javaCmd = new File(javaHome, "bin/java.exe"); - } else { - javaCmd = new File(javaHome, "bin/java"); - } - if (javaCmd.canExecute()) { - return javaCmd; - } else { - throw new UnsupportedOperationException(javaCmd.getCanonicalPath() + " is not executable"); - } - } - - public static String getMainClass() { - return System.getProperty("sun.java.command"); - } - - public static String getSystemProperties() { - StringBuilder sb = new StringBuilder(); - System.getProperties().forEach((s1, s2) -> sb.append(s1 + " - " + s2)); - return sb.toString(); - } -} +package com.baeldung.java9.process; + +import java.io.File; +import java.io.IOException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.time.Duration; +import java.time.Instant; +import java.util.stream.Stream; + +public class ProcessUtils { + + public static String getClassPath() { + String cp = System.getProperty("java.class.path"); + System.out.println("ClassPath is " + cp); + return cp; + } + + public static File getJavaCmd() throws IOException { + String javaHome = System.getProperty("java.home"); + File javaCmd; + if (System.getProperty("os.name").startsWith("Win")) { + javaCmd = new File(javaHome, "bin/java.exe"); + } else { + javaCmd = new File(javaHome, "bin/java"); + } + if (javaCmd.canExecute()) { + return javaCmd; + } else { + throw new UnsupportedOperationException(javaCmd.getCanonicalPath() + " is not executable"); + } + } + + public static String getMainClass() { + return System.getProperty("sun.java.command"); + } + + public static String getSystemProperties() { + StringBuilder sb = new StringBuilder(); + System.getProperties().forEach((s1, s2) -> sb.append(s1 + " - " + s2)); + return sb.toString(); + } +} diff --git a/core-java-os/src/main/java/com/baeldung/java9/process/ServiceMain.java b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/ServiceMain.java similarity index 96% rename from core-java-os/src/main/java/com/baeldung/java9/process/ServiceMain.java rename to core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/ServiceMain.java index 5dc00dba25..77831f601c 100644 --- a/core-java-os/src/main/java/com/baeldung/java9/process/ServiceMain.java +++ b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/ServiceMain.java @@ -1,21 +1,21 @@ -package com.baeldung.java9.process; - -import java.util.Optional; - -public class ServiceMain { - - public static void main(String[] args) throws InterruptedException { - ProcessHandle thisProcess = ProcessHandle.current(); - long pid = thisProcess.pid(); - - Optional opArgs = Optional.ofNullable(args); - String procName = opArgs.map(str -> str.length > 0 ? str[0] : null).orElse(System.getProperty("sun.java.command")); - - for (int i = 0; i < 10000; i++) { - System.out.println("Process " + procName + " with ID " + pid + " is running!"); - Thread.sleep(10000); - } - - } - -} +package com.baeldung.java9.process; + +import java.util.Optional; + +public class ServiceMain { + + public static void main(String[] args) throws InterruptedException { + ProcessHandle thisProcess = ProcessHandle.current(); + long pid = thisProcess.pid(); + + Optional opArgs = Optional.ofNullable(args); + String procName = opArgs.map(str -> str.length > 0 ? str[0] : null).orElse(System.getProperty("sun.java.command")); + + for (int i = 0; i < 10000; i++) { + System.out.println("Process " + procName + " with ID " + pid + " is running!"); + Thread.sleep(10000); + } + + } + +} diff --git a/core-java-modules/core-java-os/src/main/resources/logback.xml b/core-java-modules/core-java-os/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/core-java-modules/core-java-os/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/core-java-os/src/test/java/com/baeldung/java9/process/ProcessAPIEnhancementsUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessAPIEnhancementsUnitTest.java similarity index 100% rename from core-java-os/src/test/java/com/baeldung/java9/process/ProcessAPIEnhancementsUnitTest.java rename to core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessAPIEnhancementsUnitTest.java diff --git a/core-java-os/src/test/java/com/baeldung/java9/process/ProcessApiUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessApiUnitTest.java similarity index 97% rename from core-java-os/src/test/java/com/baeldung/java9/process/ProcessApiUnitTest.java rename to core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessApiUnitTest.java index 8bdf8cb09f..c3f390d8ae 100644 --- a/core-java-os/src/test/java/com/baeldung/java9/process/ProcessApiUnitTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessApiUnitTest.java @@ -1,111 +1,111 @@ -package com.baeldung.java9.process; - -import java.io.IOException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.time.Duration; -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.stream.Stream; - -import org.junit.Before; -import org.junit.Test; - -import junit.framework.Assert; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class ProcessApiUnitTest { - - @Before - public void init() { - - } - - @Test - public void processInfoExample() throws NoSuchAlgorithmException { - ProcessHandle self = ProcessHandle.current(); - long PID = self.pid(); - ProcessHandle.Info procInfo = self.info(); - Optional args = procInfo.arguments(); - Optional cmd = procInfo.commandLine(); - Optional startTime = procInfo.startInstant(); - Optional cpuUsage = procInfo.totalCpuDuration(); - - waistCPU(); - System.out.println("Args " + args); - System.out.println("Command " + cmd.orElse("EmptyCmd")); - System.out.println("Start time: " + startTime.get().toString()); - System.out.println(cpuUsage.get().toMillis()); - - Stream allProc = ProcessHandle.current().children(); - allProc.forEach(p -> { - System.out.println("Proc " + p.pid()); - }); - - } - - @Test - public void createAndDestroyProcess() throws IOException, InterruptedException { - int numberOfChildProcesses = 5; - for (int i = 0; i < numberOfChildProcesses; i++) { - createNewJVM(ServiceMain.class, i).pid(); - } - - Stream childProc = ProcessHandle.current().children(); - assertEquals(childProc.count(), numberOfChildProcesses); - - childProc = ProcessHandle.current().children(); - childProc.forEach(processHandle -> { - assertTrue("Process " + processHandle.pid() + " should be alive!", processHandle.isAlive()); - CompletableFuture onProcExit = processHandle.onExit(); - onProcExit.thenAccept(procHandle -> { - System.out.println("Process with PID " + procHandle.pid() + " has stopped"); - }); - }); - - Thread.sleep(10000); - - childProc = ProcessHandle.current().children(); - childProc.forEach(procHandle -> { - assertTrue("Could not kill process " + procHandle.pid(), procHandle.destroy()); - }); - - Thread.sleep(5000); - - childProc = ProcessHandle.current().children(); - childProc.forEach(procHandle -> { - assertFalse("Process " + procHandle.pid() + " should not be alive!", procHandle.isAlive()); - }); - - } - - private Process createNewJVM(Class mainClass, int number) throws IOException { - ArrayList cmdParams = new ArrayList(5); - cmdParams.add(ProcessUtils.getJavaCmd().getAbsolutePath()); - cmdParams.add("-cp"); - cmdParams.add(ProcessUtils.getClassPath()); - cmdParams.add(mainClass.getName()); - cmdParams.add("Service " + number); - ProcessBuilder myService = new ProcessBuilder(cmdParams); - myService.inheritIO(); - return myService.start(); - } - - private void waistCPU() throws NoSuchAlgorithmException { - ArrayList randArr = new ArrayList(4096); - SecureRandom sr = SecureRandom.getInstanceStrong(); - Duration somecpu = Duration.ofMillis(4200L); - Instant end = Instant.now().plus(somecpu); - while (Instant.now().isBefore(end)) { - // System.out.println(sr.nextInt()); - randArr.add(sr.nextInt()); - } - } - -} +package com.baeldung.java9.process; + +import java.io.IOException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.time.Duration; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; + +import org.junit.Before; +import org.junit.Test; + +import junit.framework.Assert; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class ProcessApiUnitTest { + + @Before + public void init() { + + } + + @Test + public void processInfoExample() throws NoSuchAlgorithmException { + ProcessHandle self = ProcessHandle.current(); + long PID = self.pid(); + ProcessHandle.Info procInfo = self.info(); + Optional args = procInfo.arguments(); + Optional cmd = procInfo.commandLine(); + Optional startTime = procInfo.startInstant(); + Optional cpuUsage = procInfo.totalCpuDuration(); + + waistCPU(); + System.out.println("Args " + args); + System.out.println("Command " + cmd.orElse("EmptyCmd")); + System.out.println("Start time: " + startTime.get().toString()); + System.out.println(cpuUsage.get().toMillis()); + + Stream allProc = ProcessHandle.current().children(); + allProc.forEach(p -> { + System.out.println("Proc " + p.pid()); + }); + + } + + @Test + public void createAndDestroyProcess() throws IOException, InterruptedException { + int numberOfChildProcesses = 5; + for (int i = 0; i < numberOfChildProcesses; i++) { + createNewJVM(ServiceMain.class, i).pid(); + } + + Stream childProc = ProcessHandle.current().children(); + assertEquals(childProc.count(), numberOfChildProcesses); + + childProc = ProcessHandle.current().children(); + childProc.forEach(processHandle -> { + assertTrue("Process " + processHandle.pid() + " should be alive!", processHandle.isAlive()); + CompletableFuture onProcExit = processHandle.onExit(); + onProcExit.thenAccept(procHandle -> { + System.out.println("Process with PID " + procHandle.pid() + " has stopped"); + }); + }); + + Thread.sleep(10000); + + childProc = ProcessHandle.current().children(); + childProc.forEach(procHandle -> { + assertTrue("Could not kill process " + procHandle.pid(), procHandle.destroy()); + }); + + Thread.sleep(5000); + + childProc = ProcessHandle.current().children(); + childProc.forEach(procHandle -> { + assertFalse("Process " + procHandle.pid() + " should not be alive!", procHandle.isAlive()); + }); + + } + + private Process createNewJVM(Class mainClass, int number) throws IOException { + ArrayList cmdParams = new ArrayList(5); + cmdParams.add(ProcessUtils.getJavaCmd().getAbsolutePath()); + cmdParams.add("-cp"); + cmdParams.add(ProcessUtils.getClassPath()); + cmdParams.add(mainClass.getName()); + cmdParams.add("Service " + number); + ProcessBuilder myService = new ProcessBuilder(cmdParams); + myService.inheritIO(); + return myService.start(); + } + + private void waistCPU() throws NoSuchAlgorithmException { + ArrayList randArr = new ArrayList(4096); + SecureRandom sr = SecureRandom.getInstanceStrong(); + Duration somecpu = Duration.ofMillis(4200L); + Instant end = Instant.now().plus(somecpu); + while (Instant.now().isBefore(end)) { + // System.out.println(sr.nextInt()); + randArr.add(sr.nextInt()); + } + } + +} diff --git a/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java similarity index 100% rename from core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java rename to core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java diff --git a/core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java similarity index 97% rename from core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java rename to core-java-modules/core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java index 0458383e99..8fc5f9f160 100644 --- a/core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java @@ -1,182 +1,182 @@ -package com.baeldung.processbuilder; - -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.lang.ProcessBuilder.Redirect; -import java.nio.file.Files; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -public class ProcessBuilderUnitTest { - - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); - - @Test - public void givenProcessBuilder_whenInvokeStart_thenSuccess() throws IOException, InterruptedException, ExecutionException { - ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); - processBuilder.redirectErrorStream(true); - - Process process = processBuilder.start(); - - List results = readOutput(process.getInputStream()); - assertThat("Results should not be empty", results, is(not(empty()))); - assertThat("Results should contain java version: ", results, hasItem(containsString("java version"))); - - int exitCode = process.waitFor(); - assertEquals("No errors should be detected", 0, exitCode); - } - - @Test - public void givenProcessBuilder_whenModifyEnvironment_thenSuccess() throws IOException, InterruptedException { - ProcessBuilder processBuilder = new ProcessBuilder(); - Map environment = processBuilder.environment(); - environment.forEach((key, value) -> System.out.println(key + value)); - - environment.put("GREETING", "Hola Mundo"); - - List command = getGreetingCommand(); - processBuilder.command(command); - Process process = processBuilder.start(); - - List results = readOutput(process.getInputStream()); - assertThat("Results should not be empty", results, is(not(empty()))); - assertThat("Results should contain a greeting ", results, hasItem(containsString("Hola Mundo"))); - - int exitCode = process.waitFor(); - assertEquals("No errors should be detected", 0, exitCode); - } - - @Test - public void givenProcessBuilder_whenModifyWorkingDir_thenSuccess() throws IOException, InterruptedException { - List command = getDirectoryListingCommand(); - ProcessBuilder processBuilder = new ProcessBuilder(command); - - processBuilder.directory(new File("src")); - Process process = processBuilder.start(); - - List results = readOutput(process.getInputStream()); - assertThat("Results should not be empty", results, is(not(empty()))); - assertThat("Results should contain directory listing: ", results, hasItems(containsString("main"), containsString("test"))); - - int exitCode = process.waitFor(); - assertEquals("No errors should be detected", 0, exitCode); - } - - @Test - public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessWriting() throws IOException, InterruptedException { - ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); - - processBuilder.redirectErrorStream(true); - File log = tempFolder.newFile("java-version.log"); - processBuilder.redirectOutput(log); - - Process process = processBuilder.start(); - - assertEquals("If redirected, should be -1 ", -1, process.getInputStream() - .read()); - int exitCode = process.waitFor(); - assertEquals("No errors should be detected", 0, exitCode); - - List lines = Files.lines(log.toPath()) - .collect(Collectors.toList()); - - assertThat("Results should not be empty", lines, is(not(empty()))); - assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); - } - - @Test - public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessAppending() throws IOException, InterruptedException { - ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); - - File log = tempFolder.newFile("java-version-append.log"); - processBuilder.redirectErrorStream(true); - processBuilder.redirectOutput(Redirect.appendTo(log)); - - Process process = processBuilder.start(); - - assertEquals("If redirected output, should be -1 ", -1, process.getInputStream() - .read()); - - int exitCode = process.waitFor(); - assertEquals("No errors should be detected", 0, exitCode); - - List lines = Files.lines(log.toPath()) - .collect(Collectors.toList()); - - assertThat("Results should not be empty", lines, is(not(empty()))); - assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); - } - - @Test - public void givenProcessBuilder_whenStartingPipeline_thenSuccess() throws IOException, InterruptedException { - if (!isWindows()) { - List builders = Arrays.asList( - new ProcessBuilder("find", "src", "-name", "*.java", "-type", "f"), - new ProcessBuilder("wc", "-l")); - - List processes = ProcessBuilder.startPipeline(builders); - Process last = processes.get(processes.size() - 1); - - List output = readOutput(last.getInputStream()); - assertThat("Results should not be empty", output, is(not(empty()))); - } - } - - @Test - public void givenProcessBuilder_whenInheritIO_thenSuccess() throws IOException, InterruptedException { - List command = getEchoCommand(); - ProcessBuilder processBuilder = new ProcessBuilder(command); - - processBuilder.inheritIO(); - Process process = processBuilder.start(); - - int exitCode = process.waitFor(); - assertEquals("No errors should be detected", 0, exitCode); - } - - private List readOutput(InputStream inputStream) throws IOException { - try (BufferedReader output = new BufferedReader(new InputStreamReader(inputStream))) { - return output.lines() - .collect(Collectors.toList()); - } - } - - private List getDirectoryListingCommand() { - return isWindows() ? Arrays.asList("cmd.exe", "/c", "dir") : Arrays.asList("/bin/sh", "-c", "ls"); - } - - private List getGreetingCommand() { - return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo %GREETING%") : Arrays.asList("/bin/bash", "-c", "echo $GREETING"); - } - - private List getEchoCommand() { - return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo hello") : Arrays.asList("/bin/sh", "-c", "echo hello"); - } - - private boolean isWindows() { - return System.getProperty("os.name") - .toLowerCase() - .startsWith("windows"); - } - -} +package com.baeldung.processbuilder; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.ProcessBuilder.Redirect; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +public class ProcessBuilderUnitTest { + + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); + + @Test + public void givenProcessBuilder_whenInvokeStart_thenSuccess() throws IOException, InterruptedException, ExecutionException { + ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); + processBuilder.redirectErrorStream(true); + + Process process = processBuilder.start(); + + List results = readOutput(process.getInputStream()); + assertThat("Results should not be empty", results, is(not(empty()))); + assertThat("Results should contain java version: ", results, hasItem(containsString("java version"))); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + } + + @Test + public void givenProcessBuilder_whenModifyEnvironment_thenSuccess() throws IOException, InterruptedException { + ProcessBuilder processBuilder = new ProcessBuilder(); + Map environment = processBuilder.environment(); + environment.forEach((key, value) -> System.out.println(key + value)); + + environment.put("GREETING", "Hola Mundo"); + + List command = getGreetingCommand(); + processBuilder.command(command); + Process process = processBuilder.start(); + + List results = readOutput(process.getInputStream()); + assertThat("Results should not be empty", results, is(not(empty()))); + assertThat("Results should contain a greeting ", results, hasItem(containsString("Hola Mundo"))); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + } + + @Test + public void givenProcessBuilder_whenModifyWorkingDir_thenSuccess() throws IOException, InterruptedException { + List command = getDirectoryListingCommand(); + ProcessBuilder processBuilder = new ProcessBuilder(command); + + processBuilder.directory(new File("src")); + Process process = processBuilder.start(); + + List results = readOutput(process.getInputStream()); + assertThat("Results should not be empty", results, is(not(empty()))); + assertThat("Results should contain directory listing: ", results, hasItems(containsString("main"), containsString("test"))); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + } + + @Test + public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessWriting() throws IOException, InterruptedException { + ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); + + processBuilder.redirectErrorStream(true); + File log = tempFolder.newFile("java-version.log"); + processBuilder.redirectOutput(log); + + Process process = processBuilder.start(); + + assertEquals("If redirected, should be -1 ", -1, process.getInputStream() + .read()); + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + + List lines = Files.lines(log.toPath()) + .collect(Collectors.toList()); + + assertThat("Results should not be empty", lines, is(not(empty()))); + assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); + } + + @Test + public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessAppending() throws IOException, InterruptedException { + ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); + + File log = tempFolder.newFile("java-version-append.log"); + processBuilder.redirectErrorStream(true); + processBuilder.redirectOutput(Redirect.appendTo(log)); + + Process process = processBuilder.start(); + + assertEquals("If redirected output, should be -1 ", -1, process.getInputStream() + .read()); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + + List lines = Files.lines(log.toPath()) + .collect(Collectors.toList()); + + assertThat("Results should not be empty", lines, is(not(empty()))); + assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); + } + + @Test + public void givenProcessBuilder_whenStartingPipeline_thenSuccess() throws IOException, InterruptedException { + if (!isWindows()) { + List builders = Arrays.asList( + new ProcessBuilder("find", "src", "-name", "*.java", "-type", "f"), + new ProcessBuilder("wc", "-l")); + + List processes = ProcessBuilder.startPipeline(builders); + Process last = processes.get(processes.size() - 1); + + List output = readOutput(last.getInputStream()); + assertThat("Results should not be empty", output, is(not(empty()))); + } + } + + @Test + public void givenProcessBuilder_whenInheritIO_thenSuccess() throws IOException, InterruptedException { + List command = getEchoCommand(); + ProcessBuilder processBuilder = new ProcessBuilder(command); + + processBuilder.inheritIO(); + Process process = processBuilder.start(); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + } + + private List readOutput(InputStream inputStream) throws IOException { + try (BufferedReader output = new BufferedReader(new InputStreamReader(inputStream))) { + return output.lines() + .collect(Collectors.toList()); + } + } + + private List getDirectoryListingCommand() { + return isWindows() ? Arrays.asList("cmd.exe", "/c", "dir") : Arrays.asList("/bin/sh", "-c", "ls"); + } + + private List getGreetingCommand() { + return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo %GREETING%") : Arrays.asList("/bin/bash", "-c", "echo $GREETING"); + } + + private List getEchoCommand() { + return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo hello") : Arrays.asList("/bin/sh", "-c", "echo hello"); + } + + private boolean isWindows() { + return System.getProperty("os.name") + .toLowerCase() + .startsWith("windows"); + } + +} diff --git a/core-java-os/src/test/resources/.gitignore b/core-java-modules/core-java-os/src/test/resources/.gitignore similarity index 100% rename from core-java-os/src/test/resources/.gitignore rename to core-java-modules/core-java-os/src/test/resources/.gitignore diff --git a/core-java-perf/README.md b/core-java-modules/core-java-perf/README.md similarity index 100% rename from core-java-perf/README.md rename to core-java-modules/core-java-perf/README.md diff --git a/core-java-perf/pom.xml b/core-java-modules/core-java-perf/pom.xml similarity index 94% rename from core-java-perf/pom.xml rename to core-java-modules/core-java-perf/pom.xml index 0e0ec79691..f225a9554b 100644 --- a/core-java-perf/pom.xml +++ b/core-java-modules/core-java-perf/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-perf/src/main/java/com/baeldung/flightrecorder/FlightRecorder.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/flightrecorder/FlightRecorder.java similarity index 100% rename from core-java-perf/src/main/java/com/baeldung/flightrecorder/FlightRecorder.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/flightrecorder/FlightRecorder.java diff --git a/core-java-perf/src/main/java/com/baeldung/gc/VerboseGarbageCollectorRunner.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/gc/VerboseGarbageCollectorRunner.java similarity index 97% rename from core-java-perf/src/main/java/com/baeldung/gc/VerboseGarbageCollectorRunner.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/gc/VerboseGarbageCollectorRunner.java index f57580bbb5..9e4e6d9902 100644 --- a/core-java-perf/src/main/java/com/baeldung/gc/VerboseGarbageCollectorRunner.java +++ b/core-java-modules/core-java-perf/src/main/java/com/baeldung/gc/VerboseGarbageCollectorRunner.java @@ -1,63 +1,63 @@ -package com.baeldung.gc; - -import java.util.HashMap; -import java.util.Map; - -/** - * A simple Java program to demonstrate how to enable verbose Garbage Collection (GC) logging. - *

- * This simple program loads 3 million {@link java.lang.String} instances into a {@link java.util.HashMap} - * object before making an explicit call to the garbage collector using System.gc(). - *

- * Finally, it removes 2 million of the {@link java.lang.String} instances from the {@link java.util.HashMap}. - * We also explicitly use System.out.println to make interpreting the output easier. - *

- * Run this program with the following arguments to see verbose GC logging in its complete form: - *

- * -XX:+UseSerialGC -Xms1024m -Xmx1024m -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:/path/to/file/gc.log
- * 
- * Where: - *
    - *
  • -XX:+UseSerialGC - specify the serial garbage collector.
  • - *
  • -Xms1024m - specify the minimal heap size.
  • - *
  • -Xmx1024m - specify the maximal heap size.
  • - *
  • -verbose:gc - activate the logging of garbage collection information in its simplest form.
  • - *
  • -XX:+PrintGCDetails - activate detailed information about garbage collection.
  • - *
  • -XX:+PrintGCTimeStamps - include a timestamp in the output reflecting the real-time passed in seconds since the JVM started.
  • - *
  • -XX:+PrintGCDateStamps - include the absolute date and time at the start of each line.
  • - *
  • -Xloggc - by default the GC log is written to stdout. Specify an output file via this argument.
  • - *
- *

- * It should be noted that the first three arguments are not strictly necessary but for the purposes or the example - * help really simplify things. - * - */ -public class VerboseGarbageCollectorRunner { - - private static Map stringContainer = new HashMap<>(); - - public static void main(String[] args) { - System.out.println("Start of program!"); - String stringWithPrefix = "stringWithPrefix"; - - // Load Java Heap with 3 M java.lang.String instances - for (int i = 0; i < 3000000; i++) { - String newString = stringWithPrefix + i; - stringContainer.put(newString, newString); - } - System.out.println("MAP size: " + stringContainer.size()); - - // Explicit GC! - System.gc(); - - // Remove 2 M out of 3 M - for (int i = 0; i < 2000000; i++) { - String newString = stringWithPrefix + i; - stringContainer.remove(newString); - } - - System.out.println("MAP size: " + stringContainer.size()); - System.out.println("End of program!"); - } - -} +package com.baeldung.gc; + +import java.util.HashMap; +import java.util.Map; + +/** + * A simple Java program to demonstrate how to enable verbose Garbage Collection (GC) logging. + *

+ * This simple program loads 3 million {@link java.lang.String} instances into a {@link java.util.HashMap} + * object before making an explicit call to the garbage collector using System.gc(). + *

+ * Finally, it removes 2 million of the {@link java.lang.String} instances from the {@link java.util.HashMap}. + * We also explicitly use System.out.println to make interpreting the output easier. + *

+ * Run this program with the following arguments to see verbose GC logging in its complete form: + *

+ * -XX:+UseSerialGC -Xms1024m -Xmx1024m -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:/path/to/file/gc.log
+ * 
+ * Where: + *
    + *
  • -XX:+UseSerialGC - specify the serial garbage collector.
  • + *
  • -Xms1024m - specify the minimal heap size.
  • + *
  • -Xmx1024m - specify the maximal heap size.
  • + *
  • -verbose:gc - activate the logging of garbage collection information in its simplest form.
  • + *
  • -XX:+PrintGCDetails - activate detailed information about garbage collection.
  • + *
  • -XX:+PrintGCTimeStamps - include a timestamp in the output reflecting the real-time passed in seconds since the JVM started.
  • + *
  • -XX:+PrintGCDateStamps - include the absolute date and time at the start of each line.
  • + *
  • -Xloggc - by default the GC log is written to stdout. Specify an output file via this argument.
  • + *
+ *

+ * It should be noted that the first three arguments are not strictly necessary but for the purposes or the example + * help really simplify things. + * + */ +public class VerboseGarbageCollectorRunner { + + private static Map stringContainer = new HashMap<>(); + + public static void main(String[] args) { + System.out.println("Start of program!"); + String stringWithPrefix = "stringWithPrefix"; + + // Load Java Heap with 3 M java.lang.String instances + for (int i = 0; i < 3000000; i++) { + String newString = stringWithPrefix + i; + stringContainer.put(newString, newString); + } + System.out.println("MAP size: " + stringContainer.size()); + + // Explicit GC! + System.gc(); + + // Remove 2 M out of 3 M + for (int i = 0; i < 2000000; i++) { + String newString = stringWithPrefix + i; + stringContainer.remove(newString); + } + + System.out.println("MAP size: " + stringContainer.size()); + System.out.println("End of program!"); + } + +} diff --git a/core-java-perf/src/main/java/com/baeldung/heapdump/HeapDump.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/heapdump/HeapDump.java similarity index 100% rename from core-java-perf/src/main/java/com/baeldung/heapdump/HeapDump.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/heapdump/HeapDump.java diff --git a/core-java-perf/src/main/java/com/baeldung/jmx/Game.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/jmx/Game.java similarity index 100% rename from core-java-perf/src/main/java/com/baeldung/jmx/Game.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/jmx/Game.java diff --git a/core-java-perf/src/main/java/com/baeldung/jmx/GameMBean.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/jmx/GameMBean.java similarity index 100% rename from core-java-perf/src/main/java/com/baeldung/jmx/GameMBean.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/jmx/GameMBean.java diff --git a/core-java-perf/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java similarity index 100% rename from core-java-perf/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java diff --git a/core-java-perf/src/main/java/com/baeldung/memoryleaks/equalshashcode/Person.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/equalshashcode/Person.java old mode 100755 new mode 100644 similarity index 94% rename from core-java-perf/src/main/java/com/baeldung/memoryleaks/equalshashcode/Person.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/equalshashcode/Person.java index e16d1ae6da..a5b5794238 --- a/core-java-perf/src/main/java/com/baeldung/memoryleaks/equalshashcode/Person.java +++ b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/equalshashcode/Person.java @@ -1,9 +1,9 @@ -package com.baeldung.memoryleaks.equalshashcode; - -public class Person { - public String name; - - public Person(String name) { - this.name = name; - } -} +package com.baeldung.memoryleaks.equalshashcode; + +public class Person { + public String name; + + public Person(String name) { + this.name = name; + } +} diff --git a/core-java-perf/src/main/java/com/baeldung/memoryleaks/equalshashcode/PersonOptimized.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/equalshashcode/PersonOptimized.java old mode 100755 new mode 100644 similarity index 96% rename from core-java-perf/src/main/java/com/baeldung/memoryleaks/equalshashcode/PersonOptimized.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/equalshashcode/PersonOptimized.java index 3af70dd1eb..3e54332264 --- a/core-java-perf/src/main/java/com/baeldung/memoryleaks/equalshashcode/PersonOptimized.java +++ b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/equalshashcode/PersonOptimized.java @@ -1,25 +1,25 @@ -package com.baeldung.memoryleaks.equalshashcode; - -public class PersonOptimized { - public String name; - - public PersonOptimized(String name) { - this.name = name; - } - - @Override - public boolean equals(Object o) { - if (o == this) return true; - if (!(o instanceof PersonOptimized)) { - return false; - } - PersonOptimized person = (PersonOptimized) o; - return person.name.equals(name); - } - - @Override - public int hashCode() { - int result = 17; - result = 31 * result + name.hashCode(); - return result; - }} +package com.baeldung.memoryleaks.equalshashcode; + +public class PersonOptimized { + public String name; + + public PersonOptimized(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (o == this) return true; + if (!(o instanceof PersonOptimized)) { + return false; + } + PersonOptimized person = (PersonOptimized) o; + return person.name.equals(name); + } + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + name.hashCode(); + return result; + }} diff --git a/core-java-perf/src/main/java/com/baeldung/memoryleaks/finalize/BulkyObject.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/finalize/BulkyObject.java old mode 100755 new mode 100644 similarity index 95% rename from core-java-perf/src/main/java/com/baeldung/memoryleaks/finalize/BulkyObject.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/finalize/BulkyObject.java index ce77d883f6..07ed52e38d --- a/core-java-perf/src/main/java/com/baeldung/memoryleaks/finalize/BulkyObject.java +++ b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/finalize/BulkyObject.java @@ -1,32 +1,32 @@ -package com.baeldung.memoryleaks.finalize; - -import java.nio.charset.Charset; -import java.util.Random; - -public class BulkyObject { - private String data[]; - - public BulkyObject() { - data = new String[1000000]; - - for(int i=0; i<1000000; i++) { - data[i] = getRandomString(); - } - } - - private String getRandomString() { - byte[] array = new byte[1000]; - new Random().nextBytes(array); - return new String(array, Charset.forName("UTF-8")); - } - - @Override - public void finalize() { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - System.out.println("Finalizer called"); - } -} +package com.baeldung.memoryleaks.finalize; + +import java.nio.charset.Charset; +import java.util.Random; + +public class BulkyObject { + private String data[]; + + public BulkyObject() { + data = new String[1000000]; + + for(int i=0; i<1000000; i++) { + data[i] = getRandomString(); + } + } + + private String getRandomString() { + byte[] array = new byte[1000]; + new Random().nextBytes(array); + return new String(array, Charset.forName("UTF-8")); + } + + @Override + public void finalize() { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("Finalizer called"); + } +} diff --git a/core-java-perf/src/main/java/com/baeldung/memoryleaks/finalize/BulkyObjectOptimized.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/finalize/BulkyObjectOptimized.java similarity index 96% rename from core-java-perf/src/main/java/com/baeldung/memoryleaks/finalize/BulkyObjectOptimized.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/finalize/BulkyObjectOptimized.java index dc1302432e..8a8f2ae6c2 100644 --- a/core-java-perf/src/main/java/com/baeldung/memoryleaks/finalize/BulkyObjectOptimized.java +++ b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/finalize/BulkyObjectOptimized.java @@ -1,22 +1,22 @@ -package com.baeldung.memoryleaks.finalize; - -import java.nio.charset.Charset; -import java.util.Random; - -public class BulkyObjectOptimized { - private String data[]; - - public BulkyObjectOptimized() { - data = new String[1000000]; - - for(int i=0; i<1000000; i++) { - data[i] = getRandomString(); - } - } - - private String getRandomString() { - byte[] array = new byte[1000]; - new Random().nextBytes(array); - return new String(array, Charset.forName("UTF-8")); - } -} +package com.baeldung.memoryleaks.finalize; + +import java.nio.charset.Charset; +import java.util.Random; + +public class BulkyObjectOptimized { + private String data[]; + + public BulkyObjectOptimized() { + data = new String[1000000]; + + for(int i=0; i<1000000; i++) { + data[i] = getRandomString(); + } + } + + private String getRandomString() { + byte[] array = new byte[1000]; + new Random().nextBytes(array); + return new String(array, Charset.forName("UTF-8")); + } +} diff --git a/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/BulkyObject.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/BulkyObject.java old mode 100755 new mode 100644 similarity index 95% rename from core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/BulkyObject.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/BulkyObject.java index bbd5310182..47801878f8 --- a/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/BulkyObject.java +++ b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/BulkyObject.java @@ -1,22 +1,22 @@ -package com.baeldung.memoryleaks.innerclass; - -import java.nio.charset.Charset; -import java.util.Random; - -public class BulkyObject { - private String data[]; - - public BulkyObject() { - data = new String[1000000]; - - for(int i=0; i<1000000; i++) { - data[i] = getRandomString(); - } - } - - private String getRandomString() { - byte[] array = new byte[1000]; - new Random().nextBytes(array); - return new String(array, Charset.forName("UTF-8")); - } -} +package com.baeldung.memoryleaks.innerclass; + +import java.nio.charset.Charset; +import java.util.Random; + +public class BulkyObject { + private String data[]; + + public BulkyObject() { + data = new String[1000000]; + + for(int i=0; i<1000000; i++) { + data[i] = getRandomString(); + } + } + + private String getRandomString() { + byte[] array = new byte[1000]; + new Random().nextBytes(array); + return new String(array, Charset.forName("UTF-8")); + } +} diff --git a/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/InnerClassDriver.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/InnerClassDriver.java old mode 100755 new mode 100644 similarity index 97% rename from core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/InnerClassDriver.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/InnerClassDriver.java index 06f928bc4a..e3e4506397 --- a/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/InnerClassDriver.java +++ b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/InnerClassDriver.java @@ -1,17 +1,17 @@ -package com.baeldung.memoryleaks.innerclass; - -public class InnerClassDriver { - public static InnerClassWrapper.SimpleInnerClass getSimpleInnerClassObj() { - return new InnerClassWrapper().new SimpleInnerClass(); - } - - public static void main2(String[] args) { - InnerClassWrapper.SimpleInnerClass simpleInnerClassObj = getSimpleInnerClassObj(); - System.out.println("Debug point"); - } - - public static void main(String[] args) { - StaticNestedClassWrapper.StaticNestedClass simpleInnerClassObj = new StaticNestedClassWrapper.StaticNestedClass(); - System.out.println("Debug point"); - } -} +package com.baeldung.memoryleaks.innerclass; + +public class InnerClassDriver { + public static InnerClassWrapper.SimpleInnerClass getSimpleInnerClassObj() { + return new InnerClassWrapper().new SimpleInnerClass(); + } + + public static void main2(String[] args) { + InnerClassWrapper.SimpleInnerClass simpleInnerClassObj = getSimpleInnerClassObj(); + System.out.println("Debug point"); + } + + public static void main(String[] args) { + StaticNestedClassWrapper.StaticNestedClass simpleInnerClassObj = new StaticNestedClassWrapper.StaticNestedClass(); + System.out.println("Debug point"); + } +} diff --git a/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/InnerClassWrapper.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/InnerClassWrapper.java old mode 100755 new mode 100644 similarity index 95% rename from core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/InnerClassWrapper.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/InnerClassWrapper.java index 25fecf9bb3..97b05ea02e --- a/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/InnerClassWrapper.java +++ b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/InnerClassWrapper.java @@ -1,10 +1,10 @@ -package com.baeldung.memoryleaks.innerclass; - - -public class InnerClassWrapper { - private BulkyObject bulkyObject = new BulkyObject(); - - public class SimpleInnerClass { - - } -} +package com.baeldung.memoryleaks.innerclass; + + +public class InnerClassWrapper { + private BulkyObject bulkyObject = new BulkyObject(); + + public class SimpleInnerClass { + + } +} diff --git a/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/StaticNestedClassWrapper.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/StaticNestedClassWrapper.java old mode 100755 new mode 100644 similarity index 95% rename from core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/StaticNestedClassWrapper.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/StaticNestedClassWrapper.java index d1729d78a3..c37e08a049 --- a/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/StaticNestedClassWrapper.java +++ b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/innerclass/StaticNestedClassWrapper.java @@ -1,10 +1,10 @@ -package com.baeldung.memoryleaks.innerclass; - - -public class StaticNestedClassWrapper { - private BulkyObject bulkyObject = new BulkyObject(); - - public static class StaticNestedClass { - - } -} +package com.baeldung.memoryleaks.innerclass; + + +public class StaticNestedClassWrapper { + private BulkyObject bulkyObject = new BulkyObject(); + + public static class StaticNestedClass { + + } +} diff --git a/core-java-perf/src/main/java/com/baeldung/memoryleaks/internedstrings/InternedString.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/internedstrings/InternedString.java similarity index 100% rename from core-java-perf/src/main/java/com/baeldung/memoryleaks/internedstrings/InternedString.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/internedstrings/InternedString.java diff --git a/core-java-perf/src/main/java/com/baeldung/memoryleaks/internedstrings/ReadStringFromFileUtil.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/internedstrings/ReadStringFromFileUtil.java similarity index 100% rename from core-java-perf/src/main/java/com/baeldung/memoryleaks/internedstrings/ReadStringFromFileUtil.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/internedstrings/ReadStringFromFileUtil.java diff --git a/core-java-perf/src/main/java/com/baeldung/memoryleaks/internedstrings/StringObject.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/internedstrings/StringObject.java similarity index 100% rename from core-java-perf/src/main/java/com/baeldung/memoryleaks/internedstrings/StringObject.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/internedstrings/StringObject.java diff --git a/core-java-perf/src/main/java/com/baeldung/memoryleaks/staticfields/NonStaticFieldsDemo.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/staticfields/NonStaticFieldsDemo.java similarity index 100% rename from core-java-perf/src/main/java/com/baeldung/memoryleaks/staticfields/NonStaticFieldsDemo.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/staticfields/NonStaticFieldsDemo.java diff --git a/core-java-perf/src/main/java/com/baeldung/memoryleaks/staticfields/StaticFieldsDemo.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/staticfields/StaticFieldsDemo.java similarity index 100% rename from core-java-perf/src/main/java/com/baeldung/memoryleaks/staticfields/StaticFieldsDemo.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/memoryleaks/staticfields/StaticFieldsDemo.java diff --git a/core-java-perf/src/main/java/com/baeldung/outofmemoryerror/OutOfMemoryGCLimitExceed.java b/core-java-modules/core-java-perf/src/main/java/com/baeldung/outofmemoryerror/OutOfMemoryGCLimitExceed.java similarity index 100% rename from core-java-perf/src/main/java/com/baeldung/outofmemoryerror/OutOfMemoryGCLimitExceed.java rename to core-java-modules/core-java-perf/src/main/java/com/baeldung/outofmemoryerror/OutOfMemoryGCLimitExceed.java diff --git a/core-java-perf/src/main/resources/logback.xml b/core-java-modules/core-java-perf/src/main/resources/logback.xml similarity index 100% rename from core-java-perf/src/main/resources/logback.xml rename to core-java-modules/core-java-perf/src/main/resources/logback.xml diff --git a/core-java-perf/src/test/java/com/baeldung/memoryleaks/equalshashcode/PersonMemoryLeakUnitTest.java b/core-java-modules/core-java-perf/src/test/java/com/baeldung/memoryleaks/equalshashcode/PersonMemoryLeakUnitTest.java similarity index 100% rename from core-java-perf/src/test/java/com/baeldung/memoryleaks/equalshashcode/PersonMemoryLeakUnitTest.java rename to core-java-modules/core-java-perf/src/test/java/com/baeldung/memoryleaks/equalshashcode/PersonMemoryLeakUnitTest.java diff --git a/core-java-perf/src/test/java/com/baeldung/memoryleaks/finalize/FinalizeMemoryLeakUnitTest.java b/core-java-modules/core-java-perf/src/test/java/com/baeldung/memoryleaks/finalize/FinalizeMemoryLeakUnitTest.java similarity index 100% rename from core-java-perf/src/test/java/com/baeldung/memoryleaks/finalize/FinalizeMemoryLeakUnitTest.java rename to core-java-modules/core-java-perf/src/test/java/com/baeldung/memoryleaks/finalize/FinalizeMemoryLeakUnitTest.java diff --git a/core-java-perf/src/test/java/com/baeldung/memoryleaks/innerclass/StaticInnerClassMemoryLeakUnitTest.java b/core-java-modules/core-java-perf/src/test/java/com/baeldung/memoryleaks/innerclass/StaticInnerClassMemoryLeakUnitTest.java similarity index 100% rename from core-java-perf/src/test/java/com/baeldung/memoryleaks/innerclass/StaticInnerClassMemoryLeakUnitTest.java rename to core-java-modules/core-java-perf/src/test/java/com/baeldung/memoryleaks/innerclass/StaticInnerClassMemoryLeakUnitTest.java diff --git a/core-java-perf/src/test/java/com/baeldung/memoryleaks/internedstrings/StringInternMemoryLeakUnitTest.java b/core-java-modules/core-java-perf/src/test/java/com/baeldung/memoryleaks/internedstrings/StringInternMemoryLeakUnitTest.java similarity index 100% rename from core-java-perf/src/test/java/com/baeldung/memoryleaks/internedstrings/StringInternMemoryLeakUnitTest.java rename to core-java-modules/core-java-perf/src/test/java/com/baeldung/memoryleaks/internedstrings/StringInternMemoryLeakUnitTest.java diff --git a/core-java-perf/src/test/java/com/baeldung/memoryleaks/staticfields/NonStaticFieldsMemoryLeakUnitTest.java b/core-java-modules/core-java-perf/src/test/java/com/baeldung/memoryleaks/staticfields/NonStaticFieldsMemoryLeakUnitTest.java similarity index 100% rename from core-java-perf/src/test/java/com/baeldung/memoryleaks/staticfields/NonStaticFieldsMemoryLeakUnitTest.java rename to core-java-modules/core-java-perf/src/test/java/com/baeldung/memoryleaks/staticfields/NonStaticFieldsMemoryLeakUnitTest.java diff --git a/core-java-perf/src/test/java/com/baeldung/memoryleaks/staticfields/StaticFieldsMemoryLeakUnitTest.java b/core-java-modules/core-java-perf/src/test/java/com/baeldung/memoryleaks/staticfields/StaticFieldsMemoryLeakUnitTest.java similarity index 100% rename from core-java-perf/src/test/java/com/baeldung/memoryleaks/staticfields/StaticFieldsMemoryLeakUnitTest.java rename to core-java-modules/core-java-perf/src/test/java/com/baeldung/memoryleaks/staticfields/StaticFieldsMemoryLeakUnitTest.java diff --git a/core-java-modules/core-java-reflection/pom.xml b/core-java-modules/core-java-reflection/pom.xml new file mode 100644 index 0000000000..e6c7f81d6c --- /dev/null +++ b/core-java-modules/core-java-reflection/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + core-java-reflection + 0.1.0-SNAPSHOT + core-java-reflection + jar + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + + + + + org.assertj + assertj-core + ${assertj-core.version} + + + + + 3.10.0 + + \ No newline at end of file diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/voidtype/Action.java b/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/voidtype/Action.java new file mode 100644 index 0000000000..1459bf25c5 --- /dev/null +++ b/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/voidtype/Action.java @@ -0,0 +1,5 @@ +package com.baeldung.reflection.voidtype; + +public interface Action { + void execute(); +} diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/voidtype/Calculator.java b/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/voidtype/Calculator.java new file mode 100644 index 0000000000..dcfbe72008 --- /dev/null +++ b/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/voidtype/Calculator.java @@ -0,0 +1,21 @@ +package com.baeldung.reflection.voidtype; + +public class Calculator { + private int result = 0; + + public int add(int number) { + return result += number; + } + + public int sub(int number) { + return result -= number; + } + + public void clear() { + result = 0; + } + + public void print() { + System.out.println(result); + } +} diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/voidtype/Defer.java b/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/voidtype/Defer.java new file mode 100644 index 0000000000..09817199fa --- /dev/null +++ b/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/voidtype/Defer.java @@ -0,0 +1,27 @@ +package com.baeldung.reflection.voidtype; + +import java.util.concurrent.Callable; +import java.util.function.Consumer; +import java.util.function.Function; + +public class Defer { + public static V defer(Callable callable) throws Exception { + return callable.call(); + } + + public static void defer(Runnable runnable) { + runnable.run(); + } + + public static R defer(Function function, T arg) { + return function.apply(arg); + } + + public static void defer(Consumer consumer, T arg) { + consumer.accept(arg); + } + + public static void defer(Action action) { + action.execute(); + } +} diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/voidtype/MyOwnDefer.java b/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/voidtype/MyOwnDefer.java new file mode 100644 index 0000000000..47468ee641 --- /dev/null +++ b/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/voidtype/MyOwnDefer.java @@ -0,0 +1,15 @@ +package com.baeldung.reflection.voidtype; + +import java.util.concurrent.Callable; + +public class MyOwnDefer { + public static void defer(Runnable runnable) throws Exception { + Defer.defer(new Callable() { + @Override + public Void call() { + runnable.run(); + return null; + } + }); + } +} diff --git a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/voidtype/CalculatorUnitTest.java b/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/voidtype/CalculatorUnitTest.java new file mode 100644 index 0000000000..0ba22bf6e3 --- /dev/null +++ b/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/voidtype/CalculatorUnitTest.java @@ -0,0 +1,23 @@ +package com.baeldung.reflection.voidtype; + +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +class CalculatorUnitTest { + @Test + void givenCalculator_whenGettingVoidMethodsByReflection_thenOnlyClearAndPrint() { + Method[] calculatorMethods = Calculator.class.getDeclaredMethods(); + List calculatorVoidMethods = Arrays.stream(calculatorMethods) + .filter(method -> method.getReturnType().equals(Void.TYPE)) + .collect(Collectors.toList()); + + assertThat(calculatorVoidMethods) + .allMatch(method -> Arrays.asList("clear", "print").contains(method.getName())); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/voidtype/DeferUnitTest.java b/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/voidtype/DeferUnitTest.java new file mode 100644 index 0000000000..e2dc68effc --- /dev/null +++ b/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/voidtype/DeferUnitTest.java @@ -0,0 +1,81 @@ +package com.baeldung.reflection.voidtype; + +import org.junit.jupiter.api.Test; + +import java.util.concurrent.Callable; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; +import java.util.function.Function; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +class DeferUnitTest { + @Test + void givenVoidCallable_whenDiffer_thenReturnNull() throws Exception { + Callable callable = new Callable() { + @Override + public Void call() { + System.out.println("Hello!"); + return null; + } + }; + + assertThat(Defer.defer(callable)).isNull(); + } + + @Test + void givenVoidRunnable_whenDiffer_thenNoReturn() { + AtomicBoolean run = new AtomicBoolean(false); + + Runnable runnable = new Runnable() { + @Override + public void run() { + System.out.println("Hello!"); + run.set(true); + } + }; + + Defer.defer(runnable); + + assertTrue(run.get()); + } + + @Test + void givenVoidFunction_whenDiffer_thenReturnNull() { + Function function = s -> { + System.out.println("Hello " + s + "!"); + return null; + }; + + assertThat(Defer.defer(function, "World")).isNull(); + } + + @Test + void givenVoidConsumer_whenDiffer_thenReturnNull() { + AtomicBoolean run = new AtomicBoolean(false); + + Consumer function = s -> { + System.out.println("Hello " + s + "!"); + run.set(true); + }; + + Defer.defer(function, "World"); + + assertTrue(run.get()); + } + + @Test + void givenAction_whenDiffer_thenNoReturn() { + AtomicBoolean run = new AtomicBoolean(false); + + Action action = () -> { + System.out.println("Hello!"); + run.set(true); + }; + + Defer.defer(action); + + assertTrue(run.get()); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/voidtype/MyOwnDeferUnitTest.java b/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/voidtype/MyOwnDeferUnitTest.java new file mode 100644 index 0000000000..e3c3612a22 --- /dev/null +++ b/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/voidtype/MyOwnDeferUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.reflection.voidtype; + +import org.junit.jupiter.api.Test; + +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.jupiter.api.Assertions.*; + +class MyOwnDeferUnitTest { + @Test + void defer() throws Exception { + AtomicBoolean run = new AtomicBoolean(false); + Runnable runnable = () -> { + System.out.println("Hello!"); + run.set(true); + }; + + MyOwnDefer.defer(runnable); + + assertTrue(run.get()); + } +} \ No newline at end of file diff --git a/core-java-security/README.md b/core-java-modules/core-java-security/README.md similarity index 100% rename from core-java-security/README.md rename to core-java-modules/core-java-security/README.md diff --git a/core-java-security/pom.xml b/core-java-modules/core-java-security/pom.xml similarity index 97% rename from core-java-security/pom.xml rename to core-java-modules/core-java-security/pom.xml index 63bc46b114..ed82a5209a 100644 --- a/core-java-security/pom.xml +++ b/core-java-modules/core-java-security/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-security/src/main/java/com/baeldung/cipher/Encryptor.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/cipher/Encryptor.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/cipher/Encryptor.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/cipher/Encryptor.java diff --git a/core-java-security/src/main/java/com/baeldung/encrypt/FileEncrypterDecrypter.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/encrypt/FileEncrypterDecrypter.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/encrypt/FileEncrypterDecrypter.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/encrypt/FileEncrypterDecrypter.java diff --git a/core-java-security/src/main/java/com/baeldung/hashing/DigestAlgorithms.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/DigestAlgorithms.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/hashing/DigestAlgorithms.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/DigestAlgorithms.java diff --git a/core-java-security/src/main/java/com/baeldung/hashing/Keccak256Hashing.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/Keccak256Hashing.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/hashing/Keccak256Hashing.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/Keccak256Hashing.java diff --git a/core-java-security/src/main/java/com/baeldung/hashing/SHA256Hashing.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHA256Hashing.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/hashing/SHA256Hashing.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHA256Hashing.java diff --git a/core-java-security/src/main/java/com/baeldung/hashing/SHA3Hashing.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHA3Hashing.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/hashing/SHA3Hashing.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHA3Hashing.java diff --git a/core-java-security/src/main/java/com/baeldung/hashing/SHACommonUtils.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHACommonUtils.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/hashing/SHACommonUtils.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHACommonUtils.java diff --git a/core-java-security/src/main/java/com/baeldung/keystore/JavaKeyStore.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/keystore/JavaKeyStore.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/keystore/JavaKeyStore.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/keystore/JavaKeyStore.java diff --git a/core-java-security/src/main/java/com/baeldung/passwordhashing/PBKDF2Hasher.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/PBKDF2Hasher.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/passwordhashing/PBKDF2Hasher.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/PBKDF2Hasher.java diff --git a/core-java-security/src/main/java/com/baeldung/passwordhashing/SHA512Hasher.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/SHA512Hasher.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/passwordhashing/SHA512Hasher.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/SHA512Hasher.java diff --git a/core-java-security/src/main/java/com/baeldung/passwordhashing/SimplePBKDF2Hasher.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/SimplePBKDF2Hasher.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/passwordhashing/SimplePBKDF2Hasher.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/SimplePBKDF2Hasher.java diff --git a/core-java-security/src/main/java/com/baeldung/ssl/EnableTLSv12.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/EnableTLSv12.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/ssl/EnableTLSv12.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/EnableTLSv12.java diff --git a/core-java-security/src/main/java/com/baeldung/ssl/SecureConnection.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/SecureConnection.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/ssl/SecureConnection.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/SecureConnection.java diff --git a/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleClient.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleClient.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/ssl/example/SimpleClient.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleClient.java diff --git a/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleServer.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleServer.java similarity index 100% rename from core-java-security/src/main/java/com/baeldung/ssl/example/SimpleServer.java rename to core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleServer.java diff --git a/core-java-security/src/main/resources/logback.xml b/core-java-modules/core-java-security/src/main/resources/logback.xml similarity index 100% rename from core-java-security/src/main/resources/logback.xml rename to core-java-modules/core-java-security/src/main/resources/logback.xml diff --git a/core-java-security/src/test/java/com/baeldung/cipher/EncryptorUnitTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/cipher/EncryptorUnitTest.java similarity index 100% rename from core-java-security/src/test/java/com/baeldung/cipher/EncryptorUnitTest.java rename to core-java-modules/core-java-security/src/test/java/com/baeldung/cipher/EncryptorUnitTest.java diff --git a/core-java-security/src/test/java/com/baeldung/encrypt/FileEncrypterDecrypterIntegrationTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/encrypt/FileEncrypterDecrypterIntegrationTest.java similarity index 100% rename from core-java-security/src/test/java/com/baeldung/encrypt/FileEncrypterDecrypterIntegrationTest.java rename to core-java-modules/core-java-security/src/test/java/com/baeldung/encrypt/FileEncrypterDecrypterIntegrationTest.java diff --git a/core-java-security/src/test/java/com/baeldung/hashing/Keccak256HashingUnitTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/Keccak256HashingUnitTest.java similarity index 100% rename from core-java-security/src/test/java/com/baeldung/hashing/Keccak256HashingUnitTest.java rename to core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/Keccak256HashingUnitTest.java diff --git a/core-java-security/src/test/java/com/baeldung/hashing/SHA256HashingUnitTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/SHA256HashingUnitTest.java similarity index 100% rename from core-java-security/src/test/java/com/baeldung/hashing/SHA256HashingUnitTest.java rename to core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/SHA256HashingUnitTest.java diff --git a/core-java-security/src/test/java/com/baeldung/hashing/SHA3HashingUnitTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/SHA3HashingUnitTest.java similarity index 100% rename from core-java-security/src/test/java/com/baeldung/hashing/SHA3HashingUnitTest.java rename to core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/SHA3HashingUnitTest.java diff --git a/core-java-security/src/test/java/com/baeldung/keystore/JavaKeyStoreUnitTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/keystore/JavaKeyStoreUnitTest.java similarity index 100% rename from core-java-security/src/test/java/com/baeldung/keystore/JavaKeyStoreUnitTest.java rename to core-java-modules/core-java-security/src/test/java/com/baeldung/keystore/JavaKeyStoreUnitTest.java diff --git a/core-java-security/src/test/java/com/baeldung/passwordhashing/PBKDF2HasherUnitTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/passwordhashing/PBKDF2HasherUnitTest.java similarity index 100% rename from core-java-security/src/test/java/com/baeldung/passwordhashing/PBKDF2HasherUnitTest.java rename to core-java-modules/core-java-security/src/test/java/com/baeldung/passwordhashing/PBKDF2HasherUnitTest.java diff --git a/core-java-security/src/test/java/com/baeldung/passwordhashing/SHA512HasherUnitTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/passwordhashing/SHA512HasherUnitTest.java similarity index 100% rename from core-java-security/src/test/java/com/baeldung/passwordhashing/SHA512HasherUnitTest.java rename to core-java-modules/core-java-security/src/test/java/com/baeldung/passwordhashing/SHA512HasherUnitTest.java diff --git a/core-java-security/src/test/java/org/baeldung/java/md5/JavaMD5UnitTest.java b/core-java-modules/core-java-security/src/test/java/org/baeldung/java/md5/JavaMD5UnitTest.java similarity index 100% rename from core-java-security/src/test/java/org/baeldung/java/md5/JavaMD5UnitTest.java rename to core-java-modules/core-java-security/src/test/java/org/baeldung/java/md5/JavaMD5UnitTest.java diff --git a/core-java-security/src/test/resources/test_md5.txt b/core-java-modules/core-java-security/src/test/resources/test_md5.txt similarity index 100% rename from core-java-security/src/test/resources/test_md5.txt rename to core-java-modules/core-java-security/src/test/resources/test_md5.txt diff --git a/core-java-sun/.gitignore b/core-java-modules/core-java-sun/.gitignore similarity index 100% rename from core-java-sun/.gitignore rename to core-java-modules/core-java-sun/.gitignore diff --git a/core-java-sun/README.md b/core-java-modules/core-java-sun/README.md similarity index 100% rename from core-java-sun/README.md rename to core-java-modules/core-java-sun/README.md diff --git a/core-java-sun/pom.xml b/core-java-modules/core-java-sun/pom.xml similarity index 99% rename from core-java-sun/pom.xml rename to core-java-modules/core-java-sun/pom.xml index 5f2065016f..da27564d96 100644 --- a/core-java-sun/pom.xml +++ b/core-java-modules/core-java-sun/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-java 0.0.1-SNAPSHOT - ../parent-java + ../../parent-java diff --git a/core-java-sun/src/main/java/com/baeldung/.gitignore b/core-java-modules/core-java-sun/src/main/java/com/baeldung/.gitignore similarity index 100% rename from core-java-sun/src/main/java/com/baeldung/.gitignore rename to core-java-modules/core-java-sun/src/main/java/com/baeldung/.gitignore diff --git a/core-java-sun/src/main/java/com/baeldung/README.md b/core-java-modules/core-java-sun/src/main/java/com/baeldung/README.md similarity index 100% rename from core-java-sun/src/main/java/com/baeldung/README.md rename to core-java-modules/core-java-sun/src/main/java/com/baeldung/README.md diff --git a/core-java-sun/src/main/java/com/baeldung/javac/Positive.java b/core-java-modules/core-java-sun/src/main/java/com/baeldung/javac/Positive.java similarity index 100% rename from core-java-sun/src/main/java/com/baeldung/javac/Positive.java rename to core-java-modules/core-java-sun/src/main/java/com/baeldung/javac/Positive.java diff --git a/core-java-sun/src/main/java/com/baeldung/javac/SampleJavacPlugin.java b/core-java-modules/core-java-sun/src/main/java/com/baeldung/javac/SampleJavacPlugin.java similarity index 100% rename from core-java-sun/src/main/java/com/baeldung/javac/SampleJavacPlugin.java rename to core-java-modules/core-java-sun/src/main/java/com/baeldung/javac/SampleJavacPlugin.java diff --git a/core-java-sun/src/main/resources/META-INF/services/com.sun.source.util.Plugin b/core-java-modules/core-java-sun/src/main/resources/META-INF/services/com.sun.source.util.Plugin similarity index 100% rename from core-java-sun/src/main/resources/META-INF/services/com.sun.source.util.Plugin rename to core-java-modules/core-java-sun/src/main/resources/META-INF/services/com.sun.source.util.Plugin diff --git a/core-java-sun/src/main/resources/log4j.properties b/core-java-modules/core-java-sun/src/main/resources/log4j.properties similarity index 100% rename from core-java-sun/src/main/resources/log4j.properties rename to core-java-modules/core-java-sun/src/main/resources/log4j.properties diff --git a/core-java-sun/src/main/resources/logback.xml b/core-java-modules/core-java-sun/src/main/resources/logback.xml similarity index 100% rename from core-java-sun/src/main/resources/logback.xml rename to core-java-modules/core-java-sun/src/main/resources/logback.xml diff --git a/core-java-sun/src/test/java/com/baeldung/javac/SampleJavacPluginIntegrationTest.java b/core-java-modules/core-java-sun/src/test/java/com/baeldung/javac/SampleJavacPluginIntegrationTest.java similarity index 100% rename from core-java-sun/src/test/java/com/baeldung/javac/SampleJavacPluginIntegrationTest.java rename to core-java-modules/core-java-sun/src/test/java/com/baeldung/javac/SampleJavacPluginIntegrationTest.java diff --git a/core-java-sun/src/test/java/com/baeldung/javac/SimpleClassFile.java b/core-java-modules/core-java-sun/src/test/java/com/baeldung/javac/SimpleClassFile.java similarity index 100% rename from core-java-sun/src/test/java/com/baeldung/javac/SimpleClassFile.java rename to core-java-modules/core-java-sun/src/test/java/com/baeldung/javac/SimpleClassFile.java diff --git a/core-java-sun/src/test/java/com/baeldung/javac/SimpleFileManager.java b/core-java-modules/core-java-sun/src/test/java/com/baeldung/javac/SimpleFileManager.java similarity index 100% rename from core-java-sun/src/test/java/com/baeldung/javac/SimpleFileManager.java rename to core-java-modules/core-java-sun/src/test/java/com/baeldung/javac/SimpleFileManager.java diff --git a/core-java-sun/src/test/java/com/baeldung/javac/SimpleSourceFile.java b/core-java-modules/core-java-sun/src/test/java/com/baeldung/javac/SimpleSourceFile.java similarity index 100% rename from core-java-sun/src/test/java/com/baeldung/javac/SimpleSourceFile.java rename to core-java-modules/core-java-sun/src/test/java/com/baeldung/javac/SimpleSourceFile.java diff --git a/core-java-sun/src/test/java/com/baeldung/javac/TestCompiler.java b/core-java-modules/core-java-sun/src/test/java/com/baeldung/javac/TestCompiler.java similarity index 100% rename from core-java-sun/src/test/java/com/baeldung/javac/TestCompiler.java rename to core-java-modules/core-java-sun/src/test/java/com/baeldung/javac/TestCompiler.java diff --git a/core-java-sun/src/test/java/com/baeldung/javac/TestRunner.java b/core-java-modules/core-java-sun/src/test/java/com/baeldung/javac/TestRunner.java similarity index 100% rename from core-java-sun/src/test/java/com/baeldung/javac/TestRunner.java rename to core-java-modules/core-java-sun/src/test/java/com/baeldung/javac/TestRunner.java diff --git a/core-java-sun/src/test/java/com/baeldung/unsafe/CASCounter.java b/core-java-modules/core-java-sun/src/test/java/com/baeldung/unsafe/CASCounter.java similarity index 100% rename from core-java-sun/src/test/java/com/baeldung/unsafe/CASCounter.java rename to core-java-modules/core-java-sun/src/test/java/com/baeldung/unsafe/CASCounter.java diff --git a/core-java-sun/src/test/java/com/baeldung/unsafe/OffHeapArray.java b/core-java-modules/core-java-sun/src/test/java/com/baeldung/unsafe/OffHeapArray.java similarity index 100% rename from core-java-sun/src/test/java/com/baeldung/unsafe/OffHeapArray.java rename to core-java-modules/core-java-sun/src/test/java/com/baeldung/unsafe/OffHeapArray.java diff --git a/core-java-sun/src/test/java/com/baeldung/unsafe/UnsafeUnitTest.java b/core-java-modules/core-java-sun/src/test/java/com/baeldung/unsafe/UnsafeUnitTest.java similarity index 100% rename from core-java-sun/src/test/java/com/baeldung/unsafe/UnsafeUnitTest.java rename to core-java-modules/core-java-sun/src/test/java/com/baeldung/unsafe/UnsafeUnitTest.java diff --git a/core-java-sun/src/test/resources/.gitignore b/core-java-modules/core-java-sun/src/test/resources/.gitignore similarity index 100% rename from core-java-sun/src/test/resources/.gitignore rename to core-java-modules/core-java-sun/src/test/resources/.gitignore diff --git a/core-java-modules/core-java/.gitignore b/core-java-modules/core-java/.gitignore new file mode 100644 index 0000000000..374c8bf907 --- /dev/null +++ b/core-java-modules/core-java/.gitignore @@ -0,0 +1,25 @@ +*.class + +0.* + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* +.resourceCache + +# Packaged files # +*.jar +*.war +*.ear + +# Files generated by integration tests +backup-pom.xml +/bin/ +/temp + +#IntelliJ specific +.idea/ +*.iml \ No newline at end of file diff --git a/core-java/README.md b/core-java-modules/core-java/README.md similarity index 100% rename from core-java/README.md rename to core-java-modules/core-java/README.md diff --git a/core-java/customers.xml b/core-java-modules/core-java/customers.xml similarity index 100% rename from core-java/customers.xml rename to core-java-modules/core-java/customers.xml diff --git a/core-java/externalizable.txt b/core-java-modules/core-java/externalizable.txt similarity index 100% rename from core-java/externalizable.txt rename to core-java-modules/core-java/externalizable.txt diff --git a/core-java-modules/core-java/pom.xml b/core-java-modules/core-java/pom.xml new file mode 100644 index 0000000000..b0f9fea26e --- /dev/null +++ b/core-java-modules/core-java/pom.xml @@ -0,0 +1,492 @@ + + 4.0.0 + core-java + 0.1.0-SNAPSHOT + core-java + jar + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + + + + + + commons-io + commons-io + ${commons-io.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.unix4j + unix4j-command + ${unix4j.version} + + + com.googlecode.grep4j + grep4j + ${grep4j.version} + + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + com.google.code.gson + gson + ${gson.version} + + + + log4j + log4j + ${log4j.version} + + + org.slf4j + log4j-over-slf4j + ${org.slf4j.version} + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + org.assertj + assertj-core + ${assertj-core.version} + test + + + org.javamoney + moneta + ${javamoney.moneta.version} + + + org.owasp.esapi + esapi + ${esapi.version} + + + com.sun.messaging.mq + fscontext + ${fscontext.version} + + + com.codepoetics + protonpack + ${protonpack.version} + + + one.util + streamex + ${streamex.version} + + + io.vavr + vavr + ${vavr.version} + + + org.openjdk.jmh + jmh-core + ${jmh-core.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh-generator-annprocess.version} + + + com.h2database + h2 + ${h2database.version} + + + + org.javassist + javassist + ${javaassist.version} + + + com.sun + tools + ${sun.tools.version} + system + ${java.home}/../lib/tools.jar + + + + + core-java + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + prepare-package + + copy-dependencies + + + ${project.build.directory}/libs + + + + + + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + + true + libs/ + org.baeldung.executable.ExecutableMavenJar + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + ${project.basedir} + + + org.baeldung.executable.ExecutableMavenJar + + + + jar-with-dependencies + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven-shade-plugin.version} + + + + shade + + + true + + + org.baeldung.executable.ExecutableMavenJar + + + + + + + + + com.jolira + onejar-maven-plugin + ${onejar-maven-plugin.version} + + + + org.baeldung.executable.ExecutableMavenJar + true + ${project.build.finalName}-onejar.${project.packaging} + + + one-jar + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-maven-plugin.version} + + + + repackage + + + spring-boot + org.baeldung.executable.ExecutableMavenJar + + + + + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin.version} + + java + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed + + -Xmx300m + -XX:+UseParallelGC + -classpath + + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + 1.8 + 1.8 + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*ManualTest.java + + + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + json + + + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin.version} + + + run-benchmarks + + none + + exec + + + test + java + + -classpath + + org.openjdk.jmh.Main + .* + + + + + + + + + + + + buildAgentLoader + + + + org.apache.maven.plugins + maven-jar-plugin + + + package + + jar + + + agentLoader + target/classes + + + true + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + com/baeldung/instrumentation/application/AgentLoader.class + com/baeldung/instrumentation/application/Launcher.class + + + + + + + + + + buildApplication + + + + org.apache.maven.plugins + maven-jar-plugin + + + package + + jar + + + application + target/classes + + + true + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + com/baeldung/instrumentation/application/MyAtm.class + com/baeldung/instrumentation/application/MyAtmApplication.class + com/baeldung/instrumentation/application/Launcher.class + + + + + + + + + + buildAgent + + + + org.apache.maven.plugins + maven-jar-plugin + + + package + + jar + + + agent + target/classes + + + true + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + com/baeldung/instrumentation/agent/AtmTransformer.class + com/baeldung/instrumentation/agent/MyInstrumentationAgent.class + + + + + + + + + + + + + + 2.8.2 + + + 3.5 + 2.5 + 3.6.1 + 1.0.3 + 0.4 + 1.8.7 + 4.6-b01 + 1.13 + 0.6.5 + 0.9.0 + + + 3.10.0 + + + 2.21.0 + + 1.1 + 1.4.197 + 2.1.0.1 + 1.19 + + 1.19 + 3.0.0-M1 + 3.0.2 + 1.4.4 + 3.1.1 + 2.0.3.RELEASE + 1.6.0 + 61.1 + + 3.21.0-GA + + 1.8.0 + + diff --git a/core-java/src/main/java/com/baeldung/.gitignore b/core-java-modules/core-java/src/main/java/com/baeldung/.gitignore similarity index 100% rename from core-java/src/main/java/com/baeldung/.gitignore rename to core-java-modules/core-java/src/main/java/com/baeldung/.gitignore diff --git a/core-java/src/main/java/com/baeldung/README.md b/core-java-modules/core-java/src/main/java/com/baeldung/README.md similarity index 100% rename from core-java/src/main/java/com/baeldung/README.md rename to core-java-modules/core-java/src/main/java/com/baeldung/README.md diff --git a/core-java/src/main/java/com/baeldung/abstractclasses/application/Application.java b/core-java-modules/core-java/src/main/java/com/baeldung/abstractclasses/application/Application.java similarity index 97% rename from core-java/src/main/java/com/baeldung/abstractclasses/application/Application.java rename to core-java-modules/core-java/src/main/java/com/baeldung/abstractclasses/application/Application.java index 3180762227..5b250635ea 100644 --- a/core-java/src/main/java/com/baeldung/abstractclasses/application/Application.java +++ b/core-java-modules/core-java/src/main/java/com/baeldung/abstractclasses/application/Application.java @@ -1,29 +1,29 @@ -package com.baeldung.abstractclasses.application; - -import com.baeldung.abstractclasses.filereaders.BaseFileReader; -import com.baeldung.abstractclasses.filereaders.LowercaseFileReader; -import com.baeldung.abstractclasses.filereaders.UppercaseFileReader; -import java.io.IOException; -import java.net.URISyntaxException; -import java.nio.file.Path; -import java.nio.file.Paths; - -public class Application { - - public static void main(String[] args) throws IOException, URISyntaxException { - - Application application = new Application(); - Path path = application.getPathFromResourcesFile("files/test.txt"); - BaseFileReader lowercaseFileReader = new LowercaseFileReader(path); - lowercaseFileReader.readFile().forEach(line -> System.out.println(line)); - - BaseFileReader uppercaseFileReader = new UppercaseFileReader(path); - uppercaseFileReader.readFile().forEach(line -> System.out.println(line)); - - } - - private Path getPathFromResourcesFile(String filePath) throws URISyntaxException { - return Paths.get(getClass().getClassLoader().getResource(filePath).toURI()); - - } -} +package com.baeldung.abstractclasses.application; + +import com.baeldung.abstractclasses.filereaders.BaseFileReader; +import com.baeldung.abstractclasses.filereaders.LowercaseFileReader; +import com.baeldung.abstractclasses.filereaders.UppercaseFileReader; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class Application { + + public static void main(String[] args) throws IOException, URISyntaxException { + + Application application = new Application(); + Path path = application.getPathFromResourcesFile("files/test.txt"); + BaseFileReader lowercaseFileReader = new LowercaseFileReader(path); + lowercaseFileReader.readFile().forEach(line -> System.out.println(line)); + + BaseFileReader uppercaseFileReader = new UppercaseFileReader(path); + uppercaseFileReader.readFile().forEach(line -> System.out.println(line)); + + } + + private Path getPathFromResourcesFile(String filePath) throws URISyntaxException { + return Paths.get(getClass().getClassLoader().getResource(filePath).toURI()); + + } +} diff --git a/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/BaseFileReader.java b/core-java-modules/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/BaseFileReader.java similarity index 96% rename from core-java/src/main/java/com/baeldung/abstractclasses/filereaders/BaseFileReader.java rename to core-java-modules/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/BaseFileReader.java index 97452a9eca..376147aa13 100644 --- a/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/BaseFileReader.java +++ b/core-java-modules/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/BaseFileReader.java @@ -1,27 +1,27 @@ -package com.baeldung.abstractclasses.filereaders; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.stream.Collectors; - -public abstract class BaseFileReader { - - protected Path filePath; - - protected BaseFileReader(Path filePath) { - this.filePath = filePath; - } - - public Path getFilePath() { - return filePath; - } - - public List readFile() throws IOException { - return Files.lines(filePath) - .map(this::mapFileLine).collect(Collectors.toList()); - } - - protected abstract String mapFileLine(String line); -} +package com.baeldung.abstractclasses.filereaders; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.stream.Collectors; + +public abstract class BaseFileReader { + + protected Path filePath; + + protected BaseFileReader(Path filePath) { + this.filePath = filePath; + } + + public Path getFilePath() { + return filePath; + } + + public List readFile() throws IOException { + return Files.lines(filePath) + .map(this::mapFileLine).collect(Collectors.toList()); + } + + protected abstract String mapFileLine(String line); +} diff --git a/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/LowercaseFileReader.java b/core-java-modules/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/LowercaseFileReader.java similarity index 95% rename from core-java/src/main/java/com/baeldung/abstractclasses/filereaders/LowercaseFileReader.java rename to core-java-modules/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/LowercaseFileReader.java index 53820d393c..33a3e098a0 100644 --- a/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/LowercaseFileReader.java +++ b/core-java-modules/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/LowercaseFileReader.java @@ -1,15 +1,15 @@ -package com.baeldung.abstractclasses.filereaders; - -import java.nio.file.Path; - -public class LowercaseFileReader extends BaseFileReader { - - public LowercaseFileReader(Path filePath) { - super(filePath); - } - - @Override - public String mapFileLine(String line) { - return line.toLowerCase(); - } -} +package com.baeldung.abstractclasses.filereaders; + +import java.nio.file.Path; + +public class LowercaseFileReader extends BaseFileReader { + + public LowercaseFileReader(Path filePath) { + super(filePath); + } + + @Override + public String mapFileLine(String line) { + return line.toLowerCase(); + } +} diff --git a/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/UppercaseFileReader.java b/core-java-modules/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/UppercaseFileReader.java similarity index 95% rename from core-java/src/main/java/com/baeldung/abstractclasses/filereaders/UppercaseFileReader.java rename to core-java-modules/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/UppercaseFileReader.java index 3144a4f27f..4c93e75df7 100644 --- a/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/UppercaseFileReader.java +++ b/core-java-modules/core-java/src/main/java/com/baeldung/abstractclasses/filereaders/UppercaseFileReader.java @@ -1,15 +1,15 @@ -package com.baeldung.abstractclasses.filereaders; - -import java.nio.file.Path; - -public class UppercaseFileReader extends BaseFileReader { - - public UppercaseFileReader(Path filePath) { - super(filePath); - } - - @Override - public String mapFileLine(String line) { - return line.toUpperCase(); - } -} +package com.baeldung.abstractclasses.filereaders; + +import java.nio.file.Path; + +public class UppercaseFileReader extends BaseFileReader { + + public UppercaseFileReader(Path filePath) { + super(filePath); + } + + @Override + public String mapFileLine(String line) { + return line.toUpperCase(); + } +} diff --git a/core-java/src/main/java/com/baeldung/asciiart/AsciiArt.java b/core-java-modules/core-java/src/main/java/com/baeldung/asciiart/AsciiArt.java similarity index 100% rename from core-java/src/main/java/com/baeldung/asciiart/AsciiArt.java rename to core-java-modules/core-java/src/main/java/com/baeldung/asciiart/AsciiArt.java diff --git a/core-java/src/main/java/com/baeldung/basicsyntax/SimpleAddition.java b/core-java-modules/core-java/src/main/java/com/baeldung/basicsyntax/SimpleAddition.java similarity index 100% rename from core-java/src/main/java/com/baeldung/basicsyntax/SimpleAddition.java rename to core-java-modules/core-java/src/main/java/com/baeldung/basicsyntax/SimpleAddition.java diff --git a/core-java/src/main/java/com/baeldung/classloader/CustomClassLoader.java b/core-java-modules/core-java/src/main/java/com/baeldung/classloader/CustomClassLoader.java similarity index 100% rename from core-java/src/main/java/com/baeldung/classloader/CustomClassLoader.java rename to core-java-modules/core-java/src/main/java/com/baeldung/classloader/CustomClassLoader.java diff --git a/core-java/src/main/java/com/baeldung/classloader/PrintClassLoader.java b/core-java-modules/core-java/src/main/java/com/baeldung/classloader/PrintClassLoader.java similarity index 100% rename from core-java/src/main/java/com/baeldung/classloader/PrintClassLoader.java rename to core-java-modules/core-java/src/main/java/com/baeldung/classloader/PrintClassLoader.java diff --git a/core-java/src/main/java/com/baeldung/console/ConsoleConsoleClass.java b/core-java-modules/core-java/src/main/java/com/baeldung/console/ConsoleConsoleClass.java similarity index 100% rename from core-java/src/main/java/com/baeldung/console/ConsoleConsoleClass.java rename to core-java-modules/core-java/src/main/java/com/baeldung/console/ConsoleConsoleClass.java diff --git a/core-java/src/main/java/com/baeldung/console/ConsoleScannerClass.java b/core-java-modules/core-java/src/main/java/com/baeldung/console/ConsoleScannerClass.java similarity index 100% rename from core-java/src/main/java/com/baeldung/console/ConsoleScannerClass.java rename to core-java-modules/core-java/src/main/java/com/baeldung/console/ConsoleScannerClass.java diff --git a/core-java/src/main/java/com/baeldung/curltojava/JavaCurlExamples.java b/core-java-modules/core-java/src/main/java/com/baeldung/curltojava/JavaCurlExamples.java similarity index 100% rename from core-java/src/main/java/com/baeldung/curltojava/JavaCurlExamples.java rename to core-java-modules/core-java/src/main/java/com/baeldung/curltojava/JavaCurlExamples.java diff --git a/core-java/src/main/java/com/baeldung/deserialization/AppleProduct.java b/core-java-modules/core-java/src/main/java/com/baeldung/deserialization/AppleProduct.java similarity index 100% rename from core-java/src/main/java/com/baeldung/deserialization/AppleProduct.java rename to core-java-modules/core-java/src/main/java/com/baeldung/deserialization/AppleProduct.java diff --git a/core-java/src/main/java/com/baeldung/deserialization/DeserializationUtility.java b/core-java-modules/core-java/src/main/java/com/baeldung/deserialization/DeserializationUtility.java similarity index 100% rename from core-java/src/main/java/com/baeldung/deserialization/DeserializationUtility.java rename to core-java-modules/core-java/src/main/java/com/baeldung/deserialization/DeserializationUtility.java diff --git a/core-java/src/main/java/com/baeldung/deserialization/SerializationUtility.java b/core-java-modules/core-java/src/main/java/com/baeldung/deserialization/SerializationUtility.java similarity index 100% rename from core-java/src/main/java/com/baeldung/deserialization/SerializationUtility.java rename to core-java-modules/core-java/src/main/java/com/baeldung/deserialization/SerializationUtility.java diff --git a/core-java/src/main/java/com/baeldung/encoding/CharacterEncodingExamples.java b/core-java-modules/core-java/src/main/java/com/baeldung/encoding/CharacterEncodingExamples.java similarity index 100% rename from core-java/src/main/java/com/baeldung/encoding/CharacterEncodingExamples.java rename to core-java-modules/core-java/src/main/java/com/baeldung/encoding/CharacterEncodingExamples.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/Arithmetic.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/Arithmetic.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/Arithmetic.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/Arithmetic.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/ArrayIndexOutOfBounds.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/ArrayIndexOutOfBounds.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/ArrayIndexOutOfBounds.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/ArrayIndexOutOfBounds.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/ClassCast.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/ClassCast.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/ClassCast.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/ClassCast.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/FileNotFound.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/FileNotFound.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/FileNotFound.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/FileNotFound.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/GlobalExceptionHandler.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/GlobalExceptionHandler.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/GlobalExceptionHandler.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/GlobalExceptionHandler.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/IllegalArgument.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/IllegalArgument.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/IllegalArgument.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/IllegalArgument.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/IllegalState.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/IllegalState.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/IllegalState.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/IllegalState.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/InterruptedExceptionExample.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/InterruptedExceptionExample.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/InterruptedExceptionExample.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/InterruptedExceptionExample.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/MalformedURL.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/MalformedURL.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/MalformedURL.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/MalformedURL.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/NullPointer.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/NullPointer.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/NullPointer.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/NullPointer.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/NumberFormat.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/NumberFormat.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/NumberFormat.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/NumberFormat.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/ParseExceptionExample.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/ParseExceptionExample.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/ParseExceptionExample.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/ParseExceptionExample.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/StackTraceToString.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/StackTraceToString.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/StackTraceToString.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/StackTraceToString.java diff --git a/core-java/src/main/java/com/baeldung/exceptions/StringIndexOutOfBounds.java b/core-java-modules/core-java/src/main/java/com/baeldung/exceptions/StringIndexOutOfBounds.java similarity index 100% rename from core-java/src/main/java/com/baeldung/exceptions/StringIndexOutOfBounds.java rename to core-java-modules/core-java/src/main/java/com/baeldung/exceptions/StringIndexOutOfBounds.java diff --git a/core-java/src/main/java/com/baeldung/executable/ExecutableMavenJar.java b/core-java-modules/core-java/src/main/java/com/baeldung/executable/ExecutableMavenJar.java similarity index 100% rename from core-java/src/main/java/com/baeldung/executable/ExecutableMavenJar.java rename to core-java-modules/core-java/src/main/java/com/baeldung/executable/ExecutableMavenJar.java diff --git a/core-java/src/main/java/com/baeldung/externalizable/Community.java b/core-java-modules/core-java/src/main/java/com/baeldung/externalizable/Community.java similarity index 100% rename from core-java/src/main/java/com/baeldung/externalizable/Community.java rename to core-java-modules/core-java/src/main/java/com/baeldung/externalizable/Community.java diff --git a/core-java/src/main/java/com/baeldung/externalizable/Country.java b/core-java-modules/core-java/src/main/java/com/baeldung/externalizable/Country.java similarity index 100% rename from core-java/src/main/java/com/baeldung/externalizable/Country.java rename to core-java-modules/core-java/src/main/java/com/baeldung/externalizable/Country.java diff --git a/core-java/src/main/java/com/baeldung/externalizable/Region.java b/core-java-modules/core-java/src/main/java/com/baeldung/externalizable/Region.java similarity index 100% rename from core-java/src/main/java/com/baeldung/externalizable/Region.java rename to core-java-modules/core-java/src/main/java/com/baeldung/externalizable/Region.java diff --git a/core-java/src/main/java/com/baeldung/fileparser/BufferedReaderExample.java b/core-java-modules/core-java/src/main/java/com/baeldung/fileparser/BufferedReaderExample.java similarity index 100% rename from core-java/src/main/java/com/baeldung/fileparser/BufferedReaderExample.java rename to core-java-modules/core-java/src/main/java/com/baeldung/fileparser/BufferedReaderExample.java diff --git a/core-java/src/main/java/com/baeldung/fileparser/FileReaderExample.java b/core-java-modules/core-java/src/main/java/com/baeldung/fileparser/FileReaderExample.java similarity index 100% rename from core-java/src/main/java/com/baeldung/fileparser/FileReaderExample.java rename to core-java-modules/core-java/src/main/java/com/baeldung/fileparser/FileReaderExample.java diff --git a/core-java/src/main/java/com/baeldung/fileparser/FilesReadLinesExample.java b/core-java-modules/core-java/src/main/java/com/baeldung/fileparser/FilesReadLinesExample.java similarity index 100% rename from core-java/src/main/java/com/baeldung/fileparser/FilesReadLinesExample.java rename to core-java-modules/core-java/src/main/java/com/baeldung/fileparser/FilesReadLinesExample.java diff --git a/core-java/src/main/java/com/baeldung/fileparser/ScannerIntExample.java b/core-java-modules/core-java/src/main/java/com/baeldung/fileparser/ScannerIntExample.java similarity index 100% rename from core-java/src/main/java/com/baeldung/fileparser/ScannerIntExample.java rename to core-java-modules/core-java/src/main/java/com/baeldung/fileparser/ScannerIntExample.java diff --git a/core-java/src/main/java/com/baeldung/fileparser/ScannerStringExample.java b/core-java-modules/core-java/src/main/java/com/baeldung/fileparser/ScannerStringExample.java similarity index 100% rename from core-java/src/main/java/com/baeldung/fileparser/ScannerStringExample.java rename to core-java-modules/core-java/src/main/java/com/baeldung/fileparser/ScannerStringExample.java diff --git a/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java b/core-java-modules/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java similarity index 100% rename from core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java rename to core-java-modules/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java diff --git a/core-java/src/main/java/com/baeldung/graph/Graph.java b/core-java-modules/core-java/src/main/java/com/baeldung/graph/Graph.java similarity index 68% rename from core-java/src/main/java/com/baeldung/graph/Graph.java rename to core-java-modules/core-java/src/main/java/com/baeldung/graph/Graph.java index 43b5c0aa08..3f2e17c43c 100644 --- a/core-java/src/main/java/com/baeldung/graph/Graph.java +++ b/core-java-modules/core-java/src/main/java/com/baeldung/graph/Graph.java @@ -59,18 +59,43 @@ public class Graph { Vertex(String label) { this.label = label; } - @Override - public boolean equals(Object obj) { - Vertex vertex = (Vertex) obj; - return vertex.label == label; - } + @Override public int hashCode() { - return label.hashCode(); + final int prime = 31; + int result = 1; + result = prime * result + getOuterType().hashCode(); + result = prime * result + ((label == null) ? 0 : label.hashCode()); + return result; } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Vertex other = (Vertex) obj; + if (!getOuterType().equals(other.getOuterType())) + return false; + if (label == null) { + if (other.label != null) + return false; + } else if (!label.equals(other.label)) + return false; + return true; + } + @Override public String toString() { return label; } + + + private Graph getOuterType() { + return Graph.this; + } } } \ No newline at end of file diff --git a/core-java/src/main/java/com/baeldung/graph/GraphTraversal.java b/core-java-modules/core-java/src/main/java/com/baeldung/graph/GraphTraversal.java similarity index 100% rename from core-java/src/main/java/com/baeldung/graph/GraphTraversal.java rename to core-java-modules/core-java/src/main/java/com/baeldung/graph/GraphTraversal.java diff --git a/core-java/src/main/java/com/baeldung/instrumentation/agent/AtmTransformer.java b/core-java-modules/core-java/src/main/java/com/baeldung/instrumentation/agent/AtmTransformer.java similarity index 100% rename from core-java/src/main/java/com/baeldung/instrumentation/agent/AtmTransformer.java rename to core-java-modules/core-java/src/main/java/com/baeldung/instrumentation/agent/AtmTransformer.java diff --git a/core-java/src/main/java/com/baeldung/instrumentation/agent/MyInstrumentationAgent.java b/core-java-modules/core-java/src/main/java/com/baeldung/instrumentation/agent/MyInstrumentationAgent.java similarity index 100% rename from core-java/src/main/java/com/baeldung/instrumentation/agent/MyInstrumentationAgent.java rename to core-java-modules/core-java/src/main/java/com/baeldung/instrumentation/agent/MyInstrumentationAgent.java diff --git a/core-java/src/main/java/com/baeldung/instrumentation/application/AgentLoader.java b/core-java-modules/core-java/src/main/java/com/baeldung/instrumentation/application/AgentLoader.java similarity index 100% rename from core-java/src/main/java/com/baeldung/instrumentation/application/AgentLoader.java rename to core-java-modules/core-java/src/main/java/com/baeldung/instrumentation/application/AgentLoader.java diff --git a/core-java/src/main/java/com/baeldung/instrumentation/application/Launcher.java b/core-java-modules/core-java/src/main/java/com/baeldung/instrumentation/application/Launcher.java similarity index 100% rename from core-java/src/main/java/com/baeldung/instrumentation/application/Launcher.java rename to core-java-modules/core-java/src/main/java/com/baeldung/instrumentation/application/Launcher.java diff --git a/core-java/src/main/java/com/baeldung/instrumentation/application/MyAtm.java b/core-java-modules/core-java/src/main/java/com/baeldung/instrumentation/application/MyAtm.java similarity index 100% rename from core-java/src/main/java/com/baeldung/instrumentation/application/MyAtm.java rename to core-java-modules/core-java/src/main/java/com/baeldung/instrumentation/application/MyAtm.java diff --git a/core-java/src/main/java/com/baeldung/instrumentation/application/MyAtmApplication.java b/core-java-modules/core-java/src/main/java/com/baeldung/instrumentation/application/MyAtmApplication.java similarity index 100% rename from core-java/src/main/java/com/baeldung/instrumentation/application/MyAtmApplication.java rename to core-java-modules/core-java/src/main/java/com/baeldung/instrumentation/application/MyAtmApplication.java diff --git a/core-java/src/main/java/com/baeldung/jar/JarExample.java b/core-java-modules/core-java/src/main/java/com/baeldung/jar/JarExample.java similarity index 100% rename from core-java/src/main/java/com/baeldung/jar/JarExample.java rename to core-java-modules/core-java/src/main/java/com/baeldung/jar/JarExample.java diff --git a/core-java/src/main/java/com/baeldung/jar/example_manifest.txt b/core-java-modules/core-java/src/main/java/com/baeldung/jar/example_manifest.txt similarity index 100% rename from core-java/src/main/java/com/baeldung/jar/example_manifest.txt rename to core-java-modules/core-java/src/main/java/com/baeldung/jar/example_manifest.txt diff --git a/core-java/src/main/java/com/baeldung/javac/Data.java b/core-java-modules/core-java/src/main/java/com/baeldung/javac/Data.java similarity index 100% rename from core-java/src/main/java/com/baeldung/javac/Data.java rename to core-java-modules/core-java/src/main/java/com/baeldung/javac/Data.java diff --git a/core-java/src/main/java/com/baeldung/javadoc/Person.java b/core-java-modules/core-java/src/main/java/com/baeldung/javadoc/Person.java similarity index 100% rename from core-java/src/main/java/com/baeldung/javadoc/Person.java rename to core-java-modules/core-java/src/main/java/com/baeldung/javadoc/Person.java diff --git a/core-java/src/main/java/com/baeldung/javadoc/SuperHero.java b/core-java-modules/core-java/src/main/java/com/baeldung/javadoc/SuperHero.java similarity index 100% rename from core-java/src/main/java/com/baeldung/javadoc/SuperHero.java rename to core-java-modules/core-java/src/main/java/com/baeldung/javadoc/SuperHero.java diff --git a/core-java/src/main/java/com/baeldung/logforging/LogForgingDemo.java b/core-java-modules/core-java/src/main/java/com/baeldung/logforging/LogForgingDemo.java similarity index 100% rename from core-java/src/main/java/com/baeldung/logforging/LogForgingDemo.java rename to core-java-modules/core-java/src/main/java/com/baeldung/logforging/LogForgingDemo.java diff --git a/core-java/src/main/java/com/baeldung/manifest/AppExample.java b/core-java-modules/core-java/src/main/java/com/baeldung/manifest/AppExample.java similarity index 100% rename from core-java/src/main/java/com/baeldung/manifest/AppExample.java rename to core-java-modules/core-java/src/main/java/com/baeldung/manifest/AppExample.java diff --git a/core-java/src/main/java/com/baeldung/manifest/ExecuteJarFile.java b/core-java-modules/core-java/src/main/java/com/baeldung/manifest/ExecuteJarFile.java similarity index 100% rename from core-java/src/main/java/com/baeldung/manifest/ExecuteJarFile.java rename to core-java-modules/core-java/src/main/java/com/baeldung/manifest/ExecuteJarFile.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF b/core-java-modules/core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF new file mode 100644 index 0000000000..a363171952 --- /dev/null +++ b/core-java-modules/core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF @@ -0,0 +1 @@ +Main-Class: com.baeldung.manifest.AppExample diff --git a/core-java/src/main/java/com/baeldung/money/JavaMoney.java b/core-java-modules/core-java/src/main/java/com/baeldung/money/JavaMoney.java similarity index 97% rename from core-java/src/main/java/com/baeldung/money/JavaMoney.java rename to core-java-modules/core-java/src/main/java/com/baeldung/money/JavaMoney.java index 3171d226ed..aa507071cf 100644 --- a/core-java/src/main/java/com/baeldung/money/JavaMoney.java +++ b/core-java-modules/core-java/src/main/java/com/baeldung/money/JavaMoney.java @@ -1,151 +1,151 @@ -package com.baeldung.money; - -import java.util.Locale; -import java.util.logging.Logger; - -import javax.money.CurrencyUnit; -import javax.money.Monetary; -import javax.money.MonetaryAmount; -import javax.money.UnknownCurrencyException; -import javax.money.convert.ConversionQueryBuilder; -import javax.money.convert.CurrencyConversion; -import javax.money.convert.MonetaryConversions; -import javax.money.format.AmountFormatQueryBuilder; -import javax.money.format.MonetaryAmountFormat; -import javax.money.format.MonetaryFormats; - -import org.javamoney.moneta.FastMoney; -import org.javamoney.moneta.Money; -import org.javamoney.moneta.format.CurrencyStyle; - -public class JavaMoney { - final static Logger LOGGER = Logger.getLogger(JavaMoney.class.getName()); - CurrencyUnit USD; - MonetaryAmount fstAmtUSD; - MonetaryAmount fstAmtEUR; - MonetaryAmount oneDolar; - MonetaryAmount moneyof; - MonetaryAmount fastmoneyof; - MonetaryAmount roundEUR; - MonetaryAmount calcAmtUSD; - MonetaryAmount[] monetaryAmounts; - MonetaryAmount sumAmtCHF; - MonetaryAmount calcMoneyFastMoney; - MonetaryAmount convertedAmountEURtoUSD; - MonetaryAmount convertedAmountEURtoUSD2; - MonetaryAmount convertedAmountUSDtoEUR; - MonetaryAmount convertedAmountUSDtoEUR2; - MonetaryAmount multiplyAmount; - MonetaryAmount divideAmount; - MonetaryAmount oneDivThree; - CurrencyConversion convEUR; - CurrencyConversion convUSD; - CurrencyConversion conversionUSD; - CurrencyConversion conversionEUR; - MonetaryAmount oneEuro; - MonetaryAmountFormat formatUSD; - MonetaryAmountFormat customFormat; - String usFormatted; - String customFormatted; - - public JavaMoney() { - USD = Monetary.getCurrency("USD"); - fstAmtUSD = Monetary.getDefaultAmountFactory().setCurrency(USD).setNumber(200.50).create(); - fstAmtEUR = Monetary.getDefaultAmountFactory().setCurrency("EUR").setNumber(1.30473908).create(); - oneDolar = Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(1).create(); - moneyof = Money.of(12, USD); - fastmoneyof = FastMoney.of(2, USD); - - LOGGER.info("First Amount in USD : " + fstAmtUSD); - LOGGER.info("First Amount in EUR : " + fstAmtEUR); - LOGGER.info("One Dolar : " + oneDolar); - LOGGER.info("MoneyOf : " + moneyof); - LOGGER.info("FastMoneyOf : " + fastmoneyof); - - try{ - @SuppressWarnings("unused") - CurrencyUnit AAA = Monetary.getCurrency("AAA"); - } catch (UnknownCurrencyException e) { - LOGGER.severe("Unknown Currency"); - } - - roundEUR = fstAmtEUR.with(Monetary.getDefaultRounding()); - - LOGGER.info("Rounded EUR : " + roundEUR); - - calcAmtUSD = Money.of(1, "USD").subtract(fstAmtUSD); - - LOGGER.info("Substracting amounts : " + calcAmtUSD); - - calcMoneyFastMoney = moneyof.subtract(fastmoneyof); - - LOGGER.info("Money & FastMoney operations : " + calcMoneyFastMoney); - - monetaryAmounts = - new MonetaryAmount[] { - Money.of(100, "CHF"), - Money.of(10.20, "CHF"), - Money.of(1.15, "CHF"), }; - sumAmtCHF = Money.of(0, "CHF"); - for (MonetaryAmount monetaryAmount : monetaryAmounts) { - sumAmtCHF = sumAmtCHF.add(monetaryAmount); - } - - LOGGER.info("Adding amounts : " + sumAmtCHF); - - multiplyAmount = oneDolar.multiply(0.25); - LOGGER.info("Multiply Amount : " + multiplyAmount); - - divideAmount = oneDolar.divide(0.25); - LOGGER.info("Divide Amount : " + divideAmount); - - try{ - oneDivThree = oneDolar.divide(3); - }catch (ArithmeticException e) { - LOGGER.severe("One divide by Three is an infinite number"); - } - - convEUR = MonetaryConversions.getConversion(ConversionQueryBuilder.of().setTermCurrency("EUR").build()); - convUSD = MonetaryConversions.getConversion(ConversionQueryBuilder.of().setTermCurrency(USD).build()); - - conversionUSD = MonetaryConversions.getConversion("USD"); - conversionEUR = MonetaryConversions.getConversion("EUR"); - - convertedAmountEURtoUSD = fstAmtEUR.with(conversionUSD); - convertedAmountEURtoUSD2 = fstAmtEUR.with(convUSD); - convertedAmountUSDtoEUR = oneDolar.with(conversionEUR); - convertedAmountUSDtoEUR2 = oneDolar.with(convEUR); - LOGGER.info("C1 - " + convertedAmountEURtoUSD); - LOGGER.info("C2 - " + convertedAmountEURtoUSD2); - LOGGER.info("One Euro -> " + convertedAmountUSDtoEUR); - LOGGER.info("One Euro2 -> " + convertedAmountUSDtoEUR2); - - oneEuro = Money.of(1, "EUR"); - - if (oneEuro.equals(FastMoney.of(1, "EUR"))) { - LOGGER.info("Money == FastMoney"); - } else { - LOGGER.info("Money != FastMoney"); - } - - if (oneDolar.equals(Money.of(1, "USD"))) { - LOGGER.info("Factory == Money"); - } else { - LOGGER.info("Factory != Money"); - } - - formatUSD = MonetaryFormats.getAmountFormat(Locale.US); - usFormatted = formatUSD.format(oneDolar); - LOGGER.info("One dolar standard formatted : " + usFormatted); - - customFormat = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder.of(Locale.US).set(CurrencyStyle.NAME).set("pattern", "00000.00 ¤").build()); - customFormatted = customFormat.format(oneDolar); - LOGGER.info("One dolar custom formatted : " + customFormatted); - } - - public static void main(String[] args) { - @SuppressWarnings("unused") - JavaMoney java9Money = new JavaMoney(); - } - -} +package com.baeldung.money; + +import java.util.Locale; +import java.util.logging.Logger; + +import javax.money.CurrencyUnit; +import javax.money.Monetary; +import javax.money.MonetaryAmount; +import javax.money.UnknownCurrencyException; +import javax.money.convert.ConversionQueryBuilder; +import javax.money.convert.CurrencyConversion; +import javax.money.convert.MonetaryConversions; +import javax.money.format.AmountFormatQueryBuilder; +import javax.money.format.MonetaryAmountFormat; +import javax.money.format.MonetaryFormats; + +import org.javamoney.moneta.FastMoney; +import org.javamoney.moneta.Money; +import org.javamoney.moneta.format.CurrencyStyle; + +public class JavaMoney { + final static Logger LOGGER = Logger.getLogger(JavaMoney.class.getName()); + CurrencyUnit USD; + MonetaryAmount fstAmtUSD; + MonetaryAmount fstAmtEUR; + MonetaryAmount oneDolar; + MonetaryAmount moneyof; + MonetaryAmount fastmoneyof; + MonetaryAmount roundEUR; + MonetaryAmount calcAmtUSD; + MonetaryAmount[] monetaryAmounts; + MonetaryAmount sumAmtCHF; + MonetaryAmount calcMoneyFastMoney; + MonetaryAmount convertedAmountEURtoUSD; + MonetaryAmount convertedAmountEURtoUSD2; + MonetaryAmount convertedAmountUSDtoEUR; + MonetaryAmount convertedAmountUSDtoEUR2; + MonetaryAmount multiplyAmount; + MonetaryAmount divideAmount; + MonetaryAmount oneDivThree; + CurrencyConversion convEUR; + CurrencyConversion convUSD; + CurrencyConversion conversionUSD; + CurrencyConversion conversionEUR; + MonetaryAmount oneEuro; + MonetaryAmountFormat formatUSD; + MonetaryAmountFormat customFormat; + String usFormatted; + String customFormatted; + + public JavaMoney() { + USD = Monetary.getCurrency("USD"); + fstAmtUSD = Monetary.getDefaultAmountFactory().setCurrency(USD).setNumber(200.50).create(); + fstAmtEUR = Monetary.getDefaultAmountFactory().setCurrency("EUR").setNumber(1.30473908).create(); + oneDolar = Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(1).create(); + moneyof = Money.of(12, USD); + fastmoneyof = FastMoney.of(2, USD); + + LOGGER.info("First Amount in USD : " + fstAmtUSD); + LOGGER.info("First Amount in EUR : " + fstAmtEUR); + LOGGER.info("One Dolar : " + oneDolar); + LOGGER.info("MoneyOf : " + moneyof); + LOGGER.info("FastMoneyOf : " + fastmoneyof); + + try{ + @SuppressWarnings("unused") + CurrencyUnit AAA = Monetary.getCurrency("AAA"); + } catch (UnknownCurrencyException e) { + LOGGER.severe("Unknown Currency"); + } + + roundEUR = fstAmtEUR.with(Monetary.getDefaultRounding()); + + LOGGER.info("Rounded EUR : " + roundEUR); + + calcAmtUSD = Money.of(1, "USD").subtract(fstAmtUSD); + + LOGGER.info("Substracting amounts : " + calcAmtUSD); + + calcMoneyFastMoney = moneyof.subtract(fastmoneyof); + + LOGGER.info("Money & FastMoney operations : " + calcMoneyFastMoney); + + monetaryAmounts = + new MonetaryAmount[] { + Money.of(100, "CHF"), + Money.of(10.20, "CHF"), + Money.of(1.15, "CHF"), }; + sumAmtCHF = Money.of(0, "CHF"); + for (MonetaryAmount monetaryAmount : monetaryAmounts) { + sumAmtCHF = sumAmtCHF.add(monetaryAmount); + } + + LOGGER.info("Adding amounts : " + sumAmtCHF); + + multiplyAmount = oneDolar.multiply(0.25); + LOGGER.info("Multiply Amount : " + multiplyAmount); + + divideAmount = oneDolar.divide(0.25); + LOGGER.info("Divide Amount : " + divideAmount); + + try{ + oneDivThree = oneDolar.divide(3); + }catch (ArithmeticException e) { + LOGGER.severe("One divide by Three is an infinite number"); + } + + convEUR = MonetaryConversions.getConversion(ConversionQueryBuilder.of().setTermCurrency("EUR").build()); + convUSD = MonetaryConversions.getConversion(ConversionQueryBuilder.of().setTermCurrency(USD).build()); + + conversionUSD = MonetaryConversions.getConversion("USD"); + conversionEUR = MonetaryConversions.getConversion("EUR"); + + convertedAmountEURtoUSD = fstAmtEUR.with(conversionUSD); + convertedAmountEURtoUSD2 = fstAmtEUR.with(convUSD); + convertedAmountUSDtoEUR = oneDolar.with(conversionEUR); + convertedAmountUSDtoEUR2 = oneDolar.with(convEUR); + LOGGER.info("C1 - " + convertedAmountEURtoUSD); + LOGGER.info("C2 - " + convertedAmountEURtoUSD2); + LOGGER.info("One Euro -> " + convertedAmountUSDtoEUR); + LOGGER.info("One Euro2 -> " + convertedAmountUSDtoEUR2); + + oneEuro = Money.of(1, "EUR"); + + if (oneEuro.equals(FastMoney.of(1, "EUR"))) { + LOGGER.info("Money == FastMoney"); + } else { + LOGGER.info("Money != FastMoney"); + } + + if (oneDolar.equals(Money.of(1, "USD"))) { + LOGGER.info("Factory == Money"); + } else { + LOGGER.info("Factory != Money"); + } + + formatUSD = MonetaryFormats.getAmountFormat(Locale.US); + usFormatted = formatUSD.format(oneDolar); + LOGGER.info("One dolar standard formatted : " + usFormatted); + + customFormat = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder.of(Locale.US).set(CurrencyStyle.NAME).set("pattern", "00000.00 ¤").build()); + customFormatted = customFormat.format(oneDolar); + LOGGER.info("One dolar custom formatted : " + customFormatted); + } + + public static void main(String[] args) { + @SuppressWarnings("unused") + JavaMoney java9Money = new JavaMoney(); + } + +} diff --git a/core-java/src/main/java/com/baeldung/objectsize/InstrumentationAgent.java b/core-java-modules/core-java/src/main/java/com/baeldung/objectsize/InstrumentationAgent.java similarity index 100% rename from core-java/src/main/java/com/baeldung/objectsize/InstrumentationAgent.java rename to core-java-modules/core-java/src/main/java/com/baeldung/objectsize/InstrumentationAgent.java diff --git a/core-java/src/main/java/com/baeldung/objectsize/InstrumentationExample.java b/core-java-modules/core-java/src/main/java/com/baeldung/objectsize/InstrumentationExample.java similarity index 100% rename from core-java/src/main/java/com/baeldung/objectsize/InstrumentationExample.java rename to core-java-modules/core-java/src/main/java/com/baeldung/objectsize/InstrumentationExample.java diff --git a/core-java/src/main/java/com/baeldung/objectsize/MANIFEST.MF b/core-java-modules/core-java/src/main/java/com/baeldung/objectsize/MANIFEST.MF similarity index 100% rename from core-java/src/main/java/com/baeldung/objectsize/MANIFEST.MF rename to core-java-modules/core-java/src/main/java/com/baeldung/objectsize/MANIFEST.MF diff --git a/core-java/src/main/java/com/baeldung/printf/PrintfExamples.java b/core-java-modules/core-java/src/main/java/com/baeldung/printf/PrintfExamples.java similarity index 100% rename from core-java/src/main/java/com/baeldung/printf/PrintfExamples.java rename to core-java-modules/core-java/src/main/java/com/baeldung/printf/PrintfExamples.java diff --git a/core-java/src/main/java/com/baeldung/printscreen/README.md b/core-java-modules/core-java/src/main/java/com/baeldung/printscreen/README.md similarity index 100% rename from core-java/src/main/java/com/baeldung/printscreen/README.md rename to core-java-modules/core-java/src/main/java/com/baeldung/printscreen/README.md diff --git a/core-java/src/main/java/com/baeldung/printscreen/Screenshot.java b/core-java-modules/core-java/src/main/java/com/baeldung/printscreen/Screenshot.java similarity index 100% rename from core-java/src/main/java/com/baeldung/printscreen/Screenshot.java rename to core-java-modules/core-java/src/main/java/com/baeldung/printscreen/Screenshot.java diff --git a/core-java/src/main/java/com/baeldung/reflection/BaeldungReflectionUtils.java b/core-java-modules/core-java/src/main/java/com/baeldung/reflection/BaeldungReflectionUtils.java similarity index 100% rename from core-java/src/main/java/com/baeldung/reflection/BaeldungReflectionUtils.java rename to core-java-modules/core-java/src/main/java/com/baeldung/reflection/BaeldungReflectionUtils.java diff --git a/core-java/src/main/java/com/baeldung/reflection/Customer.java b/core-java-modules/core-java/src/main/java/com/baeldung/reflection/Customer.java similarity index 100% rename from core-java/src/main/java/com/baeldung/reflection/Customer.java rename to core-java-modules/core-java/src/main/java/com/baeldung/reflection/Customer.java diff --git a/core-java/src/main/java/com/baeldung/reflection/Employee.java b/core-java-modules/core-java/src/main/java/com/baeldung/reflection/Employee.java similarity index 100% rename from core-java/src/main/java/com/baeldung/reflection/Employee.java rename to core-java-modules/core-java/src/main/java/com/baeldung/reflection/Employee.java diff --git a/core-java/src/main/java/com/baeldung/reflection/MonthEmployee.java b/core-java-modules/core-java/src/main/java/com/baeldung/reflection/MonthEmployee.java similarity index 100% rename from core-java/src/main/java/com/baeldung/reflection/MonthEmployee.java rename to core-java-modules/core-java/src/main/java/com/baeldung/reflection/MonthEmployee.java diff --git a/core-java/src/main/java/com/baeldung/reflection/Person.java b/core-java-modules/core-java/src/main/java/com/baeldung/reflection/Person.java similarity index 100% rename from core-java/src/main/java/com/baeldung/reflection/Person.java rename to core-java-modules/core-java/src/main/java/com/baeldung/reflection/Person.java diff --git a/core-java/src/main/java/com/baeldung/resourcebundle/ExampleControl.java b/core-java-modules/core-java/src/main/java/com/baeldung/resourcebundle/ExampleControl.java similarity index 100% rename from core-java/src/main/java/com/baeldung/resourcebundle/ExampleControl.java rename to core-java-modules/core-java/src/main/java/com/baeldung/resourcebundle/ExampleControl.java diff --git a/core-java/src/main/java/com/baeldung/resourcebundle/ExampleResource.java b/core-java-modules/core-java/src/main/java/com/baeldung/resourcebundle/ExampleResource.java similarity index 100% rename from core-java/src/main/java/com/baeldung/resourcebundle/ExampleResource.java rename to core-java-modules/core-java/src/main/java/com/baeldung/resourcebundle/ExampleResource.java diff --git a/core-java/src/main/java/com/baeldung/resourcebundle/ExampleResource_pl.java b/core-java-modules/core-java/src/main/java/com/baeldung/resourcebundle/ExampleResource_pl.java similarity index 100% rename from core-java/src/main/java/com/baeldung/resourcebundle/ExampleResource_pl.java rename to core-java-modules/core-java/src/main/java/com/baeldung/resourcebundle/ExampleResource_pl.java diff --git a/core-java/src/main/java/com/baeldung/resourcebundle/ExampleResource_pl_PL.java b/core-java-modules/core-java/src/main/java/com/baeldung/resourcebundle/ExampleResource_pl_PL.java similarity index 100% rename from core-java/src/main/java/com/baeldung/resourcebundle/ExampleResource_pl_PL.java rename to core-java-modules/core-java/src/main/java/com/baeldung/resourcebundle/ExampleResource_pl_PL.java diff --git a/core-java/src/main/java/com/baeldung/serialization/Address.java b/core-java-modules/core-java/src/main/java/com/baeldung/serialization/Address.java similarity index 100% rename from core-java/src/main/java/com/baeldung/serialization/Address.java rename to core-java-modules/core-java/src/main/java/com/baeldung/serialization/Address.java diff --git a/core-java/src/main/java/com/baeldung/serialization/Employee.java b/core-java-modules/core-java/src/main/java/com/baeldung/serialization/Employee.java similarity index 100% rename from core-java/src/main/java/com/baeldung/serialization/Employee.java rename to core-java-modules/core-java/src/main/java/com/baeldung/serialization/Employee.java diff --git a/core-java/src/main/java/com/baeldung/serialization/Person.java b/core-java-modules/core-java/src/main/java/com/baeldung/serialization/Person.java similarity index 100% rename from core-java/src/main/java/com/baeldung/serialization/Person.java rename to core-java-modules/core-java/src/main/java/com/baeldung/serialization/Person.java diff --git a/core-java/src/main/java/com/baeldung/staticclass/Pizza.java b/core-java-modules/core-java/src/main/java/com/baeldung/staticclass/Pizza.java similarity index 100% rename from core-java/src/main/java/com/baeldung/staticclass/Pizza.java rename to core-java-modules/core-java/src/main/java/com/baeldung/staticclass/Pizza.java diff --git a/core-java/src/main/java/com/baeldung/system/DetectOS.java b/core-java-modules/core-java/src/main/java/com/baeldung/system/DetectOS.java similarity index 100% rename from core-java/src/main/java/com/baeldung/system/DetectOS.java rename to core-java-modules/core-java/src/main/java/com/baeldung/system/DetectOS.java diff --git a/core-java/src/main/java/com/baeldung/urlconnection/PostJSONWithHttpURLConnection.java b/core-java-modules/core-java/src/main/java/com/baeldung/urlconnection/PostJSONWithHttpURLConnection.java similarity index 100% rename from core-java/src/main/java/com/baeldung/urlconnection/PostJSONWithHttpURLConnection.java rename to core-java-modules/core-java/src/main/java/com/baeldung/urlconnection/PostJSONWithHttpURLConnection.java diff --git a/core-java/src/main/java/com/baeldung/util/PropertiesLoader.java b/core-java-modules/core-java/src/main/java/com/baeldung/util/PropertiesLoader.java similarity index 100% rename from core-java/src/main/java/com/baeldung/util/PropertiesLoader.java rename to core-java-modules/core-java/src/main/java/com/baeldung/util/PropertiesLoader.java diff --git a/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java b/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java similarity index 100% rename from core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java rename to core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java diff --git a/core-java/src/main/java/javac-args/arguments b/core-java-modules/core-java/src/main/java/javac-args/arguments similarity index 100% rename from core-java/src/main/java/javac-args/arguments rename to core-java-modules/core-java/src/main/java/javac-args/arguments diff --git a/core-java/src/main/java/javac-args/options b/core-java-modules/core-java/src/main/java/javac-args/options similarity index 100% rename from core-java/src/main/java/javac-args/options rename to core-java-modules/core-java/src/main/java/javac-args/options diff --git a/core-java/src/main/java/javac-args/types b/core-java-modules/core-java/src/main/java/javac-args/types similarity index 100% rename from core-java/src/main/java/javac-args/types rename to core-java-modules/core-java/src/main/java/javac-args/types diff --git a/core-java/src/main/java/javac-args/xlint-ops b/core-java-modules/core-java/src/main/java/javac-args/xlint-ops similarity index 100% rename from core-java/src/main/java/javac-args/xlint-ops rename to core-java-modules/core-java/src/main/java/javac-args/xlint-ops diff --git a/core-java/src/main/java/log4j.properties b/core-java-modules/core-java/src/main/java/log4j.properties similarity index 100% rename from core-java/src/main/java/log4j.properties rename to core-java-modules/core-java/src/main/java/log4j.properties diff --git a/core-java/src/main/java/org/baeldung/executable/ExecutableMavenJar.java b/core-java-modules/core-java/src/main/java/org/baeldung/executable/ExecutableMavenJar.java similarity index 100% rename from core-java/src/main/java/org/baeldung/executable/ExecutableMavenJar.java rename to core-java-modules/core-java/src/main/java/org/baeldung/executable/ExecutableMavenJar.java diff --git a/core-java/src/main/resources/ESAPI.properties b/core-java-modules/core-java/src/main/resources/ESAPI.properties similarity index 100% rename from core-java/src/main/resources/ESAPI.properties rename to core-java-modules/core-java/src/main/resources/ESAPI.properties diff --git a/core-java/src/main/resources/META-INF/BenchmarkList b/core-java-modules/core-java/src/main/resources/META-INF/BenchmarkList old mode 100755 new mode 100644 similarity index 100% rename from core-java/src/main/resources/META-INF/BenchmarkList rename to core-java-modules/core-java/src/main/resources/META-INF/BenchmarkList diff --git a/core-java/src/main/resources/META-INF/MANIFEST.MF b/core-java-modules/core-java/src/main/resources/META-INF/MANIFEST.MF similarity index 100% rename from core-java/src/main/resources/META-INF/MANIFEST.MF rename to core-java-modules/core-java/src/main/resources/META-INF/MANIFEST.MF diff --git a/core-java/src/main/resources/META-INF/persistence.xml b/core-java-modules/core-java/src/main/resources/META-INF/persistence.xml similarity index 100% rename from core-java/src/main/resources/META-INF/persistence.xml rename to core-java-modules/core-java/src/main/resources/META-INF/persistence.xml diff --git a/core-java/src/main/resources/countries.properties b/core-java-modules/core-java/src/main/resources/countries.properties similarity index 100% rename from core-java/src/main/resources/countries.properties rename to core-java-modules/core-java/src/main/resources/countries.properties diff --git a/core-java/src/main/resources/datasource.properties b/core-java-modules/core-java/src/main/resources/datasource.properties similarity index 100% rename from core-java/src/main/resources/datasource.properties rename to core-java-modules/core-java/src/main/resources/datasource.properties diff --git a/core-java/src/main/resources/files/test.txt b/core-java-modules/core-java/src/main/resources/files/test.txt similarity index 100% rename from core-java/src/main/resources/files/test.txt rename to core-java-modules/core-java/src/main/resources/files/test.txt diff --git a/core-java/src/main/resources/js/bind.js b/core-java-modules/core-java/src/main/resources/js/bind.js similarity index 100% rename from core-java/src/main/resources/js/bind.js rename to core-java-modules/core-java/src/main/resources/js/bind.js diff --git a/core-java/src/main/resources/js/locations.js b/core-java-modules/core-java/src/main/resources/js/locations.js similarity index 100% rename from core-java/src/main/resources/js/locations.js rename to core-java-modules/core-java/src/main/resources/js/locations.js diff --git a/core-java/src/main/resources/js/math_module.js b/core-java-modules/core-java/src/main/resources/js/math_module.js similarity index 100% rename from core-java/src/main/resources/js/math_module.js rename to core-java-modules/core-java/src/main/resources/js/math_module.js diff --git a/core-java/src/main/resources/js/no_such.js b/core-java-modules/core-java/src/main/resources/js/no_such.js similarity index 100% rename from core-java/src/main/resources/js/no_such.js rename to core-java-modules/core-java/src/main/resources/js/no_such.js diff --git a/core-java/src/main/resources/js/script.js b/core-java-modules/core-java/src/main/resources/js/script.js similarity index 100% rename from core-java/src/main/resources/js/script.js rename to core-java-modules/core-java/src/main/resources/js/script.js diff --git a/core-java/src/main/resources/js/trim.js b/core-java-modules/core-java/src/main/resources/js/trim.js similarity index 100% rename from core-java/src/main/resources/js/trim.js rename to core-java-modules/core-java/src/main/resources/js/trim.js diff --git a/core-java/src/main/resources/js/typed_arrays.js b/core-java-modules/core-java/src/main/resources/js/typed_arrays.js similarity index 100% rename from core-java/src/main/resources/js/typed_arrays.js rename to core-java-modules/core-java/src/main/resources/js/typed_arrays.js diff --git a/core-java/src/main/resources/log4j.properties b/core-java-modules/core-java/src/main/resources/log4j.properties similarity index 100% rename from core-java/src/main/resources/log4j.properties rename to core-java-modules/core-java/src/main/resources/log4j.properties diff --git a/core-java/src/main/resources/log4j2.xml b/core-java-modules/core-java/src/main/resources/log4j2.xml similarity index 100% rename from core-java/src/main/resources/log4j2.xml rename to core-java-modules/core-java/src/main/resources/log4j2.xml diff --git a/core-java/src/main/resources/log4jstructuraldp.properties b/core-java-modules/core-java/src/main/resources/log4jstructuraldp.properties similarity index 100% rename from core-java/src/main/resources/log4jstructuraldp.properties rename to core-java-modules/core-java/src/main/resources/log4jstructuraldp.properties diff --git a/core-java/src/main/resources/logback.xml b/core-java-modules/core-java/src/main/resources/logback.xml similarity index 100% rename from core-java/src/main/resources/logback.xml rename to core-java-modules/core-java/src/main/resources/logback.xml diff --git a/core-java/src/main/resources/product.png b/core-java-modules/core-java/src/main/resources/product.png similarity index 100% rename from core-java/src/main/resources/product.png rename to core-java-modules/core-java/src/main/resources/product.png diff --git a/core-java/src/main/resources/resourcebundle/resource.properties b/core-java-modules/core-java/src/main/resources/resourcebundle/resource.properties similarity index 100% rename from core-java/src/main/resources/resourcebundle/resource.properties rename to core-java-modules/core-java/src/main/resources/resourcebundle/resource.properties diff --git a/core-java/src/main/resources/resourcebundle/resource_en.properties b/core-java-modules/core-java/src/main/resources/resourcebundle/resource_en.properties similarity index 100% rename from core-java/src/main/resources/resourcebundle/resource_en.properties rename to core-java-modules/core-java/src/main/resources/resourcebundle/resource_en.properties diff --git a/core-java/src/main/resources/resourcebundle/resource_pl_PL.properties b/core-java-modules/core-java/src/main/resources/resourcebundle/resource_pl_PL.properties similarity index 100% rename from core-java/src/main/resources/resourcebundle/resource_pl_PL.properties rename to core-java-modules/core-java/src/main/resources/resourcebundle/resource_pl_PL.properties diff --git a/core-java/src/test/java/com/baeldung/abstractclasses/test/LowercaseFileReaderUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/abstractclasses/test/LowercaseFileReaderUnitTest.java similarity index 97% rename from core-java/src/test/java/com/baeldung/abstractclasses/test/LowercaseFileReaderUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/abstractclasses/test/LowercaseFileReaderUnitTest.java index 4f0d3a7cd5..45e16f0d25 100644 --- a/core-java/src/test/java/com/baeldung/abstractclasses/test/LowercaseFileReaderUnitTest.java +++ b/core-java-modules/core-java/src/test/java/com/baeldung/abstractclasses/test/LowercaseFileReaderUnitTest.java @@ -1,20 +1,20 @@ -package com.baeldung.abstractclasses.test; - -import com.baeldung.abstractclasses.filereaders.BaseFileReader; -import com.baeldung.abstractclasses.filereaders.LowercaseFileReader; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; - -public class LowercaseFileReaderUnitTest { - - @Test - public void givenLowercaseFileReaderInstance_whenCalledreadFile_thenCorrect() throws Exception { - Path path = Paths.get(getClass().getClassLoader().getResource("files/test.txt").toURI()); - BaseFileReader lowercaseFileReader = new LowercaseFileReader(path); - - assertThat(lowercaseFileReader.readFile()).isInstanceOf(List.class); - } -} +package com.baeldung.abstractclasses.test; + +import com.baeldung.abstractclasses.filereaders.BaseFileReader; +import com.baeldung.abstractclasses.filereaders.LowercaseFileReader; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; + +public class LowercaseFileReaderUnitTest { + + @Test + public void givenLowercaseFileReaderInstance_whenCalledreadFile_thenCorrect() throws Exception { + Path path = Paths.get(getClass().getClassLoader().getResource("files/test.txt").toURI()); + BaseFileReader lowercaseFileReader = new LowercaseFileReader(path); + + assertThat(lowercaseFileReader.readFile()).isInstanceOf(List.class); + } +} diff --git a/core-java/src/test/java/com/baeldung/abstractclasses/test/UppercaseFileReaderUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/abstractclasses/test/UppercaseFileReaderUnitTest.java similarity index 97% rename from core-java/src/test/java/com/baeldung/abstractclasses/test/UppercaseFileReaderUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/abstractclasses/test/UppercaseFileReaderUnitTest.java index e11db57000..dc4df900e4 100644 --- a/core-java/src/test/java/com/baeldung/abstractclasses/test/UppercaseFileReaderUnitTest.java +++ b/core-java-modules/core-java/src/test/java/com/baeldung/abstractclasses/test/UppercaseFileReaderUnitTest.java @@ -1,20 +1,20 @@ -package com.baeldung.abstractclasses.test; - -import com.baeldung.abstractclasses.filereaders.BaseFileReader; -import com.baeldung.abstractclasses.filereaders.UppercaseFileReader; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; - -public class UppercaseFileReaderUnitTest { - - @Test - public void givenUppercaseFileReaderInstance_whenCalledreadFile_thenCorrect() throws Exception { - Path path = Paths.get(getClass().getClassLoader().getResource("files/test.txt").toURI()); - BaseFileReader uppercaseFileReader = new UppercaseFileReader(path); - - assertThat(uppercaseFileReader.readFile()).isInstanceOf(List.class); - } -} +package com.baeldung.abstractclasses.test; + +import com.baeldung.abstractclasses.filereaders.BaseFileReader; +import com.baeldung.abstractclasses.filereaders.UppercaseFileReader; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; + +public class UppercaseFileReaderUnitTest { + + @Test + public void givenUppercaseFileReaderInstance_whenCalledreadFile_thenCorrect() throws Exception { + Path path = Paths.get(getClass().getClassLoader().getResource("files/test.txt").toURI()); + BaseFileReader uppercaseFileReader = new UppercaseFileReader(path); + + assertThat(uppercaseFileReader.readFile()).isInstanceOf(List.class); + } +} diff --git a/core-java/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java diff --git a/core-java/src/test/java/com/baeldung/bitwiseoperator/test/BitwiseOperatorUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/bitwiseoperator/test/BitwiseOperatorUnitTest.java similarity index 96% rename from core-java/src/test/java/com/baeldung/bitwiseoperator/test/BitwiseOperatorUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/bitwiseoperator/test/BitwiseOperatorUnitTest.java index f74e181e36..1ca7b7281e 100644 --- a/core-java/src/test/java/com/baeldung/bitwiseoperator/test/BitwiseOperatorUnitTest.java +++ b/core-java-modules/core-java/src/test/java/com/baeldung/bitwiseoperator/test/BitwiseOperatorUnitTest.java @@ -1,81 +1,81 @@ -package com.baeldung.bitwiseoperator.test; - -import static org.junit.Assert.assertEquals; -import org.junit.jupiter.api.Test; - -public class BitwiseOperatorUnitTest { - - @Test - public void givenTwoIntegers_whenAndOperator_thenNewDecimalNumber() { - int value1 = 6; - int value2 = 5; - int result = value1 & value2; - assertEquals(4, result); - } - - @Test - public void givenTwoIntegers_whenOrOperator_thenNewDecimalNumber() { - int value1 = 6; - int value2 = 5; - int result = value1 | value2; - assertEquals(7, result); - } - - @Test - public void givenTwoIntegers_whenXorOperator_thenNewDecimalNumber() { - int value1 = 6; - int value2 = 5; - int result = value1 ^ value2; - assertEquals(3, result); - } - - @Test - public void givenOneInteger_whenNotOperator_thenNewDecimalNumber() { - int value1 = 6; - int result = ~value1; - assertEquals(result, -7); - } - - @Test - public void givenOnePositiveInteger_whenSignedRightShiftOperator_thenNewDecimalNumber() { - int value = 12; - int rightShift = value >> 2; - assertEquals(3, rightShift); - } - - @Test - public void givenOneNegativeInteger_whenSignedRightShiftOperator_thenNewDecimalNumber() { - int value = -12; - int rightShift = value >> 2; - assertEquals(-3, rightShift); - } - - @Test - public void givenOnePositiveInteger_whenLeftShiftOperator_thenNewDecimalNumber() { - int value = 12; - int leftShift = value << 2; - assertEquals(48, leftShift); - } - - @Test - public void givenOneNegativeInteger_whenLeftShiftOperator_thenNewDecimalNumber() { - int value = -12; - int leftShift = value << 2; - assertEquals(-48, leftShift); - } - - @Test - public void givenOnePositiveInteger_whenUnsignedRightShiftOperator_thenNewDecimalNumber() { - int value = 12; - int unsignedRightShift = value >>> 2; - assertEquals(3, unsignedRightShift); - } - - @Test - public void givenOneNegativeInteger_whenUnsignedRightShiftOperator_thenNewDecimalNumber() { - int value = -12; - int unsignedRightShift = value >>> 2; - assertEquals(1073741821, unsignedRightShift); - } - -} +package com.baeldung.bitwiseoperator.test; + +import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; + +public class BitwiseOperatorUnitTest { + + @Test + public void givenTwoIntegers_whenAndOperator_thenNewDecimalNumber() { + int value1 = 6; + int value2 = 5; + int result = value1 & value2; + assertEquals(4, result); + } + + @Test + public void givenTwoIntegers_whenOrOperator_thenNewDecimalNumber() { + int value1 = 6; + int value2 = 5; + int result = value1 | value2; + assertEquals(7, result); + } + + @Test + public void givenTwoIntegers_whenXorOperator_thenNewDecimalNumber() { + int value1 = 6; + int value2 = 5; + int result = value1 ^ value2; + assertEquals(3, result); + } + + @Test + public void givenOneInteger_whenNotOperator_thenNewDecimalNumber() { + int value1 = 6; + int result = ~value1; + assertEquals(result, -7); + } + + @Test + public void givenOnePositiveInteger_whenSignedRightShiftOperator_thenNewDecimalNumber() { + int value = 12; + int rightShift = value >> 2; + assertEquals(3, rightShift); + } + + @Test + public void givenOneNegativeInteger_whenSignedRightShiftOperator_thenNewDecimalNumber() { + int value = -12; + int rightShift = value >> 2; + assertEquals(-3, rightShift); + } + + @Test + public void givenOnePositiveInteger_whenLeftShiftOperator_thenNewDecimalNumber() { + int value = 12; + int leftShift = value << 2; + assertEquals(48, leftShift); + } + + @Test + public void givenOneNegativeInteger_whenLeftShiftOperator_thenNewDecimalNumber() { + int value = -12; + int leftShift = value << 2; + assertEquals(-48, leftShift); + } + + @Test + public void givenOnePositiveInteger_whenUnsignedRightShiftOperator_thenNewDecimalNumber() { + int value = 12; + int unsignedRightShift = value >>> 2; + assertEquals(3, unsignedRightShift); + } + + @Test + public void givenOneNegativeInteger_whenUnsignedRightShiftOperator_thenNewDecimalNumber() { + int value = -12; + int unsignedRightShift = value >>> 2; + assertEquals(1073741821, unsignedRightShift); + } + +} diff --git a/core-java/src/test/java/com/baeldung/classloader/CustomClassLoaderUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/classloader/CustomClassLoaderUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/classloader/CustomClassLoaderUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/classloader/CustomClassLoaderUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/classloader/PrintClassLoaderUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/classloader/PrintClassLoaderUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/classloader/PrintClassLoaderUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/classloader/PrintClassLoaderUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/curltojava/JavaCurlExamplesLiveTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/curltojava/JavaCurlExamplesLiveTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/curltojava/JavaCurlExamplesLiveTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/curltojava/JavaCurlExamplesLiveTest.java diff --git a/core-java/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/encoding/CharacterEncodingExamplesUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/encoding/CharacterEncodingExamplesUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/encoding/CharacterEncodingExamplesUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/encoding/CharacterEncodingExamplesUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/exceptions/GlobalExceptionHandlerUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/exceptions/GlobalExceptionHandlerUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/exceptions/GlobalExceptionHandlerUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/exceptions/GlobalExceptionHandlerUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/externalizable/ExternalizableUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/externalizable/ExternalizableUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/externalizable/ExternalizableUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/externalizable/ExternalizableUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/fileparser/BufferedReaderUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/fileparser/BufferedReaderUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/fileparser/BufferedReaderUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/fileparser/BufferedReaderUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/fileparser/FileReaderUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/fileparser/FileReaderUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/fileparser/FileReaderUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/fileparser/FileReaderUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/fileparser/FilesReadAllLinesUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/fileparser/FilesReadAllLinesUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/fileparser/FilesReadAllLinesUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/fileparser/FilesReadAllLinesUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/fileparser/ScannerIntUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/fileparser/ScannerIntUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/fileparser/ScannerIntUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/fileparser/ScannerIntUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/fileparser/ScannerStringUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/fileparser/ScannerStringUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/fileparser/ScannerStringUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/fileparser/ScannerStringUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/graph/GraphTraversalUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/graph/GraphTraversalUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/graph/GraphTraversalUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/graph/GraphTraversalUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/grep/GrepWithUnix4JIntegrationTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/grep/GrepWithUnix4JIntegrationTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/grep/GrepWithUnix4JIntegrationTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/grep/GrepWithUnix4JIntegrationTest.java diff --git a/core-java/src/test/java/com/baeldung/hexToAscii/HexToAsciiUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/hexToAscii/HexToAsciiUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/hexToAscii/HexToAsciiUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/hexToAscii/HexToAsciiUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/hexToAscii/README.md b/core-java-modules/core-java/src/test/java/com/baeldung/hexToAscii/README.md similarity index 100% rename from core-java/src/test/java/com/baeldung/hexToAscii/README.md rename to core-java-modules/core-java/src/test/java/com/baeldung/hexToAscii/README.md diff --git a/core-java/src/test/java/com/baeldung/java/clock/ClockUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/java/clock/ClockUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/java/clock/ClockUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/java/clock/ClockUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/java/currentmethod/CurrentlyExecutedMethodFinderUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/java/currentmethod/CurrentlyExecutedMethodFinderUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/java/currentmethod/CurrentlyExecutedMethodFinderUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/java/currentmethod/CurrentlyExecutedMethodFinderUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/java/properties/PropertiesUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/java/properties/PropertiesUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/java/properties/PropertiesUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/java/properties/PropertiesUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/java/regex/RegexUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/java/regex/RegexUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/java/regex/RegexUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/java/regex/RegexUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/java8/Java8MapAndFlatMap.java b/core-java-modules/core-java/src/test/java/com/baeldung/java8/Java8MapAndFlatMap.java similarity index 100% rename from core-java/src/test/java/com/baeldung/java8/Java8MapAndFlatMap.java rename to core-java-modules/core-java/src/test/java/com/baeldung/java8/Java8MapAndFlatMap.java diff --git a/core-java/src/test/java/com/baeldung/junit4vstestng/DivisibilityUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/junit4vstestng/DivisibilityUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/junit4vstestng/DivisibilityUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/junit4vstestng/DivisibilityUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/junit4vstestng/ParametrizedUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/junit4vstestng/ParametrizedUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/junit4vstestng/ParametrizedUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/junit4vstestng/ParametrizedUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/junit4vstestng/RegistrationUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/junit4vstestng/RegistrationUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/junit4vstestng/RegistrationUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/junit4vstestng/RegistrationUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/junit4vstestng/SignInUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/junit4vstestng/SignInUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/junit4vstestng/SignInUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/junit4vstestng/SignInUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/junit4vstestng/StringCaseUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/junit4vstestng/StringCaseUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/junit4vstestng/StringCaseUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/junit4vstestng/StringCaseUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/junit4vstestng/SuiteUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/junit4vstestng/SuiteUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/junit4vstestng/SuiteUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/junit4vstestng/SuiteUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/leapyear/LeapYearUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/leapyear/LeapYearUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/leapyear/LeapYearUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/leapyear/LeapYearUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/manifest/ExecuteJarFileUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/manifest/ExecuteJarFileUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/manifest/ExecuteJarFileUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/manifest/ExecuteJarFileUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/money/JavaMoneyUnitManualTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/money/JavaMoneyUnitManualTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/money/JavaMoneyUnitManualTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/money/JavaMoneyUnitManualTest.java diff --git a/core-java/src/test/java/com/baeldung/printscreen/ScreenshotLiveTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/printscreen/ScreenshotLiveTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/printscreen/ScreenshotLiveTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/printscreen/ScreenshotLiveTest.java diff --git a/core-java/src/test/java/com/baeldung/properties/MergePropertiesUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/properties/MergePropertiesUnitTest.java similarity index 97% rename from core-java/src/test/java/com/baeldung/properties/MergePropertiesUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/properties/MergePropertiesUnitTest.java index 8720aff36b..50daaed950 100644 --- a/core-java/src/test/java/com/baeldung/properties/MergePropertiesUnitTest.java +++ b/core-java-modules/core-java/src/test/java/com/baeldung/properties/MergePropertiesUnitTest.java @@ -1,84 +1,84 @@ -package com.baeldung.properties; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.stream.Stream; - -import org.junit.Test; - -public class MergePropertiesUnitTest { - - @Test - public void givenTwoProperties_whenMergedUsingIteration_thenAllPropertiesInResult() { - Properties globalProperties = mergePropertiesByIteratingKeySet(propertiesA(), propertiesB()); - - testMergedProperties(globalProperties); - } - - @Test - public void givenTwoProperties_whenMergedUsingPutAll_thenAllPropertiesInResult() { - Properties globalProperties = mergePropertiesByUsingPutAll(propertiesA(), propertiesB()); - - testMergedProperties(globalProperties); - } - - @Test - public void givenTwoProperties_whenMergedUsingStreamAPI_thenAllPropertiesInResult() { - Properties globalProperties = mergePropertiesByUsingStreamApi(propertiesB(), propertiesA()); - - testMergedProperties(globalProperties); - } - - private Properties mergePropertiesByIteratingKeySet(Properties... properties) { - Properties mergedProperties = new Properties(); - for (Properties property : properties) { - Set propertyNames = property.stringPropertyNames(); - for (String name : propertyNames) { - String propertyValue = property.getProperty(name); - mergedProperties.setProperty(name, propertyValue); - } - } - return mergedProperties; - } - - private Properties mergePropertiesByUsingPutAll(Properties... properties) { - Properties mergedProperties = new Properties(); - for (Properties property : properties) { - mergedProperties.putAll(property); - } - return mergedProperties; - } - - private Properties mergePropertiesByUsingStreamApi(Properties... properties) { - return Stream.of(properties) - .collect(Properties::new, Map::putAll, Map::putAll); - } - - private Properties propertiesA() { - Properties properties = new Properties(); - properties.setProperty("application.name", "my-app"); - properties.setProperty("application.version", "1.0"); - return properties; - } - - private Properties propertiesB() { - Properties properties = new Properties(); - properties.setProperty("property-1", "sample property"); - properties.setProperty("property-2", "another sample property"); - return properties; - } - - private void testMergedProperties(Properties globalProperties) { - assertThat("There should be 4 properties", globalProperties.size(), equalTo(4)); - assertEquals("Property should be", globalProperties.getProperty("application.name"), "my-app"); - assertEquals("Property should be", globalProperties.getProperty("application.version"), "1.0"); - assertEquals("Property should be", globalProperties.getProperty("property-1"), "sample property"); - assertEquals("Property should be", globalProperties.getProperty("property-2"), "another sample property"); - } - -} +package com.baeldung.properties; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.stream.Stream; + +import org.junit.Test; + +public class MergePropertiesUnitTest { + + @Test + public void givenTwoProperties_whenMergedUsingIteration_thenAllPropertiesInResult() { + Properties globalProperties = mergePropertiesByIteratingKeySet(propertiesA(), propertiesB()); + + testMergedProperties(globalProperties); + } + + @Test + public void givenTwoProperties_whenMergedUsingPutAll_thenAllPropertiesInResult() { + Properties globalProperties = mergePropertiesByUsingPutAll(propertiesA(), propertiesB()); + + testMergedProperties(globalProperties); + } + + @Test + public void givenTwoProperties_whenMergedUsingStreamAPI_thenAllPropertiesInResult() { + Properties globalProperties = mergePropertiesByUsingStreamApi(propertiesB(), propertiesA()); + + testMergedProperties(globalProperties); + } + + private Properties mergePropertiesByIteratingKeySet(Properties... properties) { + Properties mergedProperties = new Properties(); + for (Properties property : properties) { + Set propertyNames = property.stringPropertyNames(); + for (String name : propertyNames) { + String propertyValue = property.getProperty(name); + mergedProperties.setProperty(name, propertyValue); + } + } + return mergedProperties; + } + + private Properties mergePropertiesByUsingPutAll(Properties... properties) { + Properties mergedProperties = new Properties(); + for (Properties property : properties) { + mergedProperties.putAll(property); + } + return mergedProperties; + } + + private Properties mergePropertiesByUsingStreamApi(Properties... properties) { + return Stream.of(properties) + .collect(Properties::new, Map::putAll, Map::putAll); + } + + private Properties propertiesA() { + Properties properties = new Properties(); + properties.setProperty("application.name", "my-app"); + properties.setProperty("application.version", "1.0"); + return properties; + } + + private Properties propertiesB() { + Properties properties = new Properties(); + properties.setProperty("property-1", "sample property"); + properties.setProperty("property-2", "another sample property"); + return properties; + } + + private void testMergedProperties(Properties globalProperties) { + assertThat("There should be 4 properties", globalProperties.size(), equalTo(4)); + assertEquals("Property should be", globalProperties.getProperty("application.name"), "my-app"); + assertEquals("Property should be", globalProperties.getProperty("application.version"), "1.0"); + assertEquals("Property should be", globalProperties.getProperty("property-1"), "sample property"); + assertEquals("Property should be", globalProperties.getProperty("property-2"), "another sample property"); + } + +} diff --git a/core-java/src/test/java/com/baeldung/reflection/BaeldungReflectionUtilsUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/reflection/BaeldungReflectionUtilsUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/reflection/BaeldungReflectionUtilsUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/reflection/BaeldungReflectionUtilsUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/reflection/PersonAndEmployeeReflectionUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/reflection/PersonAndEmployeeReflectionUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/reflection/PersonAndEmployeeReflectionUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/reflection/PersonAndEmployeeReflectionUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/regexp/EscapingCharsUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/regexp/EscapingCharsUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/regexp/EscapingCharsUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/regexp/EscapingCharsUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/regexp/optmization/OptimizedMatcherManualTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/regexp/optmization/OptimizedMatcherManualTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/regexp/optmization/OptimizedMatcherManualTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/regexp/optmization/OptimizedMatcherManualTest.java diff --git a/core-java/src/test/java/com/baeldung/resourcebundle/ExampleResourceUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/resourcebundle/ExampleResourceUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/resourcebundle/ExampleResourceUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/resourcebundle/ExampleResourceUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/resourcebundle/PropertyResourceUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/resourcebundle/PropertyResourceUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/resourcebundle/PropertyResourceUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/resourcebundle/PropertyResourceUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/scripting/NashornUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/scripting/NashornUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/scripting/NashornUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/scripting/NashornUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/serialization/PersonUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/serialization/PersonUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/serialization/PersonUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/serialization/PersonUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/stack/StackUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/stack/StackUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/stack/StackUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/stack/StackUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/stringisnumeric.zip b/core-java-modules/core-java/src/test/java/com/baeldung/stringisnumeric.zip similarity index 100% rename from core-java/src/test/java/com/baeldung/stringisnumeric.zip rename to core-java-modules/core-java/src/test/java/com/baeldung/stringisnumeric.zip diff --git a/core-java/src/test/java/com/baeldung/system/WhenDetectingOSUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/system/WhenDetectingOSUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/system/WhenDetectingOSUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/system/WhenDetectingOSUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/util/PropertiesLoaderUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/util/PropertiesLoaderUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/util/PropertiesLoaderUnitTest.java rename to core-java-modules/core-java/src/test/java/com/baeldung/util/PropertiesLoaderUnitTest.java diff --git a/core-java/src/test/java/org/baeldung/java/JavaIoUnitTest.java b/core-java-modules/core-java/src/test/java/org/baeldung/java/JavaIoUnitTest.java similarity index 100% rename from core-java/src/test/java/org/baeldung/java/JavaIoUnitTest.java rename to core-java-modules/core-java/src/test/java/org/baeldung/java/JavaIoUnitTest.java diff --git a/core-java/src/test/java/org/baeldung/java/JavaTimerLongRunningUnitTest.java b/core-java-modules/core-java/src/test/java/org/baeldung/java/JavaTimerLongRunningUnitTest.java similarity index 100% rename from core-java/src/test/java/org/baeldung/java/JavaTimerLongRunningUnitTest.java rename to core-java-modules/core-java/src/test/java/org/baeldung/java/JavaTimerLongRunningUnitTest.java diff --git a/core-java/src/test/java/org/baeldung/java/arrays/ArraysJoinAndSplitJUnitTest.java b/core-java-modules/core-java/src/test/java/org/baeldung/java/arrays/ArraysJoinAndSplitJUnitTest.java similarity index 100% rename from core-java/src/test/java/org/baeldung/java/arrays/ArraysJoinAndSplitJUnitTest.java rename to core-java-modules/core-java/src/test/java/org/baeldung/java/arrays/ArraysJoinAndSplitJUnitTest.java diff --git a/core-java/src/test/java/org/baeldung/java/rawtypes/RawTypesUnitTest.java b/core-java-modules/core-java/src/test/java/org/baeldung/java/rawtypes/RawTypesUnitTest.java similarity index 100% rename from core-java/src/test/java/org/baeldung/java/rawtypes/RawTypesUnitTest.java rename to core-java-modules/core-java/src/test/java/org/baeldung/java/rawtypes/RawTypesUnitTest.java diff --git a/core-java/src/test/java/org/baeldung/java/sandbox/SandboxJavaManualTest.java b/core-java-modules/core-java/src/test/java/org/baeldung/java/sandbox/SandboxJavaManualTest.java similarity index 100% rename from core-java/src/test/java/org/baeldung/java/sandbox/SandboxJavaManualTest.java rename to core-java-modules/core-java/src/test/java/org/baeldung/java/sandbox/SandboxJavaManualTest.java diff --git a/core-java/src/test/java/org/baeldung/java/shell/JavaProcessUnitIntegrationTest.java b/core-java-modules/core-java/src/test/java/org/baeldung/java/shell/JavaProcessUnitIntegrationTest.java similarity index 100% rename from core-java/src/test/java/org/baeldung/java/shell/JavaProcessUnitIntegrationTest.java rename to core-java-modules/core-java/src/test/java/org/baeldung/java/shell/JavaProcessUnitIntegrationTest.java diff --git a/core-java/src/test/resources/.gitignore b/core-java-modules/core-java/src/test/resources/.gitignore similarity index 100% rename from core-java/src/test/resources/.gitignore rename to core-java-modules/core-java/src/test/resources/.gitignore diff --git a/core-java/src/test/resources/app.properties b/core-java-modules/core-java/src/test/resources/app.properties similarity index 100% rename from core-java/src/test/resources/app.properties rename to core-java-modules/core-java/src/test/resources/app.properties diff --git a/core-java/src/test/resources/catalog b/core-java-modules/core-java/src/test/resources/catalog similarity index 100% rename from core-java/src/test/resources/catalog rename to core-java-modules/core-java/src/test/resources/catalog diff --git a/core-java/src/test/resources/configuration.properties b/core-java-modules/core-java/src/test/resources/configuration.properties similarity index 100% rename from core-java/src/test/resources/configuration.properties rename to core-java-modules/core-java/src/test/resources/configuration.properties diff --git a/core-java/src/test/resources/default.properties b/core-java-modules/core-java/src/test/resources/default.properties similarity index 100% rename from core-java/src/test/resources/default.properties rename to core-java-modules/core-java/src/test/resources/default.properties diff --git a/core-java/src/test/resources/dictionary.in b/core-java-modules/core-java/src/test/resources/dictionary.in similarity index 100% rename from core-java/src/test/resources/dictionary.in rename to core-java-modules/core-java/src/test/resources/dictionary.in diff --git a/core-java/src/test/resources/encoding.txt b/core-java-modules/core-java/src/test/resources/encoding.txt similarity index 100% rename from core-java/src/test/resources/encoding.txt rename to core-java-modules/core-java/src/test/resources/encoding.txt diff --git a/core-java/src/test/resources/icons.xml b/core-java-modules/core-java/src/test/resources/icons.xml similarity index 100% rename from core-java/src/test/resources/icons.xml rename to core-java-modules/core-java/src/test/resources/icons.xml diff --git a/core-java/src/test/resources/newFile1.txt b/core-java-modules/core-java/src/test/resources/newFile1.txt similarity index 100% rename from core-java/src/test/resources/newFile1.txt rename to core-java-modules/core-java/src/test/resources/newFile1.txt diff --git a/core-java/src/test/resources/newFile2.txt b/core-java-modules/core-java/src/test/resources/newFile2.txt similarity index 100% rename from core-java/src/test/resources/newFile2.txt rename to core-java-modules/core-java/src/test/resources/newFile2.txt diff --git a/core-java/src/test/resources/newFile3.txt b/core-java-modules/core-java/src/test/resources/newFile3.txt similarity index 100% rename from core-java/src/test/resources/newFile3.txt rename to core-java-modules/core-java/src/test/resources/newFile3.txt diff --git a/core-java/src/test/resources/original.txt b/core-java-modules/core-java/src/test/resources/original.txt similarity index 98% rename from core-java/src/test/resources/original.txt rename to core-java-modules/core-java/src/test/resources/original.txt index cf8c89d389..8511f56bef 100644 --- a/core-java/src/test/resources/original.txt +++ b/core-java-modules/core-java/src/test/resources/original.txt @@ -1,2 +1,2 @@ -#Copy a File with Java (www.Baeldung.com) +#Copy a File with Java (www.Baeldung.com) Copying Files with Java is Fun! \ No newline at end of file diff --git a/core-java/src/test/resources/sampleNumberFile.txt b/core-java-modules/core-java/src/test/resources/sampleNumberFile.txt similarity index 100% rename from core-java/src/test/resources/sampleNumberFile.txt rename to core-java-modules/core-java/src/test/resources/sampleNumberFile.txt diff --git a/core-java/src/test/resources/sampleTextFile.txt b/core-java-modules/core-java/src/test/resources/sampleTextFile.txt similarity index 100% rename from core-java/src/test/resources/sampleTextFile.txt rename to core-java-modules/core-java/src/test/resources/sampleTextFile.txt diff --git a/core-java/src/test/resources/sourceFile.txt b/core-java-modules/core-java/src/test/resources/sourceFile.txt similarity index 100% rename from core-java/src/test/resources/sourceFile.txt rename to core-java-modules/core-java/src/test/resources/sourceFile.txt diff --git a/core-java/src/test/resources/test.find b/core-java-modules/core-java/src/test/resources/test.find similarity index 100% rename from core-java/src/test/resources/test.find rename to core-java-modules/core-java/src/test/resources/test.find diff --git a/core-java-modules/core-java/src/test/resources/test_read.in b/core-java-modules/core-java/src/test/resources/test_read.in new file mode 100644 index 0000000000..70c379b63f --- /dev/null +++ b/core-java-modules/core-java/src/test/resources/test_read.in @@ -0,0 +1 @@ +Hello world \ No newline at end of file diff --git a/core-java/src/test/resources/test_read1.in b/core-java-modules/core-java/src/test/resources/test_read1.in similarity index 100% rename from core-java/src/test/resources/test_read1.in rename to core-java-modules/core-java/src/test/resources/test_read1.in diff --git a/core-java/src/test/resources/test_read2.in b/core-java-modules/core-java/src/test/resources/test_read2.in similarity index 100% rename from core-java/src/test/resources/test_read2.in rename to core-java-modules/core-java/src/test/resources/test_read2.in diff --git a/core-java/src/test/resources/test_read3.in b/core-java-modules/core-java/src/test/resources/test_read3.in similarity index 100% rename from core-java/src/test/resources/test_read3.in rename to core-java-modules/core-java/src/test/resources/test_read3.in diff --git a/core-java/src/test/resources/test_read4.in b/core-java-modules/core-java/src/test/resources/test_read4.in similarity index 100% rename from core-java/src/test/resources/test_read4.in rename to core-java-modules/core-java/src/test/resources/test_read4.in diff --git a/core-java/src/test/resources/test_read7.in b/core-java-modules/core-java/src/test/resources/test_read7.in similarity index 100% rename from core-java/src/test/resources/test_read7.in rename to core-java-modules/core-java/src/test/resources/test_read7.in diff --git a/core-java/src/test/resources/test_read8.in b/core-java-modules/core-java/src/test/resources/test_read8.in similarity index 100% rename from core-java/src/test/resources/test_read8.in rename to core-java-modules/core-java/src/test/resources/test_read8.in diff --git a/core-java/src/test/resources/test_read_d.in b/core-java-modules/core-java/src/test/resources/test_read_d.in similarity index 100% rename from core-java/src/test/resources/test_read_d.in rename to core-java-modules/core-java/src/test/resources/test_read_d.in diff --git a/core-java/src/test/resources/test_read_multiple.in b/core-java-modules/core-java/src/test/resources/test_read_multiple.in similarity index 100% rename from core-java/src/test/resources/test_read_multiple.in rename to core-java-modules/core-java/src/test/resources/test_read_multiple.in diff --git a/core-java/yofile.txt b/core-java-modules/core-java/yofile.txt similarity index 100% rename from core-java/yofile.txt rename to core-java-modules/core-java/yofile.txt diff --git a/core-java/yofile2.txt b/core-java-modules/core-java/yofile2.txt similarity index 100% rename from core-java/yofile2.txt rename to core-java-modules/core-java/yofile2.txt diff --git a/core-java-modules/multimodulemavenproject/daomodule/pom.xml b/core-java-modules/multimodulemavenproject/daomodule/pom.xml new file mode 100644 index 0000000000..a260e15e6d --- /dev/null +++ b/core-java-modules/multimodulemavenproject/daomodule/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + com.baeldung.multimodulemavenproject + multimodulemavenproject + 1.0 + + com.baeldung.daomodule + daomodule + 1.0 + jar + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + + 9 + 9 + + \ No newline at end of file diff --git a/core-java-modules/multimodulemavenproject/daomodule/src/main/java/com/baeldung/daomodule/Dao.java b/core-java-modules/multimodulemavenproject/daomodule/src/main/java/com/baeldung/daomodule/Dao.java new file mode 100644 index 0000000000..9568bae9d9 --- /dev/null +++ b/core-java-modules/multimodulemavenproject/daomodule/src/main/java/com/baeldung/daomodule/Dao.java @@ -0,0 +1,11 @@ +package com.baeldung.daomodule; +import java.util.List; +import java.util.Optional; + +public interface Dao { + + Optional findById(int id); + + List findAll(); + +} diff --git a/core-java-modules/multimodulemavenproject/daomodule/src/main/java/module-info.java b/core-java-modules/multimodulemavenproject/daomodule/src/main/java/module-info.java new file mode 100644 index 0000000000..20c51d316a --- /dev/null +++ b/core-java-modules/multimodulemavenproject/daomodule/src/main/java/module-info.java @@ -0,0 +1,3 @@ +module com.baeldung.daomodule { + exports com.baeldung.daomodule; +} diff --git a/core-java-modules/multimodulemavenproject/entitymodule/pom.xml b/core-java-modules/multimodulemavenproject/entitymodule/pom.xml new file mode 100644 index 0000000000..1fd672d03e --- /dev/null +++ b/core-java-modules/multimodulemavenproject/entitymodule/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + com.baeldung.multimodulemavenproject + multimodulemavenproject + 1.0 + + com.baeldung.entitymodule + entitymodule + 1.0 + jar + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + + 9 + 9 + + + \ No newline at end of file diff --git a/core-java-modules/multimodulemavenproject/entitymodule/src/main/java/com/baeldung/entitymodule/User.java b/core-java-modules/multimodulemavenproject/entitymodule/src/main/java/com/baeldung/entitymodule/User.java new file mode 100644 index 0000000000..c025bffd87 --- /dev/null +++ b/core-java-modules/multimodulemavenproject/entitymodule/src/main/java/com/baeldung/entitymodule/User.java @@ -0,0 +1,19 @@ +package com.baeldung.entitymodule; + +public class User { + + private final String name; + + public User(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return "User{" + "name=" + name + '}'; + } +} \ No newline at end of file diff --git a/core-java-modules/multimodulemavenproject/entitymodule/src/main/java/module-info.java b/core-java-modules/multimodulemavenproject/entitymodule/src/main/java/module-info.java new file mode 100644 index 0000000000..b2c4553357 --- /dev/null +++ b/core-java-modules/multimodulemavenproject/entitymodule/src/main/java/module-info.java @@ -0,0 +1,3 @@ +module com.baeldung.entitymodule { + exports com.baeldung.entitymodule; +} diff --git a/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml b/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml new file mode 100644 index 0000000000..26e6a15b1e --- /dev/null +++ b/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + com.baeldung.multimodulemavenproject + multimodulemavenproject + 1.0 + + com.baeldung.mainappmodule + mainappmodule + 1.0 + jar + + + + com.baeldung.entitymodule + entitymodule + 1.0 + + + com.baeldung.daomodule + daomodule + 1.0 + + + com.baeldung.userdaomodule + userdaomodule + 1.0 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + + 9 + 9 + + \ No newline at end of file diff --git a/core-java-modules/multimodulemavenproject/mainappmodule/src/main/java/com/baeldung/mainappmodule/Application.java b/core-java-modules/multimodulemavenproject/mainappmodule/src/main/java/com/baeldung/mainappmodule/Application.java new file mode 100644 index 0000000000..cf0ba1d9bc --- /dev/null +++ b/core-java-modules/multimodulemavenproject/mainappmodule/src/main/java/com/baeldung/mainappmodule/Application.java @@ -0,0 +1,19 @@ +package com.baeldung.mainappmodule; + +import com.baeldung.daomodule.Dao; +import com.baeldung.entitymodule.User; +import com.baeldung.userdaomodule.UserDao; +import java.util.HashMap; +import java.util.Map; + +public class Application { + + public static void main(String args[]) { + Map users = new HashMap<>(); + users.put(1, new User("Julie")); + users.put(2, new User("David")); + Dao userDao = new UserDao(users); + userDao.findAll().forEach(System.out::println); + } + +} diff --git a/core-java-modules/multimodulemavenproject/mainappmodule/src/main/java/module-info.java b/core-java-modules/multimodulemavenproject/mainappmodule/src/main/java/module-info.java new file mode 100644 index 0000000000..dd7620c7bf --- /dev/null +++ b/core-java-modules/multimodulemavenproject/mainappmodule/src/main/java/module-info.java @@ -0,0 +1,8 @@ +module com.baeldung.mainppmodule { + + requires com.baeldung.entitymodule; + requires com.baeldung.daomodule; + requires com.baeldung.userdaomodule; + uses com.baeldung.userdaomodule.UserDao; + +} diff --git a/core-java-modules/multimodulemavenproject/pom.xml b/core-java-modules/multimodulemavenproject/pom.xml new file mode 100644 index 0000000000..3d56f1356b --- /dev/null +++ b/core-java-modules/multimodulemavenproject/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + com.baeldung.multimodulemavenproject + multimodulemavenproject + 1.0 + pom + multimodulemavenproject + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + ../../ + + + + + + junit + junit + 4.12 + test + + + org.assertj + assertj-core + 3.12.2 + test + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + + 1.9 + 1.9 + + + + + + + + + entitymodule + daomodule + userdaomodule + mainappmodule + + + + UTF-8 + + diff --git a/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml b/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml new file mode 100644 index 0000000000..63968452db --- /dev/null +++ b/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + com.baeldung.multimodulemavenproject + multimodulemavenproject + 1.0 + + com.baeldung.userdaomodule + userdaomodule + 1.0 + jar + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + + + com.baeldung.entitymodule + entitymodule + 1.0 + + + com.baeldung.daomodule + daomodule + 1.0 + + + + + 9 + 9 + + + \ No newline at end of file diff --git a/core-java-modules/multimodulemavenproject/userdaomodule/src/main/java/com/baeldung/userdaomodule/UserDao.java b/core-java-modules/multimodulemavenproject/userdaomodule/src/main/java/com/baeldung/userdaomodule/UserDao.java new file mode 100644 index 0000000000..aba157b431 --- /dev/null +++ b/core-java-modules/multimodulemavenproject/userdaomodule/src/main/java/com/baeldung/userdaomodule/UserDao.java @@ -0,0 +1,32 @@ +package com.baeldung.userdaomodule; + +import com.baeldung.daomodule.Dao; +import com.baeldung.entitymodule.User; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class UserDao implements Dao { + + private final Map users; + + public UserDao() { + users = new HashMap<>(); + } + + public UserDao(Map users) { + this.users = users; + } + + @Override + public List findAll() { + return new ArrayList<>(users.values()); + } + + @Override + public Optional findById(int id) { + return Optional.ofNullable(users.get(id)); + } +} \ No newline at end of file diff --git a/core-java-modules/multimodulemavenproject/userdaomodule/src/main/java/module-info.java b/core-java-modules/multimodulemavenproject/userdaomodule/src/main/java/module-info.java new file mode 100644 index 0000000000..6dd81dabe5 --- /dev/null +++ b/core-java-modules/multimodulemavenproject/userdaomodule/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module com.baeldung.userdaomodule { + requires com.baeldung.entitymodule; + requires com.baeldung.daomodule; + provides com.baeldung.daomodule.Dao with com.baeldung.userdaomodule.UserDao; + exports com.baeldung.userdaomodule; +} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml new file mode 100644 index 0000000000..ed6a056448 --- /dev/null +++ b/core-java-modules/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + com.baeldung.core-java-modules + core-java-modules + core-java-modules + pom + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + + + pre-jpms + + + diff --git a/core-java-modules/pre-jpms/pom.xml b/core-java-modules/pre-jpms/pom.xml new file mode 100644 index 0000000000..169cd21f3e --- /dev/null +++ b/core-java-modules/pre-jpms/pom.xml @@ -0,0 +1,74 @@ + + 4.0.0 + pre-jpms + 0.0.1-SNAPSHOT + jar + pre-jpms + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + ../../ + + + + + org.slf4j + slf4j-api + 1.7.25 + + + + pre-jpms + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.1 + + + copy-dependencies + package + + copy-dependencies + + + + ${project.build.directory}/dependency-jars/ + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + com.baeldung.prejpms.App + true + dependency-jars/ + + + + + + + + + UTF-8 + + diff --git a/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java new file mode 100644 index 0000000000..1afaae30e4 --- /dev/null +++ b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java @@ -0,0 +1,77 @@ +package com.baeldung.prejpms; + +import java.io.StringWriter; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sun.crypto.provider.SunJCE; + +import sun.misc.BASE64Encoder; +import sun.reflect.Reflection; + +public class App { + + private static final Logger LOGGER = LoggerFactory.getLogger(App.class); + + public static void main(String[] args) throws Exception { + + getCrytpographyProviderName(); + getCallStackClassNames(); + getXmlFromObject(new Book(100, "Java Modules Architecture")); + getBase64EncodedString("Java"); + } + + private static void getCrytpographyProviderName() { + try { + LOGGER.info("1. JCE Provider Name: {}\n", new SunJCE().getName()); + } catch (Throwable e) { + LOGGER.error(e.toString()); + } + } + + private static void getCallStackClassNames() { + try { + StringBuffer sbStack = new StringBuffer(); + int i = 0; + Class caller = Reflection.getCallerClass(i++); + do { + sbStack.append(i + ".") + .append(caller.getName()) + .append("\n"); + caller = Reflection.getCallerClass(i++); + } while (caller != null); + LOGGER.info("2. Call Stack:\n{}", sbStack); + } catch (Throwable e) { + LOGGER.error(e.toString()); + } + } + + private static void getXmlFromObject(Book book) { + try { + Marshaller marshallerObj = JAXBContext.newInstance(Book.class) + .createMarshaller(); + marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + + StringWriter sw = new StringWriter(); + marshallerObj.marshal(book, sw); + LOGGER.info("3. Xml for Book object:\n{}", sw); + } catch (Throwable e) { + LOGGER.error(e.toString()); + } + + } + + private static void getBase64EncodedString(String inputString) { + try { + String encodedString = new BASE64Encoder().encode(inputString.getBytes()); + LOGGER.info("4. Base Encoded String: {}", encodedString); + } catch (Throwable e) { + LOGGER.error(e.toString()); + } + } +} diff --git a/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/Book.java b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/Book.java new file mode 100644 index 0000000000..6780c73738 --- /dev/null +++ b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/Book.java @@ -0,0 +1,37 @@ +package com.baeldung.prejpms; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "book") +public class Book { + private long id; + private String name; + + public Book() { + } + + public Book(long id, String name) { + this.id = id; + this.name = name; + } + + @XmlAttribute + public void setId(Long id) { + this.id = id; + } + + @XmlElement(name = "title") + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public Long getId() { + return id; + } +} diff --git a/core-java-modules/pre-jpms/src/main/resources/logback.xml b/core-java-modules/pre-jpms/src/main/resources/logback.xml new file mode 100644 index 0000000000..7c5914e58e --- /dev/null +++ b/core-java-modules/pre-jpms/src/main/resources/logback.xml @@ -0,0 +1,10 @@ + + + + [%level] %msg%n + + + + + + \ No newline at end of file diff --git a/core-kotlin-2/build.gradle b/core-kotlin-2/build.gradle index b058e0ecad..1c52172404 100644 --- a/core-kotlin-2/build.gradle +++ b/core-kotlin-2/build.gradle @@ -5,7 +5,7 @@ version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.2.41' + ext.kotlin_version = '1.3.30' repositories { mavenCentral() @@ -26,8 +26,6 @@ sourceCompatibility = 1.8 compileKotlin { kotlinOptions.jvmTarget = "1.8" } compileTestKotlin { kotlinOptions.jvmTarget = "1.8" } -kotlin { experimental { coroutines "enable" } } - repositories { mavenCentral() jcenter() @@ -39,10 +37,22 @@ sourceSets { srcDirs 'com/baeldung/ktor' } } +} +test { + useJUnitPlatform() + testLogging { + events "passed", "skipped", "failed" + } } dependencies { - compile "ch.qos.logback:logback-classic:1.2.1" - testCompile group: 'junit', name: 'junit', version: '4.12' -} \ No newline at end of file + implementation "ch.qos.logback:logback-classic:1.2.1" + implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}" + testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2' + testImplementation 'junit:junit:4.12' + testImplementation 'org.assertj:assertj-core:3.12.2' + testImplementation 'org.mockito:mockito-core:2.27.0' + testImplementation "org.jetbrains.kotlin:kotlin-test:${kotlin_version}" + testImplementation "org.jetbrains.kotlin:kotlin-test-junit5:${kotlin_version}" +} diff --git a/core-kotlin-2/gradle/wrapper/gradle-wrapper.jar b/core-kotlin-2/gradle/wrapper/gradle-wrapper.jar index 01b8bf6b1f..5c2d1cf016 100644 Binary files a/core-kotlin-2/gradle/wrapper/gradle-wrapper.jar and b/core-kotlin-2/gradle/wrapper/gradle-wrapper.jar differ diff --git a/core-kotlin-2/gradle/wrapper/gradle-wrapper.properties b/core-kotlin-2/gradle/wrapper/gradle-wrapper.properties index 933b6473ce..5f1b1201a7 100644 --- a/core-kotlin-2/gradle/wrapper/gradle-wrapper.properties +++ b/core-kotlin-2/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip diff --git a/core-kotlin-2/gradlew b/core-kotlin-2/gradlew index cccdd3d517..b0d6d0ab5d 100644 --- a/core-kotlin-2/gradlew +++ b/core-kotlin-2/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" diff --git a/core-kotlin-2/gradlew.bat b/core-kotlin-2/gradlew.bat index f9553162f1..9991c50326 100644 --- a/core-kotlin-2/gradlew.bat +++ b/core-kotlin-2/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem http://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/core-kotlin-2/pom.xml b/core-kotlin-2/pom.xml index e329611593..be2f5fa68f 100644 --- a/core-kotlin-2/pom.xml +++ b/core-kotlin-2/pom.xml @@ -20,9 +20,21 @@ ${kotlin.version} - org.junit.platform - junit-platform-runner - ${junit.platform.version} + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} + test + + + org.mockito + mockito-core + ${mockito.version} + test + + + net.bytebuddy + byte-buddy + ${byte-buddy.version} test @@ -37,6 +49,12 @@ ${kotlin.version} test + + org.jetbrains.kotlin + kotlin-test-junit5 + ${kotlin.version} + test + @@ -69,10 +87,11 @@ - 1.2.71 - 1.1.1 - 5.2.0 + 1.3.30 + 5.4.2 + 2.27.0 + 1.9.12 3.10.0 - \ No newline at end of file + diff --git a/core-kotlin-2/src/main/kotlin/com/baeldung/jvmannotations/Document.kt b/core-kotlin-2/src/main/kotlin/com/baeldung/jvmannotations/Document.kt new file mode 100644 index 0000000000..3f9922b88b --- /dev/null +++ b/core-kotlin-2/src/main/kotlin/com/baeldung/jvmannotations/Document.kt @@ -0,0 +1,31 @@ +package com.baeldung.jvmannotations + +import java.util.* + +interface Document { + + @JvmDefault + fun getType() = "document" +} + +class TextDocument : Document { + override fun getType() = "text" + + fun transformList(list : List) : List { + return list.filter { n -> n.toInt() > 1 } + } + + fun transformListInverseWildcards(list : List<@JvmSuppressWildcards Number>) : List<@JvmWildcard Number> { + return list.filter { n -> n.toInt() > 1 } + } + + var list : List<@JvmWildcard Any> = ArrayList() +} + +class XmlDocument(d : Document) : Document by d + +fun main() { + val myDocument = TextDocument() + val myTextDocument = XmlDocument(myDocument) + println("${myDocument.getType()} ${myTextDocument.getType()}") +} diff --git a/core-kotlin-2/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java b/core-kotlin-2/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java new file mode 100644 index 0000000000..feb71772cb --- /dev/null +++ b/core-kotlin-2/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java @@ -0,0 +1,9 @@ +package com.baeldung.jvmannotations; + +public class HtmlDocument implements Document { + + @Override + public String getType() { + return "HTML"; + } +} \ No newline at end of file diff --git a/core-kotlin-2/src/main/kotlin/com/baeldung/jvmannotations/Message.kt b/core-kotlin-2/src/main/kotlin/com/baeldung/jvmannotations/Message.kt new file mode 100644 index 0000000000..80180bd924 --- /dev/null +++ b/core-kotlin-2/src/main/kotlin/com/baeldung/jvmannotations/Message.kt @@ -0,0 +1,66 @@ +@file:JvmName("MessageHelper") +@file:JvmMultifileClass //used +package com.baeldung.jvmannotations + +import java.util.* + +@JvmName("getMyUsername") +fun getMyName() : String { + return "myUserId" +} + +object MessageBroker { + @JvmStatic + var totalMessagesSent = 0 + + const val maxMessageLength = 0 + + @JvmStatic + fun clearAllMessages() { + } + + @JvmStatic + @JvmOverloads + @Throws(Exception::class) + fun findMessages(sender : String, type : String = "text", maxResults : Int = 10) : List { + if(sender.isEmpty()) { + throw Exception() + } + return ArrayList() + } +} + +class Message { + + // this would cause a compilation error since sender is immutable + // @set:JvmName("setSender") + val sender = "myself" + + // this works as name is overridden + @JvmName("getSenderName") + fun getSender() : String = "from:$sender" + + @get:JvmName("getReceiverName") + @set:JvmName("setReceiverName") + var receiver : String = "" + + @get:JvmName("getContent") + @set:JvmName("setContent") + var text = "" + + // generates a warning + @get:JvmName("getId") + private val id = 0 + + @get:JvmName("hasAttachment") + var hasAttachment = true + + var isEncrypted = true + + fun setReceivers(receiverNames : List) { + } + + @JvmName("setReceiverIds") + fun setReceivers(receiverNames : List) { + } +} \ No newline at end of file diff --git a/core-kotlin-2/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt b/core-kotlin-2/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt new file mode 100644 index 0000000000..3b19b12e10 --- /dev/null +++ b/core-kotlin-2/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt @@ -0,0 +1,6 @@ +@file:JvmMultifileClass +@file:JvmName("MessageHelper") //applies to all top level functions / variables / constants +package com.baeldung.jvmannotations + +fun convert(message: Message) { +} diff --git a/core-kotlin-io/.gitignore b/core-kotlin-io/.gitignore new file mode 100644 index 0000000000..f521947850 --- /dev/null +++ b/core-kotlin-io/.gitignore @@ -0,0 +1,11 @@ +/bin/ + +#ignore gradle +.gradle/ + + +#ignore build and generated files +build/ +node/ +target/ +out/ diff --git a/core-kotlin-io/README.md b/core-kotlin-io/README.md new file mode 100644 index 0000000000..cb4dac7e4d --- /dev/null +++ b/core-kotlin-io/README.md @@ -0,0 +1,5 @@ +## Relevant articles: + +- [InputStream to String in Kotlin](https://www.baeldung.com/kotlin-inputstream-to-string) +- [Console I/O in Kotlin](https://www.baeldung.com/kotlin-console-io) + diff --git a/core-kotlin-io/pom.xml b/core-kotlin-io/pom.xml new file mode 100644 index 0000000000..a0b688a223 --- /dev/null +++ b/core-kotlin-io/pom.xml @@ -0,0 +1,97 @@ + + + 4.0.0 + core-kotlin-io + core-kotlin-io + jar + + + com.baeldung + parent-kotlin + 1.0.0-SNAPSHOT + ../parent-kotlin + + + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} + test + + + org.mockito + mockito-core + ${mockito.version} + test + + + net.bytebuddy + byte-buddy + ${byte-buddy.version} + test + + + org.assertj + assertj-core + ${assertj.version} + test + + + org.jetbrains.kotlin + kotlin-test + ${kotlin.version} + test + + + org.jetbrains.kotlin + kotlin-test-junit5 + ${kotlin.version} + test + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + 1.8 + + + + + + + 1.3.30 + 5.4.2 + 2.27.0 + 1.9.12 + 3.10.0 + + + diff --git a/core-kotlin-2/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt b/core-kotlin-io/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt similarity index 100% rename from core-kotlin-2/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt rename to core-kotlin-io/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt diff --git a/core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt b/core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt new file mode 100644 index 0000000000..c73096fce6 --- /dev/null +++ b/core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt @@ -0,0 +1,79 @@ +package com.baeldung.console + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Test +import org.mockito.Mockito.`when` +import org.mockito.Mockito.mock +import java.io.BufferedReader +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream +import java.io.Console +import java.io.InputStreamReader +import java.io.PrintStream +import java.util.* + + +class ConsoleIOUnitTest { + + @Test + fun givenText_whenPrint_thenPrintText() { + val expectedTest = "Hello from Kotlin" + val out = ByteArrayOutputStream() + System.setOut(PrintStream(out)) + + print(expectedTest) + out.flush() + val printedText = String(out.toByteArray()) + + assertThat(printedText).isEqualTo(expectedTest) + } + + @Test + fun givenInput_whenRead_thenReadText() { + val expectedTest = "Hello from Kotlin" + val input = ByteArrayInputStream(expectedTest.toByteArray()) + System.setIn(input) + + val readText = readLine() + + assertThat(readText).isEqualTo(expectedTest) + } + + @Test + fun givenInput_whenReadWithScanner_thenReadText() { + val expectedTest = "Hello from Kotlin" + val scanner = Scanner(ByteArrayInputStream(expectedTest.toByteArray())) + + val readText = scanner.nextLine() + + assertThat(readText).isEqualTo(expectedTest) + } + + @Test + fun givenInput_whenReadWithBufferedReader_thenReadText() { + val expectedTest = "Hello from Kotlin" + val reader = BufferedReader(InputStreamReader(ByteArrayInputStream(expectedTest.toByteArray()))) + + val readText = reader.readLine() + + assertThat(readText).isEqualTo(expectedTest) + } + + @Test + fun givenInput_whenReadWithConsole_thenReadText() { + val expectedTest = "Hello from Kotlin" + val console = mock(Console::class.java) + `when`(console.readLine()).thenReturn(expectedTest) + + val readText = console.readLine() + + assertThat(readText).isEqualTo(expectedTest) + } + + @AfterEach + fun resetIO() { + System.setOut(System.out) + System.setIn(System.`in`) + } +} \ No newline at end of file diff --git a/core-kotlin-2/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt b/core-kotlin-io/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt similarity index 93% rename from core-kotlin-2/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt rename to core-kotlin-io/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt index 3437ddb68a..d10d23bef0 100644 --- a/core-kotlin-2/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt +++ b/core-kotlin-io/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt @@ -8,7 +8,8 @@ import kotlin.test.assertEquals class InputStreamToStringTest { private val fileName = "src/test/resources/inputstream2string.txt" - private val fileFullContent = "Computer programming can be a hassle\r\n" + + private val endOfLine = System.lineSeparator() + private val fileFullContent = "Computer programming can be a hassle$endOfLine" + "It's like trying to take a defended castle" @Test @@ -46,7 +47,7 @@ class InputStreamToStringTest { } finally { reader.close() } - assertEquals(fileFullContent.replace("\r\n", ""), content.toString()) + assertEquals(fileFullContent.replace(endOfLine, ""), content.toString()) } diff --git a/core-kotlin-2/src/test/resources/inputstream2string.txt b/core-kotlin-io/src/test/resources/inputstream2string.txt similarity index 100% rename from core-kotlin-2/src/test/resources/inputstream2string.txt rename to core-kotlin-io/src/test/resources/inputstream2string.txt diff --git a/core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 0000000000..ca6ee9cea8 --- /dev/null +++ b/core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline \ No newline at end of file diff --git a/core-kotlin/src/main/kotlin/com/baeldung/filesystem/FileReader.kt b/core-kotlin/src/main/kotlin/com/baeldung/filesystem/FileReader.kt index 8539378c91..886a3fc51e 100644 --- a/core-kotlin/src/main/kotlin/com/baeldung/filesystem/FileReader.kt +++ b/core-kotlin/src/main/kotlin/com/baeldung/filesystem/FileReader.kt @@ -17,4 +17,8 @@ class FileReader { File(fileName).inputStream().readBytes().toString(Charsets.UTF_8) fun readFileDirectlyAsText(fileName: String): String = File(fileName).readText(Charsets.UTF_8) + + fun readFileUsingGetResource(fileName: String) = this::class.java.getResource(fileName).readText(Charsets.UTF_8) + + fun readFileAsLinesUsingGetResourceAsStream(fileName: String) = this::class.java.getResourceAsStream(fileName).bufferedReader().readLines() } \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filesystem/FileReaderTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filesystem/FileReaderTest.kt index 67795dda14..ad541c446e 100644 --- a/core-kotlin/src/test/kotlin/com/baeldung/filesystem/FileReaderTest.kt +++ b/core-kotlin/src/test/kotlin/com/baeldung/filesystem/FileReaderTest.kt @@ -48,4 +48,20 @@ internal class FileReaderTest { assertTrue { text.contains("Hello to Kotlin") } } + + @Test + fun whenReadFileAsTextUsingGetResource_thenCorrect() { + val text = fileReader.readFileUsingGetResource("/Kotlin.in") + + assertTrue { text.contains("1. Concise") } + } + + @Test + fun whenReadFileUsingGetResourceAsStream_thenCorrect() { + val lines = fileReader.readFileAsLinesUsingGetResourceAsStream("/Kotlin.in") + + assertTrue { lines.contains("3. Interoperable") } + } + + } \ No newline at end of file diff --git a/ethereum/pom.xml b/ethereum/pom.xml index baa74b58a5..80e1c04676 100644 --- a/ethereum/pom.xml +++ b/ethereum/pom.xml @@ -88,7 +88,7 @@ javax.servlet javax.servlet-api - ${javax-servlet.version} + ${javax.servlet-api.version} javax.servlet.jsp.jstl @@ -98,7 +98,7 @@ javax.servlet.jsp javax.servlet.jsp-api - ${javax-jsp.version} + ${javax.servlet.jsp-api.version} @@ -160,7 +160,7 @@ org.hamcrest hamcrest-library - ${hamcrest.version} + ${org.hamcrest.version} test @@ -213,12 +213,7 @@ 3.3.1 1.5.6.RELEASE 2.21.0 - 1.3 - 2.3.1 - 3.1.0 2.4.0 - 1.2 - 4.12 1.2.3 1.7.25 2.0.4.RELEASE diff --git a/google-cloud/pom.xml b/google-cloud/pom.xml index e39e186f05..ec53b78070 100644 --- a/google-cloud/pom.xml +++ b/google-cloud/pom.xml @@ -30,7 +30,6 @@ - 1.16.18 1.16.0 diff --git a/google-web-toolkit/pom.xml b/google-web-toolkit/pom.xml index f4c6a0ab39..0723cd3be2 100644 --- a/google-web-toolkit/pom.xml +++ b/google-web-toolkit/pom.xml @@ -120,7 +120,6 @@ UTF-8 UTF-8 - 4.11 2.8.2 diff --git a/gson/pom.xml b/gson/pom.xml index 8222cb50e1..a21d783c39 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -67,7 +67,6 @@ 3.5 4.1 2.9.6 - 1.16.10 \ No newline at end of file diff --git a/guava-collections-set/.gitignore b/guava-collections-set/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/guava-collections-set/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/guava-collections-set/pom.xml b/guava-collections-set/pom.xml new file mode 100644 index 0000000000..46dcae492d --- /dev/null +++ b/guava-collections-set/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + com.baeldung + guava-collections-set + 0.1.0-SNAPSHOT + guava-collections-set + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../parent-java + + + + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + guava-collections-set + + + + + 27.1-jre + + 3.6.1 + + + diff --git a/guava-collections-set/src/test/java/org/baeldung/guava/GuavaMultiSetUnitTest.java b/guava-collections-set/src/test/java/org/baeldung/guava/GuavaMultiSetUnitTest.java new file mode 100644 index 0000000000..e74db29881 --- /dev/null +++ b/guava-collections-set/src/test/java/org/baeldung/guava/GuavaMultiSetUnitTest.java @@ -0,0 +1,92 @@ +package org.baeldung.guava; + +import com.google.common.collect.HashMultiset; +import com.google.common.collect.Multiset; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class GuavaMultiSetUnitTest { + + @Test + public void givenMultiSet_whenAddingValues_shouldReturnCorrectCount() { + Multiset bookStore = HashMultiset.create(); + bookStore.add("Potter"); + bookStore.add("Potter"); + bookStore.add("Potter"); + + assertThat(bookStore.contains("Potter")).isTrue(); + assertThat(bookStore.count("Potter")).isEqualTo(3); + } + + @Test + public void givenMultiSet_whenRemovingValues_shouldReturnCorrectCount() { + Multiset bookStore = HashMultiset.create(); + bookStore.add("Potter"); + bookStore.add("Potter"); + + bookStore.remove("Potter"); + assertThat(bookStore.contains("Potter")).isTrue(); + assertThat(bookStore.count("Potter")).isEqualTo(1); + } + + @Test + public void givenMultiSet_whenSetCount_shouldReturnCorrectCount() { + Multiset bookStore = HashMultiset.create(); + bookStore.setCount("Potter", 50); + assertThat(bookStore.count("Potter")).isEqualTo(50); + } + + @Test + public void givenMultiSet_whenSettingNegativeCount_shouldThrowException() { + Multiset bookStore = HashMultiset.create(); + assertThatThrownBy(() -> bookStore.setCount("Potter", -1)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + public void givenMultiSet_whenSettingCountWithEmptySet_shouldBeSuccessful() { + Multiset bookStore = HashMultiset.create(); + assertThat(bookStore.setCount("Potter", 0, 2)).isTrue(); + } + + @Test + public void givenMultiSet_whenSettingCountWithCorrectValue_shouldBeSuccessful() { + Multiset bookStore = HashMultiset.create(); + bookStore.add("Potter"); + bookStore.add("Potter"); + + assertThat(bookStore.setCount("Potter", 2, 52)).isTrue(); + } + + @Test + public void givenMultiSet_whenSettingCountWithIncorrectValue_shouldFail() { + Multiset bookStore = HashMultiset.create(); + bookStore.add("Potter"); + bookStore.add("Potter"); + + assertThat(bookStore.setCount("Potter", 5, 52)).isFalse(); + } + + @Test + public void givenMap_compareMultiSetOperations() { + Map bookStore = new HashMap<>(); + bookStore.put("Potter", 3); + + assertThat(bookStore.containsKey("Potter")).isTrue(); + assertThat(bookStore.get("Potter")).isEqualTo(3); + + bookStore.put("Potter", 2); + assertThat(bookStore.get("Potter")).isEqualTo(2); + + bookStore.put("Potter", null); + assertThat(bookStore.containsKey("Potter")).isTrue(); + + bookStore.put("Potter", -1); + assertThat(bookStore.containsKey("Potter")).isTrue(); + } +} \ No newline at end of file diff --git a/guest/junit5-example/pom.xml b/guest/junit5-example/pom.xml index 7c0cc3e776..c6370941d1 100644 --- a/guest/junit5-example/pom.xml +++ b/guest/junit5-example/pom.xml @@ -60,7 +60,6 @@ 5.0.0-M4 4.12.0-M4 - 1.4.195 2.8.2 1.0.0-M4 diff --git a/guest/log4j2-example/pom.xml b/guest/log4j2-example/pom.xml index 045ff7325b..31a32a4562 100644 --- a/guest/log4j2-example/pom.xml +++ b/guest/log4j2-example/pom.xml @@ -41,7 +41,6 @@ - 2.9.7 2.8.2 diff --git a/guest/tomcat-app/pom.xml b/guest/tomcat-app/pom.xml index 9ce77c758a..ab18023f70 100644 --- a/guest/tomcat-app/pom.xml +++ b/guest/tomcat-app/pom.xml @@ -31,9 +31,9 @@ ${rest-assured.version} - com.h2database + com.h2 h2 - ${h2database.version} + ${h2.version} runtime @@ -62,7 +62,6 @@ 2.25.1 - 1.4.195 3.0.3 2.8.2 1.69.0 diff --git a/httpclient-simple/.gitignore b/httpclient-simple/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/httpclient-simple/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/httpclient-simple/README.md b/httpclient-simple/README.md new file mode 100644 index 0000000000..e3535a133e --- /dev/null +++ b/httpclient-simple/README.md @@ -0,0 +1,16 @@ +========= +## This module contains articles that are part of the HTTPClient Ebook + +- [HttpClient 4 – Get the Status Code](http://www.baeldung.com/httpclient-status-code) +- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) +- [HttpClient Timeout](http://www.baeldung.com/httpclient-timeout) +- [HttpClient 4 – Send Custom Cookie](http://www.baeldung.com/httpclient-4-cookies) +- [Custom HTTP Header with the HttpClient](http://www.baeldung.com/httpclient-custom-http-header) +- [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication) +- [Posting with HttpClient](https://www.baeldung.com/httpclient-post-http-request) + + +### Running the Tests +To run the live tests, use the command: mvn clean install -Plive +This will start an embedded Jetty server on port 8082 using the Cargo plugin configured in the pom.xml file, +for the live Maven profile diff --git a/httpclient-simple/pom.xml b/httpclient-simple/pom.xml new file mode 100644 index 0000000000..efcf0452e2 --- /dev/null +++ b/httpclient-simple/pom.xml @@ -0,0 +1,312 @@ + + 4.0.0 + com.baeldung + httpclient-simple + 0.1-SNAPSHOT + httpclient-simple + war + + + com.baeldung + parent-spring-5 + 0.0.1-SNAPSHOT + ../parent-spring-5 + + + + + + + + org.springframework.security + spring-security-web + ${spring.version} + + + org.springframework.security + spring-security-config + ${spring.version} + + + + + + org.springframework + spring-core + ${spring.version} + + + commons-logging + commons-logging + + + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-jdbc + ${spring.version} + + + org.springframework + spring-beans + ${spring.version} + + + org.springframework + spring-aop + ${spring.version} + + + org.springframework + spring-tx + ${spring.version} + + + org.springframework + spring-expression + ${spring.version} + + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + + org.springframework + spring-oxm + ${spring.version} + + + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + org.apache.httpcomponents + httpcore + ${httpcore.version} + + + commons-logging + commons-logging + + + + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + + org.apache.httpcomponents + httpclient + ${httpclient.version} + + + commons-logging + commons-logging + + + + + org.apache.httpcomponents + fluent-hc + ${httpclient.version} + + + commons-logging + commons-logging + + + + + org.apache.httpcomponents + httpmime + ${httpclient.version} + + + commons-codec + commons-codec + ${commons-codec.version} + + + org.apache.httpcomponents + httpasyncclient + ${httpasyncclient.version} + + + commons-logging + commons-logging + + + + + com.github.tomakehurst + wiremock + ${wiremock.version} + test + + + + + + javax.servlet + javax.servlet-api + ${javax.servlet-api.version} + provided + + + + javax.servlet + jstl + ${jstl.version} + runtime + + + + + + com.google.guava + guava + ${guava.version} + + + + + + org.springframework + spring-test + ${spring.version} + test + + + + + httpclient-simple + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + + org.codehaus.cargo + cargo-maven2-plugin + ${cargo-maven2-plugin.version} + + true + + jetty8x + embedded + + + + + + + 8082 + + + + + + + + + + live + + + + org.codehaus.cargo + cargo-maven2-plugin + + + start-server + pre-integration-test + + start + + + + stop-server + post-integration-test + + stop + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + none + + + **/*LiveTest.java + + + cargo + + + + + + + + + + + + + + 19.0 + 3.5 + 1.10 + 4.1.4 + + 2.5.1 + 4.4.11 + 4.5.8 + + 2.6 + 1.6.1 + + + \ No newline at end of file diff --git a/httpclient-simple/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java b/httpclient-simple/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java new file mode 100644 index 0000000000..380ff9df6b --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java @@ -0,0 +1,30 @@ +package com.baeldung.basic; + +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +@Component +public class MyBasicAuthenticationEntryPoint extends BasicAuthenticationEntryPoint { + + @Override + public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException, ServletException { + response.addHeader("WWW-Authenticate", "Basic realm=\"" + getRealmName() + "\""); + response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + final PrintWriter writer = response.getWriter(); + writer.println("HTTP Status " + HttpServletResponse.SC_UNAUTHORIZED + " - " + authException.getMessage()); + } + + @Override + public void afterPropertiesSet() throws Exception { + setRealmName("Baeldung"); + super.afterPropertiesSet(); + } + +} diff --git a/httpclient-simple/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryBasicAuth.java b/httpclient-simple/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryBasicAuth.java new file mode 100644 index 0000000000..81f82a2c1c --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryBasicAuth.java @@ -0,0 +1,39 @@ +package com.baeldung.client; + +import java.net.URI; + +import org.apache.http.HttpHost; +import org.apache.http.client.AuthCache; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.impl.auth.BasicScheme; +import org.apache.http.impl.client.BasicAuthCache; +import org.apache.http.protocol.BasicHttpContext; +import org.apache.http.protocol.HttpContext; +import org.springframework.http.HttpMethod; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; + +public class HttpComponentsClientHttpRequestFactoryBasicAuth extends HttpComponentsClientHttpRequestFactory { + + HttpHost host; + + public HttpComponentsClientHttpRequestFactoryBasicAuth(HttpHost host) { + super(); + this.host = host; + } + + protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { + return createHttpContext(); + } + + private HttpContext createHttpContext() { + + AuthCache authCache = new BasicAuthCache(); + + BasicScheme basicAuth = new BasicScheme(); + authCache.put(host, basicAuth); + + BasicHttpContext localcontext = new BasicHttpContext(); + localcontext.setAttribute(HttpClientContext.AUTH_CACHE, authCache); + return localcontext; + } +} \ No newline at end of file diff --git a/httpclient-simple/src/main/java/com/baeldung/client/RestTemplateFactory.java b/httpclient-simple/src/main/java/com/baeldung/client/RestTemplateFactory.java new file mode 100644 index 0000000000..aac4f8cebd --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/client/RestTemplateFactory.java @@ -0,0 +1,44 @@ +package com.baeldung.client; + +import org.apache.http.HttpHost; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.http.client.ClientHttpRequestFactory; +import org.springframework.http.client.support.BasicAuthenticationInterceptor; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +@Component +public class RestTemplateFactory implements FactoryBean, InitializingBean { + private RestTemplate restTemplate; + + public RestTemplateFactory() { + super(); + } + + // API + + @Override + public RestTemplate getObject() { + return restTemplate; + } + + @Override + public Class getObjectType() { + return RestTemplate.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + public void afterPropertiesSet() { + HttpHost host = new HttpHost("localhost", 8082, "http"); + final ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactoryBasicAuth(host); + restTemplate = new RestTemplate(requestFactory); + restTemplate.getInterceptors().add(new BasicAuthenticationInterceptor("user1", "user1Pass")); + } + +} \ No newline at end of file diff --git a/httpclient-simple/src/main/java/com/baeldung/client/spring/ClientConfig.java b/httpclient-simple/src/main/java/com/baeldung/client/spring/ClientConfig.java new file mode 100644 index 0000000000..03994b55a5 --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/client/spring/ClientConfig.java @@ -0,0 +1,16 @@ +package com.baeldung.client.spring; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan("com.baeldung.client") +public class ClientConfig { + + public ClientConfig() { + super(); + } + + // beans + +} \ No newline at end of file diff --git a/httpclient-simple/src/main/java/com/baeldung/filter/CustomFilter.java b/httpclient-simple/src/main/java/com/baeldung/filter/CustomFilter.java new file mode 100644 index 0000000000..6bb12610fa --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/filter/CustomFilter.java @@ -0,0 +1,18 @@ +package com.baeldung.filter; + +import org.springframework.web.filter.GenericFilterBean; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import java.io.IOException; + +public class CustomFilter extends GenericFilterBean { + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + chain.doFilter(request, response); + } + +} diff --git a/httpclient-simple/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java b/httpclient-simple/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java new file mode 100644 index 0000000000..fb597e46c8 --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java @@ -0,0 +1,49 @@ +package com.baeldung.filter; + +import com.baeldung.security.RestAuthenticationEntryPoint; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; + +@Configuration +@EnableWebSecurity +public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter { + + @Autowired private RestAuthenticationEntryPoint authenticationEntryPoint; + + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth + .inMemoryAuthentication() + .withUser("user1") + .password(passwordEncoder().encode("user1Pass")) + .authorities("ROLE_USER"); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + .authorizeRequests() + .antMatchers("/securityNone") + .permitAll() + .anyRequest() + .authenticated() + .and() + .httpBasic() + .authenticationEntryPoint(authenticationEntryPoint); + + http.addFilterAfter(new CustomFilter(), BasicAuthenticationFilter.class); + } + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } +} diff --git a/httpclient-simple/src/main/java/com/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java b/httpclient-simple/src/main/java/com/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java new file mode 100644 index 0000000000..7dc53e3e1e --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java @@ -0,0 +1,48 @@ +package com.baeldung.security; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.core.Authentication; +import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; +import org.springframework.security.web.savedrequest.HttpSessionRequestCache; +import org.springframework.security.web.savedrequest.RequestCache; +import org.springframework.security.web.savedrequest.SavedRequest; +import org.springframework.util.StringUtils; + +public class MySavedRequestAwareAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { + + private RequestCache requestCache = new HttpSessionRequestCache(); + + @Override + public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) throws ServletException, IOException { + final SavedRequest savedRequest = requestCache.getRequest(request, response); + + if (savedRequest == null) { + super.onAuthenticationSuccess(request, response, authentication); + + return; + } + final String targetUrlParameter = getTargetUrlParameter(); + if (isAlwaysUseDefaultTargetUrl() || (targetUrlParameter != null && StringUtils.hasText(request.getParameter(targetUrlParameter)))) { + requestCache.removeRequest(request, response); + super.onAuthenticationSuccess(request, response, authentication); + + return; + } + + clearAuthenticationAttributes(request); + + // Use the DefaultSavedRequest URL + // final String targetUrl = savedRequest.getRedirectUrl(); + // logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl); + // getRedirectStrategy().sendRedirect(request, response, targetUrl); + } + + public void setRequestCache(final RequestCache requestCache) { + this.requestCache = requestCache; + } +} diff --git a/httpclient-simple/src/main/java/com/baeldung/security/RestAuthenticationEntryPoint.java b/httpclient-simple/src/main/java/com/baeldung/security/RestAuthenticationEntryPoint.java new file mode 100644 index 0000000000..1ae89adb89 --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/security/RestAuthenticationEntryPoint.java @@ -0,0 +1,23 @@ +package com.baeldung.security; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.stereotype.Component; + +/** + * The Entry Point will not redirect to any sort of Login - it will return the 401 + */ +@Component +public final class RestAuthenticationEntryPoint implements AuthenticationEntryPoint { + + @Override + public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException { + response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized"); + } + +} \ No newline at end of file diff --git a/httpclient-simple/src/main/java/com/baeldung/spring/SecSecurityConfig.java b/httpclient-simple/src/main/java/com/baeldung/spring/SecSecurityConfig.java new file mode 100644 index 0000000000..4ba9d47f8d --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/spring/SecSecurityConfig.java @@ -0,0 +1,16 @@ +package com.baeldung.spring; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; + +@Configuration +@ImportResource({ "classpath:webSecurityConfig.xml" }) +@ComponentScan("com.baeldung.security") +public class SecSecurityConfig { + + public SecSecurityConfig() { + super(); + } + +} diff --git a/httpclient-simple/src/main/java/com/baeldung/spring/WebConfig.java b/httpclient-simple/src/main/java/com/baeldung/spring/WebConfig.java new file mode 100644 index 0000000000..8d5c1dc7f1 --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/spring/WebConfig.java @@ -0,0 +1,30 @@ +package com.baeldung.spring; + +import java.util.List; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +@EnableWebMvc +@ComponentScan("com.baeldung.web") +public class WebConfig implements WebMvcConfigurer { + + public WebConfig() { + super(); + } + + // beans + + @Override + public void configureMessageConverters(final List> converters) { + converters.add(new MappingJackson2HttpMessageConverter()); + } + + // + +} \ No newline at end of file diff --git a/httpclient-simple/src/main/java/com/baeldung/web/controller/BarController.java b/httpclient-simple/src/main/java/com/baeldung/web/controller/BarController.java new file mode 100644 index 0000000000..02e6af03af --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/web/controller/BarController.java @@ -0,0 +1,31 @@ +package com.baeldung.web.controller; + +import com.baeldung.web.dto.Bar; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@RequestMapping(value = "/bars") +public class BarController { + + @Autowired + private ApplicationEventPublisher eventPublisher; + + public BarController() { + super(); + } + + // API + + @RequestMapping(value = "/{id}", method = RequestMethod.GET) + @ResponseBody + public Bar findOne(@PathVariable("id") final Long id) { + return new Bar(); + } + +} diff --git a/httpclient-simple/src/main/java/com/baeldung/web/controller/FooController.java b/httpclient-simple/src/main/java/com/baeldung/web/controller/FooController.java new file mode 100644 index 0000000000..461a5e351a --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/web/controller/FooController.java @@ -0,0 +1,33 @@ +package com.baeldung.web.controller; + +import com.baeldung.web.dto.Foo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@RequestMapping(value = "/foos") +public class FooController { + + @Autowired + private ApplicationEventPublisher eventPublisher; + + public FooController() { + super(); + } + + // API + + @RequestMapping(value = "/{id}", method = RequestMethod.GET) + @ResponseBody + @PreAuthorize("hasRole('ROLE_USER')") + public Foo findOne(@PathVariable("id") final Long id) { + return new Foo(); + } + +} diff --git a/httpclient-simple/src/main/java/com/baeldung/web/dto/Bar.java b/httpclient-simple/src/main/java/com/baeldung/web/dto/Bar.java new file mode 100644 index 0000000000..eb139b0ec1 --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/web/dto/Bar.java @@ -0,0 +1,14 @@ +package com.baeldung.web.dto; + +import java.io.Serializable; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class Bar implements Serializable { + + public Bar() { + super(); + } + +} diff --git a/httpclient-simple/src/main/java/com/baeldung/web/dto/Foo.java b/httpclient-simple/src/main/java/com/baeldung/web/dto/Foo.java new file mode 100644 index 0000000000..23cfab132d --- /dev/null +++ b/httpclient-simple/src/main/java/com/baeldung/web/dto/Foo.java @@ -0,0 +1,14 @@ +package com.baeldung.web.dto; + +import java.io.Serializable; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class Foo implements Serializable { + + public Foo() { + super(); + } + +} diff --git a/httpclient-simple/src/main/resources/logback.xml b/httpclient-simple/src/main/resources/logback.xml new file mode 100644 index 0000000000..56af2d397e --- /dev/null +++ b/httpclient-simple/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 diff --git a/httpclient-simple/src/main/resources/webSecurityConfig.xml b/httpclient-simple/src/main/resources/webSecurityConfig.xml new file mode 100644 index 0000000000..2ff9a1de15 --- /dev/null +++ b/httpclient-simple/src/main/resources/webSecurityConfig.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/httpclient-simple/src/main/webapp/WEB-INF/api-servlet.xml b/httpclient-simple/src/main/webapp/WEB-INF/api-servlet.xml new file mode 100644 index 0000000000..1dbff70b83 --- /dev/null +++ b/httpclient-simple/src/main/webapp/WEB-INF/api-servlet.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/httpclient-simple/src/main/webapp/WEB-INF/web.xml b/httpclient-simple/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..4b2dd54266 --- /dev/null +++ b/httpclient-simple/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,43 @@ + + + + Spring Security Custom Application + + + + contextClass + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + + + contextConfigLocation + com.baeldung.spring + + + + org.springframework.web.context.ContextLoaderListener + + + + + api + org.springframework.web.servlet.DispatcherServlet + 1 + + + api + /api/* + + + + + springSecurityFilterChain + org.springframework.web.filter.DelegatingFilterProxy + + + springSecurityFilterChain + /* + + + \ No newline at end of file diff --git a/spring-security-rest-basic-auth/src/test/java/org/baeldung/client/ClientLiveTest.java b/httpclient-simple/src/test/java/com/baeldung/client/ClientLiveTest.java similarity index 82% rename from spring-security-rest-basic-auth/src/test/java/org/baeldung/client/ClientLiveTest.java rename to httpclient-simple/src/test/java/com/baeldung/client/ClientLiveTest.java index 2a668f827a..78e9813f06 100644 --- a/spring-security-rest-basic-auth/src/test/java/org/baeldung/client/ClientLiveTest.java +++ b/httpclient-simple/src/test/java/com/baeldung/client/ClientLiveTest.java @@ -1,11 +1,11 @@ -package org.baeldung.client; +package com.baeldung.client; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; -import org.baeldung.client.spring.ClientConfig; -import org.baeldung.web.dto.Foo; +import com.baeldung.client.spring.ClientConfig; +import com.baeldung.web.dto.Foo; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -33,13 +33,13 @@ public class ClientLiveTest { @Test public final void whenSecuredRestApiIsConsumed_then200OK() { - final ResponseEntity responseEntity = secureRestTemplate.exchange("http://localhost:8082/spring-security-rest-basic-auth/api/foos/1", HttpMethod.GET, null, Foo.class); + final ResponseEntity responseEntity = secureRestTemplate.exchange("http://localhost:8082/httpclient-simple/api/foos/1", HttpMethod.GET, null, Foo.class); assertThat(responseEntity.getStatusCode().value(), is(200)); } @Test(expected = ResourceAccessException.class) public final void whenHttpsUrlIsConsumed_thenException() { - final String urlOverHttps = "https://localhost:8443/spring-security-rest-basic-auth/api/bars/1"; + final String urlOverHttps = "https://localhost:8443/httpclient-simple/api/bars/1"; final ResponseEntity response = new RestTemplate().exchange(urlOverHttps, HttpMethod.GET, null, String.class); assertThat(response.getStatusCode().value(), equalTo(200)); } diff --git a/spring-security-rest-basic-auth/src/test/java/org/baeldung/client/RestClientLiveManualTest.java b/httpclient-simple/src/test/java/com/baeldung/client/RestClientLiveManualTest.java similarity index 60% rename from spring-security-rest-basic-auth/src/test/java/org/baeldung/client/RestClientLiveManualTest.java rename to httpclient-simple/src/test/java/com/baeldung/client/RestClientLiveManualTest.java index 104129b663..a485641b34 100644 --- a/spring-security-rest-basic-auth/src/test/java/org/baeldung/client/RestClientLiveManualTest.java +++ b/httpclient-simple/src/test/java/com/baeldung/client/RestClientLiveManualTest.java @@ -1,4 +1,4 @@ -package org.baeldung.client; +package com.baeldung.client; import static org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; import static org.hamcrest.Matchers.equalTo; @@ -8,19 +8,24 @@ import java.io.IOException; import java.security.GeneralSecurityException; import java.security.cert.X509Certificate; -import javax.net.ssl.SSLException; -import javax.net.ssl.SSLPeerUnverifiedException; +import javax.net.ssl.SSLContext; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.HttpGet; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.conn.ssl.TrustStrategy; import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.BasicHttpClientConnectionManager; +import org.apache.http.ssl.SSLContexts; import org.junit.Ignore; import org.junit.Test; import org.springframework.http.HttpMethod; @@ -34,29 +39,48 @@ import org.springframework.web.client.RestTemplate; * */ public class RestClientLiveManualTest { - final String urlOverHttps = "http://localhost:8082/spring-security-rest-basic-auth/api/bars/1"; + final String urlOverHttps = "http://localhost:8082/httpclient-simple/api/bars/1"; // tests // old httpClient will throw UnsupportedOperationException @Ignore @Test - public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenException() throws GeneralSecurityException { + public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenOk_1() throws GeneralSecurityException { final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); final CloseableHttpClient httpClient = (CloseableHttpClient) requestFactory.getHttpClient(); - final TrustStrategy acceptingTrustStrategy = new TrustStrategy() { - @Override - public final boolean isTrusted(final X509Certificate[] certificate, final String authType) { - return true; - } - }; + final TrustStrategy acceptingTrustStrategy = (cert, authType) -> true; + final SSLSocketFactory sf = new SSLSocketFactory(acceptingTrustStrategy, ALLOW_ALL_HOSTNAME_VERIFIER); httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 8443, sf)); final ResponseEntity response = new RestTemplate(requestFactory).exchange(urlOverHttps, HttpMethod.GET, null, String.class); assertThat(response.getStatusCode().value(), equalTo(200)); } + + // new httpClient : 4.4 and above + @Test + public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenOk_2() throws GeneralSecurityException { + + final TrustStrategy acceptingTrustStrategy = (cert, authType) -> true; + final SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(); + final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); + final Registry socketFactoryRegistry = RegistryBuilder. create() + .register("https", sslsf) + .register("http", new PlainConnectionSocketFactory()) + .build(); + + final BasicHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager(socketFactoryRegistry); + final CloseableHttpClient httpClient = HttpClients.custom() + .setSSLSocketFactory(sslsf) + .setConnectionManager(connectionManager) + .build(); + + final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); + final ResponseEntity response = new RestTemplate(requestFactory).exchange(urlOverHttps, HttpMethod.GET, null, String.class); + assertThat(response.getStatusCode().value(), equalTo(200)); + } @Test public final void givenAcceptingAllCertificatesUsing4_4_whenHttpsUrlIsConsumed_thenCorrect() throws ClientProtocolException, IOException { diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientHeadersLiveTest.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientHeadersLiveTest.java similarity index 99% rename from httpclient/src/test/java/org/baeldung/httpclient/HttpClientHeadersLiveTest.java rename to httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientHeadersLiveTest.java index 51c3817da5..44262851fd 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientHeadersLiveTest.java +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientHeadersLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.httpclient; +package com.baeldung.httpclient; import com.google.common.collect.Lists; import org.apache.http.Header; diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientPostingLiveTest.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientPostingLiveTest.java similarity index 93% rename from httpclient/src/test/java/org/baeldung/httpclient/HttpClientPostingLiveTest.java rename to httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientPostingLiveTest.java index 39ed8f09ef..f5dff8d757 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientPostingLiveTest.java +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientPostingLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.httpclient; +package com.baeldung.httpclient; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -32,7 +32,7 @@ import static org.junit.Assert.assertThat; * NOTE : Need module spring-rest to be running */ public class HttpClientPostingLiveTest { - private static final String SAMPLE_URL = "http://localhost:8082/spring-rest/users"; + private static final String SAMPLE_URL = "http://www.example.com"; private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php"; private static final String DEFAULT_USER = "test"; private static final String DEFAULT_PASS = "test"; @@ -69,7 +69,7 @@ public class HttpClientPostingLiveTest { @Test public void whenPostJsonUsingHttpClient_thenCorrect() throws IOException { final CloseableHttpClient client = HttpClients.createDefault(); - final HttpPost httpPost = new HttpPost(SAMPLE_URL + "/detail"); + final HttpPost httpPost = new HttpPost(SAMPLE_URL); final String json = "{\"id\":1,\"name\":\"John\"}"; final StringEntity entity = new StringEntity(json); @@ -92,7 +92,7 @@ public class HttpClientPostingLiveTest { @Test public void whenSendMultipartRequestUsingHttpClient_thenCorrect() throws IOException { final CloseableHttpClient client = HttpClients.createDefault(); - final HttpPost httpPost = new HttpPost(SAMPLE_URL + "/multipart"); + final HttpPost httpPost = new HttpPost(SAMPLE_URL); final MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody("username", DEFAULT_USER); @@ -110,7 +110,7 @@ public class HttpClientPostingLiveTest { @Test public void whenUploadFileUsingHttpClient_thenCorrect() throws IOException { final CloseableHttpClient client = HttpClients.createDefault(); - final HttpPost httpPost = new HttpPost(SAMPLE_URL + "/upload"); + final HttpPost httpPost = new HttpPost(SAMPLE_URL); final MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addBinaryBody("file", new File("src/test/resources/test.in"), ContentType.APPLICATION_OCTET_STREAM, "file.ext"); @@ -126,7 +126,7 @@ public class HttpClientPostingLiveTest { @Test public void whenGetUploadFileProgressUsingHttpClient_thenCorrect() throws IOException { final CloseableHttpClient client = HttpClients.createDefault(); - final HttpPost httpPost = new HttpPost(SAMPLE_URL + "/upload"); + final HttpPost httpPost = new HttpPost(SAMPLE_URL); final MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addBinaryBody("file", new File("src/test/resources/test.in"), ContentType.APPLICATION_OCTET_STREAM, "file.ext"); diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientTimeoutLiveTest.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientTimeoutLiveTest.java similarity index 59% rename from httpclient/src/test/java/org/baeldung/httpclient/HttpClientTimeoutLiveTest.java rename to httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientTimeoutLiveTest.java index 74255e416c..8bd7042dc6 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientTimeoutLiveTest.java +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientTimeoutLiveTest.java @@ -1,20 +1,28 @@ -package org.baeldung.httpclient; - -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.config.SocketConfig; -import org.apache.http.conn.HttpHostConnectException; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.junit.After; -import org.junit.Test; - -import java.io.IOException; +package com.baeldung.httpclient; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; +import java.io.IOException; +import java.util.Timer; +import java.util.TimerTask; + +import org.apache.http.HttpResponse; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.params.ClientPNames; +import org.apache.http.config.SocketConfig; +import org.apache.http.conn.ConnectTimeoutException; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.params.CoreConnectionPNames; +import org.apache.http.params.HttpParams; +import org.junit.After; +import org.junit.Ignore; +import org.junit.Test; + public class HttpClientTimeoutLiveTest { private CloseableHttpResponse response; @@ -25,6 +33,20 @@ public class HttpClientTimeoutLiveTest { } // tests + @Test + public final void givenUsingOldApi_whenSettingTimeoutViaParameter_thenCorrect() throws IOException { + + DefaultHttpClient httpClient = new DefaultHttpClient(); + int timeout = 5; // seconds + HttpParams httpParams = httpClient.getParams(); + httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout * 1000); + httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout * 1000); + httpParams.setParameter(ClientPNames.CONN_MANAGER_TIMEOUT, new Long(timeout * 1000)); + + final HttpGet request = new HttpGet("http://www.github.com"); + HttpResponse execute = httpClient.execute(request); + assertThat(execute.getStatusLine().getStatusCode(), equalTo(200)); + } @Test public final void givenUsingNewApi_whenSettingTimeoutViaRequestConfig_thenCorrect() throws IOException { @@ -33,8 +55,6 @@ public class HttpClientTimeoutLiveTest { final CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).build(); final HttpGet request = new HttpGet("http://www.github.com"); - // httpParams.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, new Long(timeout * 1000)); // https://issues.apache.org/jira/browse/HTTPCLIENT-1418 - response = client.execute(request); assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); @@ -71,7 +91,8 @@ public class HttpClientTimeoutLiveTest { /** * This simulates a timeout against a domain with multiple routes/IPs to it (not a single raw IP) */ - @Test(expected = HttpHostConnectException.class) + @Test(expected = ConnectTimeoutException.class) + @Ignore public final void givenTimeoutIsConfigured_whenTimingOut_thenTimeoutException() throws IOException { final int timeout = 3; @@ -81,5 +102,28 @@ public class HttpClientTimeoutLiveTest { final HttpGet request = new HttpGet("http://www.google.com:81"); client.execute(request); } + + @Test + public void whenSecuredRestApiIsConsumed_then200OK() throws IOException { + CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + int timeout = 20; // seconds + RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(timeout * 1000) + .setConnectTimeout(timeout * 1000).setSocketTimeout(timeout * 1000).build(); + HttpGet getMethod = new HttpGet("http://localhost:8082/httpclient-simple/api/bars/1"); + getMethod.setConfig(requestConfig); + + int hardTimeout = 5; // seconds + TimerTask task = new TimerTask() { + @Override + public void run() { + getMethod.abort(); + } + }; + new Timer(true).schedule(task, hardTimeout * 1000); + + HttpResponse response = httpClient.execute(getMethod); + System.out.println("HTTP Status of response: " + response.getStatusLine().getStatusCode()); + } + } diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpsClientSslLiveTest.java similarity index 81% rename from httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java rename to httpclient-simple/src/test/java/com/baeldung/httpclient/HttpsClientSslLiveTest.java index 4eadfe24d5..24ceab0069 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpsClientSslLiveTest.java @@ -1,32 +1,31 @@ -package org.baeldung.httpclient; - -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.conn.ClientConnectionManager; -import org.apache.http.conn.scheme.Scheme; -import org.apache.http.conn.scheme.SchemeRegistry; -import org.apache.http.conn.ssl.NoopHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLSocketFactory; -import org.apache.http.conn.ssl.TrustSelfSignedStrategy; -import org.apache.http.conn.ssl.TrustStrategy; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.impl.conn.PoolingClientConnectionManager; -import org.apache.http.ssl.SSLContextBuilder; -import org.apache.http.ssl.SSLContexts; -import org.junit.Test; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLHandshakeException; -import java.io.IOException; -import java.security.GeneralSecurityException; +package com.baeldung.httpclient; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; +import java.io.IOException; +import java.security.GeneralSecurityException; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLHandshakeException; + +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.conn.ssl.TrustStrategy; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.ssl.SSLContextBuilder; +import org.apache.http.ssl.SSLContexts; +import org.junit.Test; + /** * This test requires a localhost server over HTTPS
* It should only be manually run, not part of the automated build @@ -50,16 +49,22 @@ public class HttpsClientSslLiveTest { .getStatusCode(), equalTo(200)); } - @SuppressWarnings("deprecation") @Test public final void givenHttpClientPre4_3_whenAcceptingAllCertificates_thenCanConsumeHttpsUriWithSelfSignedCertificate() throws IOException, GeneralSecurityException { final TrustStrategy acceptingTrustStrategy = (certificate, authType) -> true; - final SSLSocketFactory sf = new SSLSocketFactory(acceptingTrustStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); - final SchemeRegistry registry = new SchemeRegistry(); - registry.register(new Scheme("https", 443, sf)); - final ClientConnectionManager ccm = new PoolingClientConnectionManager(registry); + + final SSLContext sslContext = SSLContexts.custom() + .loadTrustMaterial(null, acceptingTrustStrategy) + .build(); - final CloseableHttpClient httpClient = new DefaultHttpClient(ccm); + final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); + Registry socketFactoryRegistry = RegistryBuilder. create().register("https", sslsf).build(); + PoolingHttpClientConnectionManager clientConnectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry); + + final CloseableHttpClient httpClient = HttpClients.custom() + .setSSLSocketFactory(sslsf) + .setConnectionManager(clientConnectionManager) + .build(); final HttpGet getMethod = new HttpGet(HOST_WITH_SSL); final HttpResponse response = httpClient.execute(getMethod); @@ -76,10 +81,9 @@ public class HttpsClientSslLiveTest { .loadTrustMaterial(null, acceptingTrustStrategy) .build(); - final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); + final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); final CloseableHttpClient httpClient = HttpClients.custom() - .setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) .setSSLSocketFactory(sslsf) .build(); diff --git a/httpclient/src/test/java/org/baeldung/httpclient/ProgressEntityWrapper.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/ProgressEntityWrapper.java similarity index 98% rename from httpclient/src/test/java/org/baeldung/httpclient/ProgressEntityWrapper.java rename to httpclient-simple/src/test/java/com/baeldung/httpclient/ProgressEntityWrapper.java index cd00d8711a..c7adf51b3e 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/ProgressEntityWrapper.java +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/ProgressEntityWrapper.java @@ -1,4 +1,4 @@ -package org.baeldung.httpclient; +package com.baeldung.httpclient; import java.io.FilterOutputStream; import java.io.IOException; diff --git a/httpclient-simple/src/test/java/com/baeldung/httpclient/ResponseUtil.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/ResponseUtil.java new file mode 100644 index 0000000000..e9ea08a723 --- /dev/null +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/ResponseUtil.java @@ -0,0 +1,26 @@ +package com.baeldung.httpclient; + +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; + +import java.io.IOException; + +public final class ResponseUtil { + private ResponseUtil() { + } + + public static void closeResponse(CloseableHttpResponse response) throws IOException { + if (response == null) { + return; + } + + try { + final HttpEntity entity = response.getEntity(); + if (entity != null) { + entity.getContent().close(); + } + } finally { + response.close(); + } + } +} diff --git a/httpclient/src/test/java/org/baeldung/httpclient/base/HttpClientBasicLiveTest.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/base/HttpClientBasicLiveTest.java similarity index 96% rename from httpclient/src/test/java/org/baeldung/httpclient/base/HttpClientBasicLiveTest.java rename to httpclient-simple/src/test/java/com/baeldung/httpclient/base/HttpClientBasicLiveTest.java index fee9dc4343..d1b093394e 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/base/HttpClientBasicLiveTest.java +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/base/HttpClientBasicLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.httpclient.base; +package com.baeldung.httpclient.base; import org.apache.http.HttpStatus; import org.apache.http.client.ClientProtocolException; @@ -8,7 +8,7 @@ import org.apache.http.entity.ContentType; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; -import org.baeldung.httpclient.ResponseUtil; +import com.baeldung.httpclient.ResponseUtil; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientAuthLiveTest.java similarity index 95% rename from httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java rename to httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientAuthLiveTest.java index c9956e5852..0f7018a9ac 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientAuthLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.httpclient.sec; +package com.baeldung.httpclient.sec; import org.apache.commons.codec.binary.Base64; import org.apache.http.HttpHeaders; @@ -17,25 +17,24 @@ import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.protocol.HttpContext; -import org.baeldung.httpclient.ResponseUtil; +import com.baeldung.httpclient.ResponseUtil; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.io.IOException; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; /* - * NOTE : Need module spring-security-rest-basic-auth to be running + * NOTE : Need module httpclient-simple to be running */ public class HttpClientAuthLiveTest { - private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://localhost:8081/spring-security-rest-basic-auth/api/foos/1"; + private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://localhost:8082/httpclient-simple/api/foos/1"; private static final String DEFAULT_USER = "user1"; private static final String DEFAULT_PASS = "user1Pass"; @@ -111,7 +110,7 @@ public class HttpClientAuthLiveTest { } private HttpContext context() { - final HttpHost targetHost = new HttpHost("localhost", 8080, "http"); + final HttpHost targetHost = new HttpHost("localhost", 8082, "http"); final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(DEFAULT_USER, DEFAULT_PASS)); diff --git a/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientCookieLiveTest.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientCookieLiveTest.java similarity index 97% rename from httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientCookieLiveTest.java rename to httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientCookieLiveTest.java index ba27aca08d..287b6e996c 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientCookieLiveTest.java +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientCookieLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.httpclient.sec; +package com.baeldung.httpclient.sec; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.CloseableHttpResponse; @@ -10,7 +10,7 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.cookie.BasicClientCookie; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; -import org.baeldung.httpclient.ResponseUtil; +import com.baeldung.httpclient.ResponseUtil; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/spring-security-rest-basic-auth/src/test/java/org/baeldung/test/LiveTestSuite.java b/httpclient-simple/src/test/java/com/baeldung/test/LiveTestSuite.java similarity index 64% rename from spring-security-rest-basic-auth/src/test/java/org/baeldung/test/LiveTestSuite.java rename to httpclient-simple/src/test/java/com/baeldung/test/LiveTestSuite.java index 8c9b48d056..c864349e02 100644 --- a/spring-security-rest-basic-auth/src/test/java/org/baeldung/test/LiveTestSuite.java +++ b/httpclient-simple/src/test/java/com/baeldung/test/LiveTestSuite.java @@ -1,7 +1,7 @@ -package org.baeldung.test; +package com.baeldung.test; -import org.baeldung.client.ClientLiveTest; -import org.baeldung.client.RestClientLiveManualTest; +import com.baeldung.client.ClientLiveTest; +import com.baeldung.client.RestClientLiveManualTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; diff --git a/httpclient-simple/src/test/resources/.gitignore b/httpclient-simple/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/httpclient-simple/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/httpclient-simple/src/test/resources/test.in b/httpclient-simple/src/test/resources/test.in new file mode 100644 index 0000000000..95d09f2b10 --- /dev/null +++ b/httpclient-simple/src/test/resources/test.in @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/httpclient/README.md b/httpclient/README.md index c5956068c6..a5fc29b089 100644 --- a/httpclient/README.md +++ b/httpclient/README.md @@ -7,14 +7,10 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: -- [HttpClient 4 – Send Custom Cookie](http://www.baeldung.com/httpclient-4-cookies) -- [HttpClient 4 – Get the Status Code](http://www.baeldung.com/httpclient-status-code) - [HttpClient 4 – Cancel Request](http://www.baeldung.com/httpclient-cancel-request) - [HttpClient 4 Cookbook](http://www.baeldung.com/httpclient4) - [Unshorten URLs with HttpClient](http://www.baeldung.com/unshorten-url-httpclient) - [HttpClient 4 – Follow Redirects for POST](http://www.baeldung.com/httpclient-redirect-on-http-post) -- [Custom HTTP Header with the HttpClient](http://www.baeldung.com/httpclient-custom-http-header) -- [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication) - [Multipart Upload with HttpClient 4](http://www.baeldung.com/httpclient-multipart-upload) - [HttpAsyncClient Tutorial](http://www.baeldung.com/httpasyncclient-tutorial) - [HttpClient 4 Tutorial](http://www.baeldung.com/httpclient-guide) diff --git a/httpclient/pom.xml b/httpclient/pom.xml index c9f9808ede..def3a05816 100644 --- a/httpclient/pom.xml +++ b/httpclient/pom.xml @@ -122,11 +122,10 @@ 19.0 3.5 1.10 - 4.1.2 + 4.1.4 2.5.1 - 4.4.5 - 4.5.3 + 4.5.8 1.6.1
diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpAsyncClientLiveTest.java b/httpclient/src/test/java/org/baeldung/httpclient/HttpAsyncClientLiveTest.java index d39697c0a9..47a587885e 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/HttpAsyncClientLiveTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/HttpAsyncClientLiveTest.java @@ -4,7 +4,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; import java.io.IOException; -import java.security.cert.X509Certificate; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -18,8 +17,7 @@ import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLContexts; +import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.conn.ssl.TrustStrategy; import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.BasicCredentialsProvider; @@ -31,6 +29,7 @@ import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor; import org.apache.http.nio.reactor.ConnectingIOReactor; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; +import org.apache.http.ssl.SSLContexts; import org.junit.Test; public class HttpAsyncClientLiveTest { @@ -104,7 +103,7 @@ public class HttpAsyncClientLiveTest { final TrustStrategy acceptingTrustStrategy = (certificate, authType) -> true; final SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(); - final CloseableHttpAsyncClient client = HttpAsyncClients.custom().setSSLHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER).setSSLContext(sslContext).build(); + final CloseableHttpAsyncClient client = HttpAsyncClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).setSSLContext(sslContext).build(); client.start(); final HttpGet request = new HttpGet(HOST_WITH_SSL); diff --git a/httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java b/httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java index 0f8ebefe6c..cf945098db 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java @@ -327,7 +327,8 @@ public class HttpClientConnectionManagementLiveTest { // 8.1 public final void whenHttpClientChecksStaleConns_thenNoExceptions() { poolingConnManager = new PoolingHttpClientConnectionManager(); - client = HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom().setStaleConnectionCheckEnabled(true).build()).setConnectionManager(poolingConnManager).build(); + poolingConnManager.setValidateAfterInactivity(1000); + client = HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom().build()).setConnectionManager(poolingConnManager).build(); } @Test diff --git a/hystrix/pom.xml b/hystrix/pom.xml index fb044588de..7bb3e98246 100644 --- a/hystrix/pom.xml +++ b/hystrix/pom.xml @@ -64,8 +64,6 @@ 1.5.8 0.20.7 - - 1.3 2.6 2.7 diff --git a/jackson-2/.gitignore b/jackson-2/.gitignore index 83c05e60c8..4b1cfaf098 100644 --- a/jackson-2/.gitignore +++ b/jackson-2/.gitignore @@ -10,4 +10,7 @@ # Packaged files # *.jar *.war -*.ear \ No newline at end of file +*.ear + +# Files +/src/main/resources/orderOutput.yaml \ No newline at end of file diff --git a/jackson-2/README.md b/jackson-2/README.md index ec147f5fd9..96ed960ac2 100644 --- a/jackson-2/README.md +++ b/jackson-2/README.md @@ -7,3 +7,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [Mapping Multiple JSON Fields to a Single Java Field](https://www.baeldung.com/json-multiple-fields-single-java-field) +- [Working with Tree Model Nodes in Jackson](https://www.baeldung.com/jackson-json-node-tree-model) diff --git a/jackson-2/pom.xml b/jackson-2/pom.xml index ddbcb81dcc..6b973dd6f5 100644 --- a/jackson-2/pom.xml +++ b/jackson-2/pom.xml @@ -22,6 +22,20 @@ ${jackson.version}
+ + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + 2.9.8 + + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.9.8 + + diff --git a/jackson-2/src/main/java/com/baeldung/jackson/entities/Order.java b/jackson-2/src/main/java/com/baeldung/jackson/entities/Order.java new file mode 100644 index 0000000000..2075b7879b --- /dev/null +++ b/jackson-2/src/main/java/com/baeldung/jackson/entities/Order.java @@ -0,0 +1,68 @@ +package com.baeldung.jackson.entities; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +public class Order { + private String orderNo; + private LocalDate date; + private String customerName; + private List orderLines; + + public Order() { + + } + + public Order(String orderNo, LocalDate date, String customerName, List orderLines) { + super(); + this.orderNo = orderNo; + this.date = date; + this.customerName = customerName; + this.orderLines = orderLines; + } + + public String getOrderNo() { + return orderNo; + } + + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } + + public LocalDate getDate() { + return date; + } + + public void setDate(LocalDate date) { + this.date = date; + } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public List getOrderLines() { + if (orderLines == null) { + orderLines = new ArrayList<>(); + } + return orderLines; + } + + public void setOrderLines(List orderLines) { + if (orderLines == null) { + orderLines = new ArrayList<>(); + } + this.orderLines = orderLines; + } + + @Override + public String toString() { + return "Order [orderNo=" + orderNo + ", date=" + date + ", customerName=" + customerName + ", orderLines=" + orderLines + "]"; + } + +} diff --git a/jackson-2/src/main/java/com/baeldung/jackson/entities/OrderLine.java b/jackson-2/src/main/java/com/baeldung/jackson/entities/OrderLine.java new file mode 100644 index 0000000000..858d094dd1 --- /dev/null +++ b/jackson-2/src/main/java/com/baeldung/jackson/entities/OrderLine.java @@ -0,0 +1,49 @@ +package com.baeldung.jackson.entities; + +import java.math.BigDecimal; + +public class OrderLine { + private String item; + private int quantity; + private BigDecimal unitPrice; + + public OrderLine() { + + } + + public OrderLine(String item, int quantity, BigDecimal unitPrice) { + super(); + this.item = item; + this.quantity = quantity; + this.unitPrice = unitPrice; + } + + public String getItem() { + return item; + } + + public void setItem(String item) { + this.item = item; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public BigDecimal getUnitPrice() { + return unitPrice; + } + + public void setUnitPrice(BigDecimal unitPrice) { + this.unitPrice = unitPrice; + } + + @Override + public String toString() { + return "OrderLine [item=" + item + ", quantity=" + quantity + ", unitPrice=" + unitPrice + "]"; + } +} diff --git a/jackson-2/src/main/java/com/baeldung/jackson/node/JsonNodeIterator.java b/jackson-2/src/main/java/com/baeldung/jackson/node/JsonNodeIterator.java new file mode 100644 index 0000000000..f582772587 --- /dev/null +++ b/jackson-2/src/main/java/com/baeldung/jackson/node/JsonNodeIterator.java @@ -0,0 +1,62 @@ +package com.baeldung.jackson.node; + +import java.util.Iterator; +import java.util.Map.Entry; + +import com.fasterxml.jackson.databind.JsonNode; + +public class JsonNodeIterator { + + private static final String NEW_LINE = "\n"; + private static final String FIELD_DELIMITER = ": "; + private static final String ARRAY_PREFIX = "- "; + private static final String YAML_PREFIX = " "; + + public String toYaml(JsonNode root) { + StringBuilder yaml = new StringBuilder(); + processNode(root, yaml, 0); + return yaml.toString(); + } + + private void processNode(JsonNode jsonNode, StringBuilder yaml, int depth) { + if (jsonNode.isValueNode()) { + yaml.append(jsonNode.asText()); + } + else if (jsonNode.isArray()) { + for (JsonNode arrayItem : jsonNode) { + appendNodeToYaml(arrayItem, yaml, depth, true); + } + } + else if (jsonNode.isObject()) { + appendNodeToYaml(jsonNode, yaml, depth, false); + } + } + + private void appendNodeToYaml(JsonNode node, StringBuilder yaml, int depth, boolean isArrayItem) { + Iterator> fields = node.fields(); + boolean isFirst = true; + while (fields.hasNext()) { + Entry jsonField = fields.next(); + addFieldNameToYaml(yaml, jsonField.getKey(), depth, isArrayItem && isFirst); + processNode(jsonField.getValue(), yaml, depth+1); + isFirst = false; + } + + } + +private void addFieldNameToYaml(StringBuilder yaml, String fieldName, int depth, boolean isFirstInArray) { + if (yaml.length()>0) { + yaml.append(NEW_LINE); + int requiredDepth = (isFirstInArray) ? depth-1 : depth; + for(int i = 0; i < requiredDepth; i++) { + yaml.append(YAML_PREFIX); + } + if (isFirstInArray) { + yaml.append(ARRAY_PREFIX); + } + } + yaml.append(fieldName); + yaml.append(FIELD_DELIMITER); +} + +} diff --git a/jackson-2/src/main/resources/orderInput.yaml b/jackson-2/src/main/resources/orderInput.yaml new file mode 100644 index 0000000000..0aaa6186a2 --- /dev/null +++ b/jackson-2/src/main/resources/orderInput.yaml @@ -0,0 +1,11 @@ +orderNo: A001 +date: 2019-04-17 +customerName: Customer, Joe +orderLines: + - item: No. 9 Sprockets + quantity: 12 + unitPrice: 1.23 + - item: Widget (10mm) + quantity: 4 + unitPrice: 3.45 + \ No newline at end of file diff --git a/jackson/src/test/java/com/baeldung/jackson/node/ExampleStructure.java b/jackson-2/src/test/java/com/baeldung/jackson/node/ExampleStructure.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/node/ExampleStructure.java rename to jackson-2/src/test/java/com/baeldung/jackson/node/ExampleStructure.java diff --git a/jackson-2/src/test/java/com/baeldung/jackson/node/JsonNodeIteratorUnitTest.java b/jackson-2/src/test/java/com/baeldung/jackson/node/JsonNodeIteratorUnitTest.java new file mode 100644 index 0000000000..05426fc844 --- /dev/null +++ b/jackson-2/src/test/java/com/baeldung/jackson/node/JsonNodeIteratorUnitTest.java @@ -0,0 +1,37 @@ +package com.baeldung.jackson.node; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.junit.Test; + +import com.fasterxml.jackson.databind.JsonNode; + +public class JsonNodeIteratorUnitTest { + + private JsonNodeIterator onTest = new JsonNodeIterator(); + private static String expectedYaml = "name: \n" + + " first: Tatu\n" + + " last: Saloranta\n" + + "title: Jackson founder\n" + + "company: FasterXML\n" + + "pets: \n" + + "- type: dog\n" + + " number: 1\n" + + "- type: fish\n" + + " number: 50"; + +@Test +public void givenANodeTree_whenIteratingSubNodes_thenWeFindExpected() throws IOException { + final JsonNode rootNode = ExampleStructure.getExampleRoot(); + + String yaml = onTest.toYaml(rootNode); + System.out.println(yaml.toString()); + + assertEquals(expectedYaml, yaml); + +} + + +} diff --git a/jackson/src/test/java/com/baeldung/jackson/node/NodeBean.java b/jackson-2/src/test/java/com/baeldung/jackson/node/NodeBean.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/node/NodeBean.java rename to jackson-2/src/test/java/com/baeldung/jackson/node/NodeBean.java diff --git a/jackson/src/test/java/com/baeldung/jackson/node/NodeOperationUnitTest.java b/jackson-2/src/test/java/com/baeldung/jackson/node/NodeOperationUnitTest.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/node/NodeOperationUnitTest.java rename to jackson-2/src/test/java/com/baeldung/jackson/node/NodeOperationUnitTest.java diff --git a/jackson-2/src/test/java/com/baeldung/jackson/yaml/YamlUnitTest.java b/jackson-2/src/test/java/com/baeldung/jackson/yaml/YamlUnitTest.java new file mode 100644 index 0000000000..3ed84db60e --- /dev/null +++ b/jackson-2/src/test/java/com/baeldung/jackson/yaml/YamlUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.jackson.yaml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.jackson.entities.Order; +import com.baeldung.jackson.entities.OrderLine; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature; + +public class YamlUnitTest { + private ObjectMapper mapper; + + @Before + public void setup() { + mapper = new ObjectMapper(new YAMLFactory().disable(Feature.WRITE_DOC_START_MARKER)); + mapper.findAndRegisterModules(); + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + } + + @Test + public void givenYamlInput_ObjectCreated() throws JsonParseException, JsonMappingException, IOException { + Order order = mapper.readValue(new File("src/main/resources/orderInput.yaml"), Order.class); + assertEquals("A001", order.getOrderNo()); + assertEquals(LocalDate.parse("2019-04-17", DateTimeFormatter.ISO_DATE), order.getDate()); + assertEquals("Customer, Joe", order.getCustomerName()); + assertEquals(2, order.getOrderLines() + .size()); + } + + @Test + public void givenYamlObject_FileWritten() throws JsonGenerationException, JsonMappingException, IOException { + List lines = new ArrayList<>(); + lines.add(new OrderLine("Copper Wire (200ft)", 1, new BigDecimal(50.67).setScale(2, RoundingMode.HALF_UP))); + lines.add(new OrderLine("Washers (1/4\")", 24, new BigDecimal(.15).setScale(2, RoundingMode.HALF_UP))); + Order order = new Order( + "B-9910", + LocalDate.parse("2019-04-18", DateTimeFormatter.ISO_DATE), + "Customer, Jane", + lines); + mapper.writeValue(new File("src/main/resources/orderOutput.yaml"), order); + + File outputYaml = new File("src/main/resources/orderOutput.yaml"); + assertTrue(outputYaml.exists()); + } +} diff --git a/jackson-2/src/test/resources/node_example.json b/jackson-2/src/test/resources/node_example.json new file mode 100644 index 0000000000..d57c1df6e3 --- /dev/null +++ b/jackson-2/src/test/resources/node_example.json @@ -0,0 +1,18 @@ +{ + "name": { + "first": "Tatu", + "last": "Saloranta" + }, + "title": "Jackson founder", + "company": "FasterXML", + "pets": [ + { + "type": "dog", + "number": 1 + }, + { + "type": "fish", + "number": 50 + } + ] +} \ No newline at end of file diff --git a/jackson-simple/.gitignore b/jackson-simple/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/jackson-simple/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/jackson-simple/README.md b/jackson-simple/README.md new file mode 100644 index 0000000000..be647e22d5 --- /dev/null +++ b/jackson-simple/README.md @@ -0,0 +1,13 @@ +========= +### Jackson Articles that are also part of the e-book + +###The Course +The "REST With Spring" Classes: http://bit.ly/restwithspring + +### Relevant Articles: +- [Jackson Ignore Properties on Marshalling](http://www.baeldung.com/jackson-ignore-properties-on-serialization) +- [Jackson Unmarshalling json with Unknown Properties](http://www.baeldung.com/jackson-deserialize-json-unknown-properties) +- [Jackson Annotation Examples](http://www.baeldung.com/jackson-annotations) +- [Intro to the Jackson ObjectMapper](http://www.baeldung.com/jackson-object-mapper-tutorial) +- [Ignore Null Fields with Jackson](http://www.baeldung.com/jackson-ignore-null-fields) +- [Jackson – Change Name of Field](http://www.baeldung.com/jackson-name-of-property) diff --git a/jackson-simple/pom.xml b/jackson-simple/pom.xml new file mode 100644 index 0000000000..5023ad87b6 --- /dev/null +++ b/jackson-simple/pom.xml @@ -0,0 +1,131 @@ + + 4.0.0 + jackson-simple + 0.1-SNAPSHOT + jackson-simple + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../parent-java + + + + + + commons-io + commons-io + ${commons-io.version} + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + ${jackson.version} + + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.version} + + + + com.fasterxml.jackson.datatype + jackson-datatype-joda + ${jackson.version} + + + + com.fasterxml.jackson.module + jackson-module-jsonSchema + ${jackson.version} + + + + com.fasterxml.jackson.datatype + jackson-datatype-jdk8 + ${jackson.version} + + + + joda-time + joda-time + ${joda-time.version} + + + + com.google.code.gson + gson + ${gson.version} + + + + + + io.rest-assured + json-schema-validator + ${rest-assured.version} + test + + + + io.rest-assured + json-path + ${rest-assured.version} + test + + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + jackson-simple + + + src/main/resources + true + + + + + + + 3.8 + 2.10 + 2.8.5 + 4.2 + + + 3.1.1 + 3.11.0 + + + diff --git a/jackson-simple/src/main/resources/logback.xml b/jackson-simple/src/main/resources/logback.xml new file mode 100644 index 0000000000..56af2d397e --- /dev/null +++ b/jackson-simple/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 diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/AliasBean.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/AliasBean.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/AliasBean.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/AliasBean.java diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithCreator.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithCreator.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithCreator.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithCreator.java diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithCustomAnnotation.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithCustomAnnotation.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithCustomAnnotation.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithCustomAnnotation.java diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithFilter.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithFilter.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithFilter.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithFilter.java diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithGetter.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithGetter.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithGetter.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithGetter.java diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithIgnore.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithIgnore.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithIgnore.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithIgnore.java diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithInject.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithInject.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithInject.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithInject.java diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/ExtendableBean.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/ExtendableBean.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/ExtendableBean.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/ExtendableBean.java diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/MyBean.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/MyBean.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/MyBean.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/MyBean.java diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/PrivateBean.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/PrivateBean.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/PrivateBean.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/PrivateBean.java diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/RawBean.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/RawBean.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/RawBean.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/RawBean.java diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/UnwrappedUser.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/UnwrappedUser.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/UnwrappedUser.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/UnwrappedUser.java diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/UserWithIgnoreType.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/UserWithIgnoreType.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/UserWithIgnoreType.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/UserWithIgnoreType.java diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/Zoo.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/Zoo.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/annotation/Zoo.java rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/Zoo.java diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithIdentity.java b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithIdentity.java new file mode 100644 index 0000000000..25de4a8f7a --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithIdentity.java @@ -0,0 +1,21 @@ +package com.baeldung.jackson.bidirection; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") +public class ItemWithIdentity { + public int id; + public String itemName; + public UserWithIdentity owner; + + public ItemWithIdentity() { + super(); + } + + public ItemWithIdentity(final int id, final String itemName, final UserWithIdentity owner) { + this.id = id; + this.itemName = itemName; + this.owner = owner; + } +} diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithIgnore.java b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithIgnore.java new file mode 100644 index 0000000000..910ccec174 --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithIgnore.java @@ -0,0 +1,17 @@ +package com.baeldung.jackson.bidirection; + +public class ItemWithIgnore { + public int id; + public String itemName; + public UserWithIgnore owner; + + public ItemWithIgnore() { + super(); + } + + public ItemWithIgnore(final int id, final String itemName, final UserWithIgnore owner) { + this.id = id; + this.itemName = itemName; + this.owner = owner; + } +} diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithRef.java b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithRef.java new file mode 100644 index 0000000000..0ca8d721e8 --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithRef.java @@ -0,0 +1,21 @@ +package com.baeldung.jackson.bidirection; + +import com.fasterxml.jackson.annotation.JsonManagedReference; + +public class ItemWithRef { + public int id; + public String itemName; + + @JsonManagedReference + public UserWithRef owner; + + public ItemWithRef() { + super(); + } + + public ItemWithRef(final int id, final String itemName, final UserWithRef owner) { + this.id = id; + this.itemName = itemName; + this.owner = owner; + } +} diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithIdentity.java b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithIdentity.java new file mode 100644 index 0000000000..db83a09389 --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithIdentity.java @@ -0,0 +1,28 @@ +package com.baeldung.jackson.bidirection; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") +public class UserWithIdentity { + public int id; + public String name; + public List userItems; + + public UserWithIdentity() { + super(); + } + + public UserWithIdentity(final int id, final String name) { + this.id = id; + this.name = name; + userItems = new ArrayList(); + } + + public void addItem(final ItemWithIdentity item) { + userItems.add(item); + } +} diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithIgnore.java b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithIgnore.java new file mode 100644 index 0000000000..857a373cc5 --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithIgnore.java @@ -0,0 +1,28 @@ +package com.baeldung.jackson.bidirection; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +public class UserWithIgnore { + public int id; + public String name; + + @JsonIgnore + public List userItems; + + public UserWithIgnore() { + super(); + } + + public UserWithIgnore(final int id, final String name) { + this.id = id; + this.name = name; + userItems = new ArrayList(); + } + + public void addItem(final ItemWithIgnore item) { + userItems.add(item); + } +} diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithRef.java b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithRef.java new file mode 100644 index 0000000000..3de03fc651 --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithRef.java @@ -0,0 +1,28 @@ +package com.baeldung.jackson.bidirection; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonBackReference; + +public class UserWithRef { + public int id; + public String name; + + @JsonBackReference + public List userItems; + + public UserWithRef() { + super(); + } + + public UserWithRef(final int id, final String name) { + this.id = id; + this.name = name; + userItems = new ArrayList(); + } + + public void addItem(final ItemWithRef item) { + userItems.add(item); + } +} diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/date/CustomDateDeserializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/date/CustomDateDeserializer.java new file mode 100644 index 0000000000..90c7d9fbac --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/date/CustomDateDeserializer.java @@ -0,0 +1,36 @@ +package com.baeldung.jackson.date; + +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; + +public class CustomDateDeserializer extends StdDeserializer { + + private static final long serialVersionUID = -5451717385630622729L; + private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"); + + public CustomDateDeserializer() { + this(null); + } + + public CustomDateDeserializer(final Class vc) { + super(vc); + } + + @Override + public Date deserialize(final JsonParser jsonparser, final DeserializationContext context) throws IOException, JsonProcessingException { + final String date = jsonparser.getText(); + try { + return formatter.parse(date); + } catch (final ParseException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/date/CustomDateSerializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/date/CustomDateSerializer.java new file mode 100644 index 0000000000..d840e1940f --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/date/CustomDateSerializer.java @@ -0,0 +1,29 @@ +package com.baeldung.jackson.date; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +public class CustomDateSerializer extends StdSerializer { + + private static final long serialVersionUID = -2894356342227378312L; + private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"); + + public CustomDateSerializer() { + this(null); + } + + public CustomDateSerializer(final Class t) { + super(t); + } + + @Override + public void serialize(final Date value, final JsonGenerator gen, final SerializerProvider arg2) throws IOException, JsonProcessingException { + gen.writeString(formatter.format(value)); + } +} diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/date/EventWithFormat.java b/jackson-simple/src/test/java/com/baeldung/jackson/date/EventWithFormat.java new file mode 100644 index 0000000000..607e694cef --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/date/EventWithFormat.java @@ -0,0 +1,29 @@ +package com.baeldung.jackson.date; + +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonFormat; + +public class EventWithFormat { + public String name; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss") + public Date eventDate; + + public EventWithFormat() { + super(); + } + + public EventWithFormat(final String name, final Date eventDate) { + this.name = name; + this.eventDate = eventDate; + } + + public Date getEventDate() { + return eventDate; + } + + public String getName() { + return name; + } +} diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/date/EventWithSerializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/date/EventWithSerializer.java new file mode 100644 index 0000000000..c359b5c846 --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/date/EventWithSerializer.java @@ -0,0 +1,31 @@ +package com.baeldung.jackson.date; + +import java.util.Date; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +public class EventWithSerializer { + public String name; + + @JsonDeserialize(using = CustomDateDeserializer.class) + @JsonSerialize(using = CustomDateSerializer.class) + public Date eventDate; + + public EventWithSerializer() { + super(); + } + + public EventWithSerializer(final String name, final Date eventDate) { + this.name = name; + this.eventDate = eventDate; + } + + public Date getEventDate() { + return eventDate; + } + + public String getName() { + return name; + } +} diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializerOnClass.java b/jackson-simple/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializerOnClass.java new file mode 100644 index 0000000000..eaba9a7173 --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializerOnClass.java @@ -0,0 +1,41 @@ +package com.baeldung.jackson.deserialization; + +import java.io.IOException; + +import com.baeldung.jackson.dtos.ItemWithSerializer; +import com.baeldung.jackson.dtos.User; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.node.IntNode; + +public class ItemDeserializerOnClass extends StdDeserializer { + + private static final long serialVersionUID = 5579141241817332594L; + + public ItemDeserializerOnClass() { + this(null); + } + + public ItemDeserializerOnClass(final Class vc) { + super(vc); + } + + /** + * {"id":1,"itemNr":"theItem","owner":2} + */ + @Override + public ItemWithSerializer deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { + final JsonNode node = jp.getCodec() + .readTree(jp); + final int id = (Integer) ((IntNode) node.get("id")).numberValue(); + final String itemName = node.get("itemName") + .asText(); + final int userId = (Integer) ((IntNode) node.get("owner")).numberValue(); + + return new ItemWithSerializer(id, itemName, new User(userId, null)); + } + +} \ No newline at end of file diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/dtos/Item.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/Item.java new file mode 100644 index 0000000000..6fce2bc88e --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/Item.java @@ -0,0 +1,32 @@ +package com.baeldung.jackson.dtos; + +public class Item { + public int id; + public String itemName; + public User owner; + + public Item() { + super(); + } + + public Item(final int id, final String itemName, final User owner) { + this.id = id; + this.itemName = itemName; + this.owner = owner; + } + + // API + + public int getId() { + return id; + } + + public String getItemName() { + return itemName; + } + + public User getOwner() { + return owner; + } + +} \ No newline at end of file diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/dtos/ItemWithSerializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/ItemWithSerializer.java new file mode 100644 index 0000000000..aea9aa770d --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/ItemWithSerializer.java @@ -0,0 +1,36 @@ +package com.baeldung.jackson.dtos; + +import com.baeldung.jackson.deserialization.ItemDeserializerOnClass; +import com.baeldung.jackson.serialization.ItemSerializerOnClass; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +@JsonSerialize(using = ItemSerializerOnClass.class) +@JsonDeserialize(using = ItemDeserializerOnClass.class) +public class ItemWithSerializer { + public final int id; + public final String itemName; + public final User owner; + + public ItemWithSerializer(final int id, final String itemName, final User owner) { + this.id = id; + this.itemName = itemName; + this.owner = owner; + } + + // API + + public int getId() { + return id; + } + + public String getItemName() { + return itemName; + } + + public User getOwner() { + return owner; + } + +} \ No newline at end of file diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDto.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDto.java new file mode 100644 index 0000000000..49cf07baea --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDto.java @@ -0,0 +1,54 @@ +package com.baeldung.jackson.dtos; + +public class MyDto { + + private String stringValue; + private int intValue; + private boolean booleanValue; + + public MyDto() { + super(); + } + + public MyDto(final String stringValue, final int intValue, final boolean booleanValue) { + super(); + + this.stringValue = stringValue; + this.intValue = intValue; + this.booleanValue = booleanValue; + } + + // API + + public String getStringValue() { + return stringValue; + } + + public void setStringValue(final String stringValue) { + this.stringValue = stringValue; + } + + public int getIntValue() { + return intValue; + } + + public void setIntValue(final int intValue) { + this.intValue = intValue; + } + + public boolean isBooleanValue() { + return booleanValue; + } + + public void setBooleanValue(final boolean booleanValue) { + this.booleanValue = booleanValue; + } + + // + + @Override + public String toString() { + return "MyDto [stringValue=" + stringValue + ", intValue=" + intValue + ", booleanValue=" + booleanValue + "]"; + } + +} diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoFieldNameChanged.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoFieldNameChanged.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoFieldNameChanged.java rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoFieldNameChanged.java diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoIncludeNonDefault.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoIncludeNonDefault.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoIncludeNonDefault.java rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoIncludeNonDefault.java diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessors.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessors.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessors.java rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessors.java diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessorsAndFieldVisibility.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessorsAndFieldVisibility.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessorsAndFieldVisibility.java rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessorsAndFieldVisibility.java diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoWithFilter.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoWithFilter.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoWithFilter.java rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoWithFilter.java diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoWithSpecialField.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoWithSpecialField.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoWithSpecialField.java rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoWithSpecialField.java diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyMixInForIgnoreType.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyMixInForIgnoreType.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyMixInForIgnoreType.java rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyMixInForIgnoreType.java diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/dtos/User.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/User.java new file mode 100644 index 0000000000..2418e8070d --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/User.java @@ -0,0 +1,26 @@ +package com.baeldung.jackson.dtos; + +public class User { + public int id; + public String name; + + public User() { + super(); + } + + public User(final int id, final String name) { + this.id = id; + this.name = name; + } + + // API + + public int getId() { + return id; + } + + public String getName() { + return name; + } + +} \ No newline at end of file diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreField.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreField.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreField.java rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreField.java diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreFieldByName.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreFieldByName.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreFieldByName.java rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreFieldByName.java diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreNull.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreNull.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreNull.java rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreNull.java diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/dtos/withEnum/DistanceEnumWithValue.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/withEnum/DistanceEnumWithValue.java new file mode 100644 index 0000000000..69c476d8a5 --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/withEnum/DistanceEnumWithValue.java @@ -0,0 +1,29 @@ +package com.baeldung.jackson.dtos.withEnum; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum DistanceEnumWithValue { + KILOMETER("km", 1000), MILE("miles", 1609.34), METER("meters", 1), INCH("inches", 0.0254), CENTIMETER("cm", 0.01), MILLIMETER("mm", 0.001); + + private String unit; + private final double meters; + + private DistanceEnumWithValue(String unit, double meters) { + this.unit = unit; + this.meters = meters; + } + + @JsonValue + public double getMeters() { + return meters; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + +} \ No newline at end of file diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/exception/UserWithRoot.java b/jackson-simple/src/test/java/com/baeldung/jackson/exception/UserWithRoot.java new file mode 100644 index 0000000000..d879c16e6a --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/exception/UserWithRoot.java @@ -0,0 +1,18 @@ +package com.baeldung.jackson.exception; + +import com.fasterxml.jackson.annotation.JsonRootName; + +@JsonRootName(value = "user") +public class UserWithRoot { + public int id; + public String name; + + public UserWithRoot() { + super(); + } + + public UserWithRoot(final int id, final String name) { + this.id = id; + this.name = name; + } +} diff --git a/jackson/src/test/java/com/baeldung/jackson/exception/UserWithRootNamespace.java b/jackson-simple/src/test/java/com/baeldung/jackson/exception/UserWithRootNamespace.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/exception/UserWithRootNamespace.java rename to jackson-simple/src/test/java/com/baeldung/jackson/exception/UserWithRootNamespace.java diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/jsonview/Item.java b/jackson-simple/src/test/java/com/baeldung/jackson/jsonview/Item.java new file mode 100644 index 0000000000..26d20d4847 --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/jsonview/Item.java @@ -0,0 +1,36 @@ +package com.baeldung.jackson.jsonview; + +import com.fasterxml.jackson.annotation.JsonView; + +public class Item { + @JsonView(Views.Public.class) + public int id; + + @JsonView(Views.Public.class) + public String itemName; + + @JsonView(Views.Internal.class) + public String ownerName; + + public Item() { + super(); + } + + public Item(final int id, final String itemName, final String ownerName) { + this.id = id; + this.itemName = itemName; + this.ownerName = ownerName; + } + + public int getId() { + return id; + } + + public String getItemName() { + return itemName; + } + + public String getOwnerName() { + return ownerName; + } +} diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/jsonview/Views.java b/jackson-simple/src/test/java/com/baeldung/jackson/jsonview/Views.java new file mode 100644 index 0000000000..65950b7f9f --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/jsonview/Views.java @@ -0,0 +1,9 @@ +package com.baeldung.jackson.jsonview; + +public class Views { + public static class Public { + } + + public static class Internal extends Public { + } +} diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarDeserializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/CustomCarDeserializer.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarDeserializer.java rename to jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/CustomCarDeserializer.java diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarSerializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/CustomCarSerializer.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarSerializer.java rename to jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/CustomCarSerializer.java diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/JavaReadWriteJsonExampleUnitTest.java b/jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/JavaReadWriteJsonExampleUnitTest.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/objectmapper/JavaReadWriteJsonExampleUnitTest.java rename to jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/JavaReadWriteJsonExampleUnitTest.java diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/SerializationDeserializationFeatureUnitTest.java b/jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/SerializationDeserializationFeatureUnitTest.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/objectmapper/SerializationDeserializationFeatureUnitTest.java rename to jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/SerializationDeserializationFeatureUnitTest.java diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/dto/Car.java b/jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/dto/Car.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/objectmapper/dto/Car.java rename to jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/dto/Car.java diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/dto/Request.java b/jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/dto/Request.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/objectmapper/dto/Request.java rename to jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/dto/Request.java diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/ItemSerializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/serialization/ItemSerializer.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/serialization/ItemSerializer.java rename to jackson-simple/src/test/java/com/baeldung/jackson/serialization/ItemSerializer.java diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/serialization/ItemSerializerOnClass.java b/jackson-simple/src/test/java/com/baeldung/jackson/serialization/ItemSerializerOnClass.java new file mode 100644 index 0000000000..1fdf44e17c --- /dev/null +++ b/jackson-simple/src/test/java/com/baeldung/jackson/serialization/ItemSerializerOnClass.java @@ -0,0 +1,32 @@ +package com.baeldung.jackson.serialization; + +import java.io.IOException; + +import com.baeldung.jackson.dtos.ItemWithSerializer; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +public class ItemSerializerOnClass extends StdSerializer { + + private static final long serialVersionUID = -1760959597313610409L; + + public ItemSerializerOnClass() { + this(null); + } + + public ItemSerializerOnClass(final Class t) { + super(t); + } + + @Override + public final void serialize(final ItemWithSerializer value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { + jgen.writeStartObject(); + jgen.writeNumberField("id", value.id); + jgen.writeStringField("itemName", value.itemName); + jgen.writeNumberField("owner", value.owner.id); + jgen.writeEndObject(); + } + +} \ No newline at end of file diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/MyDtoNullKeySerializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/serialization/MyDtoNullKeySerializer.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/serialization/MyDtoNullKeySerializer.java rename to jackson-simple/src/test/java/com/baeldung/jackson/serialization/MyDtoNullKeySerializer.java diff --git a/jackson/src/test/java/com/baeldung/jackson/test/JacksonAnnotationUnitTest.java b/jackson-simple/src/test/java/com/baeldung/jackson/test/JacksonAnnotationUnitTest.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/test/JacksonAnnotationUnitTest.java rename to jackson-simple/src/test/java/com/baeldung/jackson/test/JacksonAnnotationUnitTest.java diff --git a/jackson/src/test/java/com/baeldung/jackson/test/JacksonSerializationIgnoreUnitTest.java b/jackson-simple/src/test/java/com/baeldung/jackson/test/JacksonSerializationIgnoreUnitTest.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/test/JacksonSerializationIgnoreUnitTest.java rename to jackson-simple/src/test/java/com/baeldung/jackson/test/JacksonSerializationIgnoreUnitTest.java diff --git a/jackson/src/test/java/com/baeldung/jackson/test/JacksonSerializationUnitTest.java b/jackson-simple/src/test/java/com/baeldung/jackson/test/JacksonSerializationUnitTest.java similarity index 100% rename from jackson/src/test/java/com/baeldung/jackson/test/JacksonSerializationUnitTest.java rename to jackson-simple/src/test/java/com/baeldung/jackson/test/JacksonSerializationUnitTest.java diff --git a/jackson-simple/src/test/resources/.gitignore b/jackson-simple/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/jackson-simple/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/jackson/README.md b/jackson/README.md index eeb8f1b874..01d9419a27 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -6,9 +6,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: -- [Jackson Ignore Properties on Marshalling](http://www.baeldung.com/jackson-ignore-properties-on-serialization) - [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array) -- [Jackson Unmarshalling json with Unknown Properties](http://www.baeldung.com/jackson-deserialize-json-unknown-properties) - [Jackson – Custom Serializer](http://www.baeldung.com/jackson-custom-serialization) - [Getting Started with Custom Deserialization in Jackson](http://www.baeldung.com/jackson-deserialization) - [Jackson Exceptions – Problems and Solutions](http://www.baeldung.com/jackson-exception) @@ -17,10 +15,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Jackson JSON Tutorial](http://www.baeldung.com/jackson) - [Jackson – Working with Maps and nulls](http://www.baeldung.com/jackson-map-null-values-or-null-key) - [Jackson – Decide What Fields Get Serialized/Deserialized](http://www.baeldung.com/jackson-field-serializable-deserializable-or-not) -- [Jackson Annotation Examples](http://www.baeldung.com/jackson-annotations) -- [Working with Tree Model Nodes in Jackson](http://www.baeldung.com/jackson-json-node-tree-model) - [Jackson vs Gson](http://www.baeldung.com/jackson-vs-gson) -- [Intro to the Jackson ObjectMapper](http://www.baeldung.com/jackson-object-mapper-tutorial) - [XML Serialization and Deserialization with Jackson](http://www.baeldung.com/jackson-xml-serialization-and-deserialization) - [More Jackson Annotations](http://www.baeldung.com/jackson-advanced-annotations) - [Inheritance with Jackson](http://www.baeldung.com/jackson-inheritance) @@ -31,9 +26,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Jackson – JsonMappingException (No serializer found for class)](http://www.baeldung.com/jackson-jsonmappingexception) - [How To Serialize Enums as JSON Objects with Jackson](http://www.baeldung.com/jackson-serialize-enums) - [Jackson – Marshall String to JsonNode](http://www.baeldung.com/jackson-json-to-jsonnode) -- [Ignore Null Fields with Jackson](http://www.baeldung.com/jackson-ignore-null-fields) - [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array) -- [Jackson – Change Name of Field](http://www.baeldung.com/jackson-name-of-property) - [Serialize Only Fields that meet a Custom Criteria with Jackson](http://www.baeldung.com/jackson-serialize-field-custom-criteria) - [Mapping Nested Values with Jackson](http://www.baeldung.com/jackson-nested-values) - [Convert XML to JSON Using Jackson](https://www.baeldung.com/jackson-convert-xml-json) diff --git a/jackson/src/main/resources/node_example.json b/jackson/src/main/resources/node_example.json deleted file mode 100644 index 69d37efbf6..0000000000 --- a/jackson/src/main/resources/node_example.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": - { - "first": "Tatu", - "last": "Saloranta" - }, - - "title": "Jackson founder", - "company": "FasterXML" -} \ No newline at end of file diff --git a/jackson/src/test/java/com/baeldung/jackson/test/UnitTestSuite.java b/jackson/src/test/java/com/baeldung/jackson/test/UnitTestSuite.java index 6be2f29baa..e783c67f5b 100644 --- a/jackson/src/test/java/com/baeldung/jackson/test/UnitTestSuite.java +++ b/jackson/src/test/java/com/baeldung/jackson/test/UnitTestSuite.java @@ -12,8 +12,6 @@ import org.junit.runners.Suite; ,JacksonDeserializationUnitTest.class ,JacksonDeserializationUnitTest.class ,JacksonPrettyPrintUnitTest.class - ,JacksonSerializationIgnoreUnitTest.class - ,JacksonSerializationUnitTest.class ,SandboxUnitTest.class ,JacksonFieldUnitTest.class }) // @formatter:on diff --git a/java-collections-conversions/src/test/java/com/baeldung/convertcollectiontoarraylist/FooUnitTest.java b/java-collections-conversions/src/test/java/com/baeldung/convertcollectiontoarraylist/FooUnitTest.java index 5be4121bc7..1de600aebf 100644 --- a/java-collections-conversions/src/test/java/com/baeldung/convertcollectiontoarraylist/FooUnitTest.java +++ b/java-collections-conversions/src/test/java/com/baeldung/convertcollectiontoarraylist/FooUnitTest.java @@ -33,9 +33,6 @@ public class FooUnitTest { srcCollection.add(sam); srcCollection.add(alice); srcCollection.add(buffy); - - // make sure the collection isn't sorted accidentally - assertFalse("Oops: source collection is already sorted!", isSorted(srcCollection)); } /** diff --git a/java-collections-maps-2/pom.xml b/java-collections-maps-2/pom.xml index 4ab94a7ae3..5f27eaa2d8 100644 --- a/java-collections-maps-2/pom.xml +++ b/java-collections-maps-2/pom.xml @@ -36,6 +36,17 @@ colt ${colt.version} + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.assertj + assertj-core + ${assertj.version} + test + @@ -43,6 +54,8 @@ 3.0.2 8.1.0 1.2.0 + 3.8.1 + 3.11.1 \ No newline at end of file diff --git a/core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java b/java-collections-maps-2/src/main/java/com/baeldung/map/CopyHashMap.java similarity index 98% rename from core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java rename to java-collections-maps-2/src/main/java/com/baeldung/map/CopyHashMap.java index e1649f593c..2ebc9413c8 100644 --- a/core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java +++ b/java-collections-maps-2/src/main/java/com/baeldung/map/CopyHashMap.java @@ -1,4 +1,4 @@ -package com.baeldung.copyinghashmap; +package com.baeldung.map; import java.util.HashMap; import java.util.Map; diff --git a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java b/java-collections-maps-2/src/test/java/com/baeldung/map/CopyHashMapUnitTest.java similarity index 98% rename from core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java rename to java-collections-maps-2/src/test/java/com/baeldung/map/CopyHashMapUnitTest.java index 400696d97a..c400eea153 100644 --- a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java +++ b/java-collections-maps-2/src/test/java/com/baeldung/map/CopyHashMapUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.copyinghashmap; +package com.baeldung.map; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/Employee.java b/java-collections-maps-2/src/test/java/com/baeldung/map/Employee.java similarity index 91% rename from core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/Employee.java rename to java-collections-maps-2/src/test/java/com/baeldung/map/Employee.java index b47fdc768e..7963fa811c 100644 --- a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/Employee.java +++ b/java-collections-maps-2/src/test/java/com/baeldung/map/Employee.java @@ -1,4 +1,4 @@ -package com.baeldung.copyinghashmap; +package com.baeldung.map; import java.io.Serializable; diff --git a/java-dates-2/pom.xml b/java-dates-2/pom.xml index c2464ed47f..9307a794b9 100644 --- a/java-dates-2/pom.xml +++ b/java-dates-2/pom.xml @@ -15,6 +15,12 @@ + + joda-time + joda-time + ${joda-time.version} + + org.assertj @@ -49,6 +55,7 @@ 3.6.1 + 2.10 1.9 1.9 diff --git a/java-dates-2/src/test/java/com/baeldung/convert/ConvertDateTimeUnitTest.java b/java-dates-2/src/test/java/com/baeldung/convert/ConvertDateTimeUnitTest.java new file mode 100644 index 0000000000..cd31ccc799 --- /dev/null +++ b/java-dates-2/src/test/java/com/baeldung/convert/ConvertDateTimeUnitTest.java @@ -0,0 +1,59 @@ +package com.baeldung.convert; + +import org.joda.time.Instant; +import org.junit.Assert; +import org.junit.Test; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Calendar; +import java.util.Date; + +public class ConvertDateTimeUnitTest { + + public final long millis = 1556175797428L; + + @Test + public void givenLocalDateTime_WhenToEpochMillis_ThenMillis() { + ZoneId id = ZoneId.systemDefault(); + + LocalDateTime localDateTime = + LocalDateTime.ofInstant(java.time.Instant.ofEpochMilli(millis), id); + + ZonedDateTime zdt = ZonedDateTime.of(localDateTime, id); + + Assert.assertEquals(millis, zdt.toInstant().toEpochMilli()); + } + + @Test + public void givenJava8Instant_WhenGToEpochMillis_ThenMillis() { + java.time.Instant instant = java.time.Instant.ofEpochMilli(millis); + Assert.assertEquals(millis, instant.toEpochMilli()); + } + + @Test + public void givenDate_WhenGetTime_ThenMillis() { + Date date = new Date(millis); + Assert.assertEquals(millis, date.getTime()); + } + + @Test + public void givenCalendar_WhenGetTimeInMillis_ThenMillis() { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date(millis)); + Assert.assertEquals(millis, calendar.getTimeInMillis()); + } + + @Test + public void givenJodaInstant_WhenGetMillis_ThenMillis() { + Instant jodaInstant = Instant.ofEpochMilli(millis); + Assert.assertEquals(millis, jodaInstant.getMillis()); + } + + @Test + public void givenJODADateTime_WhenGetMillis_ThenMillis() { + org.joda.time.DateTime jodaDateTime = new org.joda.time.DateTime(millis); + Assert.assertEquals(millis, jodaDateTime.getMillis()); + } +} diff --git a/java-ee-8-security-api/app-auth-basic-store-db/pom.xml b/java-ee-8-security-api/app-auth-basic-store-db/pom.xml index cf92fe2ecd..582e82d8bb 100644 --- a/java-ee-8-security-api/app-auth-basic-store-db/pom.xml +++ b/java-ee-8-security-api/app-auth-basic-store-db/pom.xml @@ -53,7 +53,7 @@ com.h2database h2 - ${h2-version} + ${h2.version} jar ${project.build.directory}/liberty/wlp/usr/servers/defaultServer/lib/global @@ -64,8 +64,4 @@ - - - 1.4.197 - diff --git a/java-ee-8-security-api/app-auth-custom-no-store/pom.xml b/java-ee-8-security-api/app-auth-custom-no-store/pom.xml index f9d63f8623..51ee64097a 100644 --- a/java-ee-8-security-api/app-auth-custom-no-store/pom.xml +++ b/java-ee-8-security-api/app-auth-custom-no-store/pom.xml @@ -53,7 +53,7 @@ com.h2database h2 - ${h2-version} + ${h2.version} jar ${project.build.directory}/liberty/wlp/usr/servers/defaultServer/lib/global @@ -64,8 +64,4 @@ - - - 1.4.197 - diff --git a/java-ee-8-security-api/pom.xml b/java-ee-8-security-api/pom.xml index 0cce84e5f2..9b8356714f 100644 --- a/java-ee-8-security-api/pom.xml +++ b/java-ee-8-security-api/pom.xml @@ -72,7 +72,6 @@ 8.0 2.3 18.0.0.1 - 1.4.197 3.2.2 diff --git a/java-numbers/pom.xml b/java-numbers/pom.xml index eb75f85bf0..daed356f66 100644 --- a/java-numbers/pom.xml +++ b/java-numbers/pom.xml @@ -38,7 +38,7 @@ org.openjdk.jmh jmh-generator-annprocess - ${jmh-generator-annprocess.version} + ${jmh-generator.version} org.apache.commons @@ -127,8 +127,6 @@ 1.7.21 1.1.7 - 1.19 - 1.19 2.21.0 3.0.0-M1 diff --git a/java-streams-2/pom.xml b/java-streams-2/pom.xml index 5004249352..3e08e2f432 100644 --- a/java-streams-2/pom.xml +++ b/java-streams-2/pom.xml @@ -18,12 +18,12 @@ org.openjdk.jmh jmh-core - ${jmh.version} + ${jmh-core.version} org.openjdk.jmh jmh-generator-annprocess - ${jmh.version} + ${jmh-generator.version} junit @@ -44,7 +44,6 @@ UTF-8 1.8 1.8 - 1.21 3.11.1 \ No newline at end of file diff --git a/java-streams/pom.xml b/java-streams/pom.xml index 00384eeead..b0c56ecdf9 100644 --- a/java-streams/pom.xml +++ b/java-streams/pom.xml @@ -18,12 +18,12 @@ org.openjdk.jmh jmh-core - ${jmh.version} + ${jmh-core.version} org.openjdk.jmh jmh-generator-annprocess - ${jmh.version} + ${jmh-generator.version} provided @@ -106,7 +106,6 @@ - 1.21 3.5 0.9.0 1.15 diff --git a/java-strings-2/pom.xml b/java-strings-2/pom.xml new file mode 100755 index 0000000000..5279cf5777 --- /dev/null +++ b/java-strings-2/pom.xml @@ -0,0 +1,148 @@ + + 4.0.0 + java-strings-2 + 0.1.0-SNAPSHOT + jar + java-strings-2 + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../parent-java + + + + + commons-io + commons-io + ${commons-io.version} + + + log4j + log4j + ${log4j.version} + + + commons-codec + commons-codec + ${commons-codec.version} + + + + org.assertj + assertj-core + ${assertj.version} + test + + + org.openjdk.jmh + jmh-core + ${jmh-core.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh-core.version} + + + com.ibm.icu + icu4j + ${icu4j.version} + + + com.google.guava + guava + ${guava.version} + + + com.vdurmont + emoji-java + ${emoji-java.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + junit + junit + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-api + ${junit-jupiter-api.version} + test + + + + org.hamcrest + hamcrest-library + ${org.hamcrest.version} + test + + + + + org.passay + passay + ${passay.version} + + + org.apache.commons + commons-text + ${commons-text.version} + + + + org.ahocorasick + ahocorasick + ${ahocorasick.version} + + + + + + java-strings-2 + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${java.version} + ${java.version} + -parameters + + + + + + + + 3.8.1 + 1.10 + + 3.6.1 + 61.1 + 27.0.1-jre + 4.0.0 + 5.3.1 + 1.3.1 + 1.4 + 0.4.0 + + + \ No newline at end of file diff --git a/java-strings-2/src/main/java/com/baeldung/string/search/performance/SubstringSearchPerformanceComparison.java b/java-strings-2/src/main/java/com/baeldung/string/search/performance/SubstringSearchPerformanceComparison.java new file mode 100644 index 0000000000..bf33c47a7e --- /dev/null +++ b/java-strings-2/src/main/java/com/baeldung/string/search/performance/SubstringSearchPerformanceComparison.java @@ -0,0 +1,58 @@ +package com.baeldung.string.search.performance; + +import java.util.concurrent.TimeUnit; +import java.util.regex.Pattern; + +import org.apache.commons.lang3.StringUtils; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; + +/** + * Based on https://github.com/tedyoung/indexof-contains-benchmark + */ +@Fork(5) +@State(Scope.Benchmark) +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +public class SubstringSearchPerformanceComparison { + + private String message; + + private Pattern pattern; + + public static void main(String[] args) throws Exception { + org.openjdk.jmh.Main.main(args); + } + + @Setup + public void setup() { + message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum"; + pattern = Pattern.compile("(? + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/java-strings-2/src/test/java/com/baeldung/string/search/SubstringSearch.java b/java-strings-2/src/test/java/com/baeldung/string/search/SubstringSearch.java new file mode 100644 index 0000000000..4a5adb45ef --- /dev/null +++ b/java-strings-2/src/test/java/com/baeldung/string/search/SubstringSearch.java @@ -0,0 +1,70 @@ +package com.baeldung.string.search; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.lang3.StringUtils; +import org.junit.Assert; +import org.junit.Test; + +/** + * BAEL-2832: Different ways to check if a Substring could be found in a String. + */ +public class SubstringSearch { + + @Test + public void searchSubstringWithIndexOf() { + Assert.assertEquals(9, "Bohemian Rhapsodyan".indexOf("Rhap")); + + // indexOf will return -1, because it's case sensitive + Assert.assertEquals(-1, "Bohemian Rhapsodyan".indexOf("rhap")); + + // indexOf will return 9, because it's all lowercase + Assert.assertEquals(9, "Bohemian Rhapsodyan".toLowerCase() + .indexOf("rhap")); + + // it will return 6, because it's the first occurrence. Sorry Queen for being blasphemic + Assert.assertEquals(6, "Bohemian Rhapsodyan".indexOf("an")); + } + + @Test + public void searchSubstringWithContains() { + Assert.assertTrue("Hey Ho, let's go".contains("Hey")); + + // contains will return false, because it's case sensitive + Assert.assertFalse("Hey Ho, let's go".contains("hey")); + + // contains will return true, because it's all lowercase + Assert.assertTrue("Hey Ho, let's go".toLowerCase().contains("hey")); + + // contains will return false, because 'jey' can't be found + Assert.assertFalse("Hey Ho, let's go".contains("jey")); + } + + @Test + public void searchSubstringWithStringUtils() { + Assert.assertTrue(StringUtils.containsIgnoreCase("Runaway train", "train")); + + // it will also be true, because ignores case ;) + Assert.assertTrue(StringUtils.containsIgnoreCase("Runaway train", "Train")); + } + + @Test + public void searchUsingPattern() { + + // We create the Pattern first + Pattern pattern = Pattern.compile("(? org.openjdk.jmh jmh-generator-annprocess - ${jmh-core.version} + ${jmh-generator.version} com.ibm.icu @@ -79,7 +79,7 @@ org.hamcrest hamcrest-library - ${hamcrest-library.version} + ${org.hamcrest.version} test @@ -132,12 +132,10 @@ 1.10 3.6.1 - 1.19 61.1 27.0.1-jre 4.0.0 5.3.1 - 1.3 1.3.1 1.4 0.4.0 diff --git a/javax-servlets/pom.xml b/javax-servlets/pom.xml index bf85feb7ce..e3d8a430d9 100644 --- a/javax-servlets/pom.xml +++ b/javax-servlets/pom.xml @@ -48,7 +48,7 @@ javax.servlet.jsp javax.servlet.jsp-api - ${jsp.version} + ${javax.servlet.jsp-api.version} javax.servlet @@ -90,7 +90,5 @@ 1.3.3 2.6 4.0.1 - 1.2 - 2.3.1 diff --git a/jee-7/pom.xml b/jee-7/pom.xml index 62ccb9d313..d389b57cd5 100644 --- a/jee-7/pom.xml +++ b/jee-7/pom.xml @@ -527,10 +527,8 @@ 2.2.14 4.5 2.0.1.Final - 3.1.0 2.1.0.Final 2.8 - 1.2 2.2 20160715 1.0.0.Final @@ -538,7 +536,6 @@ 1.0.0.Final 1.4.2.Final 2.1.1.Final - 1.4.178 2.22.1 diff --git a/jsf/pom.xml b/jsf/pom.xml index fc6d4a0ee2..19f1265250 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -67,7 +67,7 @@ javax.servlet javax.servlet-api provided - ${javax.servlet.version} + ${javax.servlet-api.version} @@ -99,11 +99,6 @@ 2.2.14 3.0.0 - - 3.1.0 - - 1.2 - 2.6 diff --git a/jta/pom.xml b/jta/pom.xml index 6a31733996..b7e39c66e1 100644 --- a/jta/pom.xml +++ b/jta/pom.xml @@ -83,7 +83,6 @@ UTF-8 UTF-8 - 1.8 2.4.1 2.0.4.RELEASE diff --git a/kotlin-libraries-2/.gitignore b/kotlin-libraries-2/.gitignore new file mode 100644 index 0000000000..0c017e8f8c --- /dev/null +++ b/kotlin-libraries-2/.gitignore @@ -0,0 +1,14 @@ +/bin/ + +#ignore gradle +.gradle/ + + +#ignore build and generated files +build/ +node/ +out/ + +#ignore installed node modules and package lock file +node_modules/ +package-lock.json diff --git a/kotlin-libraries-2/README.md b/kotlin-libraries-2/README.md new file mode 100644 index 0000000000..fdb7c2830d --- /dev/null +++ b/kotlin-libraries-2/README.md @@ -0,0 +1,3 @@ +## Relevant articles: + +- [Jackson Support for Kotlin](https://www.baeldung.com/jackson-kotlin) diff --git a/kotlin-libraries-2/pom.xml b/kotlin-libraries-2/pom.xml new file mode 100644 index 0000000000..e2e261cb1b --- /dev/null +++ b/kotlin-libraries-2/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + kotlin-libraries-2 + kotlin-libraries-2 + jar + + + com.baeldung + parent-kotlin + 1.0.0-SNAPSHOT + ../parent-kotlin + + + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + junit + junit + test + + + + + + + + + + diff --git a/kotlin-libraries-2/resources/logback.xml b/kotlin-libraries-2/resources/logback.xml new file mode 100644 index 0000000000..9452207268 --- /dev/null +++ b/kotlin-libraries-2/resources/logback.xml @@ -0,0 +1,11 @@ + + + + %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + \ No newline at end of file diff --git a/kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Book.kt b/kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Book.kt new file mode 100644 index 0000000000..4ff47ea987 --- /dev/null +++ b/kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Book.kt @@ -0,0 +1,8 @@ +package com.baeldung.kotlin.jackson + +import com.fasterxml.jackson.annotation.* + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +data class Book(var title: String, @JsonProperty("author") var authorName: String) { + var genres: List? = emptyList() +} \ No newline at end of file diff --git a/kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Movie.kt b/kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Movie.kt new file mode 100644 index 0000000000..445b6013d5 --- /dev/null +++ b/kotlin-libraries-2/src/main/kotlin/com/baeldung/kotlin/jackson/Movie.kt @@ -0,0 +1,3 @@ +package com.baeldung.kotlin.jackson + +data class Movie(var name: String, var studio: String, var rating: Float? = 1f) \ No newline at end of file diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt new file mode 100644 index 0000000000..84171d9019 --- /dev/null +++ b/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt @@ -0,0 +1,114 @@ +package com.baeldung.kotlin.jackson + +import org.junit.Test +import kotlin.test.assertTrue +import kotlin.test.assertFalse +import kotlin.test.assertEquals +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.KotlinModule + +class JacksonUnitTest { + //val mapper = jacksonObjectMapper() + val mapper = ObjectMapper().registerModule(KotlinModule()) + + + @Test + fun whenSerializeMovie_thenSuccess() { + val movie = Movie("Endgame", "Marvel", 9.2f) + val serialized = mapper.writeValueAsString(movie) + + val json = """{"name":"Endgame","studio":"Marvel","rating":9.2}""" + assertEquals(serialized, json) + } + + @Test + fun whenDeserializeMovie_thenSuccess() { + val json = """{"name":"Endgame","studio":"Marvel","rating":9.2}""" + // val movie: Movie = mapper.readValue(json) + val movie = mapper.readValue(json) + + assertEquals(movie.name, "Endgame") + assertEquals(movie.studio, "Marvel") + assertEquals(movie.rating, 9.2f) + } + + @Test + fun whenDeserializeMovieWithMissingValue_thenUseDefaultValue() { + val json = """{"name":"Endgame","studio":"Marvel"}""" + val movie: Movie = mapper.readValue(json) + + assertEquals(movie.name, "Endgame") + assertEquals(movie.studio, "Marvel") + assertEquals(movie.rating, 1f) + } + + @Test + fun whenSerializeMap_thenSuccess() { + val map = mapOf(1 to "one", 2 to "two") + val serialized = mapper.writeValueAsString(map) + + val json = """{"1":"one","2":"two"}""" + assertEquals(serialized, json) + } + + @Test + fun whenDeserializeMap_thenSuccess() { + val json = """{"1":"one","2":"two"}""" + val aMap: Map = mapper.readValue(json) + + assertEquals(aMap[1], "one") + assertEquals(aMap[2], "two") + } + + @Test + fun whenSerializeList_thenSuccess() { + val movie1 = Movie("Endgame", "Marvel", 9.2f) + val movie2 = Movie("Shazam", "Warner Bros", 7.6f) + val movieList = listOf(movie1, movie2) + val serialized = mapper.writeValueAsString(movieList) + + val json = """[{"name":"Endgame","studio":"Marvel","rating":9.2},{"name":"Shazam","studio":"Warner Bros","rating":7.6}]""" + assertEquals(serialized, json) + } + + @Test + fun whenDeserializeList_thenSuccess() { + val json = """[{"name":"Endgame","studio":"Marvel","rating":9.2},{"name":"Shazam","studio":"Warner Bros","rating":7.6}]""" + val movieList: List = mapper.readValue(json) + + val movie1 = Movie("Endgame", "Marvel", 9.2f) + val movie2 = Movie("Shazam", "Warner Bros", 7.6f) + assertTrue(movieList.contains(movie1)) + assertTrue(movieList.contains(movie2)) + } + + @Test + fun whenSerializeBook_thenSuccess() { + val book = Book("Oliver Twist", "Charles Dickens") + val serialized = mapper.writeValueAsString(book) + + val json = """{"title":"Oliver Twist","author":"Charles Dickens"}""" + assertEquals(serialized, json) + } + + @Test + fun whenDeserializeBook_thenSuccess() { + val json = """{"title":"Oliver Twist","author":"Charles Dickens"}""" + val book: Book = mapper.readValue(json) + + assertEquals(book.title, "Oliver Twist") + assertEquals(book.authorName, "Charles Dickens") + } + + @Test + fun givenJsonInclude_whenSerializeBook_thenEmptyFieldExcluded() { + val book = Book("Oliver Twist", "Charles Dickens") + val serialized = mapper.writeValueAsString(book) + + val json = """{"title":"Oliver Twist","author":"Charles Dickens"}""" + assertEquals(serialized, json) + } + +} \ No newline at end of file diff --git a/libraries-2/README.md b/libraries-2/README.md new file mode 100644 index 0000000000..3d5dba80ee --- /dev/null +++ b/libraries-2/README.md @@ -0,0 +1,3 @@ +## Relevant Articles + +- [Guide to Classgraph Library](https://www.baeldung.com/classgraph) diff --git a/libraries-2/pom.xml b/libraries-2/pom.xml index a839f56b56..6303c0cab5 100644 --- a/libraries-2/pom.xml +++ b/libraries-2/pom.xml @@ -30,14 +30,38 @@ + + org.assertj + assertj-core + ${assertj.version} + + + io.github.classgraph + classgraph + ${classgraph.version} + org.jbpm jbpm-test ${jbpm.version} + + info.picocli + picocli + ${picocli.version} + + + org.springframework.boot + spring-boot-starter + ${spring-boot-starter.version} + + 3.6.2 + 4.8.28 6.0.0.Final + 3.9.6 + 2.1.4.RELEASE diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/Application.java b/libraries-2/src/main/java/com/baeldung/picocli/git/Application.java new file mode 100644 index 0000000000..04af524e45 --- /dev/null +++ b/libraries-2/src/main/java/com/baeldung/picocli/git/Application.java @@ -0,0 +1,41 @@ +package com.baeldung.picocli.git; + +import com.baeldung.picocli.git.commands.programmative.GitCommand; +import com.baeldung.picocli.git.commands.subcommands.GitAddCommand; +import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand; +import com.baeldung.picocli.git.commands.subcommands.GitConfigCommand; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import picocli.CommandLine; + +@SpringBootApplication +public class Application implements CommandLineRunner { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + private GitCommand gitCommand; + private GitAddCommand addCommand; + private GitCommitCommand commitCommand; + private GitConfigCommand configCommand; + + @Autowired + public Application(GitCommand gitCommand, GitAddCommand addCommand, GitCommitCommand commitCommand, GitConfigCommand configCommand) { + this.gitCommand = gitCommand; + this.addCommand = addCommand; + this.commitCommand = commitCommand; + this.configCommand = configCommand; + } + + @Override + public void run(String... args) { + CommandLine commandLine = new CommandLine(gitCommand); + commandLine.addSubcommand("add", addCommand); + commandLine.addSubcommand("commit", commitCommand); + commandLine.addSubcommand("config", configCommand); + + commandLine.parseWithHandler(new CommandLine.RunLast(), args); + } +} diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java b/libraries-2/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java new file mode 100644 index 0000000000..f3c690a3e6 --- /dev/null +++ b/libraries-2/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java @@ -0,0 +1,32 @@ +package com.baeldung.picocli.git.commands.declarative; + +import com.baeldung.picocli.git.model.ConfigElement; +import com.baeldung.picocli.git.commands.subcommands.GitAddCommand; +import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand; +import com.baeldung.picocli.git.commands.subcommands.GitConfigCommand; +import picocli.CommandLine; + +import static picocli.CommandLine.*; +import static picocli.CommandLine.Command; + +@Command( + name = "git", + subcommands = { + GitAddCommand.class, + GitCommitCommand.class, + GitConfigCommand.class + } +) +public class GitCommand implements Runnable { + public static void main(String[] args) { + CommandLine commandLine = new CommandLine(new GitCommand()); + commandLine.registerConverter(ConfigElement.class, ConfigElement::from); + + commandLine.parseWithHandler(new RunLast(), args); + } + + @Override + public void run() { + System.out.println("The popular git command"); + } +} diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java b/libraries-2/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java new file mode 100644 index 0000000000..2c3e440b8b --- /dev/null +++ b/libraries-2/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java @@ -0,0 +1,27 @@ +package com.baeldung.picocli.git.commands.methods; + +import picocli.CommandLine; + +import static picocli.CommandLine.Command; + +@Command(name = "git") +public class GitCommand implements Runnable { + public static void main(String[] args) { + CommandLine.run(new GitCommand(), args); + } + + @Override + public void run() { + System.out.println("The popular git command"); + } + + @Command(name = "add") + public void addCommand() { + System.out.println("Adding some files to the staging area"); + } + + @Command(name = "commit") + public void commitCommand() { + System.out.println("Committing files in the staging area, how wonderful?"); + } +} diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java b/libraries-2/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java new file mode 100644 index 0000000000..81ecfd78be --- /dev/null +++ b/libraries-2/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java @@ -0,0 +1,26 @@ +package com.baeldung.picocli.git.commands.programmative; + +import com.baeldung.picocli.git.commands.subcommands.GitAddCommand; +import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand; +import org.springframework.stereotype.Component; +import picocli.CommandLine; + +import static picocli.CommandLine.Command; +import static picocli.CommandLine.RunLast; + +@Command(name = "git") +@Component +public class GitCommand implements Runnable { + public static void main(String[] args) { + CommandLine commandLine = new CommandLine(new GitCommand()); + commandLine.addSubcommand("add", new GitAddCommand()); + commandLine.addSubcommand("commit", new GitCommitCommand()); + + commandLine.parseWithHandler(new RunLast(), args); + } + + @Override + public void run() { + System.out.println("The popular git command"); + } +} diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java b/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java new file mode 100644 index 0000000000..803cd8dc7d --- /dev/null +++ b/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java @@ -0,0 +1,31 @@ +package com.baeldung.picocli.git.commands.subcommands; + +import org.springframework.stereotype.Component; + +import java.nio.file.Path; +import java.util.List; + +import static picocli.CommandLine.*; + +@Command( + name = "add" +) +@Component +public class GitAddCommand implements Runnable { + @Option(names = "-A") + private boolean allFiles; + + @Parameters(index = "0..*") + private List files; + + @Override + public void run() { + if (allFiles) { + System.out.println("Adding all files to the staging area"); + } + + if (files != null) { + files.forEach(path -> System.out.println("Adding " + path + " to the staging area")); + } + } +} diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java b/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java new file mode 100644 index 0000000000..df4928983c --- /dev/null +++ b/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java @@ -0,0 +1,26 @@ +package com.baeldung.picocli.git.commands.subcommands; + +import org.springframework.stereotype.Component; + +import static picocli.CommandLine.Command; +import static picocli.CommandLine.Option; + +@Command( + name = "commit" +) +@Component +public class GitCommitCommand implements Runnable { + @Option(names = {"-m", "--message"}, required = true) + private String[] messages; + + @Override + public void run() { + System.out.println("Committing files in the staging area, how wonderful?"); + if (messages != null) { + System.out.println("The commit message is"); + for (String message : messages) { + System.out.println(message); + } + } + } +} diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java b/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java new file mode 100644 index 0000000000..80e14c0121 --- /dev/null +++ b/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java @@ -0,0 +1,24 @@ +package com.baeldung.picocli.git.commands.subcommands; + +import com.baeldung.picocli.git.model.ConfigElement; +import org.springframework.stereotype.Component; + +import static picocli.CommandLine.Command; +import static picocli.CommandLine.Parameters; + +@Command( + name = "config" +) +@Component +public class GitConfigCommand implements Runnable { + @Parameters(index = "0") + private ConfigElement element; + + @Parameters(index = "1") + private String value; + + @Override + public void run() { + System.out.println("Setting " + element.value() + " to " + value); + } +} diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java b/libraries-2/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java new file mode 100644 index 0000000000..edc6573d88 --- /dev/null +++ b/libraries-2/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java @@ -0,0 +1,25 @@ +package com.baeldung.picocli.git.model; + +import java.util.Arrays; + +public enum ConfigElement { + USERNAME("user.name"), + EMAIL("user.email"); + + private final String value; + + ConfigElement(String value) { + this.value = value; + } + + public String value() { + return value; + } + + public static ConfigElement from(String value) { + return Arrays.stream(values()) + .filter(element -> element.value.equals(value)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("The argument " + value + " doesn't match any ConfigElement")); + } +} diff --git a/libraries-2/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java b/libraries-2/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java new file mode 100644 index 0000000000..97a861e2f0 --- /dev/null +++ b/libraries-2/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java @@ -0,0 +1,20 @@ +package com.baeldung.picocli.helloworld; + +import picocli.CommandLine; + +import static picocli.CommandLine.Command; + +@Command( + name = "hello", + description = "Says hello" +) +public class HelloWorldCommand implements Runnable { + public static void main(String[] args) { + CommandLine.run(new HelloWorldCommand(), args); + } + + @Override + public void run() { + System.out.println("Hello World!"); + } +} diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java b/libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java new file mode 100644 index 0000000000..3dc99e6a32 --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java @@ -0,0 +1,74 @@ +package com.baeldung.classgraph; + +import io.github.classgraph.*; +import org.junit.Test; + +import java.io.IOException; +import java.util.function.Consumer; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ClassGraphUnitTest { + + @Test + public void whenClassAnnotationFilterIsDefined_thenTargetClassesCanBeFound() { + doTest(result -> { + ClassInfoList classInfos = result.getClassesWithAnnotation(TestAnnotation.class.getName()); + assertThat(classInfos).extracting(ClassInfo::getName).contains(ClassWithAnnotation.class.getName()); + }); + } + + @Test + public void whenMethodAnnotationFilterIsDefined_thenTargetClassesCanBeFound() { + doTest(result -> { + ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName()); + assertThat(classInfos).extracting(ClassInfo::getName).contains(MethodWithAnnotation.class.getName()); + }); + } + + @Test + public void whenMethodAnnotationValueFilterIsDefined_thenTargetClassesCanBeFound() { + doTest(result -> { + ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName()); + ClassInfoList filteredClassInfos = classInfos.filter(classInfo -> { + return classInfo.getMethodInfo().stream().anyMatch(methodInfo -> { + AnnotationInfo annotationInfo = methodInfo.getAnnotationInfo(TestAnnotation.class.getName()); + if (annotationInfo == null) { + return false; + } + + return "web".equals(annotationInfo.getParameterValues().getValue("value")); + }); + }); + assertThat(filteredClassInfos) + .extracting(ClassInfo::getName) + .contains(MethodWithAnnotationParameterWeb.class.getName()); + }); + } + + @Test + public void whenFieldAnnotationFilterIsDefined_thenTargetClassesCanBeFound() { + doTest(result -> { + ClassInfoList classInfos = result.getClassesWithFieldAnnotation(TestAnnotation.class.getName()); + assertThat(classInfos).extracting(ClassInfo::getName).contains(FieldWithAnnotation.class.getName()); + }); + } + + @Test + public void whenResourceIsUsed_thenItCanBeFoundAndLoaded() throws IOException { + try (ScanResult result = new ClassGraph().whitelistPaths("classgraph").scan()) { + ResourceList resources = result.getResourcesWithExtension("config"); + assertThat(resources).extracting(Resource::getPath).containsOnly("classgraph/my.config"); + assertThat(resources.get(0).getContentAsString()).isEqualTo("my data"); + } + } + + private void doTest(Consumer checker) { + try (ScanResult result = new ClassGraph().enableAllInfo() + .whitelistPackages(getClass().getPackage().getName()) + .scan()) + { + checker.accept(result); + } + } +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java new file mode 100644 index 0000000000..fe476769a6 --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java @@ -0,0 +1,5 @@ +package com.baeldung.classgraph; + +@TestAnnotation +public class ClassWithAnnotation { +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java new file mode 100644 index 0000000000..f72a7621f9 --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java @@ -0,0 +1,7 @@ +package com.baeldung.classgraph; + +public class FieldWithAnnotation { + + @TestAnnotation + private String s; +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java new file mode 100644 index 0000000000..29a59c09ea --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotation { + + @TestAnnotation + public void service() { + } +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java new file mode 100644 index 0000000000..f01c2743eb --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotationParameterDao { + + @TestAnnotation("dao") + public void service() { + } +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java new file mode 100644 index 0000000000..bf01f7d23c --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotationParameterWeb { + + @TestAnnotation("web") + public void service() { + } +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java new file mode 100644 index 0000000000..e3f5df92ed --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java @@ -0,0 +1,14 @@ +package com.baeldung.classgraph; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; + +@Target({TYPE, METHOD, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestAnnotation { + + String value() default ""; +} \ No newline at end of file diff --git a/libraries-2/src/test/resources/classgraph/my.config b/libraries-2/src/test/resources/classgraph/my.config new file mode 100644 index 0000000000..b99df573f6 --- /dev/null +++ b/libraries-2/src/test/resources/classgraph/my.config @@ -0,0 +1 @@ +my data \ No newline at end of file diff --git a/libraries-apache-commons/pom.xml b/libraries-apache-commons/pom.xml index c7ff918af9..cb5990df22 100644 --- a/libraries-apache-commons/pom.xml +++ b/libraries-apache-commons/pom.xml @@ -95,14 +95,11 @@ 3.6.2 2.5 1.6 - 1.4.196 4.1 - 4.12 2.0.0.0 1.10.L001 3.5.2 3.6 - 1.3 3.6.1 diff --git a/libraries-apache-commons/src/main/java/com/baeldung/commons/beanutils/CourseService.java b/libraries-apache-commons/src/main/java/com/baeldung/commons/beanutils/CourseService.java index 538fa3accb..2c7644fd64 100644 --- a/libraries-apache-commons/src/main/java/com/baeldung/commons/beanutils/CourseService.java +++ b/libraries-apache-commons/src/main/java/com/baeldung/commons/beanutils/CourseService.java @@ -29,6 +29,6 @@ public class CourseService { } public static void copyProperties(Course course, CourseEntity courseEntity) throws IllegalAccessException, InvocationTargetException { - BeanUtils.copyProperties(course, courseEntity); + BeanUtils.copyProperties(courseEntity, course); } } diff --git a/libraries-apache-commons/src/test/java/com/baeldung/commons/beanutils/CourseServiceUnitTest.java b/libraries-apache-commons/src/test/java/com/baeldung/commons/beanutils/CourseServiceUnitTest.java index 833d91b2c4..224ee8404c 100644 --- a/libraries-apache-commons/src/test/java/com/baeldung/commons/beanutils/CourseServiceUnitTest.java +++ b/libraries-apache-commons/src/test/java/com/baeldung/commons/beanutils/CourseServiceUnitTest.java @@ -44,6 +44,8 @@ public class CourseServiceUnitTest { CourseEntity courseEntity = new CourseEntity(); CourseService.copyProperties(course, courseEntity); + Assert.assertNotNull(course.getName()); + Assert.assertNotNull(courseEntity.getName()); Assert.assertEquals(course.getName(), courseEntity.getName()); Assert.assertEquals(course.getCodes(), courseEntity.getCodes()); Assert.assertNull(courseEntity.getStudent("ST-1")); diff --git a/libraries-data/pom.xml b/libraries-data/pom.xml index 85be66c067..3276ebcdbb 100644 --- a/libraries-data/pom.xml +++ b/libraries-data/pom.xml @@ -432,9 +432,7 @@ 1.2.2 4.0.1 - 1.4.196 16.5.1 - 3.7.0 5.0 1.0.0 2.4.0 diff --git a/libraries-primitive/pom.xml b/libraries-primitive/pom.xml new file mode 100644 index 0000000000..9bb58470b2 --- /dev/null +++ b/libraries-primitive/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + + com.baeldung + libraries-primitive + 1.0-SNAPSHOT + + + + + it.unimi.dsi + fastutil + 8.2.2 + + + + junit + junit + 4.12 + test + + + + org.openjdk.jmh + jmh-core + 1.19 + test + + + org.openjdk.jmh + jmh-generator-annprocess + 1.19 + test + + + diff --git a/libraries-primitive/src/test/java/com/baeldung/BigArraysUnitTest.java b/libraries-primitive/src/test/java/com/baeldung/BigArraysUnitTest.java new file mode 100644 index 0000000000..a794d1a2f6 --- /dev/null +++ b/libraries-primitive/src/test/java/com/baeldung/BigArraysUnitTest.java @@ -0,0 +1,23 @@ +package com.baeldung; + +import it.unimi.dsi.fastutil.ints.IntBigArrays; +import org.junit.Test; + +import static junit.framework.Assert.assertEquals; + +public class BigArraysUnitTest { + + @Test + public void givenValidAray_whenWrapped_checkAccessFromIntBigArraysMethodsCorrect() { + int[] oneDArray = new int[] { 2, 1, 5, 2, 1, 7 }; + int[][] twoDArray = IntBigArrays.wrap(oneDArray.clone()); + + int firstIndex = IntBigArrays.get(twoDArray, 0); + int lastIndex = IntBigArrays.get(twoDArray, IntBigArrays.length(twoDArray)-1); + + assertEquals(2, firstIndex); + assertEquals(7, lastIndex); + + } + +} diff --git a/libraries-primitive/src/test/java/com/baeldung/FastUtilTypeSpecificBenchmarkUnitTest.java b/libraries-primitive/src/test/java/com/baeldung/FastUtilTypeSpecificBenchmarkUnitTest.java new file mode 100644 index 0000000000..2c77989fe5 --- /dev/null +++ b/libraries-primitive/src/test/java/com/baeldung/FastUtilTypeSpecificBenchmarkUnitTest.java @@ -0,0 +1,58 @@ +package com.baeldung; + +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +import java.util.*; +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@State(Scope.Benchmark) +public class FastUtilTypeSpecificBenchmarkUnitTest { + + @Param({"100", "1000", "10000", "100000"}) + public int setSize; + + @Benchmark + public IntSet givenFastUtilsIntSetWithInitialSizeSet_whenPopulated_checkTimeTaken() { + IntSet intSet = new IntOpenHashSet(setSize); + for(int i = 0; i < setSize; i++){ + intSet.add(i); + } + return intSet; + } + + + @Benchmark + public Set givenCollectionsHashSetWithInitialSizeSet_whenPopulated_checkTimeTaken() { + Set intSet = new HashSet(setSize); + for(int i = 0; i < setSize; i++){ + intSet.add(i); + } + return intSet; + } + + public static void main(String... args) throws RunnerException { + Options opts = new OptionsBuilder() + .include(".*") + .warmupIterations(1) + .measurementIterations(2) + .jvmArgs("-Xms2g", "-Xmx2g") + .shouldDoGC(true) + .forks(1) + .build(); + + new Runner(opts).run(); + } + + + + +} diff --git a/libraries-primitive/src/test/java/com/baeldung/FastUtilTypeSpecificUnitTest.java b/libraries-primitive/src/test/java/com/baeldung/FastUtilTypeSpecificUnitTest.java new file mode 100644 index 0000000000..61295cc6f1 --- /dev/null +++ b/libraries-primitive/src/test/java/com/baeldung/FastUtilTypeSpecificUnitTest.java @@ -0,0 +1,20 @@ +package com.baeldung; + +import it.unimi.dsi.fastutil.doubles.Double2DoubleMap; +import it.unimi.dsi.fastutil.doubles.Double2DoubleOpenHashMap; +import org.junit.Test; + +import static junit.framework.Assert.assertEquals; + + +public class FastUtilTypeSpecificUnitTest { + + @Test + public void givenValidDouble2DoubleMap_whenContentsQueried_checkCorrect(){ + Double2DoubleMap d2dMap = new Double2DoubleOpenHashMap(); + d2dMap.put(2.0, 5.5); + d2dMap.put(3.0, 6.6); + assertEquals(5.5, d2dMap.get(2.0)); + } + +} diff --git a/libraries-security/README.md b/libraries-security/README.md index 6923e0474e..b9bbf11cdf 100644 --- a/libraries-security/README.md +++ b/libraries-security/README.md @@ -2,3 +2,4 @@ - [Guide to ScribeJava](https://www.baeldung.com/scribejava) - [Guide to Passay](https://www.baeldung.com/java-passay) +- [Guide to Google Tink](https://www.baeldung.com/google-tink) diff --git a/linkrest/pom.xml b/linkrest/pom.xml index 073a173aff..b3d3bd374e 100644 --- a/linkrest/pom.xml +++ b/linkrest/pom.xml @@ -73,7 +73,6 @@ 2.9 4.0.B1 - 1.4.196 2.25.1 diff --git a/logging-modules/log-mdc/pom.xml b/logging-modules/log-mdc/pom.xml index 3031274d0b..ae658e034e 100644 --- a/logging-modules/log-mdc/pom.xml +++ b/logging-modules/log-mdc/pom.xml @@ -29,13 +29,13 @@ javax.servlet javax.servlet-api - ${javax.servlet.version} + ${javax.servlet-api.version} provided com.fasterxml.jackson.core jackson-databind - ${jackson.library} + ${jackson.version} @@ -98,12 +98,9 @@ - 1.2.17 2.7 3.3.6 3.3.0.Final - 3.1.0 - 2.9.7 2.4 diff --git a/logging-modules/log4j2/pom.xml b/logging-modules/log4j2/pom.xml index 924abfd346..14420356de 100644 --- a/logging-modules/log4j2/pom.xml +++ b/logging-modules/log4j2/pom.xml @@ -115,8 +115,6 @@ - 2.9.7 - 1.4.193 2.1.1 2.11.0 yyyyMMddHHmmss diff --git a/logging-modules/logback/pom.xml b/logging-modules/logback/pom.xml index 41a28ffd17..22a89124b5 100644 --- a/logging-modules/logback/pom.xml +++ b/logging-modules/logback/pom.xml @@ -58,7 +58,6 @@ 1.2.3 0.1.5 - 2.9.7 3.3.5 diff --git a/lucene/pom.xml b/lucene/pom.xml index f427cfd8a7..3d1ce61782 100644 --- a/lucene/pom.xml +++ b/lucene/pom.xml @@ -32,8 +32,6 @@ - - 1.16.18 1.0.0.Final diff --git a/maven-java-11/multimodule-maven-project/daomodule/pom.xml b/maven-java-11/multimodule-maven-project/daomodule/pom.xml new file mode 100644 index 0000000000..de9be656d4 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/daomodule/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + + com.baeldung.multimodule-maven-project + multimodule-maven-project + 1.0 + + com.baeldung.daomodule + daomodule + jar + 1.0 + daomodule + diff --git a/maven-java-11/multimodule-maven-project/daomodule/src/main/java/com/baeldung/dao/Dao.java b/maven-java-11/multimodule-maven-project/daomodule/src/main/java/com/baeldung/dao/Dao.java new file mode 100644 index 0000000000..f86ae8abb3 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/daomodule/src/main/java/com/baeldung/dao/Dao.java @@ -0,0 +1,12 @@ +package com.baeldung.dao; + +import java.util.List; +import java.util.Optional; + +public interface Dao { + + Optional findById(int id); + + List findAll(); + +} diff --git a/maven-java-11/multimodule-maven-project/daomodule/src/main/java/module-info.java b/maven-java-11/multimodule-maven-project/daomodule/src/main/java/module-info.java new file mode 100644 index 0000000000..072d7ad007 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/daomodule/src/main/java/module-info.java @@ -0,0 +1,3 @@ +module com.baeldung.dao { + exports com.baeldung.dao; +} diff --git a/maven-java-11/multimodule-maven-project/entitiymodule/pom.xml b/maven-java-11/multimodule-maven-project/entitiymodule/pom.xml new file mode 100644 index 0000000000..8e700e62b5 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/entitiymodule/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + com.baeldung.multimodule-maven-project + multimodule-maven-project + 1.0 + + com.baeldung.entitymodule + entitymodule + jar + 1.0 + entitymodule + + 11 + 11 + + diff --git a/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/com/baeldung/entity/User.java b/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/com/baeldung/entity/User.java new file mode 100644 index 0000000000..22022a2e6d --- /dev/null +++ b/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/com/baeldung/entity/User.java @@ -0,0 +1,19 @@ +package com.baeldung.entity; + +public class User { + + private final String name; + + public User(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return "User{" + "name=" + name + '}'; + } +} diff --git a/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/module-info.java b/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/module-info.java new file mode 100644 index 0000000000..67a3097352 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/module-info.java @@ -0,0 +1,3 @@ +module com.baeldung.entity { + exports com.baeldung.entity; +} diff --git a/maven-java-11/multimodule-maven-project/mainppmodule/pom.xml b/maven-java-11/multimodule-maven-project/mainppmodule/pom.xml new file mode 100644 index 0000000000..d2c94527f1 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/mainppmodule/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + com.baeldung.multimodule-maven-project + multimodule-maven-project + 1.0 + + com.baeldung.mainappmodule + mainappmodule + 1.0 + jar + mainappmodule + + + + com.baeldung.entitymodule + entitymodule + 1.0 + + + com.baeldung.daomodule + daomodule + 1.0 + + + com.baeldung.userdaomodule + userdaomodule + 1.0 + + + diff --git a/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/com/baeldung/mainapp/Application.java b/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/com/baeldung/mainapp/Application.java new file mode 100644 index 0000000000..0c0df7461b --- /dev/null +++ b/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/com/baeldung/mainapp/Application.java @@ -0,0 +1,19 @@ +package com.baeldung.mainapp; + +import com.baeldung.dao.Dao; +import com.baeldung.entity.User; +import com.baeldung.userdao.UserDao; +import java.util.HashMap; +import java.util.Map; + +public class Application { + + public static void main(String[] args) { + Map users = new HashMap<>(); + users.put(1, new User("Julie")); + users.put(2, new User("David")); + Dao userDao = new UserDao(users); + userDao.findAll().forEach(System.out::println); + } + +} diff --git a/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/module-info.java b/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/module-info.java new file mode 100644 index 0000000000..c688fcf7de --- /dev/null +++ b/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module com.baeldung.mainapp { + requires com.baeldung.entity; + requires com.baeldung.userdao; + requires com.baeldung.dao; + uses com.baeldung.dao.Dao; +} diff --git a/maven-java-11/multimodule-maven-project/pom.xml b/maven-java-11/multimodule-maven-project/pom.xml new file mode 100644 index 0000000000..f22541738c --- /dev/null +++ b/maven-java-11/multimodule-maven-project/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + com.baeldung.multimodule-maven-project + multimodule-maven-project + 1.0 + pom + multimodule-maven-project + + com.baeldung.maven-java-11 + maven-java-11 + 1.0 + + + + + + junit + junit + 4.12 + test + + + org.assertj + assertj-core + 3.12.2 + test + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 11 + 11 + + + + + + + + entitymodule + daomodule + userdaomodule + mainappmodule + + + + UTF-8 + + diff --git a/maven-java-11/multimodule-maven-project/userdaomodule/pom.xml b/maven-java-11/multimodule-maven-project/userdaomodule/pom.xml new file mode 100644 index 0000000000..b4fe7f0398 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/userdaomodule/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + com.baeldung.multimodule-maven-project + multimodule-maven-project + 1.0 + + com.baeldung.userdaomodule + userdaomodule + 1.0 + jar + userdaomodule + + + com.baeldung.entitymodule + entitymodule + 1.0 + + + com.baeldung.daomodule + daomodule + 1.0 + + + junit + junit + test + + + diff --git a/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/com/baeldung/userdao/UserDao.java b/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/com/baeldung/userdao/UserDao.java new file mode 100644 index 0000000000..1f1ea38a60 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/com/baeldung/userdao/UserDao.java @@ -0,0 +1,32 @@ +package com.baeldung.userdao; + +import com.baeldung.dao.Dao; +import com.baeldung.entity.User; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class UserDao implements Dao { + + private final Map users; + + public UserDao() { + users = new HashMap<>(); + } + + public UserDao(Map users) { + this.users = users; + } + + @Override + public List findAll() { + return new ArrayList<>(users.values()); + } + + @Override + public Optional findById(int id) { + return Optional.ofNullable(users.get(id)); + } +} \ No newline at end of file diff --git a/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/module-info.java b/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/module-info.java new file mode 100644 index 0000000000..f1cb217e23 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module com.baeldung.userdao { + requires com.baeldung.entity; + requires com.baeldung.dao; + provides com.baeldung.dao.Dao with com.baeldung.userdao.UserDao; + exports com.baeldung.userdao; +} diff --git a/maven-java-11/multimodule-maven-project/userdaomodule/src/test/java/com/baeldung/userdao/test/UserDaoUnitTest.java b/maven-java-11/multimodule-maven-project/userdaomodule/src/test/java/com/baeldung/userdao/test/UserDaoUnitTest.java new file mode 100644 index 0000000000..191d17ff32 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/userdaomodule/src/test/java/com/baeldung/userdao/test/UserDaoUnitTest.java @@ -0,0 +1,36 @@ +package com.baeldung.userdao.test; + +import com.baeldung.dao.Dao; +import com.baeldung.entity.User; +import com.baeldung.userdao.UserDao; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import static org.junit.Assert.*; +import static org.hamcrest.CoreMatchers.*; +import org.junit.Before; +import org.junit.Test; + +public class UserDaoUnitTest { + + private Dao userDao; + + @Before + public void setUpUserDaoInstance() { + Map users = new HashMap<>(); + users.put(1, new User("Julie")); + users.put(2, new User("David")); + userDao = new UserDao(users); + } + + @Test + public void givenUserDaoIntance_whenCalledFindById_thenCorrect() { + assertThat(userDao.findById(1), isA(Optional.class)); + } + + @Test + public void givenUserDaoIntance_whenCalledFindAll_thenCorrect() { + assertThat(userDao.findAll(), isA(List.class)); + } +} diff --git a/maven-java-11/pom.xml b/maven-java-11/pom.xml new file mode 100644 index 0000000000..ff95840523 --- /dev/null +++ b/maven-java-11/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + com.baeldung.maven-java-11 + maven-java-11 + 1.0 + pom + maven-java-11 + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + + multimodule-maven-project + + + UTF-8 + 11 + 11 + + diff --git a/maven/profiles/pom.xml b/maven/profiles/pom.xml new file mode 100644 index 0000000000..110016f3a2 --- /dev/null +++ b/maven/profiles/pom.xml @@ -0,0 +1,88 @@ + + 4.0.0 + com.baeldung + profiles + 0.0.1-SNAPSHOT + profiles + + + + no-tests + + true + + + + integration-tests + + true + + + + mutation-tests + + + active-on-jdk-11 + + 11 + + + + active-on-windows-10 + + + windows 10 + Windows + amd64 + 10.0 + + + + + active-on-property-environment + + + environment + !test + + + + + active-on-missing-file + + + target/testreport.html + + + + + active-on-present-file + + + target/artifact.jar + + + + + + + + + org.apache.maven.plugins + maven-help-plugin + 3.2.0 + + + show-profiles + compile + + active-profiles + + + + + + + \ No newline at end of file diff --git a/parent-kotlin/pom.xml b/parent-kotlin/pom.xml index 7a3a8b10ca..6f7fe6c102 100644 --- a/parent-kotlin/pom.xml +++ b/parent-kotlin/pom.xml @@ -108,6 +108,9 @@ ${project.basedir}/src/main/java ${java.version} + + -Xjvm-default=enable + @@ -202,10 +205,10 @@ - 1.3.10 + 1.3.30 1.0.0 0.9.5 - 3.11.0 - 1.2.0 + 3.12.0 + 1.3.2 diff --git a/parent-spring-5/pom.xml b/parent-spring-5/pom.xml index 3178682d34..84df8cf30a 100644 --- a/parent-spring-5/pom.xml +++ b/parent-spring-5/pom.xml @@ -31,7 +31,6 @@ 5.1.4.RELEASE 5.0.2 - 2.9.6 5.1.4.RELEASE diff --git a/patterns/design-patterns-2/README.md b/patterns/design-patterns-2/README.md new file mode 100644 index 0000000000..c2a75d4680 --- /dev/null +++ b/patterns/design-patterns-2/README.md @@ -0,0 +1,3 @@ +### Relevant Articles + +- [The Mediator Pattern in Java](https://www.baeldung.com/java-mediator-pattern) diff --git a/patterns/pom.xml b/patterns/pom.xml index bf302a7a74..875af67d55 100644 --- a/patterns/pom.xml +++ b/patterns/pom.xml @@ -51,7 +51,6 @@ - 3.1.0 3.0.0 9.4.0.v20161208 diff --git a/performance-tests/pom.xml b/performance-tests/pom.xml index 7d77c2a0e3..d7738780bf 100644 --- a/performance-tests/pom.xml +++ b/performance-tests/pom.xml @@ -46,12 +46,12 @@ org.openjdk.jmh jmh-core - ${jmh.version} + ${jmh-core.version} org.openjdk.jmh jmh-generator-annprocess - ${jmh.version} + ${jmh-generator.version} @@ -85,7 +85,6 @@ 1.2.0.Final 1.1.0 1.6.0.1 - 1.20 1.2.0.Final diff --git a/persistence-modules/core-java-persistence/pom.xml b/persistence-modules/core-java-persistence/pom.xml index 2ad2083fec..2760489ce1 100644 --- a/persistence-modules/core-java-persistence/pom.xml +++ b/persistence-modules/core-java-persistence/pom.xml @@ -30,7 +30,7 @@ com.h2database h2 - ${h2database.version} + ${h2.version} org.apache.commons @@ -73,7 +73,6 @@ 42.2.5.jre7 8.0.15 3.10.0 - 1.4.197 2.4.0 3.2.0 0.9.5.2 diff --git a/persistence-modules/deltaspike/pom.xml b/persistence-modules/deltaspike/pom.xml index 9a4669102a..4dcef07695 100644 --- a/persistence-modules/deltaspike/pom.xml +++ b/persistence-modules/deltaspike/pom.xml @@ -317,7 +317,6 @@ 2.6 1.1.3 1.2.5.Final-redhat-1 - 1.4.197 3.5 diff --git a/persistence-modules/flyway/pom.xml b/persistence-modules/flyway/pom.xml index eb827f5675..99549ee3fc 100644 --- a/persistence-modules/flyway/pom.xml +++ b/persistence-modules/flyway/pom.xml @@ -65,7 +65,6 @@ 5.0.2 5.0.2 - 1.4.195 diff --git a/persistence-modules/hibernate-mapping/pom.xml b/persistence-modules/hibernate-mapping/pom.xml new file mode 100644 index 0000000000..6bab3c5b1f --- /dev/null +++ b/persistence-modules/hibernate-mapping/pom.xml @@ -0,0 +1,70 @@ + + + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../../ + + + hibernate-mapping + 1.0.0-SNAPSHOT + 4.0.0 + + + + org.hibernate + hibernate-core + ${hibernate.version} + + + org.assertj + assertj-core + ${assertj-core.version} + test + + + com.h2database + h2 + ${h2.version} + + + + org.hibernate + hibernate-validator + ${hibernate-validator.version} + + + javax.el + javax.el-api + ${javax.el-api.version} + + + org.glassfish + javax.el + ${org.glassfish.javax.el.version} + + + + + hibernate-mapping + + + src/test/resources + true + + + + + + 5.3.7.Final + 3.8.0 + 5.3.3.Final + 2.2.5 + 3.0.1-b08 + + + \ No newline at end of file diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java new file mode 100644 index 0000000000..7411edd225 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -0,0 +1,64 @@ +package com.baeldung.hibernate; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +public class HibernateUtil { + private static SessionFactory sessionFactory; + + private HibernateUtil() { + } + + public static SessionFactory getSessionFactory(Strategy strategy) { + if (sessionFactory == null) { + sessionFactory = buildSessionFactory(strategy); + } + return sessionFactory; + } + + private static SessionFactory buildSessionFactory(Strategy strategy) { + try { + ServiceRegistry serviceRegistry = configureServiceRegistry(); + + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + + for (Class entityClass : strategy.getEntityClasses()) { + metadataSources.addAnnotatedClass(entityClass); + } + + Metadata metadata = metadataSources.getMetadataBuilder() + .build(); + + return metadata.getSessionFactoryBuilder() + .build(); + } catch (IOException ex) { + throw new ExceptionInInitializerError(ex); + } + } + + + private static ServiceRegistry configureServiceRegistry() throws IOException { + Properties properties = getProperties(); + return new StandardServiceRegistryBuilder().applySettings(properties) + .build(); + } + + private static Properties getProperties() throws IOException { + Properties properties = new Properties(); + URL propertiesURL = Thread.currentThread() + .getContextClassLoader() + .getResource("hibernate.properties"); + try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { + properties.load(inputStream); + } + return properties; + } +} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/Strategy.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/Strategy.java new file mode 100644 index 0000000000..78434fd2a2 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/Strategy.java @@ -0,0 +1,31 @@ +package com.baeldung.hibernate; + + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public enum Strategy { + //See that the classes belongs to different packages + MAP_KEY_COLUMN_BASED(Collections.singletonList(com.baeldung.hibernate.persistmaps.mapkeycolumn.Order.class)), + MAP_KEY_BASED(Arrays.asList(com.baeldung.hibernate.persistmaps.mapkey.Item.class, + com.baeldung.hibernate.persistmaps.mapkey.Order.class,com.baeldung.hibernate.persistmaps.mapkey.User.class)), + MAP_KEY_JOIN_COLUMN_BASED(Arrays.asList(com.baeldung.hibernate.persistmaps.mapkeyjoincolumn.Seller.class, + com.baeldung.hibernate.persistmaps.mapkeyjoincolumn.Item.class, + com.baeldung.hibernate.persistmaps.mapkeyjoincolumn.Order.class)), + MAP_KEY_ENUMERATED_BASED(Arrays.asList(com.baeldung.hibernate.persistmaps.mapkeyenumerated.Order.class, + com.baeldung.hibernate.persistmaps.mapkey.Item.class)), + MAP_KEY_TEMPORAL_BASED(Arrays.asList(com.baeldung.hibernate.persistmaps.mapkeytemporal.Order.class, + com.baeldung.hibernate.persistmaps.mapkey.Item.class)); + + + private List> entityClasses; + + Strategy(List> entityClasses) { + this.entityClasses = entityClasses; + } + + public List> getEntityClasses() { + return entityClasses; + } +} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/basicannotation/Course.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/basicannotation/Course.java new file mode 100644 index 0000000000..e816fb0176 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/basicannotation/Course.java @@ -0,0 +1,34 @@ +package com.baeldung.hibernate.basicannotation; + +import javax.persistence.Basic; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Course { + + @Id + private int id; + + @Basic(optional = false, fetch = FetchType.LAZY) + private String name; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} + diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/ItemType.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/ItemType.java new file mode 100644 index 0000000000..b7f3cef9a2 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/ItemType.java @@ -0,0 +1,6 @@ +package com.baeldung.hibernate.persistmaps; + +public enum ItemType { + JEANS, + TSHIRTS +} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkey/Item.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkey/Item.java new file mode 100644 index 0000000000..385ffe93ea --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkey/Item.java @@ -0,0 +1,95 @@ +package com.baeldung.hibernate.persistmaps.mapkey; + +import com.baeldung.hibernate.persistmaps.ItemType; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import java.util.Date; +import java.util.Objects; + +@Entity +@Table(name = "item") +public class Item { + @Id + @GeneratedValue + @Column(name = "id") + private int id; + + @Column(name = "name") + private String itemName; + + @Column(name = "price") + private double itemPrice; + + @Enumerated(EnumType.STRING) + @Column(name = "item_type") + private ItemType itemType; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "created_on") + private Date createdOn; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public double getItemPrice() { + return itemPrice; + } + + public void setItemPrice(double itemPrice) { + this.itemPrice = itemPrice; + } + + public ItemType getItemType() { + return itemType; + } + + public void setItemType(ItemType itemType) { + this.itemType = itemType; + } + + public Date getCreatedOn() { + return createdOn; + } + + public void setCreatedOn(Date createdOn) { + this.createdOn = createdOn; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Item item = (Item) o; + return id == item.id && + Double.compare(item.itemPrice, itemPrice) == 0 && + Objects.equals(itemName, item.itemName) && + itemType == item.itemType && + Objects.equals(createdOn, item.createdOn); + } + + @Override + public int hashCode() { + return Objects.hash(id, itemName, itemPrice, itemType, createdOn); + } +} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkey/Order.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkey/Order.java new file mode 100644 index 0000000000..8409cacd6b --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkey/Order.java @@ -0,0 +1,44 @@ +package com.baeldung.hibernate.persistmaps.mapkey; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.MapKey; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import java.util.Map; + +@Entity +@Table(name = "orders") +public class Order { + @Id + @GeneratedValue + @Column(name = "id") + private int id; + + @OneToMany(cascade = CascadeType.ALL) + @JoinTable(name = "order_item_mapping", joinColumns = {@JoinColumn(name = "order_id", referencedColumnName = "id")}, + inverseJoinColumns = {@JoinColumn(name = "item_id", referencedColumnName = "id")}) + @MapKey(name = "itemName") + private Map itemMap; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Map getItemMap() { + return itemMap; + } + + public void setItemMap(Map itemMap) { + this.itemMap = itemMap; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkey/User.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkey/User.java new file mode 100644 index 0000000000..f6e8f1cdd6 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkey/User.java @@ -0,0 +1,66 @@ +package com.baeldung.hibernate.persistmaps.mapkey; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.validation.constraints.Size; + +import org.hibernate.validator.constraints.Length; + +@Entity +public class User { + @Id + @Column(length = 3) + private String firstName; + + @Size(min = 3, max = 15) + private String middleName; + + @Length(min = 3, max = 15) + private String lastName; + + @Column(length = 5) + @Size(min = 3, max = 5) + private String city; + + public User(String firstName, String middleName, String lastName, String city) { + super(); + this.firstName = firstName; + this.middleName = middleName; + this.lastName = lastName; + this.city = city; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getMiddleName() { + return middleName; + } + + public void setMiddleName(String middletName) { + this.middleName = middletName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + +} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeycolumn/Order.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeycolumn/Order.java new file mode 100644 index 0000000000..fa092060da --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeycolumn/Order.java @@ -0,0 +1,43 @@ +package com.baeldung.hibernate.persistmaps.mapkeycolumn; + +import javax.persistence.CollectionTable; +import javax.persistence.Column; +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.MapKeyColumn; +import javax.persistence.Table; +import java.util.Map; + +@Entity +@Table(name = "orders") +public class Order { + @Id + @GeneratedValue + @Column(name = "id") + private int id; + + @ElementCollection + @CollectionTable(name = "order_item_mapping", joinColumns = {@JoinColumn(name = "order_id", referencedColumnName = "id")}) + @MapKeyColumn(name = "item_name") + @Column(name = "price") + private Map itemPriceMap; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Map getItemPriceMap() { + return itemPriceMap; + } + + public void setItemPriceMap(Map itemPriceMap) { + this.itemPriceMap = itemPriceMap; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeyenumerated/Order.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeyenumerated/Order.java new file mode 100644 index 0000000000..e1f62599b8 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeyenumerated/Order.java @@ -0,0 +1,48 @@ +package com.baeldung.hibernate.persistmaps.mapkeyenumerated; + +import com.baeldung.hibernate.persistmaps.ItemType; +import com.baeldung.hibernate.persistmaps.mapkey.Item; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.MapKeyEnumerated; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import java.util.Map; + +@Entity +@Table(name = "orders") +public class Order { + @Id + @GeneratedValue + @Column(name = "id") + private int id; + + @OneToMany(cascade = CascadeType.ALL) + @JoinTable(name = "order_item_mapping", joinColumns = {@JoinColumn(name = "order_id", referencedColumnName = "id")}, + inverseJoinColumns = {@JoinColumn(name = "item_id", referencedColumnName = "id")}) + @MapKeyEnumerated(EnumType.STRING) + private Map itemMap; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Map getItemMap() { + return itemMap; + } + + public void setItemMap(Map itemMap) { + this.itemMap = itemMap; + } +} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeyjoincolumn/Item.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeyjoincolumn/Item.java new file mode 100644 index 0000000000..97bbd5b539 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeyjoincolumn/Item.java @@ -0,0 +1,112 @@ +package com.baeldung.hibernate.persistmaps.mapkeyjoincolumn; + +import com.baeldung.hibernate.persistmaps.ItemType; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import java.util.Date; +import java.util.Objects; + +@Entity +@Table(name = "item") +public class Item { + @Id + @GeneratedValue + @Column(name = "id") + private int id; + + @Column(name = "name") + private String itemName; + + @Column(name = "price") + private double itemPrice; + + @Column(name = "item_type") + @Enumerated(EnumType.STRING) + private ItemType itemType; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "created_on") + private Date createdOn; + + @ManyToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "seller_id") + private Seller seller; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public double getItemPrice() { + return itemPrice; + } + + public void setItemPrice(double itemPrice) { + this.itemPrice = itemPrice; + } + + public ItemType getItemType() { + return itemType; + } + + public void setItemType(ItemType itemType) { + this.itemType = itemType; + } + + public Date getCreatedOn() { + return createdOn; + } + + public void setCreatedOn(Date createdOn) { + this.createdOn = createdOn; + } + + public Seller getSeller() { + return seller; + } + + public void setSeller(Seller seller) { + this.seller = seller; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Item item = (Item) o; + return id == item.id && + Double.compare(item.itemPrice, itemPrice) == 0 && + Objects.equals(itemName, item.itemName) && + itemType == item.itemType && + Objects.equals(createdOn, item.createdOn) && + Objects.equals(seller, item.seller); + } + + @Override + public int hashCode() { + + return Objects.hash(id, itemName, itemPrice, itemType, createdOn, seller); + } +} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeyjoincolumn/Order.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeyjoincolumn/Order.java new file mode 100644 index 0000000000..d680d84501 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeyjoincolumn/Order.java @@ -0,0 +1,44 @@ +package com.baeldung.hibernate.persistmaps.mapkeyjoincolumn; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.MapKeyJoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import java.util.Map; + +@Entity +@Table(name = "orders") +public class Order { + @Id + @GeneratedValue + @Column(name = "id") + private int id; + + @OneToMany(cascade = CascadeType.ALL) + @JoinTable(name = "order_item_mapping", joinColumns = {@JoinColumn(name = "order_id", referencedColumnName = "id")}, + inverseJoinColumns = {@JoinColumn(name = "item_id", referencedColumnName = "id")}) + @MapKeyJoinColumn(name = "seller_id") + private Map sellerItemMap; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Map getSellerItemMap() { + return sellerItemMap; + } + + public void setSellerItemMap(Map sellerItemMap) { + this.sellerItemMap = sellerItemMap; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeyjoincolumn/Seller.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeyjoincolumn/Seller.java new file mode 100644 index 0000000000..15b08e9fe6 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeyjoincolumn/Seller.java @@ -0,0 +1,51 @@ +package com.baeldung.hibernate.persistmaps.mapkeyjoincolumn; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.Objects; + +@Entity +@Table(name = "seller") +public class Seller { + + @Id + @GeneratedValue + @Column(name = "id") + private int id; + + @Column(name = "name") + private String sellerName; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getSellerName() { + return sellerName; + } + + public void setSellerName(String sellerName) { + this.sellerName = sellerName; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Seller seller = (Seller) o; + return Objects.equals(sellerName, seller.sellerName); + } + + @Override + public int hashCode() { + + return Objects.hash(sellerName); + } +} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeytemporal/Order.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeytemporal/Order.java new file mode 100644 index 0000000000..be602c1e9f --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/persistmaps/mapkeytemporal/Order.java @@ -0,0 +1,48 @@ +package com.baeldung.hibernate.persistmaps.mapkeytemporal; + +import com.baeldung.hibernate.persistmaps.mapkey.Item; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.MapKeyTemporal; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TemporalType; +import java.util.Date; +import java.util.Map; + +@Entity +@Table(name = "orders") +public class Order { + @Id + @GeneratedValue + @Column(name = "id") + private int id; + + @OneToMany(cascade = CascadeType.ALL) + @JoinTable(name = "order_item_mapping", joinColumns = {@JoinColumn(name = "order_id", referencedColumnName = "id")}, + inverseJoinColumns = {@JoinColumn(name = "item_id", referencedColumnName = "id")}) + @MapKeyTemporal(TemporalType.TIMESTAMP) + private Map itemMap; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Map getItemMap() { + return itemMap; + } + + public void setItemMap(Map itemMap) { + this.itemMap = itemMap; + } +} diff --git a/persistence-modules/hibernate-mapping/src/main/resources/logback.xml b/persistence-modules/hibernate-mapping/src/main/resources/logback.xml new file mode 100644 index 0000000000..26beb6d5b4 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/basicannotation/BasicAnnotationIntegrationTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/basicannotation/BasicAnnotationIntegrationTest.java new file mode 100644 index 0000000000..70f08b4ee3 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/basicannotation/BasicAnnotationIntegrationTest.java @@ -0,0 +1,59 @@ +package com.baeldung.hibernate.basicannotation; + +import com.baeldung.hibernate.HibernateUtil; +import com.baeldung.hibernate.basicannotation.Course; +import com.baeldung.hibernate.Strategy; +import org.hibernate.PropertyValueException; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.hibernate.SessionFactory; +import org.junit.BeforeClass; + +import java.io.IOException; + +public class BasicAnnotationIntegrationTest { + + private static SessionFactory sessionFactory; + private Session session; + private Transaction transaction; + + @BeforeClass + public static void beforeTests() { + sessionFactory = HibernateUtil.getSessionFactory(Strategy.MAP_KEY_COLUMN_BASED); + } + + @Before + public void setUp() throws IOException { + session = sessionFactory.openSession(); + transaction = session.beginTransaction(); + } + + @After + public void tearDown() { + transaction.rollback(); + session.close(); + } + + @Test + public void givenACourse_whenCourseNamePresent_shouldPersist() { + Course course = new Course(); + course.setName("Computers"); + + session.save(course); + session.flush(); + session.clear(); + + } + + @Test(expected = PropertyValueException.class) + public void givenACourse_whenCourseNameAbsent_shouldFail() { + Course course = new Course(); + + session.save(course); + session.flush(); + session.clear(); + } +} diff --git a/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyColumnIntegrationTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyColumnIntegrationTest.java new file mode 100644 index 0000000000..acd77ee382 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyColumnIntegrationTest.java @@ -0,0 +1,79 @@ +package com.baeldung.hibernate.persistmaps; + +import com.baeldung.hibernate.HibernateUtil; +import com.baeldung.hibernate.Strategy; +import com.baeldung.hibernate.persistmaps.mapkeycolumn.Order; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class MapKeyColumnIntegrationTest { + private static SessionFactory sessionFactory; + + private Session session; + + @BeforeClass + public static void beforeTests() { + sessionFactory = HibernateUtil.getSessionFactory(Strategy.MAP_KEY_COLUMN_BASED); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenData_whenInsertUsingMapKeyColumn_thenPersistMap() { + Map itemPriceMap = new HashMap<>(); + itemPriceMap.put("Wrangler Jeans", 150.0); + itemPriceMap.put("Lee Jeans", 180.0); + + + Order order = new Order(); + order.setItemPriceMap(itemPriceMap); + + session.persist(order); + session.getTransaction().commit(); + + assertInsertedData(); + } + + private void assertInsertedData() { + @SuppressWarnings("unchecked") + List orderList = session.createQuery("FROM Order").list(); + + assertNotNull(orderList); + assertEquals(1, orderList.size()); + + Order order = orderList.get(0); + + Map itemPriceMap = order.getItemPriceMap(); + assertNotNull(itemPriceMap); + assertEquals(itemPriceMap.size(), 2); + assertEquals((Double) 150.0, itemPriceMap.get("Wrangler Jeans")); + assertEquals((Double) 180.0, itemPriceMap.get("Lee Jeans")); + + } + + @After + public void tearDown() { + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} diff --git a/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyEnumeratedIntegrationTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyEnumeratedIntegrationTest.java new file mode 100644 index 0000000000..221aa7b1d7 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyEnumeratedIntegrationTest.java @@ -0,0 +1,95 @@ +package com.baeldung.hibernate.persistmaps; + +import com.baeldung.hibernate.HibernateUtil; +import com.baeldung.hibernate.Strategy; +import com.baeldung.hibernate.persistmaps.mapkey.Item; +import com.baeldung.hibernate.persistmaps.mapkeyenumerated.Order; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.time.Instant; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class MapKeyEnumeratedIntegrationTest { + private static SessionFactory sessionFactory; + + private Session session; + + @BeforeClass + public static void beforeTests() { + sessionFactory = HibernateUtil.getSessionFactory(Strategy.MAP_KEY_ENUMERATED_BASED); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenData_whenInsertUsingMapKeyEnumerated_thenPersistMap() { + Item item1 = new Item(); + item1.setItemName("Wrangler Jeans"); + item1.setItemPrice(150.0); + item1.setItemType(ItemType.JEANS); + item1.setCreatedOn(Date.from(Instant.ofEpochSecond(1554926573))); + + + Item item2 = new Item(); + item2.setItemName("Armani Tshirts"); + item2.setItemPrice(180.0); + item2.setItemType(ItemType.TSHIRTS); + item2.setCreatedOn(Date.from(Instant.ofEpochSecond(1554890573))); + + Map itemMap = new HashMap<>(); + itemMap.put(item1.getItemType(), item1); + itemMap.put(item2.getItemType(), item2); + + Order order = new Order(); + order.setItemMap(itemMap); + + session.persist(order); + session.getTransaction().commit(); + + assertInsertedData(item1, item2); + } + + private void assertInsertedData(Item expectedItem1, Item expectedItem2) { + @SuppressWarnings("unchecked") + List orderList = session.createQuery("FROM Order").list(); + + assertNotNull(orderList); + assertEquals(1, orderList.size()); + + Order order = orderList.get(0); + + Map itemMap = order.getItemMap(); + assertNotNull(itemMap); + assertEquals(2, itemMap.size()); + assertEquals(expectedItem1, itemMap.get(ItemType.JEANS)); + assertEquals(expectedItem2, itemMap.get(ItemType.TSHIRTS)); + + } + + @After + public void tearDown() { + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} + diff --git a/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyIntegrationTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyIntegrationTest.java new file mode 100644 index 0000000000..b500deb78e --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyIntegrationTest.java @@ -0,0 +1,95 @@ +package com.baeldung.hibernate.persistmaps; + +import com.baeldung.hibernate.HibernateUtil; +import com.baeldung.hibernate.Strategy; +import com.baeldung.hibernate.persistmaps.mapkey.Item; +import com.baeldung.hibernate.persistmaps.mapkey.Order; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.time.Instant; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class MapKeyIntegrationTest { + private static SessionFactory sessionFactory; + + private Session session; + + @BeforeClass + public static void beforeTests() { + sessionFactory = HibernateUtil.getSessionFactory(Strategy.MAP_KEY_BASED); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenData_whenInsertUsingMapKey_thenPersistMap() { + Item item1 = new Item(); + item1.setItemName("Wrangler Jeans"); + item1.setItemPrice(150.0); + item1.setItemType(ItemType.JEANS); + item1.setCreatedOn(Date.from(Instant.ofEpochSecond(1554926573))); + + + Item item2 = new Item(); + item2.setItemName("Armani Tshirts"); + item2.setItemPrice(180.0); + item2.setItemType(ItemType.TSHIRTS); + item2.setCreatedOn(Date.from(Instant.ofEpochSecond(1554890573))); + + Map itemMap = new HashMap<>(); + itemMap.put(item1.getItemName(), item1); + itemMap.put(item2.getItemName(), item2); + + Order order = new Order(); + order.setItemMap(itemMap); + + session.persist(order); + session.getTransaction().commit(); + + assertInsertedData(item1, item2); + } + + private void assertInsertedData(Item expectedItem1, Item expectedItem2) { + @SuppressWarnings("unchecked") + List orderList = session.createQuery("FROM Order").list(); + + assertNotNull(orderList); + assertEquals(1, orderList.size()); + + Order order = orderList.get(0); + + Map itemMap = order.getItemMap(); + assertNotNull(itemMap); + assertEquals(2, itemMap.size()); + assertEquals(expectedItem1, itemMap.get("Wrangler Jeans")); + assertEquals(expectedItem2, itemMap.get("Armani Tshirts")); + + } + + @After + public void tearDown() { + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} + diff --git a/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyJoinColumnIntegrationTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyJoinColumnIntegrationTest.java new file mode 100644 index 0000000000..88b22f5c99 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyJoinColumnIntegrationTest.java @@ -0,0 +1,105 @@ +package com.baeldung.hibernate.persistmaps; + +import com.baeldung.hibernate.HibernateUtil; +import com.baeldung.hibernate.Strategy; +import com.baeldung.hibernate.persistmaps.mapkeyjoincolumn.Item; +import com.baeldung.hibernate.persistmaps.mapkeyjoincolumn.Order; +import com.baeldung.hibernate.persistmaps.mapkeyjoincolumn.Seller; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.time.Instant; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class MapKeyJoinColumnIntegrationTest { + private static SessionFactory sessionFactory; + + private Session session; + + @BeforeClass + public static void beforeTests() { + sessionFactory = HibernateUtil.getSessionFactory(Strategy.MAP_KEY_JOIN_COLUMN_BASED); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenData_whenInsertUsingMapKeyJoinColumn_thenPersistMap() { + Seller seller1 = new Seller(); + seller1.setSellerName("Walmart"); + + Item item1 = new Item(); + item1.setItemName("Wrangler Jeans"); + item1.setItemPrice(150.0); + item1.setItemType(ItemType.JEANS); + item1.setCreatedOn(Date.from(Instant.ofEpochSecond(1554926573))); + item1.setSeller(seller1); + + + Seller seller2 = new Seller(); + seller2.setSellerName("Amazon"); + + Item item2 = new Item(); + item2.setItemName("Armani Tshirts"); + item2.setItemPrice(180.0); + item2.setItemType(ItemType.TSHIRTS); + item2.setCreatedOn(Date.from(Instant.ofEpochSecond(1554890573))); + item2.setSeller(seller2); + + Map itemSellerMap = new HashMap<>(); + itemSellerMap.put(seller1, item1); + itemSellerMap.put(seller2, item2); + + Order order = new Order(); + order.setSellerItemMap(itemSellerMap); + + + session.persist(order); + session.getTransaction().commit(); + + assertInsertedData(seller1, item1, seller2, item2); + } + + private void assertInsertedData(Seller seller1, Item expectedItem1, Seller seller2, Item expectedItem2) { + @SuppressWarnings("unchecked") + List orderList = session.createQuery("FROM Order").list(); + + assertNotNull(orderList); + assertEquals(1, orderList.size()); + + Order order = orderList.get(0); + + Map sellerItemMap = order.getSellerItemMap(); + assertNotNull(sellerItemMap); + assertEquals(2, sellerItemMap.size()); + assertEquals(expectedItem1, sellerItemMap.get(seller1)); + assertEquals(expectedItem2, sellerItemMap.get(seller2)); + + } + + @After + public void tearDown() { + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} + diff --git a/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyTemporalIntegrationTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyTemporalIntegrationTest.java new file mode 100644 index 0000000000..7117cad22f --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/persistmaps/MapKeyTemporalIntegrationTest.java @@ -0,0 +1,96 @@ +package com.baeldung.hibernate.persistmaps; + +import com.baeldung.hibernate.HibernateUtil; +import com.baeldung.hibernate.Strategy; +import com.baeldung.hibernate.persistmaps.mapkey.Item; +import com.baeldung.hibernate.persistmaps.mapkeytemporal.Order; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.time.Instant; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class MapKeyTemporalIntegrationTest { + private static SessionFactory sessionFactory; + + private Session session; + + @BeforeClass + public static void beforeTests() { + sessionFactory = HibernateUtil.getSessionFactory(Strategy.MAP_KEY_TEMPORAL_BASED); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenData_whenInsertUsingMapKeyEnumerated_thenPersistMap() { + Date item1CreatedOn = Date.from(Instant.ofEpochSecond(1554926573)); + Item item1 = new Item(); + item1.setItemName("Wrangler Jeans"); + item1.setItemPrice(150.0); + item1.setItemType(ItemType.JEANS); + item1.setCreatedOn(item1CreatedOn); + + + Date item2CreatedOn = Date.from(Instant.ofEpochSecond(1554890573)); + Item item2 = new Item(); + item2.setItemName("Armani Tshirts"); + item2.setItemPrice(180.0); + item2.setItemType(ItemType.TSHIRTS); + item2.setCreatedOn(item2CreatedOn); + + Map itemMap = new HashMap<>(); + itemMap.put(item1CreatedOn, item1); + itemMap.put(item2CreatedOn, item2); + + Order order = new Order(); + order.setItemMap(itemMap); + + session.persist(order); + session.getTransaction().commit(); + + assertInsertedData(item1CreatedOn, item1, item2CreatedOn, item2); + } + + private void assertInsertedData(Date item1CreatedOn, Item expectedItem1, Date item2CreatedOn, Item expectedItem2) { + @SuppressWarnings("unchecked") + List orderList = session.createQuery("FROM Order").list(); + + assertNotNull(orderList); + assertEquals(1, orderList.size()); + + Order order = orderList.get(0); + + Map itemMap = order.getItemMap(); + assertNotNull(itemMap); + assertEquals(2, itemMap.size()); + assertEquals(expectedItem1, itemMap.get(item1CreatedOn)); + assertEquals(expectedItem2, itemMap.get(item2CreatedOn)); + + } + + @After + public void tearDown() { + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} diff --git a/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/validation/UserValidationUnitTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/validation/UserValidationUnitTest.java new file mode 100644 index 0000000000..e39f324856 --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/validation/UserValidationUnitTest.java @@ -0,0 +1,81 @@ +package com.baeldung.hibernate.validation; + +import static org.junit.Assert.assertEquals; +import java.util.Set; +import javax.persistence.PersistenceException; +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import com.baeldung.hibernate.HibernateUtil; +import com.baeldung.hibernate.Strategy; +import com.baeldung.hibernate.persistmaps.mapkey.User; + +public class UserValidationUnitTest { + + private static Validator validator; + private static SessionFactory sessionFactory; + private Session session; + private Set> constraintViolations; + + @BeforeClass + public static void before() { + ValidatorFactory config = Validation.buildDefaultValidatorFactory(); + validator = config.getValidator(); + sessionFactory = HibernateUtil.getSessionFactory(Strategy.MAP_KEY_BASED); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void whenValidationWithSizeAndInvalidMiddleName_thenConstraintViolation() { + User user = new User("john", "m", "butler", "japan"); + constraintViolations = validator.validateProperty(user, "middleName"); + assertEquals(constraintViolations.size(), 1); + } + + @Test + public void whenValidationWithSizeAndValidMiddleName_thenNoConstraintViolation() { + User user = new User("john", "mathis", "butler", "japan"); + constraintViolations = validator.validateProperty(user, "middleName"); + assertEquals(constraintViolations.size(), 0); + } + + @Test + public void whenValidationWithLengthAndInvalidLastName_thenConstraintViolation() { + User user = new User("john", "m", "b", "japan"); + constraintViolations = validator.validateProperty(user, "lastName"); + assertEquals(constraintViolations.size(), 1); + } + + @Test + public void whenValidationWithLengthAndValidLastName_thenNoConstraintViolation() { + User user = new User("john", "mathis", "butler", "japan"); + constraintViolations = validator.validateProperty(user, "lastName"); + assertEquals(constraintViolations.size(), 0); + } + + @Test(expected = PersistenceException.class) + public void whenSavingFirstNameWithInvalidFirstName_thenPersistenceException() { + User user = new User("john", "mathis", "butler", "japan"); + session.save(user); + session.getTransaction() + .commit(); + } + + @Test + public void whenValidationWithSizeAndColumnWithValidCity_thenNoConstraintViolation() { + User user = new User("john", "mathis", "butler", "japan"); + constraintViolations = validator.validateProperty(user, "city"); + assertEquals(constraintViolations.size(), 0); + } +} diff --git a/persistence-modules/hibernate-mapping/src/test/resources/hibernate.properties b/persistence-modules/hibernate-mapping/src/test/resources/hibernate.properties new file mode 100644 index 0000000000..c22da2496b --- /dev/null +++ b/persistence-modules/hibernate-mapping/src/test/resources/hibernate.properties @@ -0,0 +1,10 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 +hibernate.connection.username=sa +hibernate.connection.autocommit=true +jdbc.password= + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop + diff --git a/persistence-modules/hibernate5/pom.xml b/persistence-modules/hibernate5/pom.xml index c7f08e50d5..8799317e9c 100644 --- a/persistence-modules/hibernate5/pom.xml +++ b/persistence-modules/hibernate5/pom.xml @@ -30,7 +30,7 @@ com.h2database h2 - ${h2database.version} + ${h2.version} org.hibernate @@ -104,9 +104,7 @@ 5.3.7.Final 6.0.6 2.2.3 - 1.4.196 3.8.0 - 2.9.7 1.21 diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Course.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Course.java index 97760acd3b..2214b9a56f 100644 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Course.java +++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Course.java @@ -20,8 +20,8 @@ public class Course { public void setCourseId(UUID courseId) { this.courseId = courseId; } - - - + + + } diff --git a/persistence-modules/influxdb/pom.xml b/persistence-modules/influxdb/pom.xml index 8e1aeebe6d..a8ecaadd62 100644 --- a/persistence-modules/influxdb/pom.xml +++ b/persistence-modules/influxdb/pom.xml @@ -33,7 +33,6 @@ 2.8 - 1.16.18 diff --git a/persistence-modules/java-jpa/pom.xml b/persistence-modules/java-jpa/pom.xml index fa47d6bd9c..f23040fbdc 100644 --- a/persistence-modules/java-jpa/pom.xml +++ b/persistence-modules/java-jpa/pom.xml @@ -49,7 +49,6 @@ 5.4.0.Final - 1.4.197 2.7.4-RC1 42.2.5 diff --git a/persistence-modules/java-mongodb/pom.xml b/persistence-modules/java-mongodb/pom.xml index 9658ef567f..0f5efedb96 100644 --- a/persistence-modules/java-mongodb/pom.xml +++ b/persistence-modules/java-mongodb/pom.xml @@ -35,8 +35,8 @@ 1.8 1.8 - 3.4.1 + 3.10.1 1.11 - \ No newline at end of file + diff --git a/persistence-modules/java-mongodb/src/main/java/com/baeldung/MongoBsonExample.java b/persistence-modules/java-mongodb/src/main/java/com/baeldung/MongoBsonExample.java new file mode 100644 index 0000000000..0ad3dfae30 --- /dev/null +++ b/persistence-modules/java-mongodb/src/main/java/com/baeldung/MongoBsonExample.java @@ -0,0 +1,79 @@ +package com.baeldung; + +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import org.bson.Document; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MongoBsonExample +{ + public static void main(String[] args) + { + // + // 4.1 Connect to cluster (default is localhost:27017) + // + + MongoClient mongoClient = MongoClients.create(); + MongoDatabase database = mongoClient.getDatabase("myDB"); + MongoCollection collection = database.getCollection("employees"); + + // + // 4.2 Insert new document + // + + Document employee = new Document() + .append("first_name", "Joe") + .append("last_name", "Smith") + .append("title", "Java Developer") + .append("years_of_service", 3) + .append("skills", Arrays.asList("java", "spring", "mongodb")) + .append("manager", new Document() + .append("first_name", "Sally") + .append("last_name", "Johanson")); + collection.insertOne(employee); + + // + // 4.3 Find documents + // + + + Document query = new Document("last_name", "Smith"); + List results = new ArrayList<>(); + collection.find(query).into(results); + + query = + new Document("$or", Arrays.asList( + new Document("last_name", "Smith"), + new Document("first_name", "Joe"))); + results = new ArrayList<>(); + collection.find(query).into(results); + + // + // 4.4 Update document + // + + query = new Document( + "skills", + new Document( + "$elemMatch", + new Document("$eq", "spring"))); + Document update = new Document( + "$push", + new Document("skills", "security")); + collection.updateMany(query, update); + + // + // 4.5 Delete documents + // + + query = new Document( + "years_of_service", + new Document("$lt", 0)); + collection.deleteMany(query); + } +} diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 47c733d8a7..67a5c36fed 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -22,6 +22,7 @@ hbase hibernate5 hibernate-ogm + hibernate-mapping influxdb java-cassandra java-cockroachdb @@ -34,7 +35,7 @@ querydsl redis solr - spring-boot-h2/spring-boot-h2-database + spring-boot-persistence-h2 spring-boot-persistence spring-boot-persistence-mongodb spring-data-cassandra diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/.gitignore b/persistence-modules/spring-boot-persistence-h2/.gitignore similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/.gitignore rename to persistence-modules/spring-boot-persistence-h2/.gitignore diff --git a/persistence-modules/spring-boot-h2/README.md b/persistence-modules/spring-boot-persistence-h2/README.md similarity index 67% rename from persistence-modules/spring-boot-h2/README.md rename to persistence-modules/spring-boot-persistence-h2/README.md index af5f395440..377b7c8939 100644 --- a/persistence-modules/spring-boot-h2/README.md +++ b/persistence-modules/spring-boot-persistence-h2/README.md @@ -1,2 +1,3 @@ ### Relevant Articles: - [Access the Same In-Memory H2 Database in Multiple Spring Boot Applications](https://www.baeldung.com/spring-boot-access-h2-database-multiple-apps) +- [Spring Boot With H2 Database](https://www.baeldung.com/spring-boot-h2-database) \ No newline at end of file diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/pom.xml b/persistence-modules/spring-boot-persistence-h2/pom.xml similarity index 97% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/pom.xml rename to persistence-modules/spring-boot-persistence-h2/pom.xml index 882b88b535..4c8073ddb4 100644 --- a/persistence-modules/spring-boot-h2/spring-boot-h2-database/pom.xml +++ b/persistence-modules/spring-boot-persistence-h2/pom.xml @@ -14,7 +14,7 @@ parent-boot-2 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-2 + ../../parent-boot-2 diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/auto/configuration/AutoConfigurationDemo.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/auto/configuration/AutoConfigurationDemo.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/auto/configuration/AutoConfigurationDemo.java rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/auto/configuration/AutoConfigurationDemo.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/demo/server/SpringBootApp.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/demo/server/SpringBootApp.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/demo/server/SpringBootApp.java rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/demo/server/SpringBootApp.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/models/User.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/User.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/models/User.java rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/User.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/application.properties b/persistence-modules/spring-boot-persistence-h2/src/main/resources/application.properties similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/application.properties rename to persistence-modules/spring-boot-persistence-h2/src/main/resources/application.properties diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/resources/data.sql b/persistence-modules/spring-boot-persistence-h2/src/main/resources/data.sql new file mode 100644 index 0000000000..2d7b446005 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/main/resources/data.sql @@ -0,0 +1,13 @@ +DROP TABLE IF EXISTS billionaires; + +CREATE TABLE billionaires ( + id INT AUTO_INCREMENT PRIMARY KEY, + first_name VARCHAR(250) NOT NULL, + last_name VARCHAR(250) NOT NULL, + career VARCHAR(250) DEFAULT NULL +); + +INSERT INTO billionaires (first_name, last_name, career) VALUES +('Aliko', 'Dangote', 'Billionaire Industrialist'), +('Bill', 'Gates', 'Billionaire Tech Entrepreneur'), +('Folrunsho', 'Alakija', 'Billionaire Oil Magnate'); \ No newline at end of file diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java rename to persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringContextIntegrationTest.java b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringContextIntegrationTest.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringContextIntegrationTest.java rename to persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringContextIntegrationTest.java diff --git a/persistence-modules/spring-boot-persistence/pom.xml b/persistence-modules/spring-boot-persistence/pom.xml index ca7c7306e7..e283759c75 100644 --- a/persistence-modules/spring-boot-persistence/pom.xml +++ b/persistence-modules/spring-boot-persistence/pom.xml @@ -79,10 +79,8 @@ UTF-8 - 1.8 8.0.12 9.0.10 - 1.4.197 2.23.0 2.0.1.Final diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/config/H2JpaConfig.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/config/H2JpaConfig.java index 547a905d91..c5c77be56f 100644 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/config/H2JpaConfig.java +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/config/H2JpaConfig.java @@ -1,13 +1,9 @@ package com.baeldung.boot.config; -import java.util.Properties; - -import javax.persistence.EntityManagerFactory; -import javax.sql.DataSource; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @@ -17,10 +13,17 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.transaction.annotation.EnableTransactionManagement; +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; +import java.util.Properties; + @Configuration @EnableJpaRepositories(basePackages = { "com.baeldung.boot.repository", "com.baeldung.repository" }) @PropertySource("classpath:persistence-generic-entity.properties") @EnableTransactionManagement +@Profile("default") //only required to allow H2JpaConfig and H2TestProfileJPAConfig to coexist in same project + //this demo project is showcasing several ways to achieve the same end, and class-level + //Profile annotations are only necessary because the different techniques are sharing a project public class H2JpaConfig { @Autowired diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/jpadefaultvalues/application/Application.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/jpadefaultvalues/application/Application.java new file mode 100644 index 0000000000..3b96f68583 --- /dev/null +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/jpadefaultvalues/application/Application.java @@ -0,0 +1,14 @@ +package com.baeldung.jpadefaultvalues.application; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; + +@SpringBootApplication +public class Application { + private static ApplicationContext applicationContext; + + public static void main(String[] args) { + applicationContext = SpringApplication.run(Application.class, args); + } +} diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/jpadefaultvalues/application/User.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/jpadefaultvalues/application/User.java new file mode 100644 index 0000000000..e271c01815 --- /dev/null +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/jpadefaultvalues/application/User.java @@ -0,0 +1,55 @@ +package com.baeldung.jpadefaultvalues.application; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class User { + + @Id + @GeneratedValue + private Long id; + + @Column(columnDefinition = "varchar(255) default 'John Snow'") + private String name = "John Snow"; + + @Column(columnDefinition = "integer default 25") + private Integer age = 25; + + @Column(columnDefinition = "boolean default false") + private Boolean locked = false; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public Boolean getLocked() { + return locked; + } + + public void setLocked(Boolean locked) { + this.locked = locked; + } +} diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/jpadefaultvalues/application/UserRepository.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/jpadefaultvalues/application/UserRepository.java new file mode 100644 index 0000000000..ca0e4c4d71 --- /dev/null +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/jpadefaultvalues/application/UserRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.jpadefaultvalues.application; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface UserRepository extends JpaRepository { +} diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootProfileIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootProfileIntegrationTest.java index 0227458987..d7bb44e133 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootProfileIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootProfileIntegrationTest.java @@ -1,8 +1,9 @@ package com.baeldung; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - +import com.baeldung.boot.Application; +import com.baeldung.boot.domain.GenericEntity; +import com.baeldung.boot.repository.GenericEntityRepository; +import com.baeldung.config.H2TestProfileJPAConfig; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -10,13 +11,11 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import com.baeldung.boot.Application; -import com.baeldung.boot.config.H2JpaConfig; -import com.baeldung.boot.domain.GenericEntity; -import com.baeldung.boot.repository.GenericEntityRepository; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringRunner.class) -@SpringBootTest(classes = { Application.class, H2JpaConfig.class }) +@SpringBootTest(classes = { Application.class, H2TestProfileJPAConfig.class }) @ActiveProfiles("test") public class SpringBootProfileIntegrationTest { @Autowired diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/config/H2TestProfileJPAConfig.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/config/H2TestProfileJPAConfig.java index e0678bcf47..f73000a10e 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/config/H2TestProfileJPAConfig.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/config/H2TestProfileJPAConfig.java @@ -1,10 +1,5 @@ package com.baeldung.config; -import java.util.Properties; - -import javax.persistence.EntityManagerFactory; -import javax.sql.DataSource; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -17,9 +12,16 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.transaction.annotation.EnableTransactionManagement; +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; +import java.util.Properties; + @Configuration @EnableJpaRepositories(basePackages = { "com.baeldung.repository", "com.baeldung.boot.repository" }) @EnableTransactionManagement +@Profile("test") //only required to allow H2JpaConfig and H2TestProfileJPAConfig to coexist in same project + //this demo project is showcasing several ways to achieve the same end, and class-level + //Profile annotations are only necessary because the different techniques are sharing a project public class H2TestProfileJPAConfig { @Autowired diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/jpadefaultvalues/application/UserDefaultValuesUnitTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/jpadefaultvalues/application/UserDefaultValuesUnitTest.java new file mode 100644 index 0000000000..52a5c4dcd6 --- /dev/null +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/jpadefaultvalues/application/UserDefaultValuesUnitTest.java @@ -0,0 +1,56 @@ +package com.baeldung.jpadefaultvalues.application; + +import com.baeldung.jpadefaultvalues.application.User; +import com.baeldung.jpadefaultvalues.application.UserRepository; + +import org.junit.Test; +import org.junit.Ignore; +import org.junit.runner.RunWith; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.beans.factory.annotation.Autowired; + +import static org.junit.Assert.*; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class UserDefaultValuesUnitTest { + + @Autowired + private UserRepository userRepository; + + @Test + @Ignore // SQL default values are also defined + public void saveUser_shouldSaveWithDefaultFieldValues() { + User user = new User(); + user = userRepository.save(user); + + assertEquals(user.getName(), "John Snow"); + assertEquals(25, (int) user.getAge()); + assertFalse(user.getLocked()); + } + + @Test + @Ignore // SQL default values are also defined + public void saveUser_shouldSaveWithNullName() { + User user = new User(); + user.setName(null); + user = userRepository.save(user); + + assertNull(user.getName()); + assertEquals(25, (int) user.getAge()); + assertFalse(user.getLocked()); + } + + @Test + public void saveUser_shouldSaveWithDefaultSqlValues() { + User user = new User(); + user = userRepository.save(user); + + assertEquals(user.getName(), "John Snow"); + assertEquals(25, (int) user.getAge()); + assertFalse(user.getLocked()); + } + +} diff --git a/persistence-modules/spring-data-cassandra-reactive/pom.xml b/persistence-modules/spring-data-cassandra-reactive/pom.xml index bc8f49862d..5a34d90c9f 100644 --- a/persistence-modules/spring-data-cassandra-reactive/pom.xml +++ b/persistence-modules/spring-data-cassandra-reactive/pom.xml @@ -52,7 +52,6 @@ UTF-8 UTF-8 - 1.8 2.1.2.RELEASE diff --git a/persistence-modules/spring-data-eclipselink/pom.xml b/persistence-modules/spring-data-eclipselink/pom.xml index 618fa83ee5..61c28dc26f 100644 --- a/persistence-modules/spring-data-eclipselink/pom.xml +++ b/persistence-modules/spring-data-eclipselink/pom.xml @@ -67,7 +67,6 @@ 1.5.9.RELEASE 2.7.0 - 1.4.196 diff --git a/persistence-modules/spring-data-jpa-2/pom.xml b/persistence-modules/spring-data-jpa-2/pom.xml index 8e46112659..fbc19810ef 100644 --- a/persistence-modules/spring-data-jpa-2/pom.xml +++ b/persistence-modules/spring-data-jpa-2/pom.xml @@ -1,12 +1,13 @@ + 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 - com.baeldung + + com.baeldung spring-data-jpa-2 - spring-data-jpa - + spring-data-jpa + parent-boot-2 com.baeldung @@ -19,12 +20,26 @@ org.springframework.boot spring-boot-starter-data-jpa - + com.h2database h2 - - + + net.ttddyy + datasource-proxy + 1.4.1 + + + + com.fasterxml.jackson.core + jackson-databind + + + + org.springframework + spring-oxm + + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java new file mode 100644 index 0000000000..504357db44 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java @@ -0,0 +1,53 @@ +package com.baeldung.batchinserts; + +import java.lang.reflect.Method; +import javax.sql.DataSource; +import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.springframework.aop.framework.ProxyFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; +import org.springframework.util.ReflectionUtils; + +@Component +@Profile("batchinserts") +public class DatasourceProxyBeanPostProcessor implements BeanPostProcessor { + + @Override + public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException { + return bean; + } + + @Override + public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException { + if (bean instanceof DataSource) { + ProxyFactory factory = new ProxyFactory(bean); + factory.setProxyTargetClass(true); + factory.addAdvice(new ProxyDataSourceInterceptor((DataSource) bean)); + return factory.getProxy(); + } + + return bean; + } + + private static class ProxyDataSourceInterceptor implements MethodInterceptor { + + private final DataSource dataSource; + + public ProxyDataSourceInterceptor(final DataSource dataSource) { + this.dataSource = ProxyDataSourceBuilder.create(dataSource).name("Batch-Insert-Logger").asJson().countQuery().logQueryToSysOut().build(); + } + + @Override + public Object invoke(final MethodInvocation invocation) throws Throwable { + Method proxyMethod = ReflectionUtils.findMethod(dataSource.getClass(), invocation.getMethod().getName()); + if (proxyMethod != null) { + return proxyMethod.invoke(dataSource, invocation.getArguments()); + } + return invocation.proceed(); + } + } +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/School.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/School.java new file mode 100644 index 0000000000..6d2f333ac7 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/School.java @@ -0,0 +1,45 @@ +package com.baeldung.batchinserts.model; + +import java.util.List; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; + +@Entity +public class School { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String name; + + @OneToMany(mappedBy = "school") + private List students; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getStudents() { + return students; + } + + public void setStudents(List students) { + this.students = students; + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/Student.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/Student.java new file mode 100644 index 0000000000..d38214f122 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/Student.java @@ -0,0 +1,44 @@ +package com.baeldung.batchinserts.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class Student { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String name; + + @ManyToOne + private School school; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public School getSchool() { + return school; + } + + public void setSchool(School school) { + this.school = school; + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/config/JpaPopulators.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/config/JpaPopulators.java new file mode 100644 index 0000000000..24348d31c5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/config/JpaPopulators.java @@ -0,0 +1,35 @@ +package com.baeldung.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.data.repository.init.Jackson2RepositoryPopulatorFactoryBean; +import org.springframework.data.repository.init.UnmarshallerRepositoryPopulatorFactoryBean; +import org.springframework.oxm.jaxb.Jaxb2Marshaller; + +import com.baeldung.entity.Fruit; + +@Configuration +public class JpaPopulators { + + @Bean + public Jackson2RepositoryPopulatorFactoryBean getRespositoryPopulator() throws Exception { + Jackson2RepositoryPopulatorFactoryBean factory = new Jackson2RepositoryPopulatorFactoryBean(); + factory.setResources(new Resource[] { new ClassPathResource("fruit-data.json") }); + return factory; + } + + @Bean + public UnmarshallerRepositoryPopulatorFactoryBean repositoryPopulator() { + + Jaxb2Marshaller unmarshaller = new Jaxb2Marshaller(); + unmarshaller.setClassesToBeBound(Fruit.class); + + UnmarshallerRepositoryPopulatorFactoryBean factory = new UnmarshallerRepositoryPopulatorFactoryBean(); + factory.setUnmarshaller(unmarshaller); + factory.setResources(new Resource[] { new ClassPathResource("apple-fruit-data.xml"), new ClassPathResource("guava-fruit-data.xml") }); + return factory; + } + +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Book.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Book.java new file mode 100644 index 0000000000..deac24548a --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Book.java @@ -0,0 +1,51 @@ +package com.baeldung.datajpadelete.entity; + +import javax.persistence.*; + +@Entity +public class Book { + + @Id + @GeneratedValue + private Long id; + private String title; + + @ManyToOne + private Category category; + + public Book() { + } + + public Book(String title) { + this.title = title; + } + + public Book(String title, Category category) { + this.title = title; + this.category = category; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Category.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Category.java new file mode 100644 index 0000000000..16f1a4157f --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Category.java @@ -0,0 +1,60 @@ +package com.baeldung.datajpadelete.entity; + +import javax.persistence.*; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Entity +public class Category { + + @Id + @GeneratedValue + private Long id; + private String name; + + @OneToMany(mappedBy = "category", cascade = CascadeType.ALL, orphanRemoval = true) + private List books; + + public Category() { + } + + public Category(String name) { + this.name = name; + } + + public Category(String name, Book... books) { + this.name = name; + this.books = Stream.of(books).collect(Collectors.toList()); + this.books.forEach(x -> x.setCategory(this)); + } + + public Category(String name, List books) { + this.name = name; + this.books = books; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getBooks() { + return books; + } + + public void setBooks(List books) { + this.books = books; + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java new file mode 100644 index 0000000000..5d0f45f127 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java @@ -0,0 +1,19 @@ +package com.baeldung.datajpadelete.repository; + +import com.baeldung.datajpadelete.entity.Book; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +@Repository +public interface BookRepository extends CrudRepository { + + long deleteByTitle(String title); + + @Modifying + @Query("delete from Book b where b.title=:title") + void deleteBooks(@Param("title") String title); + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java new file mode 100644 index 0000000000..6fe7058a78 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java @@ -0,0 +1,9 @@ +package com.baeldung.datajpadelete.repository; + +import com.baeldung.datajpadelete.entity.Category; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface CategoryRepository extends CrudRepository { +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/Company.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/Company.java new file mode 100644 index 0000000000..203cff1e35 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/Company.java @@ -0,0 +1,71 @@ +package com.baeldung.embeddable.model; + +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Company { + + @Id + @GeneratedValue + private Integer id; + + private String name; + + private String address; + + private String phone; + + @Embedded + @AttributeOverrides(value = { + @AttributeOverride( name = "firstName", column = @Column(name = "contact_first_name")), + @AttributeOverride( name = "lastName", column = @Column(name = "contact_last_name")), + @AttributeOverride( name = "phone", column = @Column(name = "contact_phone")) + }) + private ContactPerson contactPerson; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public ContactPerson getContactPerson() { + return contactPerson; + } + + public void setContactPerson(ContactPerson contactPerson) { + this.contactPerson = contactPerson; + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/ContactPerson.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/ContactPerson.java new file mode 100644 index 0000000000..561da80878 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/ContactPerson.java @@ -0,0 +1,38 @@ +package com.baeldung.embeddable.model; + +import javax.persistence.Embeddable; + +@Embeddable +public class ContactPerson { + + private String firstName; + + private String lastName; + + private String phone; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java new file mode 100644 index 0000000000..f456b15652 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java @@ -0,0 +1,18 @@ +package com.baeldung.embeddable.repositories; + +import com.baeldung.embeddable.model.Company; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; + +public interface CompanyRepository extends JpaRepository { + + List findByContactPersonFirstName(String firstName); + + @Query("SELECT C FROM Company C WHERE C.contactPerson.firstName = ?1") + List findByContactPersonFirstNameWithJPQL(String firstName); + + @Query(value = "SELECT * FROM company WHERE contact_first_name = ?1", nativeQuery = true) + List findByContactPersonFirstNameWithNativeQuery(String firstName); +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Fruit.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Fruit.java index f82022e67e..d45ac33db8 100644 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Fruit.java +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Fruit.java @@ -2,7 +2,9 @@ package com.baeldung.entity; import javax.persistence.Entity; import javax.persistence.Id; +import javax.xml.bind.annotation.XmlRootElement; +@XmlRootElement @Entity public class Fruit { diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Characteristic.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Characteristic.java new file mode 100644 index 0000000000..ae20375572 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Characteristic.java @@ -0,0 +1,43 @@ +package com.baeldung.entitygraph.model; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + +@Entity +public class Characteristic { + + @Id + private Long id; + private String type; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn + private Item item; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Item getItem() { + return item; + } + + public void setItem(Item item) { + this.item = item; + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Item.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Item.java new file mode 100644 index 0000000000..e90a22ef62 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Item.java @@ -0,0 +1,48 @@ +package com.baeldung.entitygraph.model; + +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.NamedAttributeNode; +import javax.persistence.NamedEntityGraph; +import javax.persistence.OneToMany; + +@Entity +@NamedEntityGraph(name = "Item.characteristics", + attributeNodes = @NamedAttributeNode("characteristics") +) +public class Item { + + @Id + private Long id; + private String name; + + @OneToMany(mappedBy = "item") + private List characteristics = new ArrayList<>(); + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getCharacteristics() { + return characteristics; + } + + public void setCharacteristics(List characteristics) { + this.characteristics = characteristics; + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/CharacteristicsRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/CharacteristicsRepository.java new file mode 100644 index 0000000000..9f923ab241 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/CharacteristicsRepository.java @@ -0,0 +1,13 @@ +package com.baeldung.entitygraph.repository; + +import org.springframework.data.jpa.repository.EntityGraph; +import org.springframework.data.jpa.repository.JpaRepository; + +import com.baeldung.entitygraph.model.Characteristic; + +public interface CharacteristicsRepository extends JpaRepository { + + @EntityGraph(attributePaths = {"item"}) + Characteristic findByType(String type); + +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/ItemRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/ItemRepository.java new file mode 100644 index 0000000000..b2a5f223b3 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/ItemRepository.java @@ -0,0 +1,13 @@ +package com.baeldung.entitygraph.repository; + +import org.springframework.data.jpa.repository.EntityGraph; +import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType; +import org.springframework.data.jpa.repository.JpaRepository; + +import com.baeldung.entitygraph.model.Item; + +public interface ItemRepository extends JpaRepository { + + @EntityGraph(value = "Item.characteristics", type = EntityGraphType.FETCH) + Item findByName(String name); +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Address.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Address.java new file mode 100644 index 0000000000..0c5a3eac60 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Address.java @@ -0,0 +1,57 @@ +package com.baeldung.projection.model; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToOne; + +@Entity +public class Address { + @Id + private Long id; + @OneToOne + private Person person; + private String state; + private String city; + private String street; + private String zipCode; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getZipCode() { + return zipCode; + } + + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Person.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Person.java new file mode 100644 index 0000000000..d18bd1c72d --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Person.java @@ -0,0 +1,47 @@ +package com.baeldung.projection.model; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToOne; + +@Entity +public class Person { + @Id + private Long id; + private String firstName; + private String lastName; + @OneToOne(mappedBy = "person") + private Address address; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/AddressRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/AddressRepository.java new file mode 100644 index 0000000000..c1053f4867 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/AddressRepository.java @@ -0,0 +1,11 @@ +package com.baeldung.projection.repository; + +import com.baeldung.projection.view.AddressView; +import com.baeldung.projection.model.Address; +import org.springframework.data.repository.Repository; + +import java.util.List; + +public interface AddressRepository extends Repository { + List getAddressByState(String state); +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/PersonRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/PersonRepository.java new file mode 100644 index 0000000000..64bc7471e6 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/PersonRepository.java @@ -0,0 +1,14 @@ +package com.baeldung.projection.repository; + +import com.baeldung.projection.model.Person; +import com.baeldung.projection.view.PersonDto; +import com.baeldung.projection.view.PersonView; +import org.springframework.data.repository.Repository; + +public interface PersonRepository extends Repository { + PersonView findByLastName(String lastName); + + PersonDto findByFirstName(String firstName); + + T findByLastName(String lastName, Class type); +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/AddressView.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/AddressView.java new file mode 100644 index 0000000000..7a24a1e9b9 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/AddressView.java @@ -0,0 +1,7 @@ +package com.baeldung.projection.view; + +public interface AddressView { + String getZipCode(); + + PersonView getPerson(); +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonDto.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonDto.java new file mode 100644 index 0000000000..1fd924450b --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonDto.java @@ -0,0 +1,34 @@ +package com.baeldung.projection.view; + +import java.util.Objects; + +public class PersonDto { + private final String firstName; + private final String lastName; + + public PersonDto(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PersonDto personDto = (PersonDto) o; + return Objects.equals(firstName, personDto.firstName) && Objects.equals(lastName, personDto.lastName); + } + + @Override + public int hashCode() { + return Objects.hash(firstName, lastName); + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonView.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonView.java new file mode 100644 index 0000000000..36777ec26f --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonView.java @@ -0,0 +1,12 @@ +package com.baeldung.projection.view; + +import org.springframework.beans.factory.annotation.Value; + +public interface PersonView { + String getFirstName(); + + String getLastName(); + + @Value("#{target.firstName + ' ' + target.lastName}") + String getFullName(); +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/apple-fruit-data.xml b/persistence-modules/spring-data-jpa-2/src/main/resources/apple-fruit-data.xml new file mode 100644 index 0000000000..d87ae28f1e --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/resources/apple-fruit-data.xml @@ -0,0 +1,7 @@ + + + + 1 + apple + red + diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties b/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties new file mode 100644 index 0000000000..4141f5668e --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties @@ -0,0 +1,6 @@ +spring.jpa.show-sql=false + +spring.jpa.properties.hibernate.jdbc.batch_size=5 +spring.jpa.properties.hibernate.order_inserts=true +spring.jpa.properties.hibernate.order_updates=true +spring.jpa.properties.hibernate.batch_versioned_data=true \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/fruit-data.json b/persistence-modules/spring-data-jpa-2/src/main/resources/fruit-data.json new file mode 100644 index 0000000000..6dc44e2586 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/resources/fruit-data.json @@ -0,0 +1,14 @@ +[ + { + "_class": "com.baeldung.entity.Fruit", + "name": "apple", + "color": "red", + "id": 1 + }, + { + "_class": "com.baeldung.entity.Fruit", + "name": "guava", + "color": "green", + "id": 2 + } +] \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/guava-fruit-data.xml b/persistence-modules/spring-data-jpa-2/src/main/resources/guava-fruit-data.xml new file mode 100644 index 0000000000..ffd75bb4bb --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/resources/guava-fruit-data.xml @@ -0,0 +1,7 @@ + + + + 2 + guava + green + diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java new file mode 100644 index 0000000000..9e81dbc04d --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java @@ -0,0 +1,94 @@ +package com.baeldung.batchinserts; + +import static com.baeldung.batchinserts.TestObjectHelper.createSchool; +import static com.baeldung.batchinserts.TestObjectHelper.createStudent; + +import com.baeldung.batchinserts.model.School; +import com.baeldung.batchinserts.model.Student; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.TypedQuery; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional +@ActiveProfiles("batchinserts") +public class JpaBatchInsertsIntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + + private static final int BATCH_SIZE = 5; + + @Transactional + @Test + public void whenInsertingSingleTypeOfEntity_thenCreatesSingleBatch() { + for (int i = 0; i < 10; i++) { + School school = createSchool(i); + entityManager.persist(school); + } + } + + @Transactional + @Test + public void whenFlushingAfterBatch_ThenClearsMemory() { + for (int i = 0; i < 10; i++) { + if (i > 0 && i % BATCH_SIZE == 0) { + entityManager.flush(); + entityManager.clear(); + } + + School school = createSchool(i); + entityManager.persist(school); + } + } + + @Transactional + @Test + public void whenThereAreMultipleEntities_ThenCreatesNewBatch() { + for (int i = 0; i < 10; i++) { + if (i > 0 && i % BATCH_SIZE == 0) { + entityManager.flush(); + entityManager.clear(); + } + + School school = createSchool(i); + entityManager.persist(school); + Student firstStudent = createStudent(school); + Student secondStudent = createStudent(school); + entityManager.persist(firstStudent); + entityManager.persist(secondStudent); + } + } + + @Transactional + @Test + public void whenUpdatingEntities_thenCreatesBatch() { + for (int i = 0; i < 10; i++) { + School school = createSchool(i); + entityManager.persist(school); + } + + entityManager.flush(); + + TypedQuery schoolQuery = entityManager.createQuery("SELECT s from School s", School.class); + List allSchools = schoolQuery.getResultList(); + + for (School school : allSchools) { + school.setName("Updated_" + school.getName()); + } + } + + @After + public void tearDown() { + entityManager.flush(); + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java new file mode 100644 index 0000000000..20502c793d --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java @@ -0,0 +1,39 @@ +package com.baeldung.batchinserts; + +import static com.baeldung.batchinserts.TestObjectHelper.createSchool; + +import com.baeldung.batchinserts.model.School; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional +@ActiveProfiles("batchinserts") +@TestPropertySource(properties = "spring.jpa.properties.hibernate.jdbc.batch_size=-1") +public class JpaNoBatchInsertsIntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + + @Test + public void whenNotConfigured_ThenSendsInsertsSeparately() { + for (int i = 0; i < 10; i++) { + School school = createSchool(i); + entityManager.persist(school); + } + } + + @After + public void tearDown() { + entityManager.flush(); + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java new file mode 100644 index 0000000000..fcd26cb721 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java @@ -0,0 +1,20 @@ +package com.baeldung.batchinserts; + +import com.baeldung.batchinserts.model.School; +import com.baeldung.batchinserts.model.Student; + +public class TestObjectHelper { + + public static School createSchool(int nameIdentifier) { + School school = new School(); + school.setName("School" + (nameIdentifier + 1)); + return school; + } + + public static Student createStudent(School school) { + Student student = new Student(); + student.setName("Student-" + school.getName()); + student.setSchool(school); + return student; + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java new file mode 100644 index 0000000000..9e7e516735 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java @@ -0,0 +1,72 @@ +package com.baeldung.datajpadelete; + +import com.baeldung.Application; +import com.baeldung.datajpadelete.entity.Book; +import com.baeldung.datajpadelete.repository.BookRepository; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {Application.class}) +public class DeleteFromRepositoryUnitTest { + + @Autowired + private BookRepository repository; + + Book book1; + Book book2; + + @Before + public void setup() { + book1 = new Book("The Hobbit"); + book2 = new Book("All Quiet on the Western Front"); + + repository.saveAll(Arrays.asList(book1, book2)); + } + + @After + public void teardown() { + repository.deleteAll(); + } + + @Test + public void whenDeleteByIdFromRepository_thenDeletingShouldBeSuccessful() { + repository.deleteById(book1.getId()); + + assertThat(repository.count() == 1).isTrue(); + } + + @Test + public void whenDeleteAllFromRepository_thenRepositoryShouldBeEmpty() { + repository.deleteAll(); + + assertThat(repository.count() == 0).isTrue(); + } + + @Test + @Transactional + public void whenDeleteFromDerivedQuery_thenDeletingShouldBeSuccessful() { + repository.deleteByTitle("The Hobbit"); + + assertThat(repository.count() == 1).isTrue(); + } + + @Test + @Transactional + public void whenDeleteFromCustomQuery_thenDeletingShouldBeSuccessful() { + repository.deleteBooks("The Hobbit"); + + assertThat(repository.count() == 1).isTrue(); + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java new file mode 100644 index 0000000000..56de8749b2 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java @@ -0,0 +1,60 @@ +package com.baeldung.datajpadelete; + +import com.baeldung.Application; +import com.baeldung.datajpadelete.entity.Book; +import com.baeldung.datajpadelete.entity.Category; +import com.baeldung.datajpadelete.repository.BookRepository; +import com.baeldung.datajpadelete.repository.CategoryRepository; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {Application.class}) +public class DeleteInRelationshipsUnitTest { + + @Autowired + private BookRepository bookRepository; + + @Autowired + private CategoryRepository categoryRepository; + + @Before + public void setup() { + Book book1 = new Book("The Hobbit"); + Category category1 = new Category("Cat1", book1); + categoryRepository.save(category1); + + Book book2 = new Book("All Quiet on the Western Front"); + Category category2 = new Category("Cat2", book2); + categoryRepository.save(category2); + } + + @After + public void teardown() { + bookRepository.deleteAll(); + categoryRepository.deleteAll(); + } + + @Test + public void whenDeletingCategories_thenBooksShouldAlsoBeDeleted() { + categoryRepository.deleteAll(); + + assertThat(bookRepository.count() == 0).isTrue(); + assertThat(categoryRepository.count() == 0).isTrue(); + } + + @Test + public void whenDeletingBooks_thenCategoriesShouldAlsoBeDeleted() { + bookRepository.deleteAll(); + + assertThat(bookRepository.count() == 0).isTrue(); + assertThat(categoryRepository.count() == 2).isTrue(); + } +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java new file mode 100644 index 0000000000..b4c365a2d9 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java @@ -0,0 +1,125 @@ +package com.baeldung.embeddable; + +import com.baeldung.Application; +import com.baeldung.embeddable.model.Company; +import com.baeldung.embeddable.model.ContactPerson; +import com.baeldung.embeddable.repositories.CompanyRepository; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.junit.Assert.assertEquals; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {Application.class}) +public class EmbeddableIntegrationTest { + + @Autowired + private CompanyRepository companyRepository; + + @Test + @Transactional + public void whenInsertingCompany_thenEmbeddedContactPersonDetailsAreMapped() { + ContactPerson contactPerson = new ContactPerson(); + contactPerson.setFirstName("First"); + contactPerson.setLastName("Last"); + contactPerson.setPhone("123-456-789"); + + Company company = new Company(); + company.setName("Company"); + company.setAddress("1st street"); + company.setPhone("987-654-321"); + company.setContactPerson(contactPerson); + + companyRepository.save(company); + + Company result = companyRepository.getOne(company.getId()); + + assertEquals("Company", result.getName()); + assertEquals("1st street", result.getAddress()); + assertEquals("987-654-321", result.getPhone()); + assertEquals("First", result.getContactPerson().getFirstName()); + assertEquals("Last", result.getContactPerson().getLastName()); + assertEquals("123-456-789", result.getContactPerson().getPhone()); + } + + @Test + @Transactional + public void whenFindingCompanyByContactPersonAttribute_thenCompanyIsReturnedProperly() { + ContactPerson contactPerson = new ContactPerson(); + contactPerson.setFirstName("Name"); + contactPerson.setLastName("Last"); + contactPerson.setPhone("123-456-789"); + + Company company = new Company(); + company.setName("Company"); + company.setAddress("1st street"); + company.setPhone("987-654-321"); + company.setContactPerson(contactPerson); + + companyRepository.save(company); + + List result = companyRepository.findByContactPersonFirstName("Name"); + + assertEquals(1, result.size()); + + result = companyRepository.findByContactPersonFirstName("FirstName"); + + assertEquals(0, result.size()); + } + + @Test + @Transactional + public void whenFindingCompanyByContactPersonAttributeWithJPQL_thenCompanyIsReturnedProperly() { + ContactPerson contactPerson = new ContactPerson(); + contactPerson.setFirstName("@QueryName"); + contactPerson.setLastName("Last"); + contactPerson.setPhone("123-456-789"); + + Company company = new Company(); + company.setName("Company"); + company.setAddress("1st street"); + company.setPhone("987-654-321"); + company.setContactPerson(contactPerson); + + companyRepository.save(company); + + List result = companyRepository.findByContactPersonFirstNameWithJPQL("@QueryName"); + + assertEquals(1, result.size()); + + result = companyRepository.findByContactPersonFirstNameWithJPQL("FirstName"); + + assertEquals(0, result.size()); + } + + @Test + @Transactional + public void whenFindingCompanyByContactPersonAttributeWithNativeQuery_thenCompanyIsReturnedProperly() { + ContactPerson contactPerson = new ContactPerson(); + contactPerson.setFirstName("NativeQueryName"); + contactPerson.setLastName("Last"); + contactPerson.setPhone("123-456-789"); + + Company company = new Company(); + company.setName("Company"); + company.setAddress("1st street"); + company.setPhone("987-654-321"); + company.setContactPerson(contactPerson); + + companyRepository.save(company); + + List result = companyRepository.findByContactPersonFirstNameWithNativeQuery("NativeQueryName"); + + assertEquals(1, result.size()); + + result = companyRepository.findByContactPersonFirstNameWithNativeQuery("FirstName"); + + assertEquals(0, result.size()); + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/entitygraph/EntityGraphIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/entitygraph/EntityGraphIntegrationTest.java new file mode 100644 index 0000000000..24880a5dff --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/entitygraph/EntityGraphIntegrationTest.java @@ -0,0 +1,39 @@ +package com.baeldung.entitygraph; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.entitygraph.model.Characteristic; +import com.baeldung.entitygraph.model.Item; +import com.baeldung.entitygraph.repository.CharacteristicsRepository; +import com.baeldung.entitygraph.repository.ItemRepository; + +@DataJpaTest +@RunWith(SpringRunner.class) +@Sql(scripts = "/entitygraph-data.sql") +public class EntityGraphIntegrationTest { + + @Autowired + private ItemRepository itemRepo; + + @Autowired + private CharacteristicsRepository characteristicsRepo; + + @Test + public void givenEntityGraph_whenCalled_shouldRetrunDefinedFields() { + Item item = itemRepo.findByName("Table"); + assertThat(item.getId()).isEqualTo(1L); + } + + @Test + public void givenAdhocEntityGraph_whenCalled_shouldRetrunDefinedFields() { + Characteristic characteristic = characteristicsRepo.findByType("Rigid"); + assertThat(characteristic.getId()).isEqualTo(1L); + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java new file mode 100644 index 0000000000..96eaf4ed07 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java @@ -0,0 +1,63 @@ +package com.baeldung.projection; + +import com.baeldung.projection.model.Person; +import com.baeldung.projection.repository.AddressRepository; +import com.baeldung.projection.repository.PersonRepository; +import com.baeldung.projection.view.AddressView; +import com.baeldung.projection.view.PersonDto; +import com.baeldung.projection.view.PersonView; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; + +@DataJpaTest +@RunWith(SpringRunner.class) +@Sql(scripts = "/projection-insert-data.sql") +@Sql(scripts = "/projection-clean-up-data.sql", executionPhase = AFTER_TEST_METHOD) +public class JpaProjectionIntegrationTest { + @Autowired + private AddressRepository addressRepository; + + @Autowired + private PersonRepository personRepository; + + @Test + public void whenUsingClosedProjections_thenViewWithRequiredPropertiesIsReturned() { + AddressView addressView = addressRepository.getAddressByState("CA").get(0); + assertThat(addressView.getZipCode()).isEqualTo("90001"); + + PersonView personView = addressView.getPerson(); + assertThat(personView.getFirstName()).isEqualTo("John"); + assertThat(personView.getLastName()).isEqualTo("Doe"); + } + + @Test + public void whenUsingOpenProjections_thenViewWithRequiredPropertiesIsReturned() { + PersonView personView = personRepository.findByLastName("Doe"); + assertThat(personView.getFullName()).isEqualTo("John Doe"); + } + + @Test + public void whenUsingClassBasedProjections_thenDtoWithRequiredPropertiesIsReturned() { + PersonDto personDto = personRepository.findByFirstName("John"); + assertThat(personDto.getFirstName()).isEqualTo("John"); + assertThat(personDto.getLastName()).isEqualTo("Doe"); + } + + @Test + public void whenUsingDynamicProjections_thenObjectWithRequiredPropertiesIsReturned() { + Person person = personRepository.findByLastName("Doe", Person.class); + PersonView personView = personRepository.findByLastName("Doe", PersonView.class); + PersonDto personDto = personRepository.findByLastName("Doe", PersonDto.class); + + assertThat(person.getFirstName()).isEqualTo("John"); + assertThat(personView.getFirstName()).isEqualTo("John"); + assertThat(personDto.getFirstName()).isEqualTo("John"); + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/FruitPopulatorTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/FruitPopulatorTest.java new file mode 100644 index 0000000000..29ef52dcef --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/FruitPopulatorTest.java @@ -0,0 +1,38 @@ +package com.baeldung.repository; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.entity.Fruit; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class FruitPopulatorTest { + + @Autowired + private FruitRepository fruitRepository; + + @Test + public void givenFruitJsonPopulatorThenShouldInsertRecordOnStart() { + + List fruits = fruitRepository.findAll(); + assertEquals("record count is not matching", 2, fruits.size()); + + fruits.forEach(fruit -> { + if (1 == fruit.getId()) { + assertEquals("apple", fruit.getName()); + assertEquals("red", fruit.getColor()); + } else if (2 == fruit.getId()) { + assertEquals("guava", fruit.getName()); + assertEquals("green", fruit.getColor()); + } + }); + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/test/resources/entitygraph-data.sql b/persistence-modules/spring-data-jpa-2/src/test/resources/entitygraph-data.sql new file mode 100644 index 0000000000..685ec2c605 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/resources/entitygraph-data.sql @@ -0,0 +1,7 @@ +INSERT INTO Item(id,name) VALUES (1,'Table'); +INSERT INTO Item(id,name) VALUES (2,'Bottle'); + +INSERT INTO Characteristic(id,item_id, type) VALUES (1,1,'Rigid'); +INSERT INTO Characteristic(id,item_id,type) VALUES (2,1,'Big'); +INSERT INTO Characteristic(id,item_id,type) VALUES (3,2,'Fragile'); +INSERT INTO Characteristic(id,item_id,type) VALUES (4,2,'Small'); \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/resources/projection-clean-up-data.sql b/persistence-modules/spring-data-jpa-2/src/test/resources/projection-clean-up-data.sql new file mode 100644 index 0000000000..d34f6f0636 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/resources/projection-clean-up-data.sql @@ -0,0 +1,2 @@ +DELETE FROM address; +DELETE FROM person; \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/resources/projection-insert-data.sql b/persistence-modules/spring-data-jpa-2/src/test/resources/projection-insert-data.sql new file mode 100644 index 0000000000..544dcc4b88 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/resources/projection-insert-data.sql @@ -0,0 +1,2 @@ +INSERT INTO person(id,first_name,last_name) VALUES (1,'John','Doe'); +INSERT INTO address(id,person_id,state,city,street,zip_code) VALUES (1,1,'CA', 'Los Angeles', 'Standford Ave', '90001'); \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/pom.xml b/persistence-modules/spring-data-jpa/pom.xml index c512994931..a7788065c9 100644 --- a/persistence-modules/spring-data-jpa/pom.xml +++ b/persistence-modules/spring-data-jpa/pom.xml @@ -89,5 +89,9 @@ test + + + com.baeldung.boot.Application + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/Application.java similarity index 75% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/Application.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/Application.java index 72d29d9fa5..1f078801e2 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/Application.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/Application.java @@ -1,10 +1,11 @@ -package com.baeldung; +package com.baeldung.boot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import com.baeldung.dao.repositories.impl.ExtendedRepositoryImpl; +import com.baeldung.boot.daos.impl.ExtendedRepositoryImpl; +import com.baeldung.multipledb.MultipleDbApplication; @SpringBootApplication @EnableJpaRepositories(repositoryBaseClass = ExtendedRepositoryImpl.class) diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/config/PersistenceConfiguration.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/config/PersistenceConfiguration.java new file mode 100644 index 0000000000..35a603d9f4 --- /dev/null +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/config/PersistenceConfiguration.java @@ -0,0 +1,21 @@ +package com.baeldung.boot.config; + +import com.baeldung.boot.services.IBarService; +import com.baeldung.boot.services.impl.BarSpringDataJpaService; +import org.springframework.context.annotation.*; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@Profile("!tc") +@EnableTransactionManagement +@EnableJpaAuditing +public class PersistenceConfiguration { + + @Bean + public IBarService barSpringDataJpaService() { + return new BarSpringDataJpaService(); + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ArticleRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ArticleRepository.java similarity index 90% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ArticleRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ArticleRepository.java index 8402c099d9..73397ad42e 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ArticleRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ArticleRepository.java @@ -1,10 +1,11 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; -import com.baeldung.domain.Article; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import com.baeldung.boot.domain.Article; + import java.util.Date; import java.util.List; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/CustomItemRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemRepository.java similarity index 74% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/CustomItemRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemRepository.java index f5b94e507c..0aebe34921 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/CustomItemRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemRepository.java @@ -1,8 +1,8 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; import org.springframework.stereotype.Repository; -import com.baeldung.domain.Item; +import com.baeldung.boot.domain.Item; @Repository public interface CustomItemRepository { diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/CustomItemTypeRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemTypeRepository.java similarity index 71% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/CustomItemTypeRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemTypeRepository.java index 81ebdf3fda..832d61408c 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/CustomItemTypeRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemTypeRepository.java @@ -1,8 +1,8 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; import org.springframework.stereotype.Repository; -import com.baeldung.domain.ItemType; +import com.baeldung.boot.domain.ItemType; @Repository public interface CustomItemTypeRepository { diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/batchinserts/repository/CustomerRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomerRepository.java similarity index 68% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/batchinserts/repository/CustomerRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomerRepository.java index ab0214bade..2f1af6ac55 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/batchinserts/repository/CustomerRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomerRepository.java @@ -1,8 +1,8 @@ -package com.baeldung.batchinserts.repository; +package com.baeldung.boot.daos; import org.springframework.data.repository.CrudRepository; -import com.baeldung.batchinserts.model.Customer; +import com.baeldung.boot.domain.Customer; /** * JPA CrudRepository interface diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ExtendedRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedRepository.java similarity index 90% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ExtendedRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedRepository.java index 9e82f02fa6..adb2af4320 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ExtendedRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedRepository.java @@ -1,4 +1,4 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; import java.io.Serializable; import java.util.List; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ExtendedStudentRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedStudentRepository.java similarity index 54% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ExtendedStudentRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedStudentRepository.java index 199e4e5ff6..c9b0192536 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ExtendedStudentRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedStudentRepository.java @@ -1,6 +1,6 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; -import com.baeldung.domain.Student; +import com.baeldung.boot.domain.Student; public interface ExtendedStudentRepository extends ExtendedRepository { } diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/IBarCrudRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IBarCrudRepository.java similarity index 71% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/IBarCrudRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IBarCrudRepository.java index 54a7d77691..921fabe3fb 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/IBarCrudRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IBarCrudRepository.java @@ -1,8 +1,9 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; -import com.baeldung.domain.Bar; import org.springframework.data.repository.CrudRepository; +import com.baeldung.boot.domain.Bar; + import java.io.Serializable; public interface IBarCrudRepository extends CrudRepository { diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/IFooDao.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IFooDao.java similarity index 83% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/IFooDao.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IFooDao.java index bb3c229945..d537772076 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/IFooDao.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IFooDao.java @@ -1,10 +1,11 @@ -package com.baeldung.dao; +package com.baeldung.boot.daos; -import com.baeldung.domain.Foo; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import com.baeldung.boot.domain.Foo; + public interface IFooDao extends JpaRepository { @Query("SELECT f FROM Foo f WHERE LOWER(f.name) = LOWER(:name)") diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/InventoryRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/InventoryRepository.java similarity index 63% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/InventoryRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/InventoryRepository.java index a575f0b915..606f3993d5 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/InventoryRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/InventoryRepository.java @@ -1,7 +1,8 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; -import com.baeldung.domain.MerchandiseEntity; import org.springframework.data.repository.CrudRepository; +import com.baeldung.boot.domain.MerchandiseEntity; + public interface InventoryRepository extends CrudRepository { } diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ItemTypeRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ItemTypeRepository.java similarity index 76% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ItemTypeRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ItemTypeRepository.java index 2af83bc322..413c09e968 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ItemTypeRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ItemTypeRepository.java @@ -1,9 +1,9 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import com.baeldung.domain.ItemType; +import com.baeldung.boot.domain.ItemType; @Repository public interface ItemTypeRepository extends JpaRepository, CustomItemTypeRepository, CustomItemRepository { diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/LocationRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/LocationRepository.java similarity index 72% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/LocationRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/LocationRepository.java index 27bbe27af0..697ce295d0 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/LocationRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/LocationRepository.java @@ -1,9 +1,9 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import com.baeldung.domain.Location; +import com.baeldung.boot.domain.Location; @Repository public interface LocationRepository extends JpaRepository { diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ReadOnlyLocationRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ReadOnlyLocationRepository.java similarity index 79% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ReadOnlyLocationRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ReadOnlyLocationRepository.java index 8f68cdbbe5..3a2ea3cda5 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/ReadOnlyLocationRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ReadOnlyLocationRepository.java @@ -1,10 +1,10 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; import java.util.Optional; import org.springframework.data.repository.Repository; -import com.baeldung.domain.Location; +import com.baeldung.boot.domain.Location; @org.springframework.stereotype.Repository public interface ReadOnlyLocationRepository extends Repository { diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/StoreRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/StoreRepository.java similarity index 79% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/StoreRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/StoreRepository.java index 9318c32ee9..ae13f75f66 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/StoreRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/StoreRepository.java @@ -1,11 +1,11 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import com.baeldung.domain.Store; +import com.baeldung.boot.domain.Store; @Repository public interface StoreRepository extends JpaRepository { diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/impl/CustomItemRepositoryImpl.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemRepositoryImpl.java similarity index 83% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/impl/CustomItemRepositoryImpl.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemRepositoryImpl.java index 5538448c49..820a2cdd41 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/impl/CustomItemRepositoryImpl.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemRepositoryImpl.java @@ -1,12 +1,12 @@ -package com.baeldung.dao.repositories.impl; +package com.baeldung.boot.daos.impl; import javax.persistence.EntityManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; -import com.baeldung.dao.repositories.CustomItemRepository; -import com.baeldung.domain.Item; +import com.baeldung.boot.daos.CustomItemRepository; +import com.baeldung.boot.domain.Item; @Repository public class CustomItemRepositoryImpl implements CustomItemRepository { diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/impl/CustomItemTypeRepositoryImpl.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemTypeRepositoryImpl.java similarity index 84% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/impl/CustomItemTypeRepositoryImpl.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemTypeRepositoryImpl.java index 2b49f2380c..d7cba7c2c6 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/impl/CustomItemTypeRepositoryImpl.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemTypeRepositoryImpl.java @@ -1,4 +1,4 @@ -package com.baeldung.dao.repositories.impl; +package com.baeldung.boot.daos.impl; import javax.persistence.EntityManager; @@ -7,8 +7,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; -import com.baeldung.domain.ItemType; -import com.baeldung.dao.repositories.CustomItemTypeRepository; +import com.baeldung.boot.daos.CustomItemTypeRepository; +import com.baeldung.boot.domain.ItemType; @Repository public class CustomItemTypeRepositoryImpl implements CustomItemTypeRepository { diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/impl/ExtendedRepositoryImpl.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/ExtendedRepositoryImpl.java similarity index 93% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/impl/ExtendedRepositoryImpl.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/ExtendedRepositoryImpl.java index f6f06efb51..fbe6695844 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/impl/ExtendedRepositoryImpl.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/ExtendedRepositoryImpl.java @@ -1,4 +1,4 @@ -package com.baeldung.dao.repositories.impl; +package com.baeldung.boot.daos.impl; import java.io.Serializable; import java.util.List; @@ -10,10 +10,11 @@ import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; import javax.transaction.Transactional; -import com.baeldung.dao.repositories.ExtendedRepository; import org.springframework.data.jpa.repository.support.JpaEntityInformation; import org.springframework.data.jpa.repository.support.SimpleJpaRepository; +import com.baeldung.boot.daos.ExtendedRepository; + public class ExtendedRepositoryImpl extends SimpleJpaRepository implements ExtendedRepository { private EntityManager entityManager; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/impl/PersonInsertRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/PersonInsertRepository.java similarity index 90% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/impl/PersonInsertRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/PersonInsertRepository.java index d809385456..373532e1c3 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/impl/PersonInsertRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/PersonInsertRepository.java @@ -1,8 +1,9 @@ -package com.baeldung.dao.repositories.impl; +package com.baeldung.boot.daos.impl; -import com.baeldung.domain.Person; import org.springframework.stereotype.Repository; +import com.baeldung.boot.domain.Person; + import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.transaction.Transactional; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/user/PossessionRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/PossessionRepository.java similarity index 62% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/user/PossessionRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/PossessionRepository.java index f0eeb475c1..e102754c18 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/user/PossessionRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/PossessionRepository.java @@ -1,8 +1,9 @@ -package com.baeldung.dao.repositories.user; +package com.baeldung.boot.daos.user; -import com.baeldung.domain.user.Possession; import org.springframework.data.jpa.repository.JpaRepository; +import com.baeldung.boot.domain.Possession; + public interface PossessionRepository extends JpaRepository { } diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/user/UserRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepository.java similarity index 92% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/user/UserRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepository.java index 1d05a17414..d6a060740d 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/user/UserRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepository.java @@ -1,6 +1,5 @@ -package com.baeldung.dao.repositories.user; +package com.baeldung.boot.daos.user; -import com.baeldung.domain.user.User; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -9,6 +8,8 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import com.baeldung.boot.domain.User; + import java.time.LocalDate; import java.util.Collection; import java.util.List; @@ -18,11 +19,11 @@ public interface UserRepository extends JpaRepository , UserRepos Stream findAllByName(String name); - @Query("select u from User u where u.email like '%@gmail.com'") - List findUsersWithGmailAddress(); - @Query("SELECT u FROM User u WHERE u.status = 1") Collection findAllActiveUsers(); + + @Query("select u from User u where u.email like '%@gmail.com'") + List findUsersWithGmailAddress(); @Query(value = "SELECT * FROM Users u WHERE u.status = 1", nativeQuery = true) Collection findAllActiveUsersNative(); @@ -74,14 +75,14 @@ public interface UserRepository extends JpaRepository , UserRepos @Query(value = "INSERT INTO Users (name, age, email, status, active) VALUES (:name, :age, :email, :status, :active)", nativeQuery = true) @Modifying void insertUser(@Param("name") String name, @Param("age") Integer age, @Param("email") String email, @Param("status") Integer status, @Param("active") boolean active); - + @Modifying @Query(value = "UPDATE Users u SET status = ? WHERE u.name = ?", nativeQuery = true) int updateUserSetStatusForNameNativePostgres(Integer status, String name); - + @Query(value = "SELECT u FROM User u WHERE u.name IN :names") - List findUserByNameList(@Param("names") Collection names); - + List findUserByNameList(@Param("names") Collection names); + void deleteAllByCreationDateAfter(LocalDate date); @Modifying(clearAutomatically = true, flushAutomatically = true) @@ -89,11 +90,10 @@ public interface UserRepository extends JpaRepository , UserRepos void deactivateUsersNotLoggedInSince(@Param("date") LocalDate date); @Modifying(clearAutomatically = true, flushAutomatically = true) - @Query("delete from User u where u.active = false") + @Query("delete User u where u.active = false") int deleteDeactivatedUsers(); @Modifying(clearAutomatically = true, flushAutomatically = true) - @Query(value = "alter table Users add column deleted int(1) not null default 0", nativeQuery = true) + @Query(value = "alter table USERS.USERS add column deleted int(1) not null default 0", nativeQuery = true) void addDeletedColumn(); - } diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/user/UserRepositoryCustom.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java similarity index 77% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/user/UserRepositoryCustom.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java index 0f29cd656e..c586b54027 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/user/UserRepositoryCustom.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java @@ -1,14 +1,14 @@ -package com.baeldung.dao.repositories.user; +package com.baeldung.boot.daos.user; import java.util.Collection; import java.util.List; import java.util.Set; import java.util.function.Predicate; -import com.baeldung.domain.user.User; +import com.baeldung.boot.domain.User; public interface UserRepositoryCustom { List findUserByEmails(Set emails); - + List findAllUsersByPredicates(Collection> predicates); } diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/user/UserRepositoryCustomImpl.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java similarity index 95% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/user/UserRepositoryCustomImpl.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java index 7b2a7ab123..63a743b6b5 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/user/UserRepositoryCustomImpl.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java @@ -1,4 +1,4 @@ -package com.baeldung.dao.repositories.user; +package com.baeldung.boot.daos.user; import java.util.ArrayList; import java.util.Collection; @@ -15,7 +15,7 @@ import javax.persistence.criteria.Path; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; -import com.baeldung.domain.user.User; +import com.baeldung.boot.domain.User; public class UserRepositoryCustomImpl implements UserRepositoryCustom { @@ -42,7 +42,7 @@ public class UserRepositoryCustomImpl implements UserRepositoryCustom { return entityManager.createQuery(query) .getResultList(); } - + @Override public List findAllUsersByPredicates(Collection> predicates) { List allUsers = entityManager.createQuery("select u from User u", User.class).getResultList(); diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate.java similarity index 95% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate.java index bf6ff0a0b9..e435f4c85c 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.ddd.event; +package com.baeldung.boot.ddd.event; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate2.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2.java similarity index 95% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate2.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2.java index 3d2816299a..08f61db812 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate2.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.ddd.event; +package com.baeldung.boot.ddd.event; import java.util.ArrayList; import java.util.Collection; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate2Repository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2Repository.java similarity index 80% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate2Repository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2Repository.java index 2a95abe347..7f09c410fc 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate2Repository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2Repository.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.ddd.event; +package com.baeldung.boot.ddd.event; import org.springframework.data.repository.CrudRepository; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate3.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3.java similarity index 91% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate3.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3.java index e0c3131b06..f664322a59 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate3.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.ddd.event; +package com.baeldung.boot.ddd.event; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate3Repository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3Repository.java similarity index 83% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate3Repository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3Repository.java index e442bdb210..93f50bb5cf 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate3Repository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3Repository.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.ddd.event; +package com.baeldung.boot.ddd.event; import org.springframework.data.repository.CrudRepository; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/AggregateRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/AggregateRepository.java similarity index 80% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/AggregateRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/AggregateRepository.java index 5a15156d03..1c2d3884bf 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/AggregateRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/AggregateRepository.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.ddd.event; +package com.baeldung.boot.ddd.event; import org.springframework.data.repository.CrudRepository; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DddConfig.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DddConfig.java similarity index 89% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DddConfig.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DddConfig.java index 1315b11875..34cf21463b 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DddConfig.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DddConfig.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.ddd.event; +package com.baeldung.boot.ddd.event; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainEvent.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainEvent.java new file mode 100644 index 0000000000..e7626e742d --- /dev/null +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainEvent.java @@ -0,0 +1,8 @@ +/** + * + */ +package com.baeldung.boot.ddd.event; + +class DomainEvent { + +} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DomainService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainService.java similarity index 95% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DomainService.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainService.java index 082c9bd88e..80aa5ca6cb 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DomainService.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainService.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.ddd.event; +package com.baeldung.boot.ddd.event; import javax.transaction.Transactional; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Article.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Article.java similarity index 92% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Article.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Article.java index 3b5a8be088..de4dbed1a0 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Article.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Article.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import javax.persistence.*; import java.util.Date; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Bar.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Bar.java similarity index 99% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Bar.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Bar.java index efd297bafc..35d1903801 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Bar.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Bar.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import com.google.common.collect.Sets; import org.hibernate.annotations.OrderBy; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/batchinserts/model/Customer.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Customer.java similarity index 96% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/batchinserts/model/Customer.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Customer.java index 4d82cf12a2..af88be0be6 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/batchinserts/model/Customer.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Customer.java @@ -1,4 +1,4 @@ -package com.baeldung.batchinserts.model; +package com.baeldung.boot.domain; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Foo.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Foo.java similarity index 98% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Foo.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Foo.java index ef88840746..5030e5600b 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Foo.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Foo.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import org.hibernate.envers.Audited; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Item.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Item.java similarity index 97% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Item.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Item.java index 1e58fb25ba..8ac06af15a 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Item.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Item.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import java.math.BigDecimal; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/ItemType.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/ItemType.java similarity index 96% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/ItemType.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/ItemType.java index b0349e0471..8a52a9847c 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/ItemType.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/ItemType.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import java.util.ArrayList; import java.util.List; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/KVTag.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/KVTag.java similarity index 94% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/KVTag.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/KVTag.java index b3e7d78b30..1901f43c0a 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/KVTag.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/KVTag.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import javax.persistence.Embeddable; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Location.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Location.java similarity index 96% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Location.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Location.java index 4ca7295986..9c1b93d551 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Location.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Location.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import java.util.ArrayList; import java.util.List; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/MerchandiseEntity.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/MerchandiseEntity.java similarity index 97% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/MerchandiseEntity.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/MerchandiseEntity.java index bfc690e0e2..e94c23de86 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/MerchandiseEntity.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/MerchandiseEntity.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Person.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Person.java similarity index 95% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Person.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Person.java index 30d7370982..88894ccc72 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Person.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Person.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/user/Possession.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Possession.java similarity index 95% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/user/Possession.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Possession.java index b1427c0270..f13491ad82 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/user/Possession.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Possession.java @@ -1,6 +1,7 @@ -package com.baeldung.domain.user; +package com.baeldung.boot.domain; import javax.persistence.*; +import com.baeldung.boot.domain.Possession; @Entity @Table diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/SkillTag.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/SkillTag.java similarity index 93% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/SkillTag.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/SkillTag.java index 1f2778c589..0933a3e6af 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/SkillTag.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/SkillTag.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import javax.persistence.Embeddable; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Store.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Store.java similarity index 97% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Store.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Store.java index 4172051c71..5b4b831cc7 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Store.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Store.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import java.util.ArrayList; import java.util.List; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Student.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Student.java similarity index 97% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Student.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Student.java index bd7eaeb24b..1003167cc7 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Student.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Student.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.boot.domain; import javax.persistence.ElementCollection; import javax.persistence.Entity; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/user/User.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/User.java similarity index 96% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/user/User.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/User.java index 7109271eeb..cca00e52a2 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/user/User.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/User.java @@ -1,6 +1,7 @@ -package com.baeldung.domain.user; +package com.baeldung.boot.domain; import javax.persistence.*; + import java.time.LocalDate; import java.util.List; import java.util.Objects; @@ -27,7 +28,7 @@ public class User { super(); } - public User(String name, LocalDate creationDate, String email, Integer status) { + public User(String name, LocalDate creationDate,String email, Integer status) { this.name = name; this.creationDate = creationDate; this.email = email; @@ -51,10 +52,6 @@ public class User { this.name = name; } - public LocalDate getCreationDate() { - return creationDate; - } - public String getEmail() { return email; } @@ -78,6 +75,10 @@ public class User { public void setAge(final int age) { this.age = age; } + + public LocalDate getCreationDate() { + return creationDate; + } public List getPossessionList() { return possessionList; @@ -93,7 +94,7 @@ public class User { builder.append("User [name=").append(name).append(", id=").append(id).append("]"); return builder.toString(); } - + @Override public boolean equals(Object o) { if (this == o) return true; @@ -127,4 +128,5 @@ public class User { public void setActive(boolean active) { this.active = active; } + } \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/CustomPassengerRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/passenger/CustomPassengerRepository.java similarity index 77% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/CustomPassengerRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/passenger/CustomPassengerRepository.java index 7ae44bfbda..7152286c83 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/CustomPassengerRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/passenger/CustomPassengerRepository.java @@ -1,4 +1,4 @@ -package com.baeldung.passenger; +package com.baeldung.boot.passenger; import java.util.List; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/Passenger.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/passenger/Passenger.java similarity index 98% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/Passenger.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/passenger/Passenger.java index a96b1edb20..c75107a783 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/Passenger.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/passenger/Passenger.java @@ -1,4 +1,4 @@ -package com.baeldung.passenger; +package com.baeldung.boot.passenger; import javax.persistence.Basic; import javax.persistence.Column; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/passenger/PassengerRepository.java similarity index 86% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/passenger/PassengerRepository.java index b2d145899e..cdb8cc98fb 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/passenger/PassengerRepository.java @@ -1,4 +1,4 @@ -package com.baeldung.passenger; +package com.baeldung.boot.passenger; import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; @@ -9,6 +9,8 @@ interface PassengerRepository extends JpaRepository, CustomPass Passenger findFirstByOrderBySeatNumberAsc(); + Passenger findTopByOrderBySeatNumberAsc(); + List findByOrderBySeatNumberAsc(); List findByLastNameOrderBySeatNumberAsc(String lastName); diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepositoryImpl.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/passenger/PassengerRepositoryImpl.java similarity index 93% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepositoryImpl.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/passenger/PassengerRepositoryImpl.java index bd6e535e3e..508c669066 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepositoryImpl.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/passenger/PassengerRepositoryImpl.java @@ -1,4 +1,4 @@ -package com.baeldung.passenger; +package com.baeldung.boot.passenger; import org.springframework.stereotype.Repository; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IBarService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IBarService.java new file mode 100644 index 0000000000..8054cbba59 --- /dev/null +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IBarService.java @@ -0,0 +1,7 @@ +package com.baeldung.boot.services; + +import com.baeldung.boot.domain.Bar; + +public interface IBarService extends IOperations { + // +} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/IFooService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IFooService.java similarity index 76% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/IFooService.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IFooService.java index 7e16ace5b6..871cccdd45 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/IFooService.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IFooService.java @@ -1,9 +1,10 @@ -package com.baeldung.services; +package com.baeldung.boot.services; -import com.baeldung.domain.Foo; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import com.baeldung.boot.domain.Foo; + public interface IFooService extends IOperations { Foo retrieveByName(String name); diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/IOperations.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IOperations.java similarity index 92% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/IOperations.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IOperations.java index d50d465639..ec2b866b6f 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/IOperations.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IOperations.java @@ -1,4 +1,4 @@ -package com.baeldung.services; +package com.baeldung.boot.services; import org.springframework.data.domain.Page; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/impl/AbstractService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractService.java similarity index 94% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/impl/AbstractService.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractService.java index 708524225b..8e4f643adc 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/impl/AbstractService.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractService.java @@ -1,6 +1,6 @@ -package com.baeldung.services.impl; +package com.baeldung.boot.services.impl; -import com.baeldung.services.IOperations; +import com.baeldung.boot.services.IOperations; import com.google.common.collect.Lists; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/impl/AbstractSpringDataJpaService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractSpringDataJpaService.java similarity index 92% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/impl/AbstractSpringDataJpaService.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractSpringDataJpaService.java index 28c86bee28..a73a6bd7fc 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/impl/AbstractSpringDataJpaService.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractSpringDataJpaService.java @@ -1,6 +1,6 @@ -package com.baeldung.services.impl; +package com.baeldung.boot.services.impl; -import com.baeldung.services.IOperations; +import com.baeldung.boot.services.IOperations; import com.google.common.collect.Lists; import org.springframework.data.repository.CrudRepository; import org.springframework.transaction.annotation.Transactional; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/impl/BarSpringDataJpaService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/BarSpringDataJpaService.java similarity index 79% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/impl/BarSpringDataJpaService.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/BarSpringDataJpaService.java index ca3e5f868d..80568f2fd4 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/impl/BarSpringDataJpaService.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/BarSpringDataJpaService.java @@ -1,8 +1,9 @@ -package com.baeldung.services.impl; +package com.baeldung.boot.services.impl; + +import com.baeldung.boot.daos.IBarCrudRepository; +import com.baeldung.boot.domain.Bar; +import com.baeldung.boot.services.IBarService; -import com.baeldung.domain.Bar; -import com.baeldung.dao.repositories.IBarCrudRepository; -import com.baeldung.services.IBarService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.repository.CrudRepository; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/impl/FooService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/FooService.java similarity index 87% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/impl/FooService.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/FooService.java index 319ab3a825..04eec63854 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/impl/FooService.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/FooService.java @@ -1,9 +1,10 @@ -package com.baeldung.services.impl; +package com.baeldung.boot.services.impl; import com.google.common.collect.Lists; -import com.baeldung.dao.IFooDao; -import com.baeldung.domain.Foo; -import com.baeldung.services.IFooService; +import com.baeldung.boot.daos.IFooDao; +import com.baeldung.boot.domain.Foo; +import com.baeldung.boot.services.IFooService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/batchinserts/CustomerController.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/web/controllers/CustomerController.java similarity index 88% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/batchinserts/CustomerController.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/web/controllers/CustomerController.java index 7623d4d166..69a1e5507e 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/batchinserts/CustomerController.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/web/controllers/CustomerController.java @@ -1,4 +1,4 @@ -package com.baeldung.batchinserts; +package com.baeldung.boot.web.controllers; import java.net.URISyntaxException; import java.util.Arrays; @@ -9,8 +9,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; -import com.baeldung.batchinserts.model.Customer; -import com.baeldung.batchinserts.repository.CustomerRepository; +import com.baeldung.boot.daos.CustomerRepository; +import com.baeldung.boot.domain.Customer; /** * A simple controller to test the JPA CrudRepository operations diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/config/PersistenceConfiguration.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/config/PersistenceConfiguration.java deleted file mode 100644 index 891624443b..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/config/PersistenceConfiguration.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.baeldung.config; - -import com.baeldung.dao.repositories.impl.ExtendedRepositoryImpl; -import com.baeldung.services.IBarService; -import com.baeldung.services.impl.BarSpringDataJpaService; -import com.google.common.base.Preconditions; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.*; -import org.springframework.core.env.Environment; -import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; -import org.springframework.data.jpa.repository.config.EnableJpaAuditing; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.JpaVendorAdapter; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -import javax.sql.DataSource; -import java.util.Properties; - -@Configuration -@ComponentScan({ "com.baeldung.dao", "com.baeldung.services" }) -@EnableTransactionManagement -@EnableJpaRepositories(basePackages = { "com.baeldung.dao" }, repositoryBaseClass = ExtendedRepositoryImpl.class) -@EnableJpaAuditing -@PropertySource("classpath:persistence.properties") -@Profile("!tc") -public class PersistenceConfiguration { - - @Autowired - private Environment env; - - public PersistenceConfiguration() { - super(); - } - - @Bean - public LocalContainerEntityManagerFactoryBean entityManagerFactory() { - final LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); - emf.setDataSource(dataSource()); - emf.setPackagesToScan("com.baeldung.domain"); - - final JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); - emf.setJpaVendorAdapter(vendorAdapter); - emf.setJpaProperties(hibernateProperties()); - - return emf; - } - - @Bean - public DataSource dataSource() { - final DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); - dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url"))); - dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); - dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); - - return dataSource; - } - - @Bean - public PlatformTransactionManager transactionManager() { - final JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(entityManagerFactory().getObject()); - return transactionManager; - } - - @Bean - public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { - return new PersistenceExceptionTranslationPostProcessor(); - } - - @Bean - public IBarService barSpringDataJpaService() { - return new BarSpringDataJpaService(); - } - - private final Properties hibernateProperties() { - final Properties hibernateProperties = new Properties(); - hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); - hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); - - hibernateProperties.setProperty("hibernate.show_sql", "true"); - // hibernateProperties.setProperty("hibernate.format_sql", "true"); - // hibernateProperties.setProperty("hibernate.globally_quoted_identifiers", "true"); - - // Envers properties - hibernateProperties.setProperty("org.hibernate.envers.audit_table_suffix", - env.getProperty("envers.audit_table_suffix")); - - return hibernateProperties; - } - -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/product/ProductRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/product/ProductRepository.java deleted file mode 100755 index 1f9f5f9195..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/product/ProductRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.dao.repositories.product; - -import com.baeldung.domain.product.Product; - -import java.util.List; - -import org.springframework.data.domain.Pageable; -import org.springframework.data.repository.PagingAndSortingRepository; - -public interface ProductRepository extends PagingAndSortingRepository { - - List findAllByPrice(double price, Pageable pageable); -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DomainEvent.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DomainEvent.java deleted file mode 100644 index 1e6479d4fc..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DomainEvent.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -package com.baeldung.ddd.event; - -class DomainEvent { - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java new file mode 100644 index 0000000000..8ff6799e31 --- /dev/null +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java @@ -0,0 +1,14 @@ +package com.baeldung.multipledb; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MultipleDbApplication { + + public static void main(String[] args) { + SpringApplication.run(MultipleDbApplication.class, args); + } + +} + diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/config/PersistenceProductConfiguration.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java similarity index 90% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/config/PersistenceProductConfiguration.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java index ecaee82ae5..bcf2cd84eb 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/config/PersistenceProductConfiguration.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java @@ -1,4 +1,4 @@ -package com.baeldung.config; +package com.baeldung.multipledb; import com.google.common.base.Preconditions; import org.springframework.beans.factory.annotation.Autowired; @@ -19,7 +19,7 @@ import java.util.HashMap; @Configuration @PropertySource({"classpath:persistence-multiple-db.properties"}) -@EnableJpaRepositories(basePackages = "com.baeldung.dao.repositories.product", entityManagerFactoryRef = "productEntityManager", transactionManagerRef = "productTransactionManager") +@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.product", entityManagerFactoryRef = "productEntityManager", transactionManagerRef = "productTransactionManager") @Profile("!tc") public class PersistenceProductConfiguration { @Autowired @@ -35,7 +35,7 @@ public class PersistenceProductConfiguration { public LocalContainerEntityManagerFactoryBean productEntityManager() { final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(productDataSource()); - em.setPackagesToScan("com.baeldung.domain.product"); + em.setPackagesToScan("com.baeldung.multipledb.model.product"); final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); em.setJpaVendorAdapter(vendorAdapter); diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/config/PersistenceUserConfiguration.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java similarity index 88% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/config/PersistenceUserConfiguration.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java index 6893d889e6..6b48455c0c 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/config/PersistenceUserConfiguration.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java @@ -1,4 +1,4 @@ -package com.baeldung.config; +package com.baeldung.multipledb; import com.google.common.base.Preconditions; import org.springframework.beans.factory.annotation.Autowired; @@ -16,7 +16,7 @@ import java.util.HashMap; @Configuration @PropertySource({"classpath:persistence-multiple-db.properties"}) -@EnableJpaRepositories(basePackages = "com.baeldung.dao.repositories.user", entityManagerFactoryRef = "userEntityManager", transactionManagerRef = "userTransactionManager") +@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.user", entityManagerFactoryRef = "userEntityManager", transactionManagerRef = "userTransactionManager") @Profile("!tc") public class PersistenceUserConfiguration { @Autowired @@ -31,9 +31,10 @@ public class PersistenceUserConfiguration { @Primary @Bean public LocalContainerEntityManagerFactoryBean userEntityManager() { + System.out.println("loading config"); final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(userDataSource()); - em.setPackagesToScan("com.baeldung.domain.user"); + em.setPackagesToScan("com.baeldung.multipledb.model.user"); final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); em.setJpaVendorAdapter(vendorAdapter); diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java new file mode 100755 index 0000000000..022099eed0 --- /dev/null +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java @@ -0,0 +1,13 @@ +package com.baeldung.multipledb.dao.product; + +import java.util.List; + +import org.springframework.data.domain.Pageable; +import org.springframework.data.repository.PagingAndSortingRepository; + +import com.baeldung.multipledb.model.product.ProductMultipleDB; + +public interface ProductRepository extends PagingAndSortingRepository { + + List findAllByPrice(double price, Pageable pageable); +} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java new file mode 100644 index 0000000000..ae37fde20d --- /dev/null +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java @@ -0,0 +1,9 @@ +package com.baeldung.multipledb.dao.user; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.baeldung.multipledb.model.user.PossessionMultipleDB; + +public interface PossessionRepository extends JpaRepository { + +} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java new file mode 100644 index 0000000000..267a61a93f --- /dev/null +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.multipledb.dao.user; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.baeldung.multipledb.model.user.UserMultipleDB; + +public interface UserRepository extends JpaRepository { +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/product/Product.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/product/ProductMultipleDB.java similarity index 76% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/product/Product.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/product/ProductMultipleDB.java index 2f82e3e318..8bdff340ac 100755 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/product/Product.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/product/ProductMultipleDB.java @@ -1,4 +1,4 @@ -package com.baeldung.domain.product; +package com.baeldung.multipledb.model.product; import javax.persistence.Entity; import javax.persistence.Id; @@ -6,7 +6,7 @@ import javax.persistence.Table; @Entity @Table(schema = "products") -public class Product { +public class ProductMultipleDB { @Id private int id; @@ -15,19 +15,19 @@ public class Product { private double price; - public Product() { + public ProductMultipleDB() { super(); } - private Product(int id, String name, double price) { + private ProductMultipleDB(int id, String name, double price) { super(); this.id = id; this.name = name; this.price = price; } - public static Product from(int id, String name, double price) { - return new Product(id, name, price); + public static ProductMultipleDB from(int id, String name, double price) { + return new ProductMultipleDB(id, name, price); } public int getId() { diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java new file mode 100644 index 0000000000..a6a3c88bd0 --- /dev/null +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java @@ -0,0 +1,82 @@ +package com.baeldung.multipledb.model.user; + +import javax.persistence.*; + +@Entity +@Table +public class PossessionMultipleDB { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + private String name; + + public PossessionMultipleDB() { + super(); + } + + public PossessionMultipleDB(final String name) { + super(); + + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(final int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = (prime * result) + (int) (id ^ (id >>> 32)); + result = (prime * result) + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final PossessionMultipleDB other = (PossessionMultipleDB) obj; + if (id != other.id) { + return false; + } + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("Possesion [id=").append(id).append(", name=").append(name).append("]"); + return builder.toString(); + } + +} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java new file mode 100644 index 0000000000..c7cd07f7a1 --- /dev/null +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java @@ -0,0 +1,88 @@ +package com.baeldung.multipledb.model.user; + +import javax.persistence.*; + +import java.util.List; + +@Entity +@Table(name = "users") +public class UserMultipleDB { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + private String name; + private int age; + @Column(unique = true, nullable = false) + private String email; + private Integer status; + + @OneToMany + List possessionList; + + public UserMultipleDB() { + super(); + } + + public UserMultipleDB(String name, String email, Integer status) { + this.name = name; + this.email = email; + this.status = status; + } + + public int getId() { + return id; + } + + public void setId(final int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(final String email) { + this.email = email; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public int getAge() { + return age; + } + + public void setAge(final int age) { + this.age = age; + } + + public List getPossessionList() { + return possessionList; + } + + public void setPossessionList(List possessionList) { + this.possessionList = possessionList; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("User [name=").append(name).append(", id=").append(id).append("]"); + return builder.toString(); + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/IBarService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/IBarService.java deleted file mode 100644 index 7e127488db..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/services/IBarService.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.services; - -import com.baeldung.domain.Bar; - -public interface IBarService extends IOperations { - // -} diff --git a/persistence-modules/spring-data-jpa/src/main/resources/application.properties b/persistence-modules/spring-data-jpa/src/main/resources/application.properties index 239f81db7b..f127dd5e50 100644 --- a/persistence-modules/spring-data-jpa/src/main/resources/application.properties +++ b/persistence-modules/spring-data-jpa/src/main/resources/application.properties @@ -1,22 +1,6 @@ -# spring.datasource.x -spring.datasource.driver-class-name=org.h2.Driver -spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 -spring.datasource.username=sa -spring.datasource.password=sa - -# hibernate.X -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true -hibernate.hbm2ddl.auto=create-drop -hibernate.cache.use_second_level_cache=true -hibernate.cache.use_query_cache=true -hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory - -spring.datasource.data=import_entities.sql - spring.main.allow-bean-definition-overriding=true spring.jpa.properties.hibernate.jdbc.batch_size=4 spring.jpa.properties.hibernate.order_inserts=true spring.jpa.properties.hibernate.order_updates=true -spring.jpa.properties.hibernate.generate_statistics=true \ No newline at end of file +spring.jpa.properties.hibernate.generate_statistics=true diff --git a/persistence-modules/spring-data-jpa/src/main/resources/persistence.properties b/persistence-modules/spring-data-jpa/src/main/resources/persistence.properties index 3543e1b52b..6bc83edf34 100644 --- a/persistence-modules/spring-data-jpa/src/main/resources/persistence.properties +++ b/persistence-modules/spring-data-jpa/src/main/resources/persistence.properties @@ -12,5 +12,3 @@ hibernate.cache.use_second_level_cache=true hibernate.cache.use_query_cache=true hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory -# envers.X -envers.audit_table_suffix=_audit_log \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java index f60e0d21bf..7ddf36d3f0 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java @@ -9,21 +9,17 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import com.baeldung.batchinserts.CustomerController; -import com.baeldung.batchinserts.repository.CustomerRepository; -import com.baeldung.config.PersistenceConfiguration; -import com.baeldung.config.PersistenceProductConfiguration; -import com.baeldung.config.PersistenceUserConfiguration; +import com.baeldung.boot.Application; +import com.baeldung.boot.daos.CustomerRepository; +import com.baeldung.boot.web.controllers.CustomerController; @RunWith(SpringRunner.class) -@SpringBootTest +@SpringBootTest(classes=Application.class) @AutoConfigureMockMvc -@ContextConfiguration(classes = { PersistenceConfiguration.class, PersistenceProductConfiguration.class, PersistenceUserConfiguration.class }) public class BatchInsertIntegrationTest { @Autowired diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/ArticleRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ArticleRepositoryIntegrationTest.java similarity index 82% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/ArticleRepositoryIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ArticleRepositoryIntegrationTest.java index 093e744003..dfb04b3dfb 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/ArticleRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ArticleRepositoryIntegrationTest.java @@ -1,13 +1,16 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; + +import com.baeldung.boot.Application; +import com.baeldung.boot.config.PersistenceConfiguration; +import com.baeldung.boot.daos.ArticleRepository; +import com.baeldung.boot.domain.Article; -import com.baeldung.config.PersistenceConfiguration; -import com.baeldung.config.PersistenceProductConfiguration; -import com.baeldung.config.PersistenceUserConfiguration; -import com.baeldung.domain.Article; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; import org.springframework.test.context.junit4.SpringRunner; import java.text.SimpleDateFormat; @@ -18,7 +21,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @RunWith(SpringRunner.class) -@DataJpaTest(excludeAutoConfiguration = {PersistenceConfiguration.class, PersistenceUserConfiguration.class, PersistenceProductConfiguration.class}) +@DataJpaTest(properties="spring.datasource.data=classpath:import_entities.sql") public class ArticleRepositoryIntegrationTest { @Autowired diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/ExtendedStudentRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ExtendedStudentRepositoryIntegrationTest.java similarity index 80% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/ExtendedStudentRepositoryIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ExtendedStudentRepositoryIntegrationTest.java index b19a34df82..66de5911db 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/ExtendedStudentRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ExtendedStudentRepositoryIntegrationTest.java @@ -1,7 +1,10 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; + +import com.baeldung.boot.Application; +import com.baeldung.boot.config.PersistenceConfiguration; +import com.baeldung.boot.daos.ExtendedStudentRepository; +import com.baeldung.boot.domain.Student; -import com.baeldung.config.PersistenceConfiguration; -import com.baeldung.domain.Student; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -15,7 +18,7 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@ContextConfiguration(classes = {PersistenceConfiguration.class}) +@ContextConfiguration(classes = {Application.class}) @DirtiesContext public class ExtendedStudentRepositoryIntegrationTest { @Resource diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/InventoryRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/InventoryRepositoryIntegrationTest.java similarity index 85% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/InventoryRepositoryIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/InventoryRepositoryIntegrationTest.java index 9d6334445c..877e59d5a2 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/InventoryRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/InventoryRepositoryIntegrationTest.java @@ -1,11 +1,15 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; + +import com.baeldung.boot.Application; +import com.baeldung.boot.config.PersistenceConfiguration; +import com.baeldung.boot.daos.InventoryRepository; +import com.baeldung.boot.domain.MerchandiseEntity; -import com.baeldung.config.PersistenceConfiguration; -import com.baeldung.domain.MerchandiseEntity; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.math.BigDecimal; @@ -15,7 +19,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; @RunWith(SpringRunner.class) -@DataJpaTest(excludeAutoConfiguration = {PersistenceConfiguration.class}) +@SpringBootTest(classes=Application.class) public class InventoryRepositoryIntegrationTest { private static final String ORIGINAL_TITLE = "Pair of Pants"; diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/JpaRepositoriesIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/JpaRepositoriesIntegrationTest.java similarity index 80% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/JpaRepositoriesIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/JpaRepositoriesIntegrationTest.java index 01405c0b8a..30925d9b68 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/JpaRepositoriesIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/JpaRepositoriesIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertFalse; @@ -13,18 +13,24 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import com.baeldung.config.PersistenceConfiguration; -import com.baeldung.config.PersistenceProductConfiguration; -import com.baeldung.config.PersistenceUserConfiguration; -import com.baeldung.domain.Item; -import com.baeldung.domain.ItemType; -import com.baeldung.domain.Location; -import com.baeldung.domain.Store; +import com.baeldung.boot.Application; +import com.baeldung.boot.config.PersistenceConfiguration; +import com.baeldung.boot.daos.ItemTypeRepository; +import com.baeldung.boot.daos.LocationRepository; +import com.baeldung.boot.daos.ReadOnlyLocationRepository; +import com.baeldung.boot.daos.StoreRepository; +import com.baeldung.boot.domain.Item; +import com.baeldung.boot.domain.ItemType; +import com.baeldung.boot.domain.Location; +import com.baeldung.boot.domain.Store; +import com.baeldung.multipledb.PersistenceProductConfiguration; +import com.baeldung.multipledb.PersistenceUserConfiguration; @RunWith(SpringRunner.class) -@DataJpaTest(excludeAutoConfiguration = { PersistenceConfiguration.class, PersistenceUserConfiguration.class, PersistenceProductConfiguration.class }) +@DataJpaTest(properties="spring.datasource.data=classpath:import_entities.sql") public class JpaRepositoriesIntegrationTest { @Autowired private LocationRepository locationRepository; diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/PersonInsertRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/PersonInsertRepositoryIntegrationTest.java similarity index 94% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/PersonInsertRepositoryIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/PersonInsertRepositoryIntegrationTest.java index b248cf8bf1..9d45c17035 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/PersonInsertRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/PersonInsertRepositoryIntegrationTest.java @@ -1,7 +1,8 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; + +import com.baeldung.boot.daos.impl.PersonInsertRepository; +import com.baeldung.boot.domain.Person; -import com.baeldung.dao.repositories.impl.PersonInsertRepository; -import com.baeldung.domain.Person; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/UserRepositoryCommon.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java similarity index 99% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/UserRepositoryCommon.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java index abd758cec2..4aeeaf5209 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/UserRepositoryCommon.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java @@ -1,7 +1,5 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; -import com.baeldung.dao.repositories.user.UserRepository; -import com.baeldung.domain.user.User; import org.junit.After; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -12,6 +10,9 @@ import org.springframework.data.jpa.domain.JpaSort; import org.springframework.data.mapping.PropertyReferenceException; import org.springframework.transaction.annotation.Transactional; +import com.baeldung.boot.daos.user.UserRepository; +import com.baeldung.boot.domain.User; + import javax.persistence.EntityManager; import javax.persistence.Query; import java.time.LocalDate; diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/UserRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryIntegrationTest.java similarity index 86% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/UserRepositoryIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryIntegrationTest.java index 09f937c8f2..1b1d264574 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/UserRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryIntegrationTest.java @@ -1,7 +1,7 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; -import com.baeldung.config.PersistenceConfiguration; -import com.baeldung.domain.user.User; +import com.baeldung.boot.Application; +import com.baeldung.boot.domain.User; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @@ -17,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Created by adam. */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = PersistenceConfiguration.class) +@SpringBootTest(classes = Application.class) @DirtiesContext public class UserRepositoryIntegrationTest extends UserRepositoryCommon { diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/UserRepositoryTCAutoIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoIntegrationTest.java similarity index 91% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/UserRepositoryTCAutoIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoIntegrationTest.java index 6a851823e3..2f3e9c9032 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/UserRepositoryTCAutoIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoIntegrationTest.java @@ -1,6 +1,7 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; -import com.baeldung.domain.user.User; +import com.baeldung.boot.Application; +import com.baeldung.boot.domain.User; import com.baeldung.util.BaeldungPostgresqlContainer; import org.junit.ClassRule; import org.junit.Test; @@ -19,7 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Created by adam. */ @RunWith(SpringRunner.class) -@SpringBootTest +@SpringBootTest(classes = Application.class) @ActiveProfiles({"tc", "tc-auto"}) public class UserRepositoryTCAutoIntegrationTest extends UserRepositoryCommon { diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/UserRepositoryTCIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCIntegrationTest.java similarity index 94% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/UserRepositoryTCIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCIntegrationTest.java index c300a07ab9..afdf60cc81 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/UserRepositoryTCIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCIntegrationTest.java @@ -1,6 +1,7 @@ -package com.baeldung.dao.repositories; +package com.baeldung.boot.daos; -import com.baeldung.domain.user.User; +import com.baeldung.boot.Application; +import com.baeldung.boot.domain.User; import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; @@ -19,7 +20,7 @@ import java.time.LocalDate; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest +@SpringBootTest(classes = Application.class) @ActiveProfiles("tc") @ContextConfiguration(initializers = {UserRepositoryTCIntegrationTest.Initializer.class}) public class UserRepositoryTCIntegrationTest extends UserRepositoryCommon { diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/ddd/event/Aggregate2EventsIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate2EventsIntegrationTest.java similarity index 90% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/ddd/event/Aggregate2EventsIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate2EventsIntegrationTest.java index 3f650d4d63..e76b932cb9 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/ddd/event/Aggregate2EventsIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate2EventsIntegrationTest.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.ddd.event; +package com.baeldung.boot.ddd.event; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; @@ -15,6 +15,10 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import com.baeldung.boot.ddd.event.Aggregate2; +import com.baeldung.boot.ddd.event.Aggregate2Repository; +import com.baeldung.boot.ddd.event.DomainEvent; + @SpringJUnitConfig @SpringBootTest class Aggregate2EventsIntegrationTest { diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/ddd/event/Aggregate3EventsIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate3EventsIntegrationTest.java similarity index 90% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/ddd/event/Aggregate3EventsIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate3EventsIntegrationTest.java index 893dcac3f8..4193e932ee 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/ddd/event/Aggregate3EventsIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate3EventsIntegrationTest.java @@ -1,7 +1,7 @@ /** * */ -package com.baeldung.ddd.event; +package com.baeldung.boot.ddd.event; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; @@ -14,6 +14,10 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import com.baeldung.boot.ddd.event.Aggregate3; +import com.baeldung.boot.ddd.event.Aggregate3Repository; +import com.baeldung.boot.ddd.event.DomainEvent; + @SpringJUnitConfig @SpringBootTest class Aggregate3EventsIntegrationTest { diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/ddd/event/AggregateEventsIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/AggregateEventsIntegrationTest.java similarity index 91% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/ddd/event/AggregateEventsIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/AggregateEventsIntegrationTest.java index f0e1147245..ac607063b2 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/ddd/event/AggregateEventsIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/AggregateEventsIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.ddd.event; +package com.baeldung.boot.ddd.event; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; @@ -16,6 +16,11 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.Bean; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import com.baeldung.boot.ddd.event.Aggregate; +import com.baeldung.boot.ddd.event.AggregateRepository; +import com.baeldung.boot.ddd.event.DomainEvent; +import com.baeldung.boot.ddd.event.DomainService; + @SpringJUnitConfig @SpringBootTest class AggregateEventsIntegrationTest { diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/ddd/event/TestEventHandler.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/TestEventHandler.java similarity index 68% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/ddd/event/TestEventHandler.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/TestEventHandler.java index 721402c17a..0f499834eb 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/ddd/event/TestEventHandler.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/TestEventHandler.java @@ -1,10 +1,12 @@ /** * */ -package com.baeldung.ddd.event; +package com.baeldung.boot.ddd.event; import org.springframework.transaction.event.TransactionalEventListener; +import com.baeldung.boot.ddd.event.DomainEvent; + interface TestEventHandler { @TransactionalEventListener void handleEvent(DomainEvent event); diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/passenger/PassengerRepositoryIntegrationTest.java similarity index 98% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/passenger/PassengerRepositoryIntegrationTest.java index 2b303604b6..f082350019 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/passenger/PassengerRepositoryIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.passenger; +package com.baeldung.boot.passenger; import org.junit.Before; import org.junit.Test; @@ -12,6 +12,9 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.boot.passenger.Passenger; +import com.baeldung.boot.passenger.PassengerRepository; + import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import java.util.List; @@ -23,6 +26,7 @@ import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; + @DataJpaTest @RunWith(SpringRunner.class) public class PassengerRepositoryIntegrationTest { diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/services/AbstractServicePersistenceIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/AbstractServicePersistenceIntegrationTest.java similarity index 98% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/services/AbstractServicePersistenceIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/AbstractServicePersistenceIntegrationTest.java index acac66f2f7..bf0c85fca6 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/services/AbstractServicePersistenceIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/AbstractServicePersistenceIntegrationTest.java @@ -1,6 +1,7 @@ -package com.baeldung.services; +package com.baeldung.boot.services; -import com.baeldung.domain.Foo; +import com.baeldung.boot.domain.Foo; +import com.baeldung.boot.services.IOperations; import com.baeldung.util.IDUtil; import org.hamcrest.Matchers; import org.junit.Ignore; diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/services/FooServicePersistenceIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/FooServicePersistenceIntegrationTest.java similarity index 85% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/services/FooServicePersistenceIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/FooServicePersistenceIntegrationTest.java index fd17d033e1..f0e4aa7317 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/services/FooServicePersistenceIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/FooServicePersistenceIntegrationTest.java @@ -1,11 +1,16 @@ -package com.baeldung.services; +package com.baeldung.boot.services; + +import com.baeldung.boot.Application; +import com.baeldung.boot.config.PersistenceConfiguration; +import com.baeldung.boot.domain.Foo; +import com.baeldung.boot.services.IFooService; +import com.baeldung.boot.services.IOperations; -import com.baeldung.config.PersistenceConfiguration; -import com.baeldung.domain.Foo; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.test.context.ContextConfiguration; @@ -16,7 +21,7 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.junit.Assert.assertNotNull; @RunWith(SpringRunner.class) -@ContextConfiguration(classes = {PersistenceConfiguration.class}, loader = AnnotationConfigContextLoader.class) +@SpringBootTest(classes=Application.class) public class FooServicePersistenceIntegrationTest extends AbstractServicePersistenceIntegrationTest { @Autowired diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/services/SpringDataJPABarAuditIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/SpringDataJPABarAuditIntegrationTest.java similarity index 87% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/services/SpringDataJPABarAuditIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/SpringDataJPABarAuditIntegrationTest.java index f3b857c73d..810cf70769 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/services/SpringDataJPABarAuditIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/SpringDataJPABarAuditIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.services; +package com.baeldung.boot.services; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -16,16 +16,19 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.baeldung.config.PersistenceConfiguration; -import com.baeldung.domain.Bar; +import com.baeldung.boot.Application; +import com.baeldung.boot.config.PersistenceConfiguration; +import com.baeldung.boot.domain.Bar; +import com.baeldung.boot.services.IBarService; @RunWith(SpringRunner.class) -@ContextConfiguration(classes = { PersistenceConfiguration.class }, loader = AnnotationConfigContextLoader.class) +@SpringBootTest(classes=Application.class) public class SpringDataJPABarAuditIntegrationTest { private static Logger logger = LoggerFactory.getLogger(SpringDataJPABarAuditIntegrationTest.class); diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/services/JpaMultipleDBIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java similarity index 74% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/services/JpaMultipleDBIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java index 71a3fb0b44..bcc4103d08 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/services/JpaMultipleDBIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.services; +package com.baeldung.multipledb; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -10,26 +10,23 @@ import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.Transactional; -import com.baeldung.config.PersistenceProductConfiguration; -import com.baeldung.config.PersistenceUserConfiguration; -import com.baeldung.dao.repositories.product.ProductRepository; -import com.baeldung.dao.repositories.user.PossessionRepository; -import com.baeldung.dao.repositories.user.UserRepository; -import com.baeldung.domain.product.Product; -import com.baeldung.domain.user.Possession; -import com.baeldung.domain.user.User; +import com.baeldung.multipledb.dao.product.ProductRepository; +import com.baeldung.multipledb.dao.user.PossessionRepository; +import com.baeldung.multipledb.dao.user.UserRepository; +import com.baeldung.multipledb.model.product.ProductMultipleDB; +import com.baeldung.multipledb.model.user.PossessionMultipleDB; +import com.baeldung.multipledb.model.user.UserMultipleDB; @RunWith(SpringRunner.class) -@ContextConfiguration(classes = { PersistenceUserConfiguration.class, PersistenceProductConfiguration.class }) +@SpringBootTest(classes=MultipleDbApplication.class) @EnableTransactionManagement -@DirtiesContext public class JpaMultipleDBIntegrationTest { @Autowired @@ -46,15 +43,15 @@ public class JpaMultipleDBIntegrationTest { @Test @Transactional("userTransactionManager") public void whenCreatingUser_thenCreated() { - User user = new User(); + UserMultipleDB user = new UserMultipleDB(); user.setName("John"); user.setEmail("john@test.com"); user.setAge(20); - Possession p = new Possession("sample"); + PossessionMultipleDB p = new PossessionMultipleDB("sample"); p = possessionRepository.save(p); user.setPossessionList(Collections.singletonList(p)); user = userRepository.save(user); - final Optional result = userRepository.findById(user.getId()); + final Optional result = userRepository.findById(user.getId()); assertTrue(result.isPresent()); System.out.println(result.get().getPossessionList()); assertEquals(1, result.get().getPossessionList().size()); @@ -63,14 +60,14 @@ public class JpaMultipleDBIntegrationTest { @Test @Transactional("userTransactionManager") public void whenCreatingUsersWithSameEmail_thenRollback() { - User user1 = new User(); + UserMultipleDB user1 = new UserMultipleDB(); user1.setName("John"); user1.setEmail("john@test.com"); user1.setAge(20); user1 = userRepository.save(user1); assertTrue(userRepository.findById(user1.getId()).isPresent()); - User user2 = new User(); + UserMultipleDB user2 = new UserMultipleDB(); user2.setName("Tom"); user2.setEmail("john@test.com"); user2.setAge(10); @@ -88,7 +85,7 @@ public class JpaMultipleDBIntegrationTest { @Test @Transactional("productTransactionManager") public void whenCreatingProduct_thenCreated() { - Product product = new Product(); + ProductMultipleDB product = new ProductMultipleDB(); product.setName("Book"); product.setId(2); product.setPrice(20); diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/product/ProductRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java similarity index 69% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/product/ProductRepositoryIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java index 4caa0f0ca4..2c965f72f3 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/product/ProductRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.dao.repositories.product; +package com.baeldung.multipledb; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; @@ -13,6 +13,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -22,11 +23,12 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.Transactional; -import com.baeldung.config.PersistenceProductConfiguration; -import com.baeldung.domain.product.Product; +import com.baeldung.multipledb.PersistenceProductConfiguration; +import com.baeldung.multipledb.dao.product.ProductRepository; +import com.baeldung.multipledb.model.product.ProductMultipleDB; @RunWith(SpringRunner.class) -@ContextConfiguration(classes = { PersistenceProductConfiguration.class }) +@SpringBootTest(classes=MultipleDbApplication.class) @EnableTransactionManagement public class ProductRepositoryIntegrationTest { @@ -36,22 +38,22 @@ public class ProductRepositoryIntegrationTest { @Before @Transactional("productTransactionManager") public void setUp() { - productRepository.save(Product.from(1001, "Book", 21)); - productRepository.save(Product.from(1002, "Coffee", 10)); - productRepository.save(Product.from(1003, "Jeans", 30)); - productRepository.save(Product.from(1004, "Shirt", 32)); - productRepository.save(Product.from(1005, "Bacon", 10)); + productRepository.save(ProductMultipleDB.from(1001, "Book", 21)); + productRepository.save(ProductMultipleDB.from(1002, "Coffee", 10)); + productRepository.save(ProductMultipleDB.from(1003, "Jeans", 30)); + productRepository.save(ProductMultipleDB.from(1004, "Shirt", 32)); + productRepository.save(ProductMultipleDB.from(1005, "Bacon", 10)); } @Test public void whenRequestingFirstPageOfSizeTwo_ThenReturnFirstPage() { Pageable pageRequest = PageRequest.of(0, 2); - Page result = productRepository.findAll(pageRequest); + Page result = productRepository.findAll(pageRequest); assertThat(result.getContent(), hasSize(2)); assertTrue(result.stream() - .map(Product::getId) + .map(ProductMultipleDB::getId) .allMatch(id -> Arrays.asList(1001, 1002) .contains(id))); } @@ -60,11 +62,11 @@ public class ProductRepositoryIntegrationTest { public void whenRequestingSecondPageOfSizeTwo_ThenReturnSecondPage() { Pageable pageRequest = PageRequest.of(1, 2); - Page result = productRepository.findAll(pageRequest); + Page result = productRepository.findAll(pageRequest); assertThat(result.getContent(), hasSize(2)); assertTrue(result.stream() - .map(Product::getId) + .map(ProductMultipleDB::getId) .allMatch(id -> Arrays.asList(1003, 1004) .contains(id))); } @@ -73,11 +75,11 @@ public class ProductRepositoryIntegrationTest { public void whenRequestingLastPage_ThenReturnLastPageWithRemData() { Pageable pageRequest = PageRequest.of(2, 2); - Page result = productRepository.findAll(pageRequest); + Page result = productRepository.findAll(pageRequest); assertThat(result.getContent(), hasSize(1)); assertTrue(result.stream() - .map(Product::getId) + .map(ProductMultipleDB::getId) .allMatch(id -> Arrays.asList(1005) .contains(id))); } @@ -86,12 +88,12 @@ public class ProductRepositoryIntegrationTest { public void whenSortingByNameAscAndPaging_ThenReturnSortedPagedResult() { Pageable pageRequest = PageRequest.of(0, 3, Sort.by("name")); - Page result = productRepository.findAll(pageRequest); + Page result = productRepository.findAll(pageRequest); assertThat(result.getContent(), hasSize(3)); assertThat(result.getContent() .stream() - .map(Product::getId) + .map(ProductMultipleDB::getId) .collect(Collectors.toList()), equalTo(Arrays.asList(1005, 1001, 1002))); } @@ -101,12 +103,12 @@ public class ProductRepositoryIntegrationTest { Pageable pageRequest = PageRequest.of(0, 3, Sort.by("price") .descending()); - Page result = productRepository.findAll(pageRequest); + Page result = productRepository.findAll(pageRequest); assertThat(result.getContent(), hasSize(3)); assertThat(result.getContent() .stream() - .map(Product::getId) + .map(ProductMultipleDB::getId) .collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001))); } @@ -117,12 +119,12 @@ public class ProductRepositoryIntegrationTest { .descending() .and(Sort.by("name"))); - Page result = productRepository.findAll(pageRequest); + Page result = productRepository.findAll(pageRequest); assertThat(result.getContent(), hasSize(5)); assertThat(result.getContent() .stream() - .map(Product::getId) + .map(ProductMultipleDB::getId) .collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001, 1005, 1002))); } @@ -131,11 +133,11 @@ public class ProductRepositoryIntegrationTest { public void whenRequestingFirstPageOfSizeTwoUsingCustomMethod_ThenReturnFirstPage() { Pageable pageRequest = PageRequest.of(0, 2); - List result = productRepository.findAllByPrice(10, pageRequest); + List result = productRepository.findAllByPrice(10, pageRequest); assertThat(result, hasSize(2)); assertTrue(result.stream() - .map(Product::getId) + .map(ProductMultipleDB::getId) .allMatch(id -> Arrays.asList(1002, 1005) .contains(id))); } diff --git a/persistence-modules/spring-data-jpa/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/org/baeldung/SpringContextIntegrationTest.java index 7f906bdbcd..e885d0fe51 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/org/baeldung/SpringContextIntegrationTest.java @@ -5,7 +5,7 @@ import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import com.baeldung.Application; +import com.baeldung.boot.Application; @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) diff --git a/persistence-modules/spring-data-jpa/src/test/java/org/baeldung/SpringJpaContextIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/org/baeldung/SpringJpaContextIntegrationTest.java index 66b5b20b97..4a36407884 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/org/baeldung/SpringJpaContextIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/org/baeldung/SpringJpaContextIntegrationTest.java @@ -6,10 +6,10 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import com.baeldung.Application; -import com.baeldung.config.PersistenceConfiguration; -import com.baeldung.config.PersistenceProductConfiguration; -import com.baeldung.config.PersistenceUserConfiguration; +import com.baeldung.boot.Application; +import com.baeldung.boot.config.PersistenceConfiguration; +import com.baeldung.multipledb.PersistenceProductConfiguration; +import com.baeldung.multipledb.PersistenceUserConfiguration; @RunWith(SpringRunner.class) @DataJpaTest(excludeAutoConfiguration = { diff --git a/persistence-modules/spring-hibernate-3/pom.xml b/persistence-modules/spring-hibernate-3/pom.xml index 6c1bdace30..ec35f35bb3 100644 --- a/persistence-modules/spring-hibernate-3/pom.xml +++ b/persistence-modules/spring-hibernate-3/pom.xml @@ -91,7 +91,6 @@ 3.6.10.Final 5.1.40 8.5.8 - 1.4.193 19.0 3.5 diff --git a/persistence-modules/spring-hibernate-5/pom.xml b/persistence-modules/spring-hibernate-5/pom.xml index 832cf8dca7..16e55cb0c0 100644 --- a/persistence-modules/spring-hibernate-5/pom.xml +++ b/persistence-modules/spring-hibernate-5/pom.xml @@ -143,7 +143,6 @@ 9.0.0.M26 1.1 2.3.4 - 1.4.195 21.0 diff --git a/persistence-modules/spring-hibernate4/pom.xml b/persistence-modules/spring-hibernate4/pom.xml index fad84870df..4289c9c3d5 100644 --- a/persistence-modules/spring-hibernate4/pom.xml +++ b/persistence-modules/spring-hibernate4/pom.xml @@ -160,7 +160,6 @@ 8.5.8 1.1 2.3.4 - 1.4.193 5.3.3.Final diff --git a/persistence-modules/spring-jpa/pom.xml b/persistence-modules/spring-jpa/pom.xml index 3daba6cd55..0fdffad8db 100644 --- a/persistence-modules/spring-jpa/pom.xml +++ b/persistence-modules/spring-jpa/pom.xml @@ -93,7 +93,7 @@ javax.servlet jstl - ${javax.servlet.jstl.version} + ${jstl.version} javax.servlet @@ -163,10 +163,8 @@ 5.2.17.Final 6.0.6 2.1.5.RELEASE - 1.4.195 - 1.2 2.5 diff --git a/pom.xml b/pom.xml index d57fa1694e..89c9416ebb 100644 --- a/pom.xml +++ b/pom.xml @@ -9,9 +9,10 @@ 1.0.0-SNAPSHOT parent-modules pom - + lombok-custom + quarkus @@ -233,7 +234,7 @@ ${maven-war-plugin.version} - + com.vackosar.gitflowincrementalbuilder @@ -338,6 +339,7 @@ algorithms-genetic algorithms-miscellaneous-1 algorithms-miscellaneous-2 + algorithms-miscellaneous-3 algorithms-sorting animal-sniffer-mvn-plugin annotations @@ -376,35 +378,39 @@ cdi checker-plugin core-groovy - - - - core-java-8 - core-java-8-2 - core-java-lambdas - - - core-java-arrays - core-java-collections - core-java-collections-map - core-java-collections-list - core-java-concurrency-basic - core-java-concurrency-collections - core-java-io - core-java-security - core-java-lang-syntax - core-java-lang - core-java-lang-oop - core-java-lang-oop-2 - core-java-networking - core-java-perf - core-java-sun - core-java - core-java-jvm + core-groovy-2 + core-groovy-collections + + + + core-java-modules/core-java-8 + core-java-modules/core-java-8-2 + core-java-modules/core-java-lambdas + + + core-java-modules/core-java-arrays + core-java-modules/core-java-collections + core-java-modules/core-java-collections-list + core-java-modules/core-java-collections-set + core-java-modules/core-java-concurrency-basic + core-java-modules/core-java-concurrency-collections + core-java-modules/core-java-io + core-java-modules/core-java-security + core-java-modules/core-java-lang-syntax + core-java-modules/core-java-lang + core-java-modules/core-java-lang-oop + core-java-modules/core-java-lang-oop-2 + core-java-modules + core-java-modules/core-java-networking + core-java-modules/core-java-perf + core-java-modules/core-java-reflection + core-java-modules/core-java-sun + core-java-modules/core-java + core-java-modules/core-java-jvm core-scala couchbase custom-pmd - + dagger data-structures ddd @@ -412,13 +418,13 @@ disruptor dozer drools - dubbo - + dubbo + ethereum - + feign flyway-cdi-extension - + geotools google-cloud google-web-toolkit @@ -432,17 +438,19 @@ guava-modules guice - + hazelcast helidon httpclient + httpclient-simple hystrix - + image-processing immutables jackson jackson-2 + jackson-simple java-collections-conversions java-collections-maps java-collections-maps-2 @@ -456,6 +464,7 @@ java-streams java-streams-2 java-strings + java-strings-2 java-vavr-stream java-websocket javafx @@ -484,12 +493,14 @@ kotlin-libraries - + kotlin-libraries-2 + libraries libraries-2 libraries-data libraries-apache-commons + libraries-primitive libraries-security libraries-server linkrest @@ -511,8 +522,8 @@ mustache mybatis - - + + optaplanner orika osgi @@ -522,9 +533,10 @@ performance-tests protobuffer - + persistence-modules - + quarkus + rabbitmq ratpack @@ -536,16 +548,17 @@ rule-engines rsocket rxjava - rxjava-2 + rxjava-2 software-security/sql-injection-samples - + tensorflow-java spring-boot-flowable - + spring-security-kerberos + - + default-second @@ -579,12 +592,12 @@ parent-spring-5 parent-java parent-kotlin - + saas spark-java - + spring-4 - + spring-5 spring-5-webflux spring-5-data-reactive @@ -595,7 +608,7 @@ spring-5-reactive-security spring-5-security spring-5-security-oauth - + spring-activiti spring-akka spring-all @@ -605,7 +618,7 @@ spring-apache-camel spring-batch spring-bom - + spring-boot spring-boot-admin spring-boot-angular @@ -615,17 +628,20 @@ spring-boot-camel spring-boot-client + spring-boot-crud spring-boot-ctx-fluent spring-boot-custom-starter spring-boot-disable-console-logging + spring-boot-exceptions spring-boot-jasypt spring-boot-keycloak spring-boot-logging-log4j2 spring-boot-mvc spring-boot-mvc-birt spring-boot-ops + spring-boot-ops-2 spring-boot-rest spring-boot-data spring-boot-property-exp @@ -633,41 +649,41 @@ spring-boot-testing spring-boot-vue spring-boot-libraries - + spring-cloud spring-cloud-bus spring-cloud-data-flow - + spring-core spring-cucumber - + spring-data-rest spring-data-rest-querydsl spring-dispatcher-servlet spring-drools - + spring-ehcache spring-ejb spring-exceptions - + spring-freemarker - + spring-groovy - + spring-integration - + spring-jenkins-pipeline spring-jersey spring-jinq spring-jms spring-jooq - + spring-kafka spring-katharsis - + spring-ldap - + spring-mobile spring-mockito spring-mvc-forms-jsp @@ -679,12 +695,12 @@ spring-mvc-velocity spring-mvc-webflow spring-mvc-xml - + spring-protobuf - + spring-quartz - + spring-reactive-kotlin spring-reactor spring-remoting @@ -700,9 +716,9 @@ spring-security-acl spring-security-angular/server spring-security-cache-control - + spring-security-client - + spring-security-core spring-security-mvc-boot spring-security-mvc-custom @@ -730,49 +746,50 @@ spring-state-machine spring-static-resources spring-swagger-codegen - + spring-thymeleaf - + spring-userservice - + spring-vault spring-vertx - + spring-webflux-amqp - + spring-zuul - + static-analysis stripe structurizr struts-2 - + testing-modules - + twilio Twitter4J - + undertow - + vavr vertx vertx-and-rxjava video-tutorials vraptor - + wicket - + xml xmlunit-2 xstream - + tensorflow-java spring-boot-flowable - + spring-security-kerberos + - + spring-context @@ -815,7 +832,8 @@ spring-boot-camel spring-boot-client spring-boot-custom-starter - greeter-spring-boot-autoconfigure + spring-boot-exceptions + greeter-spring-boot-autoconfigure greeter-spring-boot-sample-app persistence-modules/spring-boot-h2/spring-boot-h2-database spring-boot-jasypt @@ -910,8 +928,9 @@ persistence-modules/spring-data-eclipselink persistence-modules/spring-data-solr persistence-modules/spring-hibernate-5 - + spring-boot-flowable + spring-security-kerberos @@ -949,10 +968,11 @@ parent-spring-5 parent-java parent-kotlin - - core-java-concurrency-advanced + + core-java-modules/core-java-concurrency-advanced core-kotlin core-kotlin-2 + core-kotlin-io jenkins/hello-world jws @@ -960,14 +980,15 @@ libraries persistence-modules/hibernate5 + persistence-modules/hibernate-mapping persistence-modules/java-jpa persistence-modules/java-mongodb - persistence-modules/jnosql + persistence-modules/jnosql - vaadin + vaadin - + integration-lite-first @@ -1002,6 +1023,7 @@ algorithms-genetic algorithms-miscellaneous-1 algorithms-miscellaneous-2 + algorithms-miscellaneous-3 algorithms-sorting animal-sniffer-mvn-plugin annotations @@ -1038,31 +1060,34 @@ cdi checker-plugin core-groovy - - - core-java-8 - core-java-8-2 - - - core-java-arrays - core-java-collections - core-java-collections-map - core-java-collections-list - core-java-concurrency-basic - core-java-concurrency-collections - core-java-io - core-java-security - core-java-lang-syntax - core-java-lang - core-java-lang-oop - core-java-lang-oop-2 - core-java-networking - core-java-perf - core-java-sun + core-groovy-2 + core-groovy-collections + + + core-java-modules/core-java-8 + core-java-modules/core-java-8-2 + + + core-java-modules/core-java-arrays + core-java-modules/core-java-collections + core-java-modules/core-java-collections-list + core-java-modules/core-java-collections-set + core-java-modules/core-java-concurrency-basic + core-java-modules/core-java-concurrency-collections + core-java-modules/core-java-io + core-java-modules/core-java-security + core-java-modules/core-java-lang-syntax + core-java-modules/core-java-lang + core-java-modules/core-java-lang-oop + core-java-modules/core-java-lang-oop-2 + core-java-modules + core-java-modules/core-java-networking + core-java-modules/core-java-perf + core-java-modules/core-java-sun core-scala couchbase custom-pmd - + dagger data-structures ddd @@ -1070,13 +1095,13 @@ disruptor dozer drools - dubbo - + dubbo + ethereum - + feign flyway-cdi-extension - + geotools google-cloud google-web-toolkit @@ -1090,17 +1115,19 @@ guava-modules guice - + hazelcast helidon httpclient + httpclient-simple hystrix - + image-processing immutables jackson jackson-2 + jackson-simple java-collections-conversions java-collections-maps java-collections-maps-2 @@ -1113,6 +1140,7 @@ java-streams java-streams-2 java-strings + java-strings-2 java-vavr-stream java-websocket javafx @@ -1141,7 +1169,7 @@ kotlin-libraries - + libraries libraries-data @@ -1155,6 +1183,7 @@ mapstruct maven + maven-archetype maven-polyglot/maven-polyglot-json-extension @@ -1167,8 +1196,8 @@ mustache mybatis - - + + optaplanner orika osgi @@ -1178,9 +1207,9 @@ performance-tests protobuffer - + persistence-modules - + rabbitmq ratpack @@ -1192,8 +1221,8 @@ rule-engines rsocket rxjava - rxjava-2 - + rxjava-2 + @@ -1227,12 +1256,12 @@ parent-spring-5 parent-java parent-kotlin - + saas spark-java - + spring-4 - + spring-5 spring-5-data-reactive spring-5-mvc @@ -1242,7 +1271,7 @@ spring-5-reactive-security spring-5-security spring-5-security-oauth - + spring-activiti spring-akka spring-all @@ -1252,7 +1281,7 @@ spring-apache-camel spring-batch spring-bom - + spring-boot spring-boot-admin spring-boot-angular @@ -1266,6 +1295,7 @@ spring-boot-ctx-fluent spring-boot-custom-starter spring-boot-disable-console-logging + spring-boot-exceptions spring-boot-jasypt spring-boot-keycloak @@ -1273,46 +1303,47 @@ spring-boot-mvc spring-boot-mvc-birt spring-boot-ops + spring-boot-ops-2 spring-boot-rest spring-boot-data spring-boot-property-exp spring-boot-security spring-boot-vue - + spring-cloud spring-cloud-bus spring-cloud-data-flow - + spring-core spring-cucumber - + spring-data-rest spring-data-rest-querydsl spring-dispatcher-servlet spring-drools - - spring-ehcache + + spring-ehcache spring-ejb spring-exceptions - + spring-freemarker - + spring-groovy - + spring-integration - + spring-jenkins-pipeline spring-jersey spring-jinq spring-jms spring-jooq - + spring-kafka spring-katharsis - + spring-ldap - + spring-mobile spring-mockito spring-mvc-forms-jsp @@ -1324,12 +1355,12 @@ spring-mvc-velocity spring-mvc-webflow spring-mvc-xml - + spring-protobuf - + spring-quartz - + spring-reactive-kotlin spring-reactor spring-remoting @@ -1342,13 +1373,13 @@ spring-rest-simple spring-resttemplate spring-roo - + spring-security-acl spring-security-angular/server spring-security-cache-control - + spring-security-client - + spring-security-core spring-security-mvc-boot spring-security-mvc-custom @@ -1375,42 +1406,42 @@ spring-state-machine spring-static-resources spring-swagger-codegen - + spring-thymeleaf - + spring-userservice - + spring-vault spring-vertx - + spring-webflux-amqp - + spring-zuul - + static-analysis stripe structurizr struts-2 - + testing-modules - + twilio Twitter4J - + undertow - + vavr vertx vertx-and-rxjava video-tutorials vraptor - + wicket - + xml xmlunit-2 xstream - + @@ -1444,9 +1475,9 @@ parent-spring-5 parent-java parent-kotlin - - core-java - core-java-concurrency-advanced + + core-java-modules/core-java + core-java-modules/core-java-concurrency-advanced core-kotlin core-kotlin-2 @@ -1458,9 +1489,9 @@ persistence-modules/hibernate5 persistence-modules/java-jpa persistence-modules/java-mongodb - persistence-modules/jnosql + persistence-modules/jnosql - vaadin + vaadin @@ -1482,19 +1513,20 @@ UTF-8 UTF-8 refs/remotes/origin/master - true + true + false false false false - + 4.12 1.3 2.21.0 - + 1.7.21 1.1.7 - + 2.21.0 3.7.0 @@ -1523,10 +1555,11 @@ 0.3.1 2.5.1 0.0.1 - 3.4 + 3.8 2.3 3.8 1.16.12 + 1.4.197 diff --git a/quarkus/.dockerignore b/quarkus/.dockerignore new file mode 100644 index 0000000000..b86c7ac340 --- /dev/null +++ b/quarkus/.dockerignore @@ -0,0 +1,4 @@ +* +!target/*-runner +!target/*-runner.jar +!target/lib/* \ No newline at end of file diff --git a/quarkus/.mvn/wrapper/MavenWrapperDownloader.java b/quarkus/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100755 index 0000000000..b20a55a7a9 --- /dev/null +++ b/quarkus/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,117 @@ +/* + * Copyright 2007-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + private static final String WRAPPER_VERSION = "0.5.3"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + " .jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + String username = System.getenv("MVNW_USERNAME"); + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/quarkus/.mvn/wrapper/maven-wrapper.jar b/quarkus/.mvn/wrapper/maven-wrapper.jar new file mode 100755 index 0000000000..e89f07c229 Binary files /dev/null and b/quarkus/.mvn/wrapper/maven-wrapper.jar differ diff --git a/quarkus/.mvn/wrapper/maven-wrapper.properties b/quarkus/.mvn/wrapper/maven-wrapper.properties new file mode 100755 index 0000000000..1703626ce7 --- /dev/null +++ b/quarkus/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar diff --git a/quarkus/mvnw b/quarkus/mvnw new file mode 100755 index 0000000000..34d9dae8d0 --- /dev/null +++ b/quarkus/mvnw @@ -0,0 +1,305 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # 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.3/maven-wrapper-0.5.3.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.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 + +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/quarkus/mvnw.cmd b/quarkus/mvnw.cmd new file mode 100755 index 0000000000..77b451d837 --- /dev/null +++ b/quarkus/mvnw.cmd @@ -0,0 +1,172 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@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.3/maven-wrapper-0.5.3.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% ( + echo Found %WRAPPER_JAR% +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar" + ) + 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%')"^ + "}" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + +%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/quarkus/pom.xml b/quarkus/pom.xml new file mode 100644 index 0000000000..d8f274df6d --- /dev/null +++ b/quarkus/pom.xml @@ -0,0 +1,113 @@ + + + 4.0.0 + com.baeldung.quarkus + quarkus + 1.0-SNAPSHOT + + 2.22.0 + 0.13.1 + 1.8 + UTF-8 + 1.8 + + + + + io.quarkus + quarkus-bom + ${quarkus.version} + pom + import + + + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + io.quarkus + quarkus-maven-plugin + ${quarkus.version} + + + + build + + + + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + + + + + + + + native + + + native + + + + + + io.quarkus + quarkus-maven-plugin + ${quarkus.version} + + + + native-image + + + true + + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + + + + + + + + + + diff --git a/quarkus/src/main/docker/Dockerfile.jvm b/quarkus/src/main/docker/Dockerfile.jvm new file mode 100644 index 0000000000..c91417af87 --- /dev/null +++ b/quarkus/src/main/docker/Dockerfile.jvm @@ -0,0 +1,21 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the docker image run: +# +# mvn package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/quarkus-project-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-project-jvm +# +### +FROM fabric8/java-jboss-openjdk8-jdk +ENV JAVA_OPTIONS=-Dquarkus.http.host=0.0.0.0 +COPY target/lib/* /deployments/lib/ +COPY target/*-runner.jar /deployments/app.jar +ENTRYPOINT [ "/deployments/run-java.sh" ] \ No newline at end of file diff --git a/quarkus/src/main/docker/Dockerfile.native b/quarkus/src/main/docker/Dockerfile.native new file mode 100644 index 0000000000..f076fe3f60 --- /dev/null +++ b/quarkus/src/main/docker/Dockerfile.native @@ -0,0 +1,22 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode +# +# Before building the docker image run: +# +# mvn package -Pnative -Dnative-image.docker-build=true +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native -t quarkus/quarkus-project . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-project +# +### +FROM registry.fedoraproject.org/fedora-minimal +WORKDIR /work/ +COPY target/*-runner /work/application +RUN chmod 775 /work +EXPOSE 8080 +CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] \ No newline at end of file diff --git a/quarkus/src/main/java/com/baeldung/quarkus/HelloResource.java b/quarkus/src/main/java/com/baeldung/quarkus/HelloResource.java new file mode 100644 index 0000000000..884275f313 --- /dev/null +++ b/quarkus/src/main/java/com/baeldung/quarkus/HelloResource.java @@ -0,0 +1,28 @@ +package com.baeldung.quarkus; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/hello") +public class HelloResource { + + @Inject + HelloService helloService; + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/polite/{name}") + public String greeting(@PathParam("name") String name) { + return helloService.politeHello(name); + } + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "hello"; + } +} \ No newline at end of file diff --git a/quarkus/src/main/java/com/baeldung/quarkus/HelloService.java b/quarkus/src/main/java/com/baeldung/quarkus/HelloService.java new file mode 100644 index 0000000000..4b19de1b63 --- /dev/null +++ b/quarkus/src/main/java/com/baeldung/quarkus/HelloService.java @@ -0,0 +1,16 @@ +package com.baeldung.quarkus; + +import org.eclipse.microprofile.config.inject.ConfigProperty; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class HelloService { + + @ConfigProperty(name = "greeting") + private String greeting; + + public String politeHello(String name){ + return greeting + " " + name; + } +} diff --git a/quarkus/src/main/resources/META-INF/resources/index.html b/quarkus/src/main/resources/META-INF/resources/index.html new file mode 100644 index 0000000000..070a1f672b --- /dev/null +++ b/quarkus/src/main/resources/META-INF/resources/index.html @@ -0,0 +1,152 @@ + + + + + quarkus-project - 1.0-SNAPSHOT + + + + +

+ +
+
+

Congratulations, you have created a new Quarkus application.

+ +

Why do you see this?

+ +

This page is served by Quarkus. The source is in + src/main/resources/META-INF/resources/index.html.

+ +

What can I do from here?

+ +

If not already done, run the application in dev mode using: mvn compile quarkus:dev. +

+
    +
  • Add REST resources, Servlets, functions and other services in src/main/java.
  • +
  • Your static assets are located in src/main/resources/META-INF/resources.
  • +
  • Configure your application in src/main/resources/application.properties. +
  • +
+ +

How do I get rid of this page?

+

Just delete the src/main/resources/META-INF/resources/index.html file.

+
+
+
+

Application

+
    +
  • GroupId: com.baeldung.quarkus
  • +
  • ArtifactId: quarkus-project
  • +
  • Version: 1.0-SNAPSHOT
  • +
  • Quarkus Version: 0.13.1
  • +
+
+ +
+
+ + + + \ No newline at end of file diff --git a/quarkus/src/main/resources/application.properties b/quarkus/src/main/resources/application.properties new file mode 100644 index 0000000000..3f05d2198f --- /dev/null +++ b/quarkus/src/main/resources/application.properties @@ -0,0 +1,3 @@ +# Configuration file +# key = value +greeting=Good morning \ No newline at end of file diff --git a/quarkus/src/test/java/com/baeldung/quarkus/HelloResourceTest.java b/quarkus/src/test/java/com/baeldung/quarkus/HelloResourceTest.java new file mode 100644 index 0000000000..3d0fff7562 --- /dev/null +++ b/quarkus/src/test/java/com/baeldung/quarkus/HelloResourceTest.java @@ -0,0 +1,21 @@ +package com.baeldung.quarkus; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.is; + +@QuarkusTest +public class HelloResourceTest { + + @Test + public void testHelloEndpoint() { + given() + .when().get("/hello") + .then() + .statusCode(200) + .body(is("hello")); + } + +} \ No newline at end of file diff --git a/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java b/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java new file mode 100644 index 0000000000..4b0606f588 --- /dev/null +++ b/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java @@ -0,0 +1,9 @@ +package com.baeldung.quarkus; + +import io.quarkus.test.junit.SubstrateTest; + +@SubstrateTest +public class NativeHelloResourceIT extends HelloResourceTest { + + // Execute the same tests but in native mode. +} \ No newline at end of file diff --git a/ratpack/pom.xml b/ratpack/pom.xml index a4389275b6..7c145eff91 100644 --- a/ratpack/pom.xml +++ b/ratpack/pom.xml @@ -61,7 +61,7 @@ com.h2database h2 - ${h2database.version} + ${h2.version} org.apache.httpcomponents @@ -90,7 +90,6 @@ 1.5.4 4.5.3 4.4.6 - 1.4.193 1.5.12 diff --git a/rxjava/pom.xml b/rxjava/pom.xml index 596a5196da..85106d1127 100644 --- a/rxjava/pom.xml +++ b/rxjava/pom.xml @@ -62,7 +62,6 @@ 1.0.0 1.1.1 1.7.0 - 1.4.196 \ No newline at end of file diff --git a/software-security/sql-injection-samples/pom.xml b/software-security/sql-injection-samples/pom.xml index 0a28a96a07..b982a34e75 100644 --- a/software-security/sql-injection-samples/pom.xml +++ b/software-security/sql-injection-samples/pom.xml @@ -64,8 +64,4 @@
- - 1.8 - - \ No newline at end of file diff --git a/spring-4/pom.xml b/spring-4/pom.xml index eb64c1839f..59b74782ec 100644 --- a/spring-4/pom.xml +++ b/spring-4/pom.xml @@ -88,8 +88,6 @@ com.baeldung.flips.ApplicationConfig 1.0.1 - 1.16.18 - 1.4.197 diff --git a/spring-5-reactive-oauth/pom.xml b/spring-5-reactive-oauth/pom.xml index ff076985e4..06ce817a02 100644 --- a/spring-5-reactive-oauth/pom.xml +++ b/spring-5-reactive-oauth/pom.xml @@ -69,7 +69,6 @@ UTF-8 UTF-8 - 1.8 2.1.0.RELEASE diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java b/spring-5-security-oauth/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java new file mode 100644 index 0000000000..ae03e0a802 --- /dev/null +++ b/spring-5-security-oauth/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java @@ -0,0 +1,16 @@ +package com.baeldung.cognito; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +@PropertySource("cognito/application_cognito.yml") +public class CognitoWebConfiguration implements WebMvcConfigurer { + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/").setViewName("home"); + } +} diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java b/spring-5-security-oauth/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java new file mode 100644 index 0000000000..7f7b751cd9 --- /dev/null +++ b/spring-5-security-oauth/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java @@ -0,0 +1,14 @@ +package com.baeldung.cognito; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.PropertySource; + +@SpringBootApplication +@PropertySource("cognito/application_cognito.yml") +public class SpringCognitoApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringCognitoApplication.class, args); + } +} diff --git a/spring-5-security-oauth/src/main/resources/cognito/application_cognito.yml b/spring-5-security-oauth/src/main/resources/cognito/application_cognito.yml new file mode 100644 index 0000000000..0a28dbccb4 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/cognito/application_cognito.yml @@ -0,0 +1,15 @@ +spring: + security: + oauth2: + client: + registration: + cognito: + client-id: clientId + client-secret: clientSecret + scope: openid + redirectUriTemplate: "http://localhost:8080/login/oauth2/code/cognito" + clientName: cognito-client-name + provider: + cognito: + issuerUri: https://cognito-idp.{region}.amazonaws.com/{poolId} + usernameAttribute: cognito:username diff --git a/spring-5-security-oauth/src/main/resources/cognito/home.html b/spring-5-security-oauth/src/main/resources/cognito/home.html new file mode 100644 index 0000000000..f0bd9e52a8 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/cognito/home.html @@ -0,0 +1,32 @@ + + + + + + OAuth2 Cognito Demo + + + + + +
+
+
+

OAuth2 Spring Security Cognito Demo

+ +
+
+ Hello, ! +
+
+ + +
+
+
+ + diff --git a/spring-5-security-oauth/src/main/resources/cognito/style.css b/spring-5-security-oauth/src/main/resources/cognito/style.css new file mode 100644 index 0000000000..45190d6d70 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/cognito/style.css @@ -0,0 +1,9 @@ +.login { + background-color: #7289da; + color: #fff; +} + +.login:hover { + background-color: #697ec4; + color: #fff; +} diff --git a/spring-5-webflux/README.md b/spring-5-webflux/README.md index 84c3d5a4ca..4345c8746b 100644 --- a/spring-5-webflux/README.md +++ b/spring-5-webflux/README.md @@ -2,3 +2,4 @@ - [Spring Boot Reactor Netty Configuration](https://www.baeldung.com/spring-boot-reactor-netty) - [How to Return 404 with Spring WebFlux](https://www.baeldung.com/spring-webflux-404) +- [WebClient request with parameters](https://www.baeldung.com/webclient-request-with-parameters) diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/webclientrequests/SpringWebClientRequestsApp.java b/spring-5-webflux/src/main/java/com/baeldung/spring/webclientrequests/SpringWebClientRequestsApp.java new file mode 100644 index 0000000000..314fe2fdf9 --- /dev/null +++ b/spring-5-webflux/src/main/java/com/baeldung/spring/webclientrequests/SpringWebClientRequestsApp.java @@ -0,0 +1,12 @@ +package com.baeldung.spring.webclientrequests; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringWebClientRequestsApp { + + public static void main(String[] args) { + SpringApplication.run(SpringWebClientRequestsApp.class, args); + } +} diff --git a/spring-5-webflux/src/test/java/com/baeldung/spring/webclientrequests/WebClientRequestsUnitTest.java b/spring-5-webflux/src/test/java/com/baeldung/spring/webclientrequests/WebClientRequestsUnitTest.java new file mode 100644 index 0000000000..8919daa9fb --- /dev/null +++ b/spring-5-webflux/src/test/java/com/baeldung/spring/webclientrequests/WebClientRequestsUnitTest.java @@ -0,0 +1,164 @@ +package com.baeldung.spring.webclientrequests; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.ClientRequest; +import org.springframework.web.reactive.function.client.ClientResponse; +import org.springframework.web.reactive.function.client.ExchangeFunction; +import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.util.DefaultUriBuilderFactory; +import reactor.core.publisher.Mono; + +import static org.mockito.Mockito.*; + +@RunWith(SpringRunner.class) +@WebFluxTest +public class WebClientRequestsUnitTest { + + private static final String BASE_URL = "https://example.com"; + + private WebClient webClient; + + @Captor + private ArgumentCaptor argumentCaptor; + + private ExchangeFunction exchangeFunction; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + this.exchangeFunction = mock(ExchangeFunction.class); + ClientResponse mockResponse = mock(ClientResponse.class); + when(this.exchangeFunction.exchange(this.argumentCaptor.capture())).thenReturn(Mono.just(mockResponse)); + this.webClient = WebClient + .builder() + .baseUrl(BASE_URL) + .exchangeFunction(exchangeFunction) + .build(); + } + + + @Test + public void whenCallSimpleURI_thenURIMatched() { + this.webClient.get() + .uri("/products") + .retrieve(); + verifyCalledUrl("/products"); + } + + @Test + public void whenCallSinglePathSegmentUri_thenURIMatched() { + this.webClient.get() + .uri(uriBuilder -> uriBuilder + .path("/products/{id}") + .build(2)) + .retrieve(); + verifyCalledUrl("/products/2"); + } + + @Test + public void whenCallMultiplePathSegmentsUri_thenURIMatched() { + this.webClient.get() + .uri(uriBuilder -> uriBuilder + .path("/products/{id}/attributes/{attributeId}") + .build(2, 13)) + .retrieve(); + verifyCalledUrl("/products/2/attributes/13"); + } + + @Test + public void whenCallSingleQueryParams_thenURIMatched() { + this.webClient.get() + .uri(uriBuilder -> uriBuilder + .path("/products/") + .queryParam("name", "AndroidPhone") + .queryParam("color", "black") + .queryParam("deliveryDate", "13/04/2019") + .build()) + .retrieve(); + verifyCalledUrl("/products/?name=AndroidPhone&color=black&deliveryDate=13/04/2019"); + } + + @Test + public void whenCallSingleQueryParamsPlaceholders_thenURIMatched() { + this.webClient.get() + .uri(uriBuilder -> uriBuilder + .path("/products/") + .queryParam("name", "{title}") + .queryParam("color", "{authorId}") + .queryParam("deliveryDate", "{date}") + .build("AndroidPhone", "black", "13/04/2019")) + .retrieve(); + verifyCalledUrl("/products/?name=AndroidPhone&color=black&deliveryDate=13%2F04%2F2019"); + } + + @Test + public void whenCallArrayQueryParamsBrackets_thenURIMatched() { + this.webClient.get() + .uri(uriBuilder -> uriBuilder + .path("/products/") + .queryParam("tag[]", "Snapdragon", "NFC") + .build()) + .retrieve(); + verifyCalledUrl("/products/?tag%5B%5D=Snapdragon&tag%5B%5D=NFC"); + } + + + @Test + public void whenCallArrayQueryParams_thenURIMatched() { + this.webClient.get() + .uri(uriBuilder -> uriBuilder + .path("/products/") + .queryParam("category", "Phones", "Tablets") + .build()) + .retrieve(); + verifyCalledUrl("/products/?category=Phones&category=Tablets"); + } + + @Test + public void whenCallArrayQueryParamsComma_thenURIMatched() { + this.webClient.get() + .uri(uriBuilder -> uriBuilder + .path("/products/") + .queryParam("category", String.join(",", "Phones", "Tablets")) + .build()) + .retrieve(); + verifyCalledUrl("/products/?category=Phones,Tablets"); + } + + @Test + public void whenUriComponentEncoding_thenQueryParamsNotEscaped() { + DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(BASE_URL); + factory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.URI_COMPONENT); + this.webClient = WebClient + .builder() + .uriBuilderFactory(factory) + .baseUrl(BASE_URL) + .exchangeFunction(exchangeFunction) + .build(); + this.webClient.get() + .uri(uriBuilder -> uriBuilder + .path("/products/") + .queryParam("name", "AndroidPhone") + .queryParam("color", "black") + .queryParam("deliveryDate", "13/04/2019") + .build()) + .retrieve(); + verifyCalledUrl("/products/?name=AndroidPhone&color=black&deliveryDate=13/04/2019"); + } + + private void verifyCalledUrl(String relativeUrl) { + ClientRequest request = this.argumentCaptor.getValue(); + Assert.assertEquals(String.format("%s%s", BASE_URL, relativeUrl), request.url().toString()); + Mockito.verify(this.exchangeFunction).exchange(request); + verifyNoMoreInteractions(this.exchangeFunction); + } +} diff --git a/spring-activiti/pom.xml b/spring-activiti/pom.xml index 3d67a2ab7b..e0196e807d 100644 --- a/spring-activiti/pom.xml +++ b/spring-activiti/pom.xml @@ -59,7 +59,6 @@ UTF-8 UTF-8 6.0.0 - 1.8 diff --git a/spring-boot-angular-ecommerce/pom.xml b/spring-boot-angular-ecommerce/pom.xml index a5296eade8..510e6c6ec3 100644 --- a/spring-boot-angular-ecommerce/pom.xml +++ b/spring-boot-angular-ecommerce/pom.xml @@ -75,7 +75,6 @@ UTF-8 UTF-8 - 1.8 2.0.3.RELEASE 2.0.4.RELEASE diff --git a/spring-boot-crud/pom.xml b/spring-boot-crud/pom.xml index 73635b0a1c..15ff6c5d11 100644 --- a/spring-boot-crud/pom.xml +++ b/spring-boot-crud/pom.xml @@ -60,7 +60,6 @@ UTF-8 - 1.8 \ No newline at end of file diff --git a/spring-boot-exceptions/.gitignore b/spring-boot-exceptions/.gitignore new file mode 100644 index 0000000000..153c9335eb --- /dev/null +++ b/spring-boot-exceptions/.gitignore @@ -0,0 +1,29 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ + +### VS Code ### +.vscode/ diff --git a/spring-boot-exceptions/pom.xml b/spring-boot-exceptions/pom.xml new file mode 100644 index 0000000000..01d6973642 --- /dev/null +++ b/spring-boot-exceptions/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + com.baeldung + spring-boot-exceptions + 0.0.4-SNAPSHOT + pass-exception-to-client-json-spring-boot + Baeldung article code on how to pass exceptions to client in JSON format using Spring Boot + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + diff --git a/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/CustomException.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/CustomException.java new file mode 100644 index 0000000000..f1a1d94f54 --- /dev/null +++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/CustomException.java @@ -0,0 +1,11 @@ +package com.baeldung.jsonexception; + +public class CustomException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public CustomException() { + super("Custom exception message."); + } + +} \ No newline at end of file diff --git a/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/ErrorHandler.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/ErrorHandler.java new file mode 100644 index 0000000000..a890dfa3a2 --- /dev/null +++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/ErrorHandler.java @@ -0,0 +1,19 @@ +package com.baeldung.jsonexception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ControllerAdvice +@ResponseBody +public class ErrorHandler { + + @ExceptionHandler(CustomException.class) + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + public CustomException handleCustomException(CustomException ce) { + return ce; + } + +} \ No newline at end of file diff --git a/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/JsonErrorApplication.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/JsonErrorApplication.java new file mode 100644 index 0000000000..188584bd7c --- /dev/null +++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/JsonErrorApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.jsonexception; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class JsonErrorApplication { + + public static void main(String[] args) { + SpringApplication.run(JsonErrorApplication.class, args); + } + +} \ No newline at end of file diff --git a/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/MainController.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/MainController.java new file mode 100644 index 0000000000..5d73c239a4 --- /dev/null +++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/MainController.java @@ -0,0 +1,14 @@ +package com.baeldung.jsonexception; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class MainController { + + @GetMapping("/") + public void index() throws CustomException { + throw new CustomException(); + } + +} \ No newline at end of file diff --git a/spring-boot-exceptions/src/main/resources/application.properties b/spring-boot-exceptions/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/spring-boot-exceptions/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/spring-boot-exceptions/src/main/resources/static/.gitignore b/spring-boot-exceptions/src/main/resources/static/.gitignore new file mode 100644 index 0000000000..5e7d2734cf --- /dev/null +++ b/spring-boot-exceptions/src/main/resources/static/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/spring-boot-exceptions/src/main/resources/templates/.gitignore b/spring-boot-exceptions/src/main/resources/templates/.gitignore new file mode 100644 index 0000000000..5e7d2734cf --- /dev/null +++ b/spring-boot-exceptions/src/main/resources/templates/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/MainControllerIntegrationTest.java b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/MainControllerIntegrationTest.java new file mode 100644 index 0000000000..77e71b7d21 --- /dev/null +++ b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/MainControllerIntegrationTest.java @@ -0,0 +1,19 @@ +package com.baeldung.jsonexception; + +import org.junit.Test; + +import com.baeldung.jsonexception.CustomException; +import com.baeldung.jsonexception.MainController; + +public class MainControllerIntegrationTest { + + @Test(expected = CustomException.class) + public void givenIndex_thenCustomException() throws CustomException { + + MainController mainController = new MainController(); + + mainController.index(); + + } + +} \ No newline at end of file diff --git a/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/SpringContextIntegrationTest.java b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..aa91e242ab --- /dev/null +++ b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/SpringContextIntegrationTest.java @@ -0,0 +1,16 @@ +package com.baeldung.jsonexception; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class SpringContextIntegrationTest { + + @Test + public void contextLoads() { + } + +} diff --git a/spring-boot-mvc-birt/README.md b/spring-boot-mvc-birt/README.md new file mode 100644 index 0000000000..9fe3d94e2a --- /dev/null +++ b/spring-boot-mvc-birt/README.md @@ -0,0 +1,3 @@ +### Relevant Articles + +- [BIRT Reporting with Spring Boot](https://www.baeldung.com/birt-reports-spring-boot) diff --git a/spring-boot-mvc-birt/pom.xml b/spring-boot-mvc-birt/pom.xml index 05d3f3865a..8f41e8410a 100644 --- a/spring-boot-mvc-birt/pom.xml +++ b/spring-boot-mvc-birt/pom.xml @@ -75,7 +75,7 @@ 2.1.1.RELEASE - com.baeldung.springbootmvc.SpringBootMvcApplication + com.baeldung.birt.engine.ReportEngineApplication 1.8 1.8 diff --git a/spring-boot-ops-2/.gitignore b/spring-boot-ops-2/.gitignore new file mode 100644 index 0000000000..153c9335eb --- /dev/null +++ b/spring-boot-ops-2/.gitignore @@ -0,0 +1,29 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ + +### VS Code ### +.vscode/ diff --git a/spring-boot-ops-2/README.MD b/spring-boot-ops-2/README.MD new file mode 100644 index 0000000000..20b30515fb --- /dev/null +++ b/spring-boot-ops-2/README.MD @@ -0,0 +1,3 @@ +### Relevant Articles + +- [How to Configure Spring Boot Tomcat](https://www.baeldung.com/spring-boot-configure-tomcat) \ No newline at end of file diff --git a/spring-boot-ops-2/pom.xml b/spring-boot-ops-2/pom.xml new file mode 100644 index 0000000000..dc5280df48 --- /dev/null +++ b/spring-boot-ops-2/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + com.baeldung + spring-boot-ops-2 + 0.0.1-SNAPSHOT + spring-boot-ops-2 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-boot-ops-2/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java b/spring-boot-ops-2/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java new file mode 100644 index 0000000000..96297459a4 --- /dev/null +++ b/spring-boot-ops-2/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.springbootconfiguration; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootConfigurationApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootConfigurationApplication.class, args); + } + +} diff --git a/spring-boot-ops-2/src/main/resources/application-tomcat.properties b/spring-boot-ops-2/src/main/resources/application-tomcat.properties new file mode 100644 index 0000000000..d7c1ba9ac3 --- /dev/null +++ b/spring-boot-ops-2/src/main/resources/application-tomcat.properties @@ -0,0 +1,23 @@ +# server configuration +server.port=80 +server.address=127.0.0.1 + +## Error handling configuration +server.error.whitelabel.enabled=true +server.error.path=/user-error +server.error.include-exception=true +server.error.include-stacktrace=always + +## Server connections configuration +server.tomcat.max-threads=200 +server.connection-timeout=5s +server.max-http-header-size=8KB +server.tomcat.max-swallow-size=2MB +server.tomcat.max-http-post-size=2MB + +## Access logs configuration +server.tomcat.accesslog.enabled=true +server.tomcat.accesslog.directory=logs +server.tomcat.accesslog.file-date-format=yyyy-MM-dd +server.tomcat.accesslog.prefix=access_log +server.tomcat.accesslog.suffix=.log diff --git a/spring-boot-ops-2/src/main/resources/application.properties b/spring-boot-ops-2/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/spring-boot-ops-2/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/spring-boot-ops-2/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java b/spring-boot-ops-2/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..24bef73ef9 --- /dev/null +++ b/spring-boot-ops-2/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java @@ -0,0 +1,15 @@ +package com.baeldung.springbootconfiguration; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class SpringContextIntegrationTest { + + @Test + public void contextLoads() { + } +} diff --git a/spring-boot-rest/README.md b/spring-boot-rest/README.md index e3e93a21db..b28192cf62 100644 --- a/spring-boot-rest/README.md +++ b/spring-boot-rest/README.md @@ -1,14 +1,18 @@ Module for the articles that are part of the Spring REST E-book: 1. [Bootstrap a Web Application with Spring 5](https://www.baeldung.com/bootstraping-a-web-application-with-spring-and-java-based-configuration) -2. [Error Handling for REST with Spring](http://www.baeldung.com/exception-handling-for-rest-with-spring) -3. [REST Pagination in Spring](http://www.baeldung.com/rest-api-pagination-in-spring) -4. [Build a REST API with Spring and Java Config](http://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration) -5. [HATEOAS for a Spring REST Service](http://www.baeldung.com/rest-api-discoverability-with-spring) -6. [REST API Discoverability and HATEOAS](http://www.baeldung.com/restful-web-service-discoverability) -7. [Versioning a REST API](http://www.baeldung.com/rest-versioning) -8. [Http Message Converters with the Spring Framework](http://www.baeldung.com/spring-httpmessageconverter-rest) -9. [ETags for REST with Spring](http://www.baeldung.com/etags-for-rest-with-spring) -10. [Testing REST with multiple MIME types](http://www.baeldung.com/testing-rest-api-with-multiple-media-types) -11. [Spring Boot Consuming and Producing JSON](https://www.baeldung.com/spring-boot-json) -12. [Testing Web APIs with Postman Collections](https://www.baeldung.com/postman-testing-collections) +2. [Build a REST API with Spring and Java Config](http://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration) +3. [Http Message Converters with the Spring Framework](http://www.baeldung.com/spring-httpmessageconverter-rest) +4. [Spring’s RequestBody and ResponseBody Annotations](https://www.baeldung.com/spring-request-response-body) +5. [Entity To DTO Conversion for a Spring REST API](https://www.baeldung.com/entity-to-and-from-dto-for-a-java-spring-application) +6. [Error Handling for REST with Spring](http://www.baeldung.com/exception-handling-for-rest-with-spring) +7. [REST API Discoverability and HATEOAS](http://www.baeldung.com/restful-web-service-discoverability) +8. [An Intro to Spring HATEOAS](http://www.baeldung.com/spring-hateoas-tutorial) +9. [REST Pagination in Spring](http://www.baeldung.com/rest-api-pagination-in-spring) +10. [Test a REST API with Java](http://www.baeldung.com/integration-testing-a-rest-api) + +- [HATEOAS for a Spring REST Service](http://www.baeldung.com/rest-api-discoverability-with-spring) +- [Versioning a REST API](http://www.baeldung.com/rest-versioning) +- [ETags for REST with Spring](http://www.baeldung.com/etags-for-rest-with-spring) +- [Testing REST with multiple MIME types](http://www.baeldung.com/testing-rest-api-with-multiple-media-types) +- [Testing Web APIs with Postman Collections](https://www.baeldung.com/postman-testing-collections) diff --git a/spring-boot-rest/pom.xml b/spring-boot-rest/pom.xml index decaccd148..598b589ea0 100644 --- a/spring-boot-rest/pom.xml +++ b/spring-boot-rest/pom.xml @@ -44,6 +44,12 @@ org.springframework.boot spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-hateoas + @@ -63,6 +69,11 @@ htmlunit test + + org.modelmapper + modelmapper + ${modelmapper.version} +
@@ -78,5 +89,6 @@ com.baeldung.SpringBootRestApplication 27.0.1-jre 1.4.11.1 + 2.3.3 diff --git a/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java b/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java index 62aae7619d..1c0d0d19e8 100644 --- a/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java +++ b/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java @@ -1,7 +1,9 @@ package com.baeldung; +import org.modelmapper.ModelMapper; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; @SpringBootApplication public class SpringBootRestApplication { @@ -9,5 +11,10 @@ public class SpringBootRestApplication { public static void main(String[] args) { SpringApplication.run(SpringBootRestApplication.class, args); } + + @Bean + public ModelMapper modelMapper() { + return new ModelMapper(); + } } diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java similarity index 99% rename from spring-boot/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java index c0cbca5220..68c17975d4 100644 --- a/spring-boot/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java +++ b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java @@ -21,6 +21,7 @@ import com.baeldung.modelmapper.service.IPostService; import com.baeldung.modelmapper.service.IUserService; @Controller +@RequestMapping("/posts") public class PostRestController { @Autowired diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/dto/PostDto.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/dto/PostDto.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/dto/PostDto.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/dto/PostDto.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/dto/UserDto.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/dto/UserDto.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/dto/UserDto.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/dto/UserDto.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/model/Post.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/Post.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/model/Post.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/Post.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/model/Preference.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/Preference.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/model/Preference.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/Preference.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/model/User.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/User.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/model/User.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/User.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/repository/PostRepository.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/repository/PostRepository.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/repository/PostRepository.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/repository/PostRepository.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/service/IPostService.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/IPostService.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/service/IPostService.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/IPostService.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/service/IUserService.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/IUserService.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/service/IUserService.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/IUserService.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/service/PostService.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/PostService.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/service/PostService.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/PostService.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/service/UserService.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/UserService.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/service/UserService.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/UserService.java diff --git a/spring-security-rest/src/main/java/org/baeldung/persistence/model/Customer.java b/spring-boot-rest/src/main/java/com/baeldung/persistence/model/Customer.java similarity index 97% rename from spring-security-rest/src/main/java/org/baeldung/persistence/model/Customer.java rename to spring-boot-rest/src/main/java/com/baeldung/persistence/model/Customer.java index b302ec057a..10da2e10f0 100644 --- a/spring-security-rest/src/main/java/org/baeldung/persistence/model/Customer.java +++ b/spring-boot-rest/src/main/java/com/baeldung/persistence/model/Customer.java @@ -1,4 +1,4 @@ -package org.baeldung.persistence.model; +package com.baeldung.persistence.model; import java.util.Map; diff --git a/spring-security-rest/src/main/java/org/baeldung/persistence/model/Order.java b/spring-boot-rest/src/main/java/com/baeldung/persistence/model/Order.java similarity index 96% rename from spring-security-rest/src/main/java/org/baeldung/persistence/model/Order.java rename to spring-boot-rest/src/main/java/com/baeldung/persistence/model/Order.java index ca551423e8..7aea9bce5c 100644 --- a/spring-security-rest/src/main/java/org/baeldung/persistence/model/Order.java +++ b/spring-boot-rest/src/main/java/com/baeldung/persistence/model/Order.java @@ -1,4 +1,4 @@ -package org.baeldung.persistence.model; +package com.baeldung.persistence.model; import org.springframework.hateoas.ResourceSupport; diff --git a/spring-security-rest/src/main/java/org/baeldung/web/service/CustomerService.java b/spring-boot-rest/src/main/java/com/baeldung/services/CustomerService.java similarity index 64% rename from spring-security-rest/src/main/java/org/baeldung/web/service/CustomerService.java rename to spring-boot-rest/src/main/java/com/baeldung/services/CustomerService.java index da016af2d5..a5e95e693b 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/service/CustomerService.java +++ b/spring-boot-rest/src/main/java/com/baeldung/services/CustomerService.java @@ -1,8 +1,8 @@ -package org.baeldung.web.service; +package com.baeldung.services; import java.util.List; -import org.baeldung.persistence.model.Customer; +import com.baeldung.persistence.model.Customer; public interface CustomerService { diff --git a/spring-security-rest/src/main/java/org/baeldung/web/service/CustomerServiceImpl.java b/spring-boot-rest/src/main/java/com/baeldung/services/CustomerServiceImpl.java similarity index 92% rename from spring-security-rest/src/main/java/org/baeldung/web/service/CustomerServiceImpl.java rename to spring-boot-rest/src/main/java/com/baeldung/services/CustomerServiceImpl.java index e179de2554..58030483ec 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/service/CustomerServiceImpl.java +++ b/spring-boot-rest/src/main/java/com/baeldung/services/CustomerServiceImpl.java @@ -1,12 +1,13 @@ -package org.baeldung.web.service; +package com.baeldung.services; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import org.baeldung.persistence.model.Customer; import org.springframework.stereotype.Service; +import com.baeldung.persistence.model.Customer; + @Service public class CustomerServiceImpl implements CustomerService { diff --git a/spring-rest/src/main/java/com/baeldung/services/ExampleService.java b/spring-boot-rest/src/main/java/com/baeldung/services/ExampleService.java similarity index 100% rename from spring-rest/src/main/java/com/baeldung/services/ExampleService.java rename to spring-boot-rest/src/main/java/com/baeldung/services/ExampleService.java diff --git a/spring-security-rest/src/main/java/org/baeldung/web/service/OrderService.java b/spring-boot-rest/src/main/java/com/baeldung/services/OrderService.java similarity index 70% rename from spring-security-rest/src/main/java/org/baeldung/web/service/OrderService.java rename to spring-boot-rest/src/main/java/com/baeldung/services/OrderService.java index 9a23488c50..775701e042 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/service/OrderService.java +++ b/spring-boot-rest/src/main/java/com/baeldung/services/OrderService.java @@ -1,8 +1,8 @@ -package org.baeldung.web.service; +package com.baeldung.services; import java.util.List; -import org.baeldung.persistence.model.Order; +import com.baeldung.persistence.model.Order; public interface OrderService { diff --git a/spring-security-rest/src/main/java/org/baeldung/web/service/OrderServiceImpl.java b/spring-boot-rest/src/main/java/com/baeldung/services/OrderServiceImpl.java similarity index 93% rename from spring-security-rest/src/main/java/org/baeldung/web/service/OrderServiceImpl.java rename to spring-boot-rest/src/main/java/com/baeldung/services/OrderServiceImpl.java index 0a6d4708a1..fffdf88969 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/service/OrderServiceImpl.java +++ b/spring-boot-rest/src/main/java/com/baeldung/services/OrderServiceImpl.java @@ -1,14 +1,15 @@ -package org.baeldung.web.service; +package com.baeldung.services; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.baeldung.persistence.model.Customer; -import org.baeldung.persistence.model.Order; import org.springframework.stereotype.Service; +import com.baeldung.persistence.model.Customer; +import com.baeldung.persistence.model.Order; + @Service public class OrderServiceImpl implements OrderService { diff --git a/spring-boot-rest/src/main/java/com/baeldung/spring/PersistenceConfig.java b/spring-boot-rest/src/main/java/com/baeldung/spring/PersistenceConfig.java index 5179c66978..2e967751ad 100644 --- a/spring-boot-rest/src/main/java/com/baeldung/spring/PersistenceConfig.java +++ b/spring-boot-rest/src/main/java/com/baeldung/spring/PersistenceConfig.java @@ -24,8 +24,8 @@ import com.google.common.base.Preconditions; @Configuration @EnableTransactionManagement @PropertySource({ "classpath:persistence-${envTarget:h2}.properties" }) -@ComponentScan({ "com.baeldung.persistence" }) -@EnableJpaRepositories(basePackages = "com.baeldung.persistence.dao") +@ComponentScan(basePackages = { "com.baeldung.persistence", "com.baeldung.modelmapper" }) +@EnableJpaRepositories(basePackages = {"com.baeldung.persistence.dao", "com.baeldung.modelmapper.repository"}) public class PersistenceConfig { @Autowired @@ -39,7 +39,7 @@ public class PersistenceConfig { public LocalContainerEntityManagerFactoryBean entityManagerFactory() { final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(dataSource()); - em.setPackagesToScan(new String[] { "com.baeldung.persistence.model" }); + em.setPackagesToScan(new String[] { "com.baeldung.persistence.model", "com.baeldung.modelmapper.model" }); final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); // vendorAdapter.set diff --git a/spring-boot-rest/src/main/java/com/baeldung/transfer/LoginForm.java b/spring-boot-rest/src/main/java/com/baeldung/transfer/LoginForm.java new file mode 100644 index 0000000000..caafcdb500 --- /dev/null +++ b/spring-boot-rest/src/main/java/com/baeldung/transfer/LoginForm.java @@ -0,0 +1,31 @@ +package com.baeldung.transfer; + +public class LoginForm { + private String username; + private String password; + + public LoginForm() { + } + + public LoginForm(String username, String password) { + super(); + this.username = username; + this.password = password; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} \ No newline at end of file diff --git a/spring-rest/src/main/java/com/baeldung/transfer/ResponseTransfer.java b/spring-boot-rest/src/main/java/com/baeldung/transfer/ResponseTransfer.java similarity index 100% rename from spring-rest/src/main/java/com/baeldung/transfer/ResponseTransfer.java rename to spring-boot-rest/src/main/java/com/baeldung/transfer/ResponseTransfer.java diff --git a/spring-security-rest/src/main/java/org/baeldung/web/controller/CustomerController.java b/spring-boot-rest/src/main/java/com/baeldung/web/controller/CustomerController.java similarity index 64% rename from spring-security-rest/src/main/java/org/baeldung/web/controller/CustomerController.java rename to spring-boot-rest/src/main/java/com/baeldung/web/controller/CustomerController.java index e1db105d18..91aa9f2144 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/controller/CustomerController.java +++ b/spring-boot-rest/src/main/java/com/baeldung/web/controller/CustomerController.java @@ -1,24 +1,25 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; import java.util.List; -import org.baeldung.persistence.model.Customer; -import org.baeldung.persistence.model.Order; -import org.baeldung.web.service.CustomerService; -import org.baeldung.web.service.OrderService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.hateoas.Link; import org.springframework.hateoas.Resources; import org.springframework.hateoas.config.EnableHypermediaSupport; import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import com.baeldung.persistence.model.Customer; +import com.baeldung.persistence.model.Order; +import com.baeldung.services.CustomerService; +import com.baeldung.services.OrderService; + @RestController @RequestMapping(value = "/customers") @EnableHypermediaSupport(type = HypermediaType.HAL) @@ -29,45 +30,49 @@ public class CustomerController { @Autowired private OrderService orderService; - @RequestMapping(value = "/{customerId}", method = RequestMethod.GET) + @GetMapping("/{customerId}") public Customer getCustomerById(@PathVariable final String customerId) { return customerService.getCustomerDetail(customerId); } - @RequestMapping(value = "/{customerId}/{orderId}", method = RequestMethod.GET) + @GetMapping("/{customerId}/{orderId}") public Order getOrderById(@PathVariable final String customerId, @PathVariable final String orderId) { return orderService.getOrderByIdForCustomer(customerId, orderId); } - @RequestMapping(value = "/{customerId}/orders", method = RequestMethod.GET , produces = {"application/hal+json"}) + @GetMapping(value = "/{customerId}/orders", produces = { "application/hal+json" }) public Resources getOrdersForCustomer(@PathVariable final String customerId) { final List orders = orderService.getAllOrdersForCustomer(customerId); for (final Order order : orders) { - final Link selfLink = linkTo(methodOn(CustomerController.class).getOrderById(customerId, order.getOrderId())).withSelfRel(); + final Link selfLink = linkTo( + methodOn(CustomerController.class).getOrderById(customerId, order.getOrderId())).withSelfRel(); order.add(selfLink); } - - Link link =linkTo(methodOn(CustomerController.class).getOrdersForCustomer(customerId)).withSelfRel(); - Resources result = new Resources<>(orders,link); + + Link link = linkTo(methodOn(CustomerController.class).getOrdersForCustomer(customerId)).withSelfRel(); + Resources result = new Resources<>(orders, link); return result; } - @RequestMapping(method = RequestMethod.GET, produces = {"application/hal+json"}) + @GetMapping(produces = { "application/hal+json" }) public Resources getAllCustomers() { final List allCustomers = customerService.allCustomers(); - + for (final Customer customer : allCustomers) { String customerId = customer.getCustomerId(); - Link selfLink = linkTo(CustomerController.class).slash(customerId).withSelfRel(); + Link selfLink = linkTo(CustomerController.class).slash(customerId) + .withSelfRel(); customer.add(selfLink); - if (orderService.getAllOrdersForCustomer(customerId).size() > 0) { - final Link ordersLink = linkTo(methodOn(CustomerController.class).getOrdersForCustomer(customerId)).withRel("allOrders"); + if (orderService.getAllOrdersForCustomer(customerId) + .size() > 0) { + final Link ordersLink = linkTo(methodOn(CustomerController.class).getOrdersForCustomer(customerId)) + .withRel("allOrders"); customer.add(ordersLink); } } - - Link link =linkTo(CustomerController.class).withSelfRel(); - Resources result = new Resources<>(allCustomers,link); + + Link link = linkTo(CustomerController.class).withSelfRel(); + Resources result = new Resources<>(allCustomers, link); return result; } diff --git a/spring-rest/src/main/java/com/baeldung/controllers/ExamplePostController.java b/spring-boot-rest/src/main/java/com/baeldung/web/controller/ExamplePostController.java similarity index 97% rename from spring-rest/src/main/java/com/baeldung/controllers/ExamplePostController.java rename to spring-boot-rest/src/main/java/com/baeldung/web/controller/ExamplePostController.java index 93f96756b4..1519d95d4d 100644 --- a/spring-rest/src/main/java/com/baeldung/controllers/ExamplePostController.java +++ b/spring-boot-rest/src/main/java/com/baeldung/web/controller/ExamplePostController.java @@ -1,4 +1,4 @@ -package com.baeldung.controllers; +package com.baeldung.web.controller; import com.baeldung.services.ExampleService; import com.baeldung.transfer.ResponseTransfer; diff --git a/spring-boot-rest/src/test/java/com/baeldung/SpringContextIntegrationTest.java b/spring-boot-rest/src/test/java/com/baeldung/SpringContextIntegrationTest.java index 25fbc4cc02..3db1ecb462 100644 --- a/spring-boot-rest/src/test/java/com/baeldung/SpringContextIntegrationTest.java +++ b/spring-boot-rest/src/test/java/com/baeldung/SpringContextIntegrationTest.java @@ -6,7 +6,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) -@SpringBootTest +@SpringBootTest(classes = {SpringBootRestApplication.class}) public class SpringContextIntegrationTest { @Test diff --git a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java b/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java similarity index 92% rename from spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java rename to spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java index 94b8bf40e7..fc533072c8 100644 --- a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java +++ b/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java @@ -1,8 +1,10 @@ package com.baeldung.controllers; -import com.baeldung.sampleapp.config.MainApplication; -import com.baeldung.services.ExampleService; -import com.baeldung.transfer.LoginForm; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -14,13 +16,13 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.baeldung.SpringBootRestApplication; +import com.baeldung.services.ExampleService; +import com.baeldung.transfer.LoginForm; +import com.baeldung.web.controller.ExamplePostController; @RunWith(SpringRunner.class) -@SpringBootTest(classes = MainApplication.class) +@SpringBootTest(classes = SpringBootRestApplication.class) public class ExamplePostControllerRequestIntegrationTest { MockMvc mockMvc; diff --git a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java b/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java similarity index 92% rename from spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java rename to spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java index 5743ad450b..cbe21b1d90 100644 --- a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java +++ b/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java @@ -1,8 +1,11 @@ package com.baeldung.controllers; -import com.baeldung.sampleapp.config.MainApplication; -import com.baeldung.services.ExampleService; -import com.baeldung.transfer.LoginForm; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -11,18 +14,16 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; - import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.baeldung.SpringBootRestApplication; +import com.baeldung.services.ExampleService; +import com.baeldung.transfer.LoginForm; +import com.baeldung.web.controller.ExamplePostController; @RunWith(SpringRunner.class) -@SpringBootTest(classes = MainApplication.class) +@SpringBootTest(classes = SpringBootRestApplication.class) public class ExamplePostControllerResponseIntegrationTest { MockMvc mockMvc; diff --git a/spring-boot/src/test/java/com/baeldung/modelmapper/PostDtoUnitTest.java b/spring-boot-rest/src/test/java/com/baeldung/modelmapper/PostDtoUnitTest.java similarity index 100% rename from spring-boot/src/test/java/com/baeldung/modelmapper/PostDtoUnitTest.java rename to spring-boot-rest/src/test/java/com/baeldung/modelmapper/PostDtoUnitTest.java diff --git a/spring-boot-rest/src/test/java/com/baeldung/springhateoas/CustomerControllerIntegrationTest.java b/spring-boot-rest/src/test/java/com/baeldung/springhateoas/CustomerControllerIntegrationTest.java new file mode 100644 index 0000000000..b08da6d2cd --- /dev/null +++ b/spring-boot-rest/src/test/java/com/baeldung/springhateoas/CustomerControllerIntegrationTest.java @@ -0,0 +1,98 @@ +package com.baeldung.springhateoas; + +import static org.hamcrest.Matchers.is; +import static org.mockito.BDDMockito.given; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.Collections; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.hateoas.MediaTypes; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import com.baeldung.persistence.model.Customer; +import com.baeldung.persistence.model.Order; +import com.baeldung.services.CustomerService; +import com.baeldung.services.OrderService; +import com.baeldung.web.controller.CustomerController; + +@RunWith(SpringRunner.class) +@WebMvcTest(CustomerController.class) +public class CustomerControllerIntegrationTest { + + @Autowired + private MockMvc mvc; + + @MockBean + private CustomerService customerService; + + @MockBean + private OrderService orderService; + + private static final String DEFAULT_CUSTOMER_ID = "customer1"; + private static final String DEFAULT_ORDER_ID = "order1"; + + @Test + public void givenExistingCustomer_whenCustomerRequested_thenResourceRetrieved() throws Exception { + given(this.customerService.getCustomerDetail(DEFAULT_CUSTOMER_ID)) + .willReturn(new Customer(DEFAULT_CUSTOMER_ID, "customerJohn", "companyOne")); + + this.mvc.perform(get("/customers/" + DEFAULT_CUSTOMER_ID)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$._links").doesNotExist()) + .andExpect(jsonPath("$.customerId", is(DEFAULT_CUSTOMER_ID))); + } + + @Test + public void givenExistingOrder_whenOrderRequested_thenResourceRetrieved() throws Exception { + given(this.orderService.getOrderByIdForCustomer(DEFAULT_CUSTOMER_ID, DEFAULT_ORDER_ID)) + .willReturn(new Order(DEFAULT_ORDER_ID, 1., 1)); + + this.mvc.perform(get("/customers/" + DEFAULT_CUSTOMER_ID + "/" + DEFAULT_ORDER_ID)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$._links").doesNotExist()) + .andExpect(jsonPath("$.orderId", is(DEFAULT_ORDER_ID))); + } + + @Test + public void givenExistingCustomerWithOrders_whenOrdersRequested_thenHalResourceRetrieved() throws Exception { + Order order1 = new Order(DEFAULT_ORDER_ID, 1., 1); + List orders = Collections.singletonList(order1); + given(this.orderService.getAllOrdersForCustomer(DEFAULT_CUSTOMER_ID)).willReturn(orders); + + this.mvc.perform(get("/customers/" + DEFAULT_CUSTOMER_ID + "/orders").accept(MediaTypes.HAL_JSON_VALUE)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$._embedded.orderList[0]._links.self.href", + is("http://localhost/customers/customer1/order1"))) + .andExpect(jsonPath("$._links.self.href", is("http://localhost/customers/customer1/orders"))); + } + + @Test + public void givenExistingCustomer_whenAllCustomersRequested_thenHalResourceRetrieved() throws Exception { + // customers + Customer retrievedCustomer = new Customer(DEFAULT_CUSTOMER_ID, "customerJohn", "companyOne"); + List customers = Collections.singletonList(retrievedCustomer); + given(this.customerService.allCustomers()).willReturn(customers); + // orders + Order order1 = new Order(DEFAULT_ORDER_ID, 1., 1); + List orders = Collections.singletonList(order1); + given(this.orderService.getAllOrdersForCustomer(DEFAULT_CUSTOMER_ID)).willReturn(orders); + + this.mvc.perform(get("/customers/").accept(MediaTypes.HAL_JSON_VALUE)) + .andExpect(status().isOk()) + .andExpect( + jsonPath("$._embedded.customerList[0]._links.self.href", is("http://localhost/customers/customer1"))) + .andExpect(jsonPath("$._embedded.customerList[0]._links.allOrders.href", + is("http://localhost/customers/customer1/orders"))) + .andExpect(jsonPath("$._links.self.href", is("http://localhost/customers"))); + } + +} diff --git a/spring-boot-testing/src/main/java/com/baeldung/component/OtherComponent.java b/spring-boot-testing/src/main/java/com/baeldung/component/OtherComponent.java new file mode 100644 index 0000000000..97f001a9e5 --- /dev/null +++ b/spring-boot-testing/src/main/java/com/baeldung/component/OtherComponent.java @@ -0,0 +1,19 @@ +package com.baeldung.component; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class OtherComponent { + + private static final Logger LOG = LoggerFactory.getLogger(OtherComponent.class); + + public void processData() { + LOG.trace("This is a TRACE log from another package"); + LOG.debug("This is a DEBUG log from another package"); + LOG.info("This is an INFO log from another package"); + LOG.error("This is an ERROR log from another package"); + } + +} diff --git a/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelApplication.java b/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelApplication.java new file mode 100644 index 0000000000..ed8218c6a3 --- /dev/null +++ b/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.testloglevel; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import com.baeldung.boot.Application; + +@SpringBootApplication(scanBasePackages = {"com.baeldung.testloglevel", "com.baeldung.component"}) +public class TestLogLevelApplication { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelController.java b/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelController.java new file mode 100644 index 0000000000..22078562b4 --- /dev/null +++ b/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelController.java @@ -0,0 +1,31 @@ +package com.baeldung.testloglevel; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.component.OtherComponent; + +@RestController +public class TestLogLevelController { + + private static final Logger LOG = LoggerFactory.getLogger(TestLogLevelController.class); + + @Autowired + private OtherComponent otherComponent; + + @GetMapping("/testLogLevel") + public String testLogLevel() { + LOG.trace("This is a TRACE log"); + LOG.debug("This is a DEBUG log"); + LOG.info("This is an INFO log"); + LOG.error("This is an ERROR log"); + + otherComponent.processData(); + + return "Added some log output to console..."; + } + +} diff --git a/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java b/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java new file mode 100644 index 0000000000..7a1eb4adbe --- /dev/null +++ b/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java @@ -0,0 +1,70 @@ +package com.baeldung.testloglevel; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.rule.OutputCapture; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = TestLogLevelApplication.class) +@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class) +@ActiveProfiles("logback-test2") +public class LogbackMultiProfileTestLogLevelIntegrationTest { + + @Autowired + private TestRestTemplate restTemplate; + + @Rule + public OutputCapture outputCapture = new OutputCapture(); + + private String baseUrl = "/testLogLevel"; + + @Test + public void givenErrorRootLevelAndTraceLevelForOurPackage_whenCall_thenPrintTraceLogsForOurPackage() { + ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class); + + assertThat(response.getStatusCode().value()).isEqualTo(200); + assertThatOutputContainsLogForOurPackage("TRACE"); + } + + @Test + public void givenErrorRootLevelAndTraceLevelForOurPackage_whenCall_thenNoTraceLogsForOtherPackages() { + ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class); + + assertThat(response.getStatusCode().value()).isEqualTo(200); + assertThatOutputDoesntContainLogForOtherPackages("TRACE"); + } + + @Test + public void givenErrorRootLevelAndTraceLevelForOurPackage_whenCall_thenPrintErrorLogs() { + ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class); + + assertThat(response.getStatusCode().value()).isEqualTo(200); + assertThatOutputContainsLogForOurPackage("ERROR"); + assertThatOutputContainsLogForOtherPackages("ERROR"); + } + + private void assertThatOutputContainsLogForOurPackage(String level) { + assertThat(outputCapture.toString()).containsPattern("TestLogLevelController.*" + level + ".*"); + } + + private void assertThatOutputDoesntContainLogForOtherPackages(String level) { + assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).doesNotContain(level); + } + + private void assertThatOutputContainsLogForOtherPackages(String level) { + assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).contains(level); + } + +} diff --git a/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java b/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java new file mode 100644 index 0000000000..af3bafdc2e --- /dev/null +++ b/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java @@ -0,0 +1,70 @@ +package com.baeldung.testloglevel; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.rule.OutputCapture; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = TestLogLevelApplication.class) +@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class) +@ActiveProfiles("logback-test") +public class LogbackTestLogLevelIntegrationTest { + + @Autowired + private TestRestTemplate restTemplate; + + @Rule + public OutputCapture outputCapture = new OutputCapture(); + + private String baseUrl = "/testLogLevel"; + + @Test + public void givenErrorRootLevelAndDebugLevelForOurPackage_whenCall_thenPrintDebugLogsForOurPackage() { + ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class); + + assertThat(response.getStatusCode().value()).isEqualTo(200); + assertThatOutputContainsLogForOurPackage("DEBUG"); + } + + @Test + public void givenErrorRootLevelAndDebugLevelForOurPackage_whenCall_thenNoDebugLogsForOtherPackages() { + ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class); + + assertThat(response.getStatusCode().value()).isEqualTo(200); + assertThatOutputDoesntContainLogForOtherPackages("DEBUG"); + } + + @Test + public void givenErrorRootLevelAndDebugLevelForOurPackage_whenCall_thenPrintErrorLogs() { + ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class); + + assertThat(response.getStatusCode().value()).isEqualTo(200); + assertThatOutputContainsLogForOurPackage("ERROR"); + assertThatOutputContainsLogForOtherPackages("ERROR"); + } + + private void assertThatOutputContainsLogForOurPackage(String level) { + assertThat(outputCapture.toString()).containsPattern("TestLogLevelController.*" + level + ".*"); + } + + private void assertThatOutputDoesntContainLogForOtherPackages(String level) { + assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).doesNotContain(level); + } + + private void assertThatOutputContainsLogForOtherPackages(String level) { + assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).contains(level); + } + +} diff --git a/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java b/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java new file mode 100644 index 0000000000..5609ce6c01 --- /dev/null +++ b/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java @@ -0,0 +1,70 @@ +package com.baeldung.testloglevel; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.rule.OutputCapture; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = TestLogLevelApplication.class) +@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class) +@ActiveProfiles("logging-test") +public class TestLogLevelWithProfileIntegrationTest { + + @Autowired + private TestRestTemplate restTemplate; + + @Rule + public OutputCapture outputCapture = new OutputCapture(); + + private String baseUrl = "/testLogLevel"; + + @Test + public void givenInfoRootLevelAndDebugLevelForOurPackage_whenCall_thenPrintDebugLogsForOurPackage() { + ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class); + + assertThat(response.getStatusCode().value()).isEqualTo(200); + assertThatOutputContainsLogForOurPackage("DEBUG"); + } + + @Test + public void givenInfoRootLevelAndDebugLevelForOurPackage_whenCall_thenNoDebugLogsForOtherPackages() { + ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class); + + assertThat(response.getStatusCode().value()).isEqualTo(200); + assertThatOutputDoesntContainLogForOtherPackages("DEBUG"); + } + + @Test + public void givenInfoRootLevelAndDebugLevelForOurPackage_whenCall_thenPrintInfoLogs() { + ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class); + + assertThat(response.getStatusCode().value()).isEqualTo(200); + assertThatOutputContainsLogForOurPackage("INFO"); + assertThatOutputContainsLogForOtherPackages("INFO"); + } + + private void assertThatOutputContainsLogForOurPackage(String level) { + assertThat(outputCapture.toString()).containsPattern("TestLogLevelController.*" + level + ".*"); + } + + private void assertThatOutputDoesntContainLogForOtherPackages(String level) { + assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).doesNotContain(level); + } + + private void assertThatOutputContainsLogForOtherPackages(String level) { + assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).contains(level); + } + +} diff --git a/spring-boot-testing/src/test/resources/application-logback-test.properties b/spring-boot-testing/src/test/resources/application-logback-test.properties new file mode 100644 index 0000000000..587302fa01 --- /dev/null +++ b/spring-boot-testing/src/test/resources/application-logback-test.properties @@ -0,0 +1 @@ +logging.config=classpath:logback-test.xml diff --git a/spring-boot-testing/src/test/resources/application-logback-test2.properties b/spring-boot-testing/src/test/resources/application-logback-test2.properties new file mode 100644 index 0000000000..aeed46e3ca --- /dev/null +++ b/spring-boot-testing/src/test/resources/application-logback-test2.properties @@ -0,0 +1 @@ +logging.config=classpath:logback-multiprofile.xml \ No newline at end of file diff --git a/spring-boot-testing/src/test/resources/application-logging-test.properties b/spring-boot-testing/src/test/resources/application-logging-test.properties new file mode 100644 index 0000000000..b5adb4cc11 --- /dev/null +++ b/spring-boot-testing/src/test/resources/application-logging-test.properties @@ -0,0 +1,2 @@ +logging.level.com.baeldung.testloglevel=DEBUG +logging.level.root=INFO \ No newline at end of file diff --git a/spring-boot-testing/src/test/resources/logback-multiprofile.xml b/spring-boot-testing/src/test/resources/logback-multiprofile.xml new file mode 100644 index 0000000000..be790234f2 --- /dev/null +++ b/spring-boot-testing/src/test/resources/logback-multiprofile.xml @@ -0,0 +1,18 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + diff --git a/spring-boot-testing/src/test/resources/logback-test.xml b/spring-boot-testing/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..0528aa88f3 --- /dev/null +++ b/spring-boot-testing/src/test/resources/logback-test.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + diff --git a/spring-boot-vue/pom.xml b/spring-boot-vue/pom.xml index 4e47a98d6f..5d19f01d1e 100644 --- a/spring-boot-vue/pom.xml +++ b/spring-boot-vue/pom.xml @@ -47,7 +47,6 @@ UTF-8 UTF-8 - 1.8 diff --git a/spring-boot/README.MD b/spring-boot/README.MD index b8b51153a7..c0392d38de 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -35,5 +35,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Display Auto-Configuration Report in Spring Boot](https://www.baeldung.com/spring-boot-auto-configuration-report) - [Injecting Git Information Into Spring](https://www.baeldung.com/spring-git-information) - [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation) -- [Entity To DTO Conversion for a Spring REST API](https://www.baeldung.com/entity-to-and-from-dto-for-a-java-spring-application) - [Guide to Creating and Running a Jar File in Java](https://www.baeldung.com/java-create-jar) diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index ed2d8259df..401e0289e8 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -153,12 +153,6 @@ javax.validation validation-api - - - org.modelmapper - modelmapper - ${modelmapper.version} -
@@ -256,7 +250,6 @@ 5.2.4 18.0 2.2.4 - 2.3.2 diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/PostApplication.java b/spring-boot/src/main/java/com/baeldung/modelmapper/PostApplication.java deleted file mode 100644 index 7684c43648..0000000000 --- a/spring-boot/src/main/java/com/baeldung/modelmapper/PostApplication.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.modelmapper; - -import org.modelmapper.ModelMapper; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -public class PostApplication { - - public static void main(String[] args) { - SpringApplication.run(PostApplication.class, args); - } - - @Bean - public ModelMapper modelMapper() { - return new ModelMapper(); - } - -} diff --git a/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java b/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java index 3698d8ef30..1a3c985fe4 100644 --- a/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java +++ b/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java @@ -9,6 +9,7 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.Pattern; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.validation.annotation.Validated; @@ -80,4 +81,10 @@ public class ConfigProperties { public void setCredentials(Credentials credentials) { this.credentials = credentials; } + + @Bean + @ConfigurationProperties(prefix = "item") + public Item item(){ + return new Item(); + } } diff --git a/spring-boot/src/main/java/org/baeldung/properties/Item.java b/spring-boot/src/main/java/org/baeldung/properties/Item.java new file mode 100644 index 0000000000..0314654ada --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/properties/Item.java @@ -0,0 +1,31 @@ +package org.baeldung.properties; + +public class Item { + + private String name; + private int size; + + public Item() { + } + + public Item(String name, int size) { + this.name = name; + this.size = size; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } +} diff --git a/spring-boot/src/main/resources/configprops.properties b/spring-boot/src/main/resources/configprops.properties index 2dad11f9cc..424b3632f9 100644 --- a/spring-boot/src/main/resources/configprops.properties +++ b/spring-boot/src/main/resources/configprops.properties @@ -17,4 +17,8 @@ mail.credentials.username=john mail.credentials.password=password mail.credentials.authMethod=SHA1 +#Bean method properties +item.name=Item name +item.size=42 + diff --git a/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java index 4ba6bf29d8..f864fd4f8c 100644 --- a/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java @@ -53,4 +53,11 @@ public class ConfigPropertiesIntegrationTest { Assert.assertEquals("Incorrectly bound object property, username", "john", credentials.getUsername()); Assert.assertEquals("Incorrectly bound object property, password", "password", credentials.getPassword()); } + + @Test + public void whenBeanMethodAnnotatedThenPropertiesCorrectlyBound(){ + Item item = properties.item(); + Assert.assertEquals("Incorrectly bound object property, item.name","Test item name", item.getName()); + Assert.assertEquals("Incorrectly bound object property, item.size", 21, item.getSize()); + } } diff --git a/spring-boot/src/test/resources/configprops-test.properties b/spring-boot/src/test/resources/configprops-test.properties index 697771ae6e..ea11f2159e 100644 --- a/spring-boot/src/test/resources/configprops-test.properties +++ b/spring-boot/src/test/resources/configprops-test.properties @@ -17,3 +17,6 @@ mail.credentials.username=john mail.credentials.password=password mail.credentials.authMethod=SHA1 +#Bean method properties +item.name=Test item name +item.size=21 diff --git a/spring-cloud-data-flow/etl/customer-mongodb-sink/pom.xml b/spring-cloud-data-flow/etl/customer-mongodb-sink/pom.xml index 456caf480c..409db34829 100644 --- a/spring-cloud-data-flow/etl/customer-mongodb-sink/pom.xml +++ b/spring-cloud-data-flow/etl/customer-mongodb-sink/pom.xml @@ -63,7 +63,6 @@ UTF-8 UTF-8 - 1.8 Greenwich.RELEASE diff --git a/spring-cloud-data-flow/etl/customer-transform/pom.xml b/spring-cloud-data-flow/etl/customer-transform/pom.xml index b7376f7bd4..66f1d5e0d7 100644 --- a/spring-cloud-data-flow/etl/customer-transform/pom.xml +++ b/spring-cloud-data-flow/etl/customer-transform/pom.xml @@ -55,7 +55,6 @@ UTF-8 UTF-8 - 1.8 Greenwich.RELEASE diff --git a/spring-cloud/spring-cloud-archaius/basic-config/src/test/java/com/baeldung/spring/cloud/archaius/basic/ArchaiusBasicConfigurationIntegrationTest.java b/spring-cloud/spring-cloud-archaius/basic-config/src/test/java/com/baeldung/spring/cloud/archaius/basic/ArchaiusBasicConfigurationIntegrationTest.java index 2948606c0b..d49a8dfa7e 100644 --- a/spring-cloud/spring-cloud-archaius/basic-config/src/test/java/com/baeldung/spring/cloud/archaius/basic/ArchaiusBasicConfigurationIntegrationTest.java +++ b/spring-cloud/spring-cloud-archaius/basic-config/src/test/java/com/baeldung/spring/cloud/archaius/basic/ArchaiusBasicConfigurationIntegrationTest.java @@ -5,21 +5,18 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Collections; import org.junit.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.junit4.SpringRunner; import com.netflix.config.DynamicPropertyFactory; import com.netflix.config.DynamicStringProperty; -@RunWith(JUnitPlatform.class) -@ExtendWith(SpringExtension.class) +@RunWith(SpringRunner.class) @SpringBootTest public class ArchaiusBasicConfigurationIntegrationTest { diff --git a/spring-cloud/spring-cloud-archaius/dynamodb-config/src/test/java/com/baeldung/spring/cloud/archaius/dynamosources/SpringContextLiveTest.java b/spring-cloud/spring-cloud-archaius/dynamodb-config/src/test/java/com/baeldung/spring/cloud/archaius/dynamosources/SpringContextLiveTest.java new file mode 100644 index 0000000000..a1a6c46c60 --- /dev/null +++ b/spring-cloud/spring-cloud-archaius/dynamodb-config/src/test/java/com/baeldung/spring/cloud/archaius/dynamosources/SpringContextLiveTest.java @@ -0,0 +1,20 @@ +package com.baeldung.spring.cloud.archaius.dynamosources; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * To run this Live Test we need to: + * * start a dynamodb instance locally on port 8000(e.g. with the following command `docker run -p 8000:8000 --name bael-dynamodb amazon/dynamodb-local`) + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = DynamoSourcesApplication.class) +public class SpringContextLiveTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/discovery/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-archaius/jdbc-config/src/test/java/com/baeldung/spring/cloud/archaius/jdbconfig/SpringContextIntegrationTest.java similarity index 70% rename from spring-cloud/spring-cloud-bootstrap/discovery/java/org/baeldung/SpringContextIntegrationTest.java rename to spring-cloud/spring-cloud-archaius/jdbc-config/src/test/java/com/baeldung/spring/cloud/archaius/jdbconfig/SpringContextIntegrationTest.java index 6016788eab..b3cd01e684 100644 --- a/spring-cloud/spring-cloud-bootstrap/discovery/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-cloud/spring-cloud-archaius/jdbc-config/src/test/java/com/baeldung/spring/cloud/archaius/jdbconfig/SpringContextIntegrationTest.java @@ -1,17 +1,15 @@ -package org.baeldung; +package com.baeldung.spring.cloud.archaius.jdbconfig; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import com.baeldung.spring.cloud.bootstrap.config.ConfigApplication; - @RunWith(SpringRunner.class) -@SpringBootTest(classes = ConfigApplication.class) +@SpringBootTest(classes = JdbcSourcesApplication.class) public class SpringContextIntegrationTest { @Test public void whenSpringContextIsBootstrapped_thenNoExceptions() { } -} +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-archaius/zookeeper-config/src/test/java/com/baeldung/spring/cloud/archaius/zookeeperconfig/SpringContextLiveTest.java b/spring-cloud/spring-cloud-archaius/zookeeper-config/src/test/java/com/baeldung/spring/cloud/archaius/zookeeperconfig/SpringContextLiveTest.java new file mode 100644 index 0000000000..a827b8e27d --- /dev/null +++ b/spring-cloud/spring-cloud-archaius/zookeeper-config/src/test/java/com/baeldung/spring/cloud/archaius/zookeeperconfig/SpringContextLiveTest.java @@ -0,0 +1,20 @@ +package com.baeldung.spring.cloud.archaius.zookeeperconfig; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * This Live tTest requires: + * * A Zookeeper instance running locally on port 2181 (e.g. using `docker run --name bael-zookeeper -p 2181:2181 --restart always zookeeper`) + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ZookeeperConfigApplication.class) +public class SpringContextLiveTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-aws/README.md b/spring-cloud/spring-cloud-aws/README.md index 36d0c7080e..3b7b4dbcd7 100644 --- a/spring-cloud/spring-cloud-aws/README.md +++ b/spring-cloud/spring-cloud-aws/README.md @@ -8,7 +8,7 @@ #### Running the Integration Tests -To run the Integration Tests, we need to have an AWS account and have API keys generated for programmatic access. Edit +To run the Live Tests, we need to have an AWS account and have API keys generated for programmatic access. Edit the `application.properties` file to add the following properties: ``` diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextLiveTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextLiveTest.java new file mode 100644 index 0000000000..90ad9c518c --- /dev/null +++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextLiveTest.java @@ -0,0 +1,22 @@ +package com.baeldung.spring.cloud.aws; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * + * To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access. + * + * Check the README file in this module for more information. + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SpringCloudAwsApplication.class) +public class SpringContextLiveTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataIntegrationTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataLiveTest.java similarity index 86% rename from spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataIntegrationTest.java rename to spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataLiveTest.java index 1e75134194..853777ed25 100644 --- a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataIntegrationTest.java +++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataLiveTest.java @@ -16,12 +16,19 @@ import org.springframework.test.context.junit4.SpringRunner; import com.amazonaws.regions.Regions; import com.amazonaws.services.ec2.AmazonEC2; +/** + * + * To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access. + * + * Check the README file in this module for more information. + * + */ @SpringBootTest @RunWith(SpringRunner.class) @TestPropertySource("classpath:application-test.properties") -public class EC2MetadataIntegrationTest { +public class EC2MetadataLiveTest { - private static final Logger logger = LoggerFactory.getLogger(EC2MetadataIntegrationTest.class); + private static final Logger logger = LoggerFactory.getLogger(EC2MetadataLiveTest.class); private boolean serverEc2; diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/rds/SpringCloudRDSIntegrationTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/rds/SpringCloudRDSLiveTest.java similarity index 85% rename from spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/rds/SpringCloudRDSIntegrationTest.java rename to spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/rds/SpringCloudRDSLiveTest.java index 9e163d6dc4..e7004c6b9f 100644 --- a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/rds/SpringCloudRDSIntegrationTest.java +++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/rds/SpringCloudRDSLiveTest.java @@ -14,9 +14,16 @@ import java.sql.Statement; import static org.assertj.core.api.Assertions.assertThat; +/** + * + * To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access. + * + * Check the README file in this module for more information. + * + */ @SpringBootTest @RunWith(SpringRunner.class) -public class SpringCloudRDSIntegrationTest { +public class SpringCloudRDSLiveTest { @Autowired DataSource dataSource; diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3IntegrationTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3LiveTest.java similarity index 94% rename from spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3IntegrationTest.java rename to spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3LiveTest.java index a866287dec..dff3a06fe0 100644 --- a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3IntegrationTest.java +++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3LiveTest.java @@ -23,10 +23,17 @@ import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; +/** + * + * To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access. + * + * Check the README file in this module for more information. + * + */ @SpringBootTest @RunWith(SpringRunner.class) @TestPropertySource("classpath:application-test.properties") -public class SpringCloudS3IntegrationTest { +public class SpringCloudS3LiveTest { @Autowired private SpringCloudS3 springCloudS3; diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sns/SpringCloudSNSIntegrationTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sns/SpringCloudSNSLiveTest.java similarity index 88% rename from spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sns/SpringCloudSNSIntegrationTest.java rename to spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sns/SpringCloudSNSLiveTest.java index e1f23d5c76..b773520089 100644 --- a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sns/SpringCloudSNSIntegrationTest.java +++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sns/SpringCloudSNSLiveTest.java @@ -16,10 +16,17 @@ import com.amazonaws.services.sns.model.CreateTopicResult; import com.baeldung.spring.cloud.aws.SpringCloudAwsTestUtil; import com.baeldung.spring.cloud.aws.sqs.Greeting; +/** + * + * To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access. + * + * Check the README file in this module for more information. + * + */ @SpringBootTest @RunWith(SpringRunner.class) @TestPropertySource("classpath:application-test.properties") -public class SpringCloudSNSIntegrationTest { +public class SpringCloudSNSLiveTest { @Autowired private SNSMessageSender snsMessageSender; diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sqs/SpringCloudSQSIntegrationTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sqs/SpringCloudSQSLiveTest.java similarity index 95% rename from spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sqs/SpringCloudSQSIntegrationTest.java rename to spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sqs/SpringCloudSQSLiveTest.java index 76d2fd7c0d..24917e52f1 100644 --- a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sqs/SpringCloudSQSIntegrationTest.java +++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sqs/SpringCloudSQSLiveTest.java @@ -26,12 +26,19 @@ import java.util.concurrent.CountDownLatch; import static org.assertj.core.api.Assertions.assertThat; +/** + * + * To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access. + * + * Check the README file in this module for more information. + * + */ @SpringBootTest @RunWith(SpringRunner.class) @TestPropertySource("classpath:application-test.properties") -public class SpringCloudSQSIntegrationTest { +public class SpringCloudSQSLiveTest { - private static final Logger logger = LoggerFactory.getLogger(SpringCloudSQSIntegrationTest.class); + private static final Logger logger = LoggerFactory.getLogger(SpringCloudSQSLiveTest.class); @Autowired @Lazy diff --git a/spring-cloud/spring-cloud-bootstrap/README.MD b/spring-cloud/spring-cloud-bootstrap/README.MD index 5185200469..7a3a94c8e3 100644 --- a/spring-cloud/spring-cloud-bootstrap/README.MD +++ b/spring-cloud/spring-cloud-bootstrap/README.MD @@ -6,7 +6,7 @@ - [Spring Cloud – Adding Angular 4](http://www.baeldung.com/spring-cloud-angular) - To run the project: - - copy the appliction-config folder to c:\Users\{username}\ on Windows or /Users/{username}/ on *nix. Then open a git bash terminal in application-config and run: + - copy the appliction-config folder to c:\Users\{username}\ on Windows or /home/{username}/ on *nix. Then open a git bash terminal in application-config and run: - git init - git add . - git commit -m "First commit" diff --git a/spring-cloud/spring-cloud-bootstrap/discovery/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-bootstrap/discovery/src/test/java/org/baeldung/SpringContextLiveTest.java similarity index 70% rename from spring-cloud/spring-cloud-bootstrap/discovery/src/test/java/org/baeldung/SpringContextIntegrationTest.java rename to spring-cloud/spring-cloud-bootstrap/discovery/src/test/java/org/baeldung/SpringContextLiveTest.java index 1e2db33395..e4e2e95e04 100644 --- a/spring-cloud/spring-cloud-bootstrap/discovery/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-cloud/spring-cloud-bootstrap/discovery/src/test/java/org/baeldung/SpringContextLiveTest.java @@ -7,9 +7,15 @@ import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.spring.cloud.bootstrap.discovery.DiscoveryApplication; +/** + * + * This Live Test requires: + * * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`) + * + */ @RunWith(SpringRunner.class) @SpringBootTest(classes = DiscoveryApplication.class) -public class SpringContextIntegrationTest { +public class SpringContextLiveTest { @Test public void whenSpringContextIsBootstrapped_thenNoExceptions() { diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml b/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml index 2efa926e3a..4f9c60a26a 100644 --- a/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml @@ -98,6 +98,6 @@ - Brixton.SR7 + Dalston.RELEASE \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplication.java b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplication.java index 10ed66bfd4..79785a3f20 100644 --- a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplication.java +++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplication.java @@ -71,7 +71,7 @@ public class GatewayApplication { InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false); if (!(baseUrl != null && instance.getHomePageUrl().equals(baseUrl))) { baseUrl = instance.getHomePageUrl(); - delegate = new HttpZipkinSpanReporter(baseUrl, zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter); + delegate = new HttpZipkinSpanReporter(new RestTemplate(), baseUrl, zipkinProperties.getFlushInterval(), spanMetricReporter); if (!span.name.matches(skipPattern)) delegate.report(span); } if (!span.name.matches(skipPattern)) delegate.report(span); diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/org/baeldung/SpringContextLiveTest.java similarity index 70% rename from spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/org/baeldung/SpringContextIntegrationTest.java rename to spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/org/baeldung/SpringContextLiveTest.java index ef3bb5ef95..e0342cf82c 100644 --- a/spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/org/baeldung/SpringContextLiveTest.java @@ -7,9 +7,15 @@ import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.spring.cloud.bootstrap.gateway.GatewayApplication; +/** + * + * This Live Test requires: + * * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`) + * + */ @RunWith(SpringRunner.class) @SpringBootTest(classes = GatewayApplication.class) -public class SpringContextIntegrationTest { +public class SpringContextLiveTest { @Test public void whenSpringContextIsBootstrapped_thenNoExceptions() { diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/test/resources/bootstrap.properties b/spring-cloud/spring-cloud-bootstrap/gateway/src/test/resources/bootstrap.properties new file mode 100644 index 0000000000..c76df21ff1 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/test/resources/bootstrap.properties @@ -0,0 +1,2 @@ +# This property would be provided by the config service in a real-case scenario +spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.) \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml b/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml index eb855a91e3..a88b77dda0 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml @@ -72,7 +72,7 @@ - Brixton.SR7 + Dalston.RELEASE \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/BookServiceApplication.java b/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/BookServiceApplication.java index 3d55a59dbc..91fd23e32d 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/BookServiceApplication.java +++ b/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/BookServiceApplication.java @@ -12,6 +12,8 @@ import org.springframework.cloud.sleuth.zipkin.HttpZipkinSpanReporter; import org.springframework.cloud.sleuth.zipkin.ZipkinProperties; import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter; import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; + import zipkin.Span; @SpringBootApplication @@ -42,7 +44,7 @@ public class BookServiceApplication { InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false); if (!(baseUrl != null && instance.getHomePageUrl().equals(baseUrl))) { baseUrl = instance.getHomePageUrl(); - delegate = new HttpZipkinSpanReporter(baseUrl, zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter); + delegate = new HttpZipkinSpanReporter(new RestTemplate(), baseUrl, zipkinProperties.getFlushInterval(), spanMetricReporter); if (!span.name.matches(skipPattern)) delegate.report(span); } } diff --git a/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/java/org/baeldung/SpringContextLiveTest.java similarity index 70% rename from spring-cloud/spring-cloud-bootstrap/svc-book/src/test/java/org/baeldung/SpringContextIntegrationTest.java rename to spring-cloud/spring-cloud-bootstrap/svc-book/src/test/java/org/baeldung/SpringContextLiveTest.java index 0ffc2410e3..2e437aa3f7 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/java/org/baeldung/SpringContextLiveTest.java @@ -7,9 +7,15 @@ import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.spring.cloud.bootstrap.svcbook.BookServiceApplication; +/** + * + * This Live Test requires: + * * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`) + * + */ @RunWith(SpringRunner.class) @SpringBootTest(classes = BookServiceApplication.class) -public class SpringContextIntegrationTest { +public class SpringContextLiveTest { @Test public void whenSpringContextIsBootstrapped_thenNoExceptions() { diff --git a/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/resources/bootstrap.properties b/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/resources/bootstrap.properties new file mode 100644 index 0000000000..c76df21ff1 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/resources/bootstrap.properties @@ -0,0 +1,2 @@ +# This property would be provided by the config service in a real-case scenario +spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.) \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml b/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml index 7c1e93bad1..f0b19922d8 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml @@ -81,7 +81,7 @@ - Brixton.SR7 + Dalston.RELEASE \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/RatingServiceApplication.java b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/RatingServiceApplication.java index 31ca69c139..8dacbaa79d 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/RatingServiceApplication.java +++ b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/RatingServiceApplication.java @@ -16,6 +16,7 @@ import org.springframework.context.annotation.Primary; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.web.client.RestTemplate; import com.netflix.appinfo.InstanceInfo; import com.netflix.discovery.EurekaClient; @@ -52,7 +53,7 @@ public class RatingServiceApplication { InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false); if (!(baseUrl != null && instance.getHomePageUrl().equals(baseUrl))) { baseUrl = instance.getHomePageUrl(); - delegate = new HttpZipkinSpanReporter(baseUrl, zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter); + delegate = new HttpZipkinSpanReporter(new RestTemplate(), baseUrl, zipkinProperties.getFlushInterval(), spanMetricReporter); if (!span.name.matches(skipPattern)) delegate.report(span); } if (!span.name.matches(skipPattern)) delegate.report(span); diff --git a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/java/org/baeldung/SpringContextLiveTest.java similarity index 70% rename from spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/java/org/baeldung/SpringContextIntegrationTest.java rename to spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/java/org/baeldung/SpringContextLiveTest.java index 3589666f17..e2921f0308 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/java/org/baeldung/SpringContextLiveTest.java @@ -7,9 +7,16 @@ import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.spring.cloud.bootstrap.svcrating.RatingServiceApplication; + +/** + * + * This Live Test requires: + * * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`) + * + */ @RunWith(SpringRunner.class) @SpringBootTest(classes = RatingServiceApplication.class) -public class SpringContextIntegrationTest { +public class SpringContextLiveTest { @Test public void whenSpringContextIsBootstrapped_thenNoExceptions() { diff --git a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/resources/bootstrap.properties b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/resources/bootstrap.properties new file mode 100644 index 0000000000..c76df21ff1 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/resources/bootstrap.properties @@ -0,0 +1,2 @@ +# This property would be provided by the config service in a real-case scenario +spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.) \ No newline at end of file diff --git a/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml b/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml index 8ecda40d0a..afd045189c 100644 --- a/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml +++ b/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml @@ -50,7 +50,6 @@ UTF-8 UTF-8 - 1.8 1.2.2.RELEASE 1.5.9.RELEASE diff --git a/spring-cloud/spring-cloud-contract/spring-cloud-contract-producer/pom.xml b/spring-cloud/spring-cloud-contract/spring-cloud-contract-producer/pom.xml index 47759a818a..07429687c7 100644 --- a/spring-cloud/spring-cloud-contract/spring-cloud-contract-producer/pom.xml +++ b/spring-cloud/spring-cloud-contract/spring-cloud-contract-producer/pom.xml @@ -64,7 +64,6 @@ UTF-8 UTF-8 - 1.8 Edgware.SR1 1.5.9.RELEASE diff --git a/spring-cloud/spring-cloud-functions/pom.xml b/spring-cloud/spring-cloud-functions/pom.xml index 4d03e07e89..7a44e4ae0f 100644 --- a/spring-cloud/spring-cloud-functions/pom.xml +++ b/spring-cloud/spring-cloud-functions/pom.xml @@ -85,7 +85,6 @@ UTF-8 UTF-8 - 1.8 1.0.1.RELEASE 2.0.2 2.0.4.RELEASE diff --git a/spring-cloud/spring-cloud-functions/src/test/java/com/baeldung/spring/cloudfunction/aws/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-functions/src/test/java/com/baeldung/spring/cloudfunction/aws/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..beee84246d --- /dev/null +++ b/spring-cloud/spring-cloud-functions/src/test/java/com/baeldung/spring/cloudfunction/aws/SpringContextIntegrationTest.java @@ -0,0 +1,15 @@ +package com.baeldung.spring.cloudfunction.aws; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = CloudFunctionAwsApplication.class) +public class SpringContextIntegrationTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-kubernetes/client-service/pom.xml b/spring-cloud/spring-cloud-kubernetes/client-service/pom.xml index a4de796ee3..41e09fa13b 100644 --- a/spring-cloud/spring-cloud-kubernetes/client-service/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/client-service/pom.xml @@ -88,7 +88,6 @@ - 1.8 Finchley.SR2 1.0.0.RELEASE diff --git a/spring-cloud/spring-cloud-kubernetes/liveness-example/pom.xml b/spring-cloud/spring-cloud-kubernetes/liveness-example/pom.xml index 012a81bd8d..293b215918 100644 --- a/spring-cloud/spring-cloud-kubernetes/liveness-example/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/liveness-example/pom.xml @@ -44,7 +44,6 @@ UTF-8 UTF-8 - 1.8 1.5.17.RELEASE diff --git a/spring-cloud/spring-cloud-kubernetes/readiness-example/pom.xml b/spring-cloud/spring-cloud-kubernetes/readiness-example/pom.xml index 2b2e57a19c..07589e65b6 100644 --- a/spring-cloud/spring-cloud-kubernetes/readiness-example/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/readiness-example/pom.xml @@ -44,7 +44,6 @@ UTF-8 UTF-8 - 1.8 1.5.17.RELEASE diff --git a/spring-cloud/spring-cloud-kubernetes/travel-agency-service/pom.xml b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/pom.xml index 19eea2612c..0d7639b179 100755 --- a/spring-cloud/spring-cloud-kubernetes/travel-agency-service/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/pom.xml @@ -68,7 +68,6 @@ - 1.8 Finchley.SR2 diff --git a/spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/test/java/com/baeldung/spring/cloud/kubernetes/travelagency/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/test/java/com/baeldung/spring/cloud/kubernetes/travelagency/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..2f901d39f6 --- /dev/null +++ b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/test/java/com/baeldung/spring/cloud/kubernetes/travelagency/SpringContextIntegrationTest.java @@ -0,0 +1,16 @@ +package com.baeldung.spring.cloud.kubernetes.travelagency; + + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +public class SpringContextIntegrationTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/SpringContextIntegrationTest.java similarity index 77% rename from spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextIntegrationTest.java rename to spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/SpringContextIntegrationTest.java index e0026ce441..77d294093c 100644 --- a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextIntegrationTest.java +++ b/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/SpringContextIntegrationTest.java @@ -1,4 +1,5 @@ -package com.baeldung.spring.cloud.aws; +package com.baeldung.cloud.openfeign; + import org.junit.Test; import org.junit.runner.RunWith; @@ -6,10 +7,10 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) -@SpringBootTest(classes = SpringCloudAwsApplication.class) +@SpringBootTest(classes = ExampleApplication.class) public class SpringContextIntegrationTest { - + @Test public void whenSpringContextIsBootstrapped_thenNoExceptions() { } -} +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml b/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml index 1187c12fe7..71275793ec 100644 --- a/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml +++ b/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml @@ -3,11 +3,11 @@ logging: org: springframework: cloud: - task=DEBUG + task: DEBUG spring: application: - name=helloWorld + name: helloWorld datasource: url: jdbc:mysql://localhost:3306/springcloud?useSSL=false username: root diff --git a/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/java/org/baeldung/SpringContextIntegrationTest.java deleted file mode 100644 index 4b5aff2db8..0000000000 --- a/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.baeldung.task.JobConfiguration; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = JobConfiguration.class) -public class SpringContextIntegrationTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/java/org/baeldung/SpringContextLiveTest.java b/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/java/org/baeldung/SpringContextLiveTest.java new file mode 100644 index 0000000000..ddbcbf65ea --- /dev/null +++ b/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/java/org/baeldung/SpringContextLiveTest.java @@ -0,0 +1,29 @@ +package org.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.task.JobConfiguration; +import com.baeldung.task.TaskDemo; + +/** + * This Live Test requires: + * * a MySql instance running, that allows a root user with no password, and with a database named + * + * (e.g. with the following command `docker run -p 3306:3306 --name bael-mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=true -e MYSQL_DATABASE=springcloud mysql:latest`) + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootApplication +@ContextConfiguration(classes = { JobConfiguration.class, TaskDemo.class }, initializers = { + ConfigFileApplicationContextInitializer.class }) +public class SpringContextLiveTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-cloud/spring-cloud-vault/pom.xml b/spring-cloud/spring-cloud-vault/pom.xml index 3466f657be..9a1be3f5c0 100644 --- a/spring-cloud/spring-cloud-vault/pom.xml +++ b/spring-cloud/spring-cloud-vault/pom.xml @@ -68,7 +68,6 @@ UTF-8 UTF-8 - 1.8 Greenwich.RELEASE diff --git a/spring-cloud/spring-cloud-vault/src/test/java/org/baeldung/spring/cloud/vaultsample/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-vault/src/test/java/org/baeldung/spring/cloud/vaultsample/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..e1eb2f8e24 --- /dev/null +++ b/spring-cloud/spring-cloud-vault/src/test/java/org/baeldung/spring/cloud/vaultsample/SpringContextIntegrationTest.java @@ -0,0 +1,15 @@ +package org.baeldung.spring.cloud.vaultsample; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = VaultSampleApplication.class) +public class SpringContextIntegrationTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-zookeeper/HelloWorld/pom.xml b/spring-cloud/spring-cloud-zookeeper/HelloWorld/pom.xml index 262b059544..0da0f7503e 100644 --- a/spring-cloud/spring-cloud-zookeeper/HelloWorld/pom.xml +++ b/spring-cloud/spring-cloud-zookeeper/HelloWorld/pom.xml @@ -34,6 +34,12 @@ + + org.springframework.boot + spring-boot-starter-test + ${spring-boot.version} + test +
diff --git a/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/test/java/com/baeldung/spring/cloud/helloworld/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/test/java/com/baeldung/spring/cloud/helloworld/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..2770649aa3 --- /dev/null +++ b/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/test/java/com/baeldung/spring/cloud/helloworld/SpringContextIntegrationTest.java @@ -0,0 +1,16 @@ +package com.baeldung.spring.cloud.helloworld; + + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = HelloWorldApplication.class) +public class SpringContextIntegrationTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-zuul/pom.xml b/spring-cloud/spring-cloud-zuul/pom.xml index 08990357d6..5d44ae9590 100644 --- a/spring-cloud/spring-cloud-zuul/pom.xml +++ b/spring-cloud/spring-cloud-zuul/pom.xml @@ -70,7 +70,6 @@ UTF-8 UTF-8 - 1.8 Finchley.SR1 2.0.6.RELEASE diff --git a/spring-cloud/spring-cloud-zuul/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-zuul/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..dbcdbdd434 --- /dev/null +++ b/spring-cloud/spring-cloud-zuul/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/SpringContextIntegrationTest.java @@ -0,0 +1,17 @@ +package com.baeldung.spring.cloud.zuulratelimitdemo.controller; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.spring.cloud.zuulratelimitdemo.ZuulRatelimitDemoApplication; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ZuulRatelimitDemoApplication.class) +public class SpringContextIntegrationTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file diff --git a/spring-core/pom.xml b/spring-core/pom.xml index d348d742e7..814addecdd 100644 --- a/spring-core/pom.xml +++ b/spring-core/pom.xml @@ -10,9 +10,9 @@ com.baeldung - parent-spring-4 + parent-spring-5 0.0.1-SNAPSHOT - ../parent-spring-4 + ../parent-spring-5 diff --git a/spring-data-rest/README.md b/spring-data-rest/README.md index 1624a3abfd..abbacb69cc 100644 --- a/spring-data-rest/README.md +++ b/spring-data-rest/README.md @@ -22,3 +22,4 @@ To view the running application, visit [http://localhost:8080](http://localhost: - [Spring Data REST Events with @RepositoryEventHandler](http://www.baeldung.com/spring-data-rest-events) - [Customizing HTTP Endpoints in Spring Data REST](https://www.baeldung.com/spring-data-rest-customize-http-endpoints) - [Spring Boot with SQLite](https://www.baeldung.com/spring-boot-sqlite) +- [Spring Data Web Support](https://www.baeldung.com/spring-data-web-support) diff --git a/spring-data-rest/pom.xml b/spring-data-rest/pom.xml index 525c88c9d8..8400993a38 100644 --- a/spring-data-rest/pom.xml +++ b/spring-data-rest/pom.xml @@ -41,6 +41,11 @@ spring-boot-starter-test test + + com.h2database + h2 + runtime + com.querydsl querydsl-apt @@ -87,4 +92,4 @@ com.baeldung.SpringDataRestApplication - + \ No newline at end of file diff --git a/spring-exceptions/pom.xml b/spring-exceptions/pom.xml index 16f6286606..ff28ac89bb 100644 --- a/spring-exceptions/pom.xml +++ b/spring-exceptions/pom.xml @@ -179,7 +179,6 @@ 4.3.4.RELEASE 4.2.0.RELEASE 3.21.0-GA - 1.2 5.2.5.Final @@ -189,7 +188,6 @@ 5.3.3.Final - 3.1.0 2.2 diff --git a/spring-freemarker/pom.xml b/spring-freemarker/pom.xml index 40558476ef..be34f84495 100644 --- a/spring-freemarker/pom.xml +++ b/spring-freemarker/pom.xml @@ -35,7 +35,7 @@ javax.servlet javax.servlet-api - ${servletapi.version} + ${javax.servlet-api.version} provided @@ -57,7 +57,6 @@ 5.0.8.RELEASE 2.3.28 - 3.1.0 false 1.5.10.RELEASE diff --git a/spring-kafka/pom.xml b/spring-kafka/pom.xml index b76d4f10c0..2fb4c776fe 100644 --- a/spring-kafka/pom.xml +++ b/spring-kafka/pom.xml @@ -34,7 +34,6 @@ 2.2.2.RELEASE - 2.9.7 \ No newline at end of file diff --git a/spring-mvc-forms-jsp/pom.xml b/spring-mvc-forms-jsp/pom.xml index e0539c3216..20912e71e5 100644 --- a/spring-mvc-forms-jsp/pom.xml +++ b/spring-mvc-forms-jsp/pom.xml @@ -100,9 +100,6 @@ 2.6 - 1.2 - 2.3.1 - 3.1.0 6.0.10.Final 1.3.3 5.2.5.Final diff --git a/spring-mvc-simple/pom.xml b/spring-mvc-simple/pom.xml index cdd4a9e13a..a767cf3c37 100644 --- a/spring-mvc-simple/pom.xml +++ b/spring-mvc-simple/pom.xml @@ -163,9 +163,7 @@ 1.8 1.8 3.2.0 - 3.7.0 2.21.0 - 1.2 2.3.2-b02 4.0.0 6.0.10.Final @@ -177,7 +175,6 @@ 1.2.5 1.0.2 1.9.0 - 2.9.7 1.4.9 5.1.0 20180130 diff --git a/spring-mvc-velocity/pom.xml b/spring-mvc-velocity/pom.xml index 60ac8b9c2f..df19b67e8e 100644 --- a/spring-mvc-velocity/pom.xml +++ b/spring-mvc-velocity/pom.xml @@ -110,8 +110,6 @@ 4.4.5 4.5.2 - - 3.1.0 1.7 2.0 2.9.0 diff --git a/spring-mvc-webflow/pom.xml b/spring-mvc-webflow/pom.xml index e1a279a787..c8de990da0 100644 --- a/spring-mvc-webflow/pom.xml +++ b/spring-mvc-webflow/pom.xml @@ -90,9 +90,6 @@ 2.5.0.RELEASE - 3.1.0 - 1.2 - 4.4.5 4.5.2 diff --git a/spring-rest/README.md b/spring-rest/README.md index 9a2c1fd96c..6d3aac3eb8 100644 --- a/spring-rest/README.md +++ b/spring-rest/README.md @@ -20,5 +20,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Using the Spring RestTemplate Interceptor](http://www.baeldung.com/spring-rest-template-interceptor) - [Get and Post Lists of Objects with RestTemplate](http://www.baeldung.com/spring-rest-template-list) - [How to Set a Header on a Response with Spring 5](http://www.baeldung.com/spring-response-header) -- [Spring’s RequestBody and ResponseBody Annotations](https://www.baeldung.com/spring-request-response-body) - [Uploading MultipartFile with Spring RestTemplate](http://www.baeldung.com/spring-rest-template-multipart-upload) diff --git a/spring-resttemplate/README.md b/spring-resttemplate/README.md index 353e9f955e..c2c4965231 100644 --- a/spring-resttemplate/README.md +++ b/spring-resttemplate/README.md @@ -9,3 +9,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring RestTemplate Error Handling](http://www.baeldung.com/spring-rest-template-error-handling) - [Configure a RestTemplate with RestTemplateBuilder](http://www.baeldung.com/spring-rest-template-builder) - [Mocking a RestTemplate in Spring](https://www.baeldung.com/spring-mock-rest-template) +- [RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json) diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/controller/PersonAPI.java b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/controller/PersonAPI.java new file mode 100644 index 0000000000..b1b56ec2f3 --- /dev/null +++ b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/controller/PersonAPI.java @@ -0,0 +1,38 @@ +package org.baeldung.resttemplate.web.controller; + +import javax.servlet.http.HttpServletResponse; + +import org.baeldung.resttemplate.web.dto.Person; +import org.baeldung.resttemplate.web.service.PersonService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +@RestController +public class PersonAPI { + + @Autowired + private PersonService personService; + + @GetMapping("/") + public String home() { + return "Spring boot is working!"; + } + + @PostMapping(value = "/createPerson", consumes = "application/json", produces = "application/json") + public Person createPerson(@RequestBody Person person) { + return personService.saveUpdatePerson(person); + } + + @PostMapping(value = "/updatePerson", consumes = "application/json", produces = "application/json") + public Person updatePerson(@RequestBody Person person, HttpServletResponse response) { + response.setHeader("Location", ServletUriComponentsBuilder.fromCurrentContextPath() + .path("/findPerson/" + person.getId()) + .toUriString()); + return personService.saveUpdatePerson(person); + } + +} \ No newline at end of file diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/dto/Person.java b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/dto/Person.java new file mode 100644 index 0000000000..4b7679638f --- /dev/null +++ b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/dto/Person.java @@ -0,0 +1,32 @@ +package org.baeldung.resttemplate.web.dto; + +public class Person { + private Integer id; + private String name; + + public Person() { + + } + + public Person(Integer id, String name) { + this.id = id; + this.name = name; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonService.java b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonService.java new file mode 100644 index 0000000000..c5ad39e101 --- /dev/null +++ b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonService.java @@ -0,0 +1,10 @@ +package org.baeldung.resttemplate.web.service; + +import org.baeldung.resttemplate.web.dto.Person; + +public interface PersonService { + + public Person saveUpdatePerson(Person person); + + public Person findPersonById(Integer id); +} \ No newline at end of file diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonServiceImpl.java b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonServiceImpl.java new file mode 100644 index 0000000000..658e0fade0 --- /dev/null +++ b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonServiceImpl.java @@ -0,0 +1,19 @@ +package org.baeldung.resttemplate.web.service; + +import org.baeldung.resttemplate.web.dto.Person; +import org.springframework.stereotype.Component; + +@Component +public class PersonServiceImpl implements PersonService { + + @Override + public Person saveUpdatePerson(Person person) { + return person; + } + + @Override + public Person findPersonById(Integer id) { + return new Person(id, "John"); + } + +} diff --git a/spring-resttemplate/src/test/java/org/baeldung/resttemplate/PersonAPILiveTest.java b/spring-resttemplate/src/test/java/org/baeldung/resttemplate/PersonAPILiveTest.java new file mode 100644 index 0000000000..de18f6db09 --- /dev/null +++ b/spring-resttemplate/src/test/java/org/baeldung/resttemplate/PersonAPILiveTest.java @@ -0,0 +1,96 @@ +package org.baeldung.resttemplate; + +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; +import java.net.URI; + +import org.baeldung.resttemplate.web.dto.Person; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = RestTemplateConfigurationApplication.class) +public class PersonAPILiveTest { + + private static String createPersonUrl; + private static String updatePersonUrl; + + private static RestTemplate restTemplate; + + private static HttpHeaders headers; + + private final ObjectMapper objectMapper = new ObjectMapper(); + + private static JSONObject personJsonObject; + + @BeforeClass + public static void runBeforeAllTestMethods() throws JSONException { + createPersonUrl = "http://localhost:8082/spring-rest/createPerson"; + updatePersonUrl = "http://localhost:8082/spring-rest/updatePerson"; + + restTemplate = new RestTemplate(); + + headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + personJsonObject = new JSONObject(); + personJsonObject.put("id", 1); + personJsonObject.put("name", "John"); + } + + @Test + public void givenDataIsJson_whenDataIsPostedByPostForObject_thenResponseBodyIsNotNull() throws IOException { + HttpEntity request = new HttpEntity(personJsonObject.toString(), headers); + String personResultAsJsonStr = restTemplate.postForObject(createPersonUrl, request, String.class); + JsonNode root = objectMapper.readTree(personResultAsJsonStr); + + Person person = restTemplate.postForObject(createPersonUrl, request, Person.class); + + assertNotNull(personResultAsJsonStr); + assertNotNull(root); + assertNotNull(root.path("name") + .asText()); + + assertNotNull(person); + assertNotNull(person.getName()); + } + + @Test + public void givenDataIsJson_whenDataIsPostedByPostForEntity_thenResponseBodyIsNotNull() throws IOException { + HttpEntity request = new HttpEntity(personJsonObject.toString(), headers); + ResponseEntity responseEntityStr = restTemplate.postForEntity(createPersonUrl, request, String.class); + JsonNode root = objectMapper.readTree(responseEntityStr.getBody()); + + ResponseEntity responseEntityPerson = restTemplate.postForEntity(createPersonUrl, request, Person.class); + + assertNotNull(responseEntityStr.getBody()); + assertNotNull(root.path("name") + .asText()); + + assertNotNull(responseEntityPerson.getBody()); + assertNotNull(responseEntityPerson.getBody() + .getName()); + } + + @Test + public void givenDataIsJson_whenDataIsPostedByPostForLocation_thenResponseBodyIsTheLocationHeader() throws JsonProcessingException { + HttpEntity request = new HttpEntity(personJsonObject.toString(), headers); + URI locationHeader = restTemplate.postForLocation(updatePersonUrl, request); + + assertNotNull(locationHeader); + } +} \ No newline at end of file diff --git a/spring-security-cache-control/pom.xml b/spring-security-cache-control/pom.xml index c630774849..e68f92d2ee 100644 --- a/spring-security-cache-control/pom.xml +++ b/spring-security-cache-control/pom.xml @@ -65,8 +65,4 @@ - - 3.1.0 - - \ No newline at end of file diff --git a/spring-security-kerberos/README.md b/spring-security-kerberos/README.md new file mode 100644 index 0000000000..0338c2058c --- /dev/null +++ b/spring-security-kerberos/README.md @@ -0,0 +1,10 @@ +## @PreFilter and @PostFilter annotations + +### Build the Project ### + +``` +mvn clean install +``` + +### Relevant Articles: +- [Spring Security – Kerberos](http://www.baeldung.com/xxxxxx) diff --git a/spring-security-kerberos/pom.xml b/spring-security-kerberos/pom.xml new file mode 100644 index 0000000000..35c4ba4926 --- /dev/null +++ b/spring-security-kerberos/pom.xml @@ -0,0 +1,61 @@ + + 4.0.0 + com.baeldung + spring-security-kerberos + 0.1-SNAPSHOT + spring-security-kerberos + war + + parent-boot-1 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-1 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-security + + + + org.springframework.security.kerberos + spring-security-kerberos-core + 1.0.1.RELEASE + + + org.springframework.security.kerberos + spring-security-kerberos-web + 1.0.1.RELEASE + + + org.springframework.security.kerberos + spring-security-kerberos-client + 1.0.1.RELEASE + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + + + org.apache.maven.plugins + maven-war-plugin + + + + diff --git a/spring-security-kerberos/src/main/java/org/baeldung/Application.java b/spring-security-kerberos/src/main/java/org/baeldung/Application.java new file mode 100644 index 0000000000..39c2b51356 --- /dev/null +++ b/spring-security-kerberos/src/main/java/org/baeldung/Application.java @@ -0,0 +1,13 @@ +package org.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/spring-security-kerberos/src/main/java/org/baeldung/config/WebSecurityConfig.java b/spring-security-kerberos/src/main/java/org/baeldung/config/WebSecurityConfig.java new file mode 100644 index 0000000000..49a1cf0a8e --- /dev/null +++ b/spring-security-kerberos/src/main/java/org/baeldung/config/WebSecurityConfig.java @@ -0,0 +1,87 @@ +package org.baeldung.config; + +import org.baeldung.security.DummyUserDetailsService; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.FileSystemResource; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider; +import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider; +import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient; +import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator; +import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter; +import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint; +import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; + +@Configuration +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests() + .anyRequest() + .authenticated() + .and() + .addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()), BasicAuthenticationFilter.class); + } + + @Override + @Bean + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.authenticationProvider(kerberosAuthenticationProvider()) + .authenticationProvider(kerberosServiceAuthenticationProvider()); + } + + @Bean + public KerberosAuthenticationProvider kerberosAuthenticationProvider() { + KerberosAuthenticationProvider provider = new KerberosAuthenticationProvider(); + SunJaasKerberosClient client = new SunJaasKerberosClient(); + client.setDebug(true); + provider.setKerberosClient(client); + provider.setUserDetailsService(dummyUserDetailsService()); + return provider; + } + + @Bean + public SpnegoEntryPoint spnegoEntryPoint() { + return new SpnegoEntryPoint("/login"); + } + + @Bean + public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(AuthenticationManager authenticationManager) { + SpnegoAuthenticationProcessingFilter filter = new SpnegoAuthenticationProcessingFilter(); + filter.setAuthenticationManager(authenticationManager); + return filter; + } + + @Bean + public KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() { + KerberosServiceAuthenticationProvider provider = new KerberosServiceAuthenticationProvider(); + provider.setTicketValidator(sunJaasKerberosTicketValidator()); + provider.setUserDetailsService(dummyUserDetailsService()); + return provider; + } + + @Bean + public SunJaasKerberosTicketValidator sunJaasKerberosTicketValidator() { + SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator(); + ticketValidator.setServicePrincipal("HTTP/demo.kerberos.bealdung.com@baeldung.com"); + ticketValidator.setKeyTabLocation(new FileSystemResource("baeldung.keytab")); + ticketValidator.setDebug(true); + return ticketValidator; + } + + @Bean + public DummyUserDetailsService dummyUserDetailsService() { + return new DummyUserDetailsService(); + } + +} \ No newline at end of file diff --git a/spring-security-kerberos/src/main/java/org/baeldung/security/DummyUserDetailsService.java b/spring-security-kerberos/src/main/java/org/baeldung/security/DummyUserDetailsService.java new file mode 100644 index 0000000000..10d71fca8f --- /dev/null +++ b/spring-security-kerberos/src/main/java/org/baeldung/security/DummyUserDetailsService.java @@ -0,0 +1,16 @@ +package org.baeldung.security; + +import org.springframework.security.core.authority.AuthorityUtils; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; + +public class DummyUserDetailsService implements UserDetailsService { + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + return new User(username, "notUsed", true, true, true, true, AuthorityUtils.createAuthorityList("ROLE_USER")); + } + +} \ No newline at end of file diff --git a/spring-security-mvc-boot/pom.xml b/spring-security-mvc-boot/pom.xml index 00d8f032c2..4c25dc01e8 100644 --- a/spring-security-mvc-boot/pom.xml +++ b/spring-security-mvc-boot/pom.xml @@ -234,10 +234,8 @@ 1.1.2 - 1.2 1.6.1 2.6.11 - 1.8 diff --git a/spring-security-mvc-custom/pom.xml b/spring-security-mvc-custom/pom.xml index 7c60a8e18a..4e932f3245 100644 --- a/spring-security-mvc-custom/pom.xml +++ b/spring-security-mvc-custom/pom.xml @@ -94,7 +94,7 @@ javax.servlet javax.servlet-api - ${javax.servlet.version} + ${javax.servlet-api.version} provided @@ -192,14 +192,9 @@ - - 3.1.0 - 1.2 - 19.0 3.5 - 2.9.7 2.6 diff --git a/spring-security-mvc-digest-auth/pom.xml b/spring-security-mvc-digest-auth/pom.xml index 33b3b5ff31..cf1de1730d 100644 --- a/spring-security-mvc-digest-auth/pom.xml +++ b/spring-security-mvc-digest-auth/pom.xml @@ -94,7 +94,7 @@ javax.servlet javax.servlet-api - ${javax.servlet.version} + ${javax.servlet-api.version} provided @@ -194,10 +194,6 @@ 4.2.6.RELEASE - - 1.2 - 3.1.0 - 19.0 3.5 diff --git a/spring-security-mvc-digest-auth/src/test/java/org/baeldung/client/RawClientLiveTest.java b/spring-security-mvc-digest-auth/src/test/java/org/baeldung/client/RawClientLiveTest.java index 90c2a29968..e8dcf82ebc 100644 --- a/spring-security-mvc-digest-auth/src/test/java/org/baeldung/client/RawClientLiveTest.java +++ b/spring-security-mvc-digest-auth/src/test/java/org/baeldung/client/RawClientLiveTest.java @@ -1,7 +1,8 @@ package org.baeldung.client; +import java.io.IOException; + import org.apache.http.HttpResponse; -import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; @@ -12,10 +13,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import java.io.IOException; -import java.util.Timer; -import java.util.TimerTask; - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {ClientConfig.class}, loader = AnnotationConfigContextLoader.class) public class RawClientLiveTest { @@ -25,22 +22,7 @@ public class RawClientLiveTest { @Test public void whenSecuredRestApiIsConsumed_then200OK() throws IOException { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - - int timeout = 20; // seconds - RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(timeout) - .setConnectTimeout(timeout).setSocketTimeout(timeout).build(); HttpGet getMethod = new HttpGet("http://localhost:8082/spring-security-rest-basic-auth/api/bars/1"); - getMethod.setConfig(requestConfig); - - int hardTimeout = 5; // seconds - TimerTask task = new TimerTask() { - @Override - public void run() { - getMethod.abort(); - } - }; - new Timer(true).schedule(task, hardTimeout * 1000); - HttpResponse response = httpClient.execute(getMethod); System.out.println("HTTP Status of response: " + response.getStatusLine().getStatusCode()); } diff --git a/spring-security-mvc-login/pom.xml b/spring-security-mvc-login/pom.xml index 048297bbd4..02ed0e36f2 100644 --- a/spring-security-mvc-login/pom.xml +++ b/spring-security-mvc-login/pom.xml @@ -94,7 +94,7 @@ javax.servlet javax.servlet-api - ${javax.servlet.version} + ${javax.servlet-api.version} provided @@ -174,16 +174,9 @@ - - - - 3.1.0 - 1.2 - 2.6 1.6.1 - \ No newline at end of file diff --git a/spring-security-mvc-persisted-remember-me/pom.xml b/spring-security-mvc-persisted-remember-me/pom.xml index d10565255d..5e987dcb77 100644 --- a/spring-security-mvc-persisted-remember-me/pom.xml +++ b/spring-security-mvc-persisted-remember-me/pom.xml @@ -198,7 +198,6 @@ 4.2.6.RELEASE - 1.4.193 9.4.1212 diff --git a/spring-security-mvc-session/pom.xml b/spring-security-mvc-session/pom.xml index 03c75b99e2..c0e1527a24 100644 --- a/spring-security-mvc-session/pom.xml +++ b/spring-security-mvc-session/pom.xml @@ -94,7 +94,7 @@ javax.servlet javax.servlet-api - ${javax.servlet.version} + ${javax.servlet-api.version} provided @@ -171,8 +171,6 @@ 3.0.2 - 1.2 - 3.1.0 2.6 diff --git a/spring-security-mvc-socket/pom.xml b/spring-security-mvc-socket/pom.xml index b83f10d9fe..f1d28355fd 100644 --- a/spring-security-mvc-socket/pom.xml +++ b/spring-security-mvc-socket/pom.xml @@ -188,7 +188,6 @@ 1.11.3.RELEASE 1.4.196 1.2.3 - 2.9.7 \ No newline at end of file diff --git a/spring-security-react/pom.xml b/spring-security-react/pom.xml index eaf10791bc..c7b7c85be8 100644 --- a/spring-security-react/pom.xml +++ b/spring-security-react/pom.xml @@ -72,7 +72,7 @@ javax.servlet javax.servlet-api - ${javax.servlet.version} + ${javax.servlet-api.version} provided @@ -167,10 +167,6 @@ 4.3.6.RELEASE 4.2.1.RELEASE - - 3.1.0 - 1.2 - 19.0 3.5 diff --git a/spring-security-rest-basic-auth/README.md b/spring-security-rest-basic-auth/README.md index 30da3afbcf..b905824161 100644 --- a/spring-security-rest-basic-auth/README.md +++ b/spring-security-rest-basic-auth/README.md @@ -7,7 +7,5 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com ### Relevant Articles: - [Basic Authentication with the RestTemplate](http://www.baeldung.com/how-to-use-resttemplate-with-basic-authentication-in-spring) -- [HttpClient Timeout](http://www.baeldung.com/httpclient-timeout) -- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) - [A Custom Filter in the Spring Security Filter Chain](http://www.baeldung.com/spring-security-custom-filter) - [Spring Security Basic Authentication](http://www.baeldung.com/spring-security-basic-authentication) diff --git a/spring-security-rest-basic-auth/pom.xml b/spring-security-rest-basic-auth/pom.xml index ca5c4c38e6..8a90247386 100644 --- a/spring-security-rest-basic-auth/pom.xml +++ b/spring-security-rest-basic-auth/pom.xml @@ -142,7 +142,7 @@ javax.servlet javax.servlet-api - ${javax.servlet.version} + ${javax.servlet-api.version} provided @@ -272,12 +272,8 @@ - 4.4.5 - 4.5.3 - - - 1.2 - 3.1.0 + 4.4.11 + 4.5.8 19.0 diff --git a/spring-security-rest/README.md b/spring-security-rest/README.md index f71eead9ae..f450a514b2 100644 --- a/spring-security-rest/README.md +++ b/spring-security-rest/README.md @@ -11,7 +11,6 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com - [Spring REST Service Security](http://www.baeldung.com/2011/10/31/securing-a-restful-web-service-with-spring-security-3-1-part-3/) - [Setting Up Swagger 2 with a Spring REST API](http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api) - [Custom Error Message Handling for REST API](http://www.baeldung.com/global-error-handler-in-a-spring-rest-api) -- [An Intro to Spring HATEOAS](http://www.baeldung.com/spring-hateoas-tutorial) - [Spring Security Context Propagation with @Async](http://www.baeldung.com/spring-security-async-principal-propagation) - [Servlet 3 Async Support with Spring MVC and Spring Security](http://www.baeldung.com/spring-mvc-async-security) - [Intro to Spring Security Expressions](http://www.baeldung.com/spring-security-expressions) diff --git a/spring-security-rest/pom.xml b/spring-security-rest/pom.xml index 24f1c5807a..af38c1ffef 100644 --- a/spring-security-rest/pom.xml +++ b/spring-security-rest/pom.xml @@ -84,13 +84,6 @@ ${spring.version} - - - org.springframework.hateoas - spring-hateoas - ${org.springframework.hateoas.version} - - @@ -273,14 +266,8 @@ - - 0.25.0.RELEASE - - 3.1.0 1.1.0.Final - 1.2 - 2.9.7 26.0-jre diff --git a/spring-session/spring-session-jdbc/pom.xml b/spring-session/spring-session-jdbc/pom.xml index b46b549ce2..432715bc0e 100644 --- a/spring-session/spring-session-jdbc/pom.xml +++ b/spring-session/spring-session-jdbc/pom.xml @@ -48,8 +48,4 @@ - - 1.4.197 - - \ No newline at end of file diff --git a/spring-static-resources/pom.xml b/spring-static-resources/pom.xml index fc2b3336bc..f01e807919 100644 --- a/spring-static-resources/pom.xml +++ b/spring-static-resources/pom.xml @@ -199,14 +199,10 @@ 1.8.9 2.3.2-b02 - - 2.9.6 - 6.0.10.Final 4.1.0 2.10 - 1.2 4.0.1 1 diff --git a/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml b/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml index 320745b6e5..cfbc90155c 100644 --- a/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml +++ b/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml @@ -158,27 +158,27 @@ com.fasterxml.jackson.core jackson-core - ${jackson-version} + ${jackson.version} com.fasterxml.jackson.core jackson-annotations - ${jackson-version} + ${jackson.version} com.fasterxml.jackson.core jackson-databind - ${jackson-version} + ${jackson.version} com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider - ${jackson-version} + ${jackson.version} com.fasterxml.jackson.datatype jackson-datatype-joda - ${jackson-version} + ${jackson.version} joda-time @@ -190,7 +190,6 @@ 1.5.15 4.3.9.RELEASE - 2.9.7 2.9.9 2.2 1.5 diff --git a/spring-userservice/pom.xml b/spring-userservice/pom.xml index e562171103..e6e8553c80 100644 --- a/spring-userservice/pom.xml +++ b/spring-userservice/pom.xml @@ -176,7 +176,7 @@ javax.servlet.jsp.jstl jstl-api - ${jstl-api.version} + ${jstl.version} org.springframework.boot @@ -191,7 +191,7 @@ javax.servlet javax.servlet-api - ${javax.servlet.version} + ${javax.servlet-api.version}
@@ -225,15 +225,12 @@ 5.2.10.Final 5.1.40 1.10.5.RELEASE - 1.4.193 10.13.1.1 5.3.3.Final 2.2.5 1.1.2 - 1.2 - 3.1.0 19.0 diff --git a/stripe/pom.xml b/stripe/pom.xml index b0cb194bfe..86c6389f7f 100644 --- a/stripe/pom.xml +++ b/stripe/pom.xml @@ -40,7 +40,6 @@
- 1.16.16 4.2.0 diff --git a/struts-2/pom.xml b/struts-2/pom.xml index 7f0fba727d..7de688ff2c 100644 --- a/struts-2/pom.xml +++ b/struts-2/pom.xml @@ -33,7 +33,7 @@ javax.servlet javax.servlet-api - ${servlet.version} + ${javax.servlet-api.version} org.springframework @@ -69,7 +69,6 @@ 2.5.5 2.5.8 - 3.0.1 4.3.6.RELEASE 3.0.0 diff --git a/tensorflow-java/pom.xml b/tensorflow-java/pom.xml index f52cd4a68f..f9abde737c 100644 --- a/tensorflow-java/pom.xml +++ b/tensorflow-java/pom.xml @@ -45,7 +45,6 @@ - 1.8 1.12.0 5.4.0 diff --git a/testing-modules/groovy-spock/.gitignore b/testing-modules/groovy-spock/.gitignore new file mode 100644 index 0000000000..37118ef42c --- /dev/null +++ b/testing-modules/groovy-spock/.gitignore @@ -0,0 +1 @@ +/report-*.json \ No newline at end of file diff --git a/testing-modules/groovy-spock/README.md b/testing-modules/groovy-spock/README.md index a98df27172..e61c56d470 100644 --- a/testing-modules/groovy-spock/README.md +++ b/testing-modules/groovy-spock/README.md @@ -2,3 +2,4 @@ - [Introduction to Testing with Spock and Groovy](http://www.baeldung.com/groovy-spock) - [Difference Between Stub, Mock, and Spy in the Spock Framework](https://www.baeldung.com/spock-stub-mock-spy) +- [Guide to Spock Extensions](https://www.baeldung.com/spock-extensions) diff --git a/testing-modules/junit-5-configuration/README.md b/testing-modules/junit-5-configuration/README.md new file mode 100644 index 0000000000..c274391766 --- /dev/null +++ b/testing-modules/junit-5-configuration/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- diff --git a/testing-modules/junit-5-configuration/pom.xml b/testing-modules/junit-5-configuration/pom.xml new file mode 100644 index 0000000000..0f19bc19b7 --- /dev/null +++ b/testing-modules/junit-5-configuration/pom.xml @@ -0,0 +1,159 @@ + + + 4.0.0 + junit-5-configuration + 1.0-SNAPSHOT + junit-5-configuration + Intro to JUnit 5 configuration + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../../ + + + + + org.junit.platform + junit-platform-engine + ${junit.platform.version} + + + org.junit.jupiter + junit-jupiter-params + ${junit.jupiter.version} + + + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit.vintage.version} + test + + + org.junit.jupiter + junit-jupiter-migrationsupport + ${junit.vintage.version} + test + + + com.h2database + h2 + ${h2.version} + + + org.springframework + spring-test + ${spring.version} + test + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-orm + ${spring.version} + + + + + + + src/test/resources + true + + + src/main/resources + true + + + + + + + + filtering + + false + + + + + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + **/*IntegrationTest.java + + + + + + + + category + + false + + + + + maven-surefire-plugin + ${maven-surefire-plugin.version} + + com.baeldung.categories.UnitTest + com.baeldung.categories.IntegrationTest + + + + + + + tags + + false + + + + + maven-surefire-plugin + ${maven-surefire-plugin.version} + + UnitTest + IntegrationTest + + + + + + + + + + 5.4.2 + 1.2.0 + 5.2.0 + 1.4.196 + 5.0.6.RELEASE + 2.21.0 + + + diff --git a/testing-modules/junit-5-configuration/src/main/java/com/baeldung/junit/tags/example/Employee.java b/testing-modules/junit-5-configuration/src/main/java/com/baeldung/junit/tags/example/Employee.java new file mode 100644 index 0000000000..66f41ee885 --- /dev/null +++ b/testing-modules/junit-5-configuration/src/main/java/com/baeldung/junit/tags/example/Employee.java @@ -0,0 +1,44 @@ +package com.baeldung.junit.tags.example; + +public class Employee { + private int id; + + private String firstName; + + private String lastName; + + private String address; + + public int getId() { + return id; + } + + public void setId(final int id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(final String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(final String lastName) { + this.lastName = lastName; + } + + public String getAddress() { + return address; + } + + public void setAddress(final String address) { + this.address = address; + } + +} diff --git a/testing-modules/junit-5-configuration/src/main/java/com/baeldung/junit/tags/example/EmployeeDAO.java b/testing-modules/junit-5-configuration/src/main/java/com/baeldung/junit/tags/example/EmployeeDAO.java new file mode 100644 index 0000000000..2e9016018e --- /dev/null +++ b/testing-modules/junit-5-configuration/src/main/java/com/baeldung/junit/tags/example/EmployeeDAO.java @@ -0,0 +1,58 @@ +package com.baeldung.junit.tags.example; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.jdbc.core.simple.SimpleJdbcInsert; +import org.springframework.stereotype.Repository; + +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Repository +public class EmployeeDAO { + + private JdbcTemplate jdbcTemplate; + + private NamedParameterJdbcTemplate namedParameterJdbcTemplate; + + private SimpleJdbcInsert simpleJdbcInsert; + + @Autowired + public void setDataSource(final DataSource dataSource) { + jdbcTemplate = new JdbcTemplate(dataSource); + + namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); + simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("EMPLOYEE"); + + } + + public int getCountOfEmployees() { + return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM EMPLOYEE", Integer.class); + } + + public List getAllEmployees() { + return jdbcTemplate.query("SELECT * FROM EMPLOYEE", new EmployeeRowMapper()); + } + + public int addEmplyee(final int id) { + return jdbcTemplate.update("INSERT INTO EMPLOYEE VALUES (?, ?, ?, ?)", id, "Bill", "Gates", "USA"); + } + + public int addEmplyeeUsingSimpelJdbcInsert(final Employee emp) { + final Map parameters = new HashMap(); + parameters.put("ID", emp.getId()); + parameters.put("FIRST_NAME", emp.getFirstName()); + parameters.put("LAST_NAME", emp.getLastName()); + parameters.put("ADDRESS", emp.getAddress()); + + return simpleJdbcInsert.execute(parameters); + } + + // for testing + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } +} diff --git a/testing-modules/junit-5-configuration/src/main/java/com/baeldung/junit/tags/example/EmployeeRowMapper.java b/testing-modules/junit-5-configuration/src/main/java/com/baeldung/junit/tags/example/EmployeeRowMapper.java new file mode 100644 index 0000000000..f480aac9a2 --- /dev/null +++ b/testing-modules/junit-5-configuration/src/main/java/com/baeldung/junit/tags/example/EmployeeRowMapper.java @@ -0,0 +1,21 @@ +package com.baeldung.junit.tags.example; + +import org.springframework.jdbc.core.RowMapper; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class EmployeeRowMapper implements RowMapper { + + @Override + public Employee mapRow(final ResultSet rs, final int rowNum) throws SQLException { + final Employee employee = new Employee(); + + employee.setId(rs.getInt("ID")); + employee.setFirstName(rs.getString("FIRST_NAME")); + employee.setLastName(rs.getString("LAST_NAME")); + employee.setAddress(rs.getString("ADDRESS")); + + return employee; + } +} diff --git a/testing-modules/junit-5-configuration/src/main/java/com/baeldung/junit/tags/example/SpringJdbcConfig.java b/testing-modules/junit-5-configuration/src/main/java/com/baeldung/junit/tags/example/SpringJdbcConfig.java new file mode 100644 index 0000000000..dc82409df9 --- /dev/null +++ b/testing-modules/junit-5-configuration/src/main/java/com/baeldung/junit/tags/example/SpringJdbcConfig.java @@ -0,0 +1,19 @@ +package com.baeldung.junit.tags.example; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; + +import javax.sql.DataSource; + +@Configuration +@ComponentScan("com.baeldung.junit.tags.example") +public class SpringJdbcConfig { + + @Bean + public DataSource dataSource() { + return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).addScript("classpath:jdbc/schema.sql").addScript("classpath:jdbc/test-data.sql").build(); + } +} \ No newline at end of file diff --git a/testing-modules/junit-5-configuration/src/main/resources/jdbc/schema.sql b/testing-modules/junit-5-configuration/src/main/resources/jdbc/schema.sql new file mode 100644 index 0000000000..c86d35cdae --- /dev/null +++ b/testing-modules/junit-5-configuration/src/main/resources/jdbc/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE EMPLOYEE +( + ID int NOT NULL PRIMARY KEY, + FIRST_NAME varchar(255), + LAST_NAME varchar(255), + ADDRESS varchar(255), +); \ No newline at end of file diff --git a/testing-modules/junit-5-configuration/src/main/resources/jdbc/springJdbc-config.xml b/testing-modules/junit-5-configuration/src/main/resources/jdbc/springJdbc-config.xml new file mode 100644 index 0000000000..5fd2699b41 --- /dev/null +++ b/testing-modules/junit-5-configuration/src/main/resources/jdbc/springJdbc-config.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testing-modules/junit-5-configuration/src/main/resources/jdbc/test-data.sql b/testing-modules/junit-5-configuration/src/main/resources/jdbc/test-data.sql new file mode 100644 index 0000000000..b9ef8fec25 --- /dev/null +++ b/testing-modules/junit-5-configuration/src/main/resources/jdbc/test-data.sql @@ -0,0 +1,7 @@ +INSERT INTO EMPLOYEE VALUES (1, 'James', 'Gosling', 'Canada'); + +INSERT INTO EMPLOYEE VALUES (2, 'Donald', 'Knuth', 'USA'); + +INSERT INTO EMPLOYEE VALUES (3, 'Linus', 'Torvalds', 'Finland'); + +INSERT INTO EMPLOYEE VALUES (4, 'Dennis', 'Ritchie', 'USA'); \ No newline at end of file diff --git a/testing-modules/junit-5-configuration/src/test/java/com/baeldung/categories/EmployeeDAOCategoryIntegrationTest.java b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/categories/EmployeeDAOCategoryIntegrationTest.java new file mode 100644 index 0000000000..6aa1652321 --- /dev/null +++ b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/categories/EmployeeDAOCategoryIntegrationTest.java @@ -0,0 +1,66 @@ +package com.baeldung.categories; + +import com.baeldung.junit.tags.example.Employee; +import com.baeldung.junit.tags.example.EmployeeDAO; +import com.baeldung.junit.tags.example.SpringJdbcConfig; +import org.hamcrest.CoreMatchers; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { SpringJdbcConfig.class }, loader = AnnotationConfigContextLoader.class) +public class EmployeeDAOCategoryIntegrationTest { + + @Autowired + private EmployeeDAO employeeDao; + + @Mock + private JdbcTemplate jdbcTemplate; + private EmployeeDAO employeeDAO; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + employeeDAO = new EmployeeDAO(); + employeeDAO.setJdbcTemplate(jdbcTemplate); + } + + @Test + @Category(IntegrationTest.class) + public void testAddEmployeeUsingSimpelJdbcInsert() { + final Employee emp = new Employee(); + emp.setId(12); + emp.setFirstName("testFirstName"); + emp.setLastName("testLastName"); + emp.setAddress("testAddress"); + + Assert.assertEquals(employeeDao.addEmplyeeUsingSimpelJdbcInsert(emp), 1); + } + + @Test + @Category(UnitTest.class) + public void givenNumberOfEmployeeWhenCountEmployeeThenCountMatch() { + + // given + Mockito.when(jdbcTemplate.queryForObject(Mockito.any(String.class), Mockito.eq(Integer.class))) + .thenReturn(1); + + // when + int countOfEmployees = employeeDAO.getCountOfEmployees(); + + // then + Assert.assertThat(countOfEmployees, CoreMatchers.is(1)); + } + +} diff --git a/testing-modules/junit-5-configuration/src/test/java/com/baeldung/categories/EmployeeDAOUnitTestSuite.java b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/categories/EmployeeDAOUnitTestSuite.java new file mode 100644 index 0000000000..252e7ffe64 --- /dev/null +++ b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/categories/EmployeeDAOUnitTestSuite.java @@ -0,0 +1,12 @@ +package com.baeldung.categories; + +import org.junit.experimental.categories.Categories; +import org.junit.experimental.categories.Categories.IncludeCategory; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Categories.class) +@IncludeCategory(UnitTest.class) +@SuiteClasses(EmployeeDAOCategoryIntegrationTest.class) +public class EmployeeDAOUnitTestSuite { +} diff --git a/testing-modules/junit-5-configuration/src/test/java/com/baeldung/categories/IntegrationTest.java b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/categories/IntegrationTest.java new file mode 100644 index 0000000000..9ced880ffc --- /dev/null +++ b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/categories/IntegrationTest.java @@ -0,0 +1,4 @@ +package com.baeldung.categories; + +public interface IntegrationTest { +} diff --git a/testing-modules/junit-5-configuration/src/test/java/com/baeldung/categories/UnitTest.java b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/categories/UnitTest.java new file mode 100644 index 0000000000..3790fc1d91 --- /dev/null +++ b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/categories/UnitTest.java @@ -0,0 +1,4 @@ +package com.baeldung.categories; + +public interface UnitTest { +} diff --git a/testing-modules/junit-5-configuration/src/test/java/com/baeldung/example/EmployeeDAOIntegrationTest.java b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/example/EmployeeDAOIntegrationTest.java new file mode 100644 index 0000000000..d3b6a52726 --- /dev/null +++ b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/example/EmployeeDAOIntegrationTest.java @@ -0,0 +1,41 @@ +package com.baeldung.example; + +import com.baeldung.junit.tags.example.Employee; +import com.baeldung.junit.tags.example.EmployeeDAO; +import com.baeldung.junit.tags.example.SpringJdbcConfig; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { SpringJdbcConfig.class }, loader = AnnotationConfigContextLoader.class) +public class EmployeeDAOIntegrationTest { + + @Autowired + private EmployeeDAO employeeDao; + + @Test + public void testQueryMethod() { + Assert.assertEquals(employeeDao.getAllEmployees().size(), 4); + } + + @Test + public void testUpdateMethod() { + Assert.assertEquals(employeeDao.addEmplyee(5), 1); + } + + @Test + public void testAddEmployeeUsingSimpelJdbcInsert() { + final Employee emp = new Employee(); + emp.setId(11); + emp.setFirstName("testFirstName"); + emp.setLastName("testLastName"); + emp.setAddress("testAddress"); + + Assert.assertEquals(employeeDao.addEmplyeeUsingSimpelJdbcInsert(emp), 1); + } +} diff --git a/testing-modules/junit-5-configuration/src/test/java/com/baeldung/example/EmployeeUnitTest.java b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/example/EmployeeUnitTest.java new file mode 100644 index 0000000000..f706af94ad --- /dev/null +++ b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/example/EmployeeUnitTest.java @@ -0,0 +1,40 @@ +package com.baeldung.example; + +import com.baeldung.junit.tags.example.EmployeeDAO; +import org.hamcrest.CoreMatchers; +import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.springframework.jdbc.core.JdbcTemplate; + +public class EmployeeUnitTest { + + @Mock + private JdbcTemplate jdbcTemplate; + + private EmployeeDAO employeeDAO; + + @BeforeEach + public void setup() { + MockitoAnnotations.initMocks(this); + employeeDAO = new EmployeeDAO(); + employeeDAO.setJdbcTemplate(jdbcTemplate); + } + + @Test + public void givenNumberOfEmployeeWhenCountEmployeeThenCountMatch() { + + // given + Mockito.when(jdbcTemplate.queryForObject(Mockito.any(String.class), Mockito.eq(Integer.class))) + .thenReturn(1); + + // when + int countOfEmployees = employeeDAO.getCountOfEmployees(); + + // then + Assert.assertThat(countOfEmployees, CoreMatchers.is(1)); + } +} diff --git a/testing-modules/junit-5-configuration/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryUnitTest.java b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryUnitTest.java new file mode 100644 index 0000000000..20fa372abd --- /dev/null +++ b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryUnitTest.java @@ -0,0 +1,45 @@ +package com.baeldung.resourcedirectory; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class ReadResourceDirectoryUnitTest { + + @Test + public void givenResourcePath_whenReadAbsolutePathWithFile_thenAbsolutePathEndsWithDirectory() { + String path = "src/test/resources"; + + File file = new File(path); + String absolutePath = file.getAbsolutePath(); + + System.out.println(absolutePath); + Assert.assertTrue(absolutePath.endsWith("src/test/resources")); + } + + @Test + public void givenResourcePath_whenReadAbsolutePathWithPaths_thenAbsolutePathEndsWithDirectory() { + Path resourceDirectory = Paths.get("src", "test", "resources"); + + String absolutePath = resourceDirectory.toFile().getAbsolutePath(); + + System.out.println(absolutePath); + Assert.assertTrue(absolutePath.endsWith("src/test/resources")); + } + + @Test + public void givenResourceFile_whenReadResourceWithClassLoader_thenPathEndWithFilename() { + String resourceName = "example_resource.txt"; + + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource(resourceName).getFile()); + String absolutePath = file.getAbsolutePath(); + + System.out.println(absolutePath); + Assert.assertTrue(absolutePath.endsWith("/example_resource.txt")); + } + +} diff --git a/testing-modules/junit-5-configuration/src/test/java/com/baeldung/tags/EmployeeDAOIntegrationTest.java b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/tags/EmployeeDAOIntegrationTest.java new file mode 100644 index 0000000000..bcd76cb4c2 --- /dev/null +++ b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/tags/EmployeeDAOIntegrationTest.java @@ -0,0 +1,65 @@ +package com.baeldung.tags; + +import com.baeldung.junit.tags.example.Employee; +import com.baeldung.junit.tags.example.EmployeeDAO; +import com.baeldung.junit.tags.example.SpringJdbcConfig; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = { SpringJdbcConfig.class }, loader = AnnotationConfigContextLoader.class) +public class EmployeeDAOIntegrationTest { + + @Autowired + private EmployeeDAO employeeDao; + + @Mock + private JdbcTemplate jdbcTemplate; + private EmployeeDAO employeeDAO; + + @BeforeEach + public void setup() { + MockitoAnnotations.initMocks(this); + employeeDAO = new EmployeeDAO(); + employeeDAO.setJdbcTemplate(jdbcTemplate); + } + + @Test + @Tag("IntegrationTest") + public void testAddEmployeeUsingSimpelJdbcInsert() { + final Employee emp = new Employee(); + emp.setId(12); + emp.setFirstName("testFirstName"); + emp.setLastName("testLastName"); + emp.setAddress("testAddress"); + + Assertions.assertEquals(employeeDao.addEmplyeeUsingSimpelJdbcInsert(emp), 1); + } + + @Test + @Tag("UnitTest") + public void givenNumberOfEmployeeWhenCountEmployeeThenCountMatch() { + + // given + Mockito.when(jdbcTemplate.queryForObject(Mockito.any(String.class), Mockito.eq(Integer.class))) + .thenReturn(1); + + // when + int countOfEmployees = employeeDAO.getCountOfEmployees(); + + // then + Assertions.assertEquals(1, countOfEmployees); + } + +} diff --git a/testing-modules/junit-5-configuration/src/test/java/com/baeldung/tags/EmployeeDAOTestSuite.java b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/tags/EmployeeDAOTestSuite.java new file mode 100644 index 0000000000..783e5a81a2 --- /dev/null +++ b/testing-modules/junit-5-configuration/src/test/java/com/baeldung/tags/EmployeeDAOTestSuite.java @@ -0,0 +1,12 @@ +package com.baeldung.tags; + +import org.junit.platform.runner.JUnitPlatform; +import org.junit.platform.suite.api.IncludeTags; +import org.junit.platform.suite.api.SelectPackages; +import org.junit.runner.RunWith; + +@RunWith(JUnitPlatform.class) +@SelectPackages("com.baeldung.tags") +@IncludeTags("UnitTest") +public class EmployeeDAOTestSuite { +} diff --git a/testing-modules/junit-5-configuration/src/test/resources/example_resource.txt b/testing-modules/junit-5-configuration/src/test/resources/example_resource.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testing-modules/junit-5/pom.xml b/testing-modules/junit-5/pom.xml index a5a1ddaf0b..f27630a76d 100644 --- a/testing-modules/junit-5/pom.xml +++ b/testing-modules/junit-5/pom.xml @@ -103,13 +103,6 @@ maven-surefire-plugin ${maven-surefire-plugin.version} - - - org.junit.platform - junit-platform-surefire-provider - ${junit.platform.version} - - org.codehaus.mojo @@ -130,12 +123,11 @@ - 5.3.1 + 5.4.2 2.23.0 - 1.2.0 - 5.2.0 + 1.4.2 + 5.4.2 2.8.2 - 1.4.196 2.0.0-RC.1 2.21.0 1.6.0 diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/parameterized/StringsUnitTest.java b/testing-modules/junit-5/src/test/java/com/baeldung/parameterized/StringsUnitTest.java index 7d02a5a74b..6aea7668f1 100644 --- a/testing-modules/junit-5/src/test/java/com/baeldung/parameterized/StringsUnitTest.java +++ b/testing-modules/junit-5/src/test/java/com/baeldung/parameterized/StringsUnitTest.java @@ -86,7 +86,30 @@ class StringsUnitTest { assertEquals(expected, actualValue); } + @ParameterizedTest + @NullSource + void isBlank_ShouldReturnTrueForNullInputs(String input) { + assertTrue(Strings.isBlank(input)); + } + @ParameterizedTest + @EmptySource + void isBlank_ShouldReturnTrueForEmptyStrings(String input) { + assertTrue(Strings.isBlank(input)); + } + + @ParameterizedTest + @NullAndEmptySource + void isBlank_ShouldReturnTrueForNullAndEmptyStrings(String input) { + assertTrue(Strings.isBlank(input)); + } + + @ParameterizedTest + @NullAndEmptySource + @ValueSource(strings = {" ", "\t", "\n"}) + void isBlank_ShouldReturnTrueForAllTypesOfBlankStrings(String input) { + assertTrue(Strings.isBlank(input)); + } private static Stream provideStringsForIsBlank() { return Stream.of( diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/misusing/ExpectedTestFailureRule.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/misusing/ExpectedTestFailureRule.java new file mode 100644 index 0000000000..53ad60a2fa --- /dev/null +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/misusing/ExpectedTestFailureRule.java @@ -0,0 +1,51 @@ +package com.baeldung.mockito.misusing; + +import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.rules.MethodRule; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.Statement; + +public class ExpectedTestFailureRule implements MethodRule { + + private final MethodRule testedRule; + private FailureAssert failureAssert = null; + + public ExpectedTestFailureRule(MethodRule testedRule) { + this.testedRule = testedRule; + } + + @Override + public Statement apply(final Statement base, final FrameworkMethod method, final Object target) { + return new Statement() { + public void evaluate() throws Throwable { + try { + testedRule.apply(base, method, target) + .evaluate(); + } catch (Throwable t) { + if (failureAssert == null) { + throw t; + } + failureAssert.doAssert(t); + return; + } + } + }; + } + + @SuppressWarnings("unchecked") + public void expectedFailure(final Class expected) { + FailureAssert assertion = t -> Assert.assertThat(t, Matchers.isA((Class) expected)); + this.expectedFailure(assertion); + } + + private void expectedFailure(FailureAssert failureAssert) { + this.failureAssert = failureAssert; + } + + @FunctionalInterface + private interface FailureAssert { + abstract void doAssert(Throwable t); + } + +} diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/misusing/MockitoUnecessaryStubUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/misusing/MockitoUnecessaryStubUnitTest.java new file mode 100644 index 0000000000..00edb699de --- /dev/null +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/misusing/MockitoUnecessaryStubUnitTest.java @@ -0,0 +1,52 @@ +package com.baeldung.mockito.misusing; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.exceptions.misusing.UnnecessaryStubbingException; +import org.mockito.junit.MockitoJUnit; +import org.mockito.quality.Strictness; + +public class MockitoUnecessaryStubUnitTest { + + @Rule + public ExpectedTestFailureRule rule = new ExpectedTestFailureRule(MockitoJUnit.rule() + .strictness(Strictness.STRICT_STUBS)); + + @Mock + private ArrayList mockList; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void givenUnusedStub_whenInvokingGetThenThrowUnnecessaryStubbingException() { + rule.expectedFailure(UnnecessaryStubbingException.class); + + when(mockList.add("one")).thenReturn(true); + when(mockList.get(anyInt())).thenReturn("hello"); + + assertEquals("List should contain hello", "hello", mockList.get(1)); + } + + @Test + public void givenLenientdStub_whenInvokingGetThenDontThrowUnnecessaryStubbingException() { + lenient().when(mockList.add("one")) + .thenReturn(true); + when(mockList.get(anyInt())).thenReturn("hello"); + + assertEquals("List should contain hello", "hello", mockList.get(1)); + } + +} diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml index 39047fb756..40ed63bc12 100644 --- a/testing-modules/pom.xml +++ b/testing-modules/pom.xml @@ -32,5 +32,6 @@ test-containers testing testng + junit-5-configuration diff --git a/testing-modules/rest-assured/pom.xml b/testing-modules/rest-assured/pom.xml index cd342ccd11..4ed10f0641 100644 --- a/testing-modules/rest-assured/pom.xml +++ b/testing-modules/rest-assured/pom.xml @@ -162,6 +162,11 @@ commons-collections ${commons-collections.version} + + + org.springframework.boot + spring-boot-starter-security + @@ -179,6 +184,12 @@ json-schema-validator test + + com.github.scribejava + scribejava-apis + ${scribejava.version} + test +
@@ -186,8 +197,6 @@ 2.9.7 1.8 19.0 - - 3.1.0 2.5 1.4.7 9.4.0.v20161208 @@ -211,6 +220,8 @@ 3.0.1 3.0.1 + + 2.5.3 diff --git a/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/BasicAuthenticationLiveTest.java b/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/BasicAuthenticationLiveTest.java new file mode 100644 index 0000000000..aff765dfa3 --- /dev/null +++ b/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/BasicAuthenticationLiveTest.java @@ -0,0 +1,38 @@ +package com.baeldung.restassured.authentication; + +import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.given; + +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; + +/** + * For this Live Test we need: + * * a running instance of the service located in the spring-security-rest-basic-auth module. + * @see spring-security-rest-basic-auth module + * + */ +public class BasicAuthenticationLiveTest { + + private static final String USER = "user1"; + private static final String PASSWORD = "user1Pass"; + private static final String SVC_URL = "http://localhost:8080/spring-security-rest-basic-auth/api/foos/1"; + + @Test + public void givenNoAuthentication_whenRequestSecuredResource_thenUnauthorizedResponse() { + get(SVC_URL).then() + .assertThat() + .statusCode(HttpStatus.UNAUTHORIZED.value()); + } + + @Test + public void givenBasicAuthentication_whenRequestSecuredResource_thenResourceRetrieved() { + given().auth() + .basic(USER, PASSWORD) + .when() + .get(SVC_URL) + .then() + .assertThat() + .statusCode(HttpStatus.OK.value()); + } +} diff --git a/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/BasicPreemtiveAuthenticationLiveTest.java b/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/BasicPreemtiveAuthenticationLiveTest.java new file mode 100644 index 0000000000..02138f22e3 --- /dev/null +++ b/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/BasicPreemtiveAuthenticationLiveTest.java @@ -0,0 +1,56 @@ +package com.baeldung.restassured.authentication; + +import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; + +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; + +/** + * For this Live Test we need: + * * a running instance of the service located in the spring-boot-admin/spring-boot-admin-server module. + * @see spring-boot-admin/spring-boot-admin-server module + * + */ +public class BasicPreemtiveAuthenticationLiveTest { + + private static final String USER = "admin"; + private static final String PASSWORD = "admin"; + private static final String SVC_URL = "http://localhost:8080/api/applications/"; + + @Test + public void givenNoAuthentication_whenRequestSecuredResource_thenUnauthorizedResponse() { + get(SVC_URL).then() + .assertThat() + .statusCode(HttpStatus.OK.value()) + .content(containsString("spring-security-mvc-digest-auth module + * + */ +public class DigestAuthenticationLiveTest { + + private static final String USER = "user1"; + private static final String PASSWORD = "user1Pass"; + private static final String SVC_URL = "http://localhost:8080/spring-security-mvc-digest-auth/homepage.html"; + + @Test + public void givenNoAuthentication_whenRequestSecuredResource_thenUnauthorizedResponse() { + get(SVC_URL).then() + .assertThat() + .statusCode(HttpStatus.UNAUTHORIZED.value()); + } + + @Test + public void givenFormAuthentication_whenRequestSecuredResource_thenResourceRetrieved() { + given().auth() + .digest(USER, PASSWORD) + .when() + .get(SVC_URL) + .then() + .assertThat() + .statusCode(HttpStatus.OK.value()) + .content(containsString("This is the body of the sample view")); + } +} diff --git a/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/FormAuthenticationLiveTest.java b/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/FormAuthenticationLiveTest.java new file mode 100644 index 0000000000..66ae9fb162 --- /dev/null +++ b/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/FormAuthenticationLiveTest.java @@ -0,0 +1,57 @@ +package com.baeldung.restassured.authentication; + +import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.isEmptyString; + +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; + +import io.restassured.authentication.FormAuthConfig; + +/** + * For this Live Test we need: + * * a running instance of the service located in the spring-security-mvc-login module. + * @see spring-security-mvc-login module + * + */ +public class FormAuthenticationLiveTest { + + private static final String USER = "user1"; + private static final String PASSWORD = "user1Pass"; + private static final String SVC_URL = "http://localhost:8080/spring-security-mvc-login/secured"; + + @Test + public void givenNoAuthentication_whenRequestSecuredResource_thenLoginFormResponse() { + get(SVC_URL).then() + .assertThat() + .statusCode(HttpStatus.OK.value()) + .content(containsString("spring-boot-admin/spring-boot-admin-server module + * + */ +public class FormAutoconfAuthenticationLiveTest { + + private static final String USER = "admin"; + private static final String PASSWORD = "admin"; + private static final String SVC_URL = "http://localhost:8080/ger1/api/applications/"; + + @Test + public void givenNoAuthentication_whenRequestSecuredResource_thenUnauthorizedResponse() { + get(SVC_URL).then() + .assertThat() + .statusCode(HttpStatus.OK.value()) + .content(containsString("spring-security-oauth/oauth-authorization-server module + * + * * a running instance of the service located in the spring-security-oauth repo - oauth-resource-server-1 module. + * @see spring-security-oauth/oauth-resource-server-1 module + * + */ +public class OAuth2AuthenticationLiveTest { + + private static final String USER = "john"; + private static final String PASSWORD = "123"; + private static final String CLIENT_ID = "fooClientIdPassword"; + private static final String SECRET = "secret"; + private static final String AUTH_SVC_TOKEN_URL = "http://localhost:8081/spring-security-oauth-server/oauth/token"; + private static final String RESOURCE_SVC_URL = "http://localhost:8082/spring-security-oauth-resource/foos/1"; + + @Test + public void givenNoAuthentication_whenRequestSecuredResource_thenUnauthorizedResponse() { + get(RESOURCE_SVC_URL).then() + .assertThat() + .statusCode(HttpStatus.UNAUTHORIZED.value()); + } + + @Test + public void givenAccessTokenAuthentication_whenRequestSecuredResource_thenResourceRetrieved() { + String accessToken = given().auth() + .basic(CLIENT_ID, SECRET) + .formParam("grant_type", "password") + .formParam("username", USER) + .formParam("password", PASSWORD) + .formParam("scope", "read foo") + .when() + .post(AUTH_SVC_TOKEN_URL) + .then() + .assertThat() + .statusCode(HttpStatus.OK.value()) + .extract() + .path("access_token"); + + given().auth() + .oauth2(accessToken) + .when() + .get(RESOURCE_SVC_URL) + .then() + .assertThat() + .statusCode(HttpStatus.OK.value()) + .body("$", hasKey("id")) + .body("$", hasKey("name")); + } +} diff --git a/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/OAuthAuthenticationLiveTest.java b/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/OAuthAuthenticationLiveTest.java new file mode 100644 index 0000000000..c720bc04e4 --- /dev/null +++ b/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/OAuthAuthenticationLiveTest.java @@ -0,0 +1,53 @@ +package com.baeldung.restassured.authentication; + +import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.hasKey; + +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; + +import io.restassured.http.ContentType; + +/** + * For this Live Test we need to obtain a valid Access Token and Token Secret: + * * start spring-mvc-simple application in debug mode + * @see spring-mvc-simple module + * * calling localhost:8080/spring-mvc-simple/twitter/authorization/ using the browser + * * debug the callback function where we can obtain the fields + */ +public class OAuthAuthenticationLiveTest { + + // We can obtain these two from the spring-mvc-simple / TwitterController class + private static final String OAUTH_API_KEY = "PSRszoHhRDVhyo2RIkThEbWko"; + private static final String OAUTH_API_SECRET = "prpJbz03DcGRN46sb4ucdSYtVxG8unUKhcnu3an5ItXbEOuenL"; + private static final String TWITTER_ENDPOINT = "https://api.twitter.com/1.1/account/settings.json"; + /* We can obtain the following by: + * - starting the spring-mvc-simple application + * - calling localhost:8080/spring-mvc-simple/twitter/authorization/ + * - debugging the callback function */ + private static final String ACCESS_TOKEN = "..."; + private static final String TOKEN_SECRET = "..."; + + @Test + public void givenNoAuthentication_whenRequestSecuredResource_thenUnauthorizedResponse() { + get(TWITTER_ENDPOINT).then() + .assertThat() + .statusCode(HttpStatus.BAD_REQUEST.value()); + } + + @Test + public void givenAccessTokenAuthentication_whenRequestSecuredResource_thenResourceIsRequested() { + given().accept(ContentType.JSON) + .auth() + .oauth(OAUTH_API_KEY, OAUTH_API_SECRET, ACCESS_TOKEN, TOKEN_SECRET) + .when() + .get(TWITTER_ENDPOINT) + .then() + .assertThat() + .statusCode(HttpStatus.OK.value()) + .body("$", hasKey("geo_enabled")) + .body("$", hasKey("language")); + } + +} diff --git a/testing-modules/rest-testing/README.md b/testing-modules/rest-testing/README.md index a07c8cb256..2d366bd550 100644 --- a/testing-modules/rest-testing/README.md +++ b/testing-modules/rest-testing/README.md @@ -6,7 +6,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: -- [Test a REST API with Java](http://www.baeldung.com/integration-testing-a-rest-api) - [Introduction to WireMock](http://www.baeldung.com/introduction-to-wiremock) - [Using WireMock Scenarios](https://www.baeldung.com/wiremock-scenarios) - [REST API Testing with Cucumber](http://www.baeldung.com/cucumber-rest-api-testing) diff --git a/testing-modules/rest-testing/pom.xml b/testing-modules/rest-testing/pom.xml index c3a9477a47..6dad3be117 100644 --- a/testing-modules/rest-testing/pom.xml +++ b/testing-modules/rest-testing/pom.xml @@ -149,9 +149,6 @@ - - 2.9.7 - 19.0 3.5 diff --git a/testing-modules/test-containers/pom.xml b/testing-modules/test-containers/pom.xml index 1f4c483988..7ee002ea8b 100644 --- a/testing-modules/test-containers/pom.xml +++ b/testing-modules/test-containers/pom.xml @@ -103,7 +103,6 @@ 1.0.1 4.12.1 2.8.2 - 1.4.196 2.21.0 5.0.1.RELEASE 1.7.2 diff --git a/vaadin/pom.xml b/vaadin/pom.xml index d24b3dff1b..648343fcd8 100644 --- a/vaadin/pom.xml +++ b/vaadin/pom.xml @@ -33,22 +33,6 @@ javax.servlet-api provided - - com.vaadin - vaadin-server - - - com.vaadin - vaadin-push - - - com.vaadin - vaadin-client-compiled - - - com.vaadin - vaadin-themes - org.springframework.boot @@ -86,17 +70,6 @@ com.vaadin vaadin-maven-plugin ${vaadin.plugin.version} - - - - update-theme - update-widgetset - compile - - compile-theme - - - org.apache.maven.plugins @@ -182,10 +155,9 @@ - 3.0.1 - 7.7.10 - 8.0.6 - 10.0.1 + 10.0.11 + 10.0.11 + 10.0.11 9.3.9.v20160517 UTF-8 1.8 diff --git a/vaadin/src/main/java/com/baeldung/introduction/VaadinUI.java b/vaadin/src/main/java/com/baeldung/introduction/VaadinUI.java deleted file mode 100644 index 1b3733ad74..0000000000 --- a/vaadin/src/main/java/com/baeldung/introduction/VaadinUI.java +++ /dev/null @@ -1,281 +0,0 @@ -package com.baeldung.introduction; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -import javax.servlet.annotation.WebServlet; - -import com.vaadin.annotations.Push; -import com.vaadin.annotations.Theme; -import com.vaadin.annotations.VaadinServletConfiguration; -import com.vaadin.data.Validator.InvalidValueException; -import com.vaadin.data.fieldgroup.BeanFieldGroup; -import com.vaadin.data.validator.StringLengthValidator; -import com.vaadin.server.ExternalResource; -import com.vaadin.server.FontAwesome; -import com.vaadin.server.VaadinRequest; -import com.vaadin.server.VaadinServlet; -import com.vaadin.ui.Button; -import com.vaadin.ui.CheckBox; -import com.vaadin.ui.ComboBox; -import com.vaadin.ui.DateField; -import com.vaadin.ui.FormLayout; -import com.vaadin.ui.Grid; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.InlineDateField; -import com.vaadin.ui.Label; -import com.vaadin.ui.Link; -import com.vaadin.ui.ListSelect; -import com.vaadin.ui.NativeButton; -import com.vaadin.ui.NativeSelect; -import com.vaadin.ui.Panel; -import com.vaadin.ui.PasswordField; -import com.vaadin.ui.RichTextArea; -import com.vaadin.ui.TextArea; -import com.vaadin.ui.TextField; -import com.vaadin.ui.TwinColSelect; -import com.vaadin.ui.UI; -import com.vaadin.ui.VerticalLayout; - -@SuppressWarnings("serial") -@Push -@Theme("mytheme") -public class VaadinUI extends UI { - - private Label currentTime; - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - protected void init(VaadinRequest vaadinRequest) { - final VerticalLayout verticalLayout = new VerticalLayout(); - verticalLayout.setSpacing(true); - verticalLayout.setMargin(true); - final GridLayout gridLayout = new GridLayout(3, 2); - gridLayout.setSpacing(true); - gridLayout.setMargin(true); - final HorizontalLayout horizontalLayout = new HorizontalLayout(); - horizontalLayout.setSpacing(true); - horizontalLayout.setMargin(true); - final FormLayout formLayout = new FormLayout(); - formLayout.setSpacing(true); - formLayout.setMargin(true); - final GridLayout buttonLayout = new GridLayout(3, 5); - buttonLayout.setMargin(true); - buttonLayout.setSpacing(true); - - final Label label = new Label(); - label.setId("Label"); - label.setValue("Label Value"); - label.setCaption("Label"); - gridLayout.addComponent(label); - - final Link link = new Link("Baeldung", new ExternalResource("http://www.baeldung.com/")); - link.setId("Link"); - link.setTargetName("_blank"); - gridLayout.addComponent(link); - - final TextField textField = new TextField(); - textField.setId("TextField"); - textField.setCaption("TextField:"); - textField.setValue("TextField Value"); - textField.setIcon(FontAwesome.USER); - gridLayout.addComponent(textField); - - final TextArea textArea = new TextArea(); - textArea.setCaption("TextArea"); - textArea.setId("TextArea"); - textArea.setValue("TextArea Value"); - gridLayout.addComponent(textArea); - - final DateField dateField = new DateField("DateField", new Date(0)); - dateField.setId("DateField"); - gridLayout.addComponent(dateField); - - final PasswordField passwordField = new PasswordField(); - passwordField.setId("PasswordField"); - passwordField.setCaption("PasswordField:"); - passwordField.setValue("password"); - gridLayout.addComponent(passwordField); - - final RichTextArea richTextArea = new RichTextArea(); - richTextArea.setCaption("Rich Text Area"); - richTextArea.setValue("

RichTextArea

"); - richTextArea.setSizeFull(); - - Panel richTextPanel = new Panel(); - richTextPanel.setContent(richTextArea); - - final InlineDateField inlineDateField = new InlineDateField(); - inlineDateField.setValue(new Date(0)); - inlineDateField.setCaption("Inline Date Field"); - horizontalLayout.addComponent(inlineDateField); - - Button normalButton = new Button("Normal Button"); - normalButton.setId("NormalButton"); - normalButton.addClickListener(e -> { - label.setValue("CLICK"); - }); - buttonLayout.addComponent(normalButton); - - Button tinyButton = new Button("Tiny Button"); - tinyButton.addStyleName("tiny"); - buttonLayout.addComponent(tinyButton); - - Button smallButton = new Button("Small Button"); - smallButton.addStyleName("small"); - buttonLayout.addComponent(smallButton); - - Button largeButton = new Button("Large Button"); - largeButton.addStyleName("large"); - buttonLayout.addComponent(largeButton); - - Button hugeButton = new Button("Huge Button"); - hugeButton.addStyleName("huge"); - buttonLayout.addComponent(hugeButton); - - Button disabledButton = new Button("Disabled Button"); - disabledButton.setDescription("This button cannot be clicked"); - disabledButton.setEnabled(false); - buttonLayout.addComponent(disabledButton); - - Button dangerButton = new Button("Danger Button"); - dangerButton.addStyleName("danger"); - buttonLayout.addComponent(dangerButton); - - Button friendlyButton = new Button("Friendly Button"); - friendlyButton.addStyleName("friendly"); - buttonLayout.addComponent(friendlyButton); - - Button primaryButton = new Button("Primary Button"); - primaryButton.addStyleName("primary"); - buttonLayout.addComponent(primaryButton); - - NativeButton nativeButton = new NativeButton("Native Button"); - buttonLayout.addComponent(nativeButton); - - Button iconButton = new Button("Icon Button"); - iconButton.setIcon(FontAwesome.ALIGN_LEFT); - buttonLayout.addComponent(iconButton); - - Button borderlessButton = new Button("BorderLess Button"); - borderlessButton.addStyleName("borderless"); - buttonLayout.addComponent(borderlessButton); - - Button linkButton = new Button("Link Button"); - linkButton.addStyleName("link"); - buttonLayout.addComponent(linkButton); - - Button quietButton = new Button("Quiet Button"); - quietButton.addStyleName("quiet"); - buttonLayout.addComponent(quietButton); - - horizontalLayout.addComponent(buttonLayout); - - final CheckBox checkbox = new CheckBox("CheckBox"); - checkbox.setValue(true); - checkbox.addValueChangeListener(e -> checkbox.setValue(!checkbox.getValue())); - formLayout.addComponent(checkbox); - - List numbers = new ArrayList(); - numbers.add("One"); - numbers.add("Ten"); - numbers.add("Eleven"); - ComboBox comboBox = new ComboBox("ComboBox"); - comboBox.addItems(numbers); - formLayout.addComponent(comboBox); - - ListSelect listSelect = new ListSelect("ListSelect"); - listSelect.addItems(numbers); - listSelect.setRows(2); - formLayout.addComponent(listSelect); - - NativeSelect nativeSelect = new NativeSelect("NativeSelect"); - nativeSelect.addItems(numbers); - formLayout.addComponent(nativeSelect); - - TwinColSelect twinColSelect = new TwinColSelect("TwinColSelect"); - twinColSelect.addItems(numbers); - - Grid grid = new Grid("Grid"); - grid.setColumns("Column1", "Column2", "Column3"); - grid.addRow("Item1", "Item2", "Item3"); - grid.addRow("Item4", "Item5", "Item6"); - - Panel panel = new Panel("Panel"); - panel.setContent(grid); - panel.setSizeUndefined(); - - Panel serverPushPanel = new Panel("Server Push"); - FormLayout timeLayout = new FormLayout(); - timeLayout.setSpacing(true); - timeLayout.setMargin(true); - currentTime = new Label("No TIME..."); - timeLayout.addComponent(currentTime); - serverPushPanel.setContent(timeLayout); - serverPushPanel.setSizeUndefined(); - ScheduledExecutorService scheduleExecutor = Executors.newScheduledThreadPool(1); - Runnable task = () -> { - currentTime.setValue("Current Time : " + Instant.now()); - }; - scheduleExecutor.scheduleWithFixedDelay(task, 0, 1, TimeUnit.SECONDS); - - FormLayout dataBindingLayout = new FormLayout(); - dataBindingLayout.setSpacing(true); - dataBindingLayout.setMargin(true); - - BindData bindData = new BindData("BindData"); - BeanFieldGroup beanFieldGroup = new BeanFieldGroup(BindData.class); - beanFieldGroup.setItemDataSource(bindData); - TextField bindedTextField = (TextField) beanFieldGroup.buildAndBind("BindName", "bindName"); - bindedTextField.setWidth("250px"); - dataBindingLayout.addComponent(bindedTextField); - - FormLayout validatorLayout = new FormLayout(); - validatorLayout.setSpacing(true); - validatorLayout.setMargin(true); - - HorizontalLayout textValidatorLayout = new HorizontalLayout(); - textValidatorLayout.setSpacing(true); - textValidatorLayout.setMargin(true); - - TextField stringValidator = new TextField(); - stringValidator.setNullSettingAllowed(true); - stringValidator.setNullRepresentation(""); - stringValidator.addValidator(new StringLengthValidator("String must have 2-5 characters lenght", 2, 5, true)); - stringValidator.setValidationVisible(false); - textValidatorLayout.addComponent(stringValidator); - Button buttonStringValidator = new Button("Validate String"); - buttonStringValidator.addClickListener(e -> { - try { - stringValidator.setValidationVisible(false); - stringValidator.validate(); - } catch (InvalidValueException err) { - stringValidator.setValidationVisible(true); - } - }); - textValidatorLayout.addComponent(buttonStringValidator); - - validatorLayout.addComponent(textValidatorLayout); - verticalLayout.addComponent(gridLayout); - verticalLayout.addComponent(richTextPanel); - verticalLayout.addComponent(horizontalLayout); - verticalLayout.addComponent(formLayout); - verticalLayout.addComponent(twinColSelect); - verticalLayout.addComponent(panel); - verticalLayout.addComponent(serverPushPanel); - verticalLayout.addComponent(dataBindingLayout); - verticalLayout.addComponent(validatorLayout); - setContent(verticalLayout); - } - - @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true) - @VaadinServletConfiguration(ui = VaadinUI.class, productionMode = false) - public static class MyUIServlet extends VaadinServlet { - } -} diff --git a/vavr/pom.xml b/vavr/pom.xml index ae495e9830..a2c6e29cde 100644 --- a/vavr/pom.xml +++ b/vavr/pom.xml @@ -41,7 +41,6 @@
- 1.8 0.9.1 3.0.0 diff --git a/video-tutorials/jackson-annotations/pom.xml b/video-tutorials/jackson-annotations/pom.xml index b0e1c7e8d9..2492951d1a 100644 --- a/video-tutorials/jackson-annotations/pom.xml +++ b/video-tutorials/jackson-annotations/pom.xml @@ -136,10 +136,6 @@ - - - 2.9.7 - 2.9.6 2.8.0 diff --git a/vraptor/pom.xml b/vraptor/pom.xml index 214a44cede..3904eb8c63 100644 --- a/vraptor/pom.xml +++ b/vraptor/pom.xml @@ -67,7 +67,7 @@ javax.servlet javax.servlet-api - ${servlet.version} + ${javax.servlet-api.version} provided @@ -129,8 +129,6 @@ 2.1.2.Final 2.2 5.1.1.Final - 1.2 - 3.1.0 1.7.5 4.1.0-RC3 4.0.4