From b44883b364cbc2e53d93157701b4fbb02d32d999 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Sat, 14 Jul 2018 15:00:37 +0200 Subject: [PATCH] BAEL-1889 - Let's move the Java Number articles into a new module (#4619) * BAEL-1849 - Convert from String to Date in Java * BAEL-1863 - Calling Callbacks with Mockito * BAEL-1889 - Let's move the Java Number articles into a new module * BAEL-1889 - Let's move the Java Number articles into a new module --- algorithms/README.md | 2 - .../com/baeldung/algorithms/RunAlgorithm.java | 7 - .../algorithms/prime/PrimeGenerator.java | 59 ---- .../prime/PrimeGeneratorUnitTest.java | 28 -- core-java-8/README.md | 1 - core-java/README.md | 6 - core-java/pom.xml | 11 +- .../com/baeldung/maths/BigDecimalImpl.java | 18 -- .../com/baeldung/maths/BigIntegerImpl.java | 16 - java-numbers/.gitignore | 26 ++ java-numbers/README.md | 14 + java-numbers/pom.xml | 286 ++++++++++++++++++ .../primechecker/BigIntegerPrimeChecker.java | 0 .../primechecker/BruteForcePrimeChecker.java | 8 +- .../primechecker/OptimisedPrimeChecker.java | 4 +- .../algorithms/primechecker/PrimeChecker.java | 0 .../primechecker/PrimesPrimeChecker.java | 0 .../maths/FloatingPointArithmetic.java | 0 .../main/java/com/baeldung/maths/Round.java | 0 .../java/com/baeldung/nan/NaNExample.java | 0 .../baeldung/numberofdigits/Benchmarking.java | 0 .../numberofdigits/NumberOfDigits.java | 0 .../numberofdigits/NumberOfDigitsDriver.java | 20 +- .../pairsaddupnumber/DifferentPairs.java | 6 +- .../pairsaddupnumber/ExistingPairs.java | 2 +- .../baeldung}/pairsaddupnumber/FindPairs.java | 2 +- .../java/com/baeldung/pow/PowerExample.java | 0 .../com/baeldung/prime/PrimeGenerator.java | 0 .../src/main/resources/log4j.properties | 6 + java-numbers/src/main/resources/logback.xml | 13 + .../primechecker/PrimeCheckerUnitTest.java | 19 +- .../maths/BigDecimalImplUnitTest.java | 0 .../maths/BigIntegerImplUnitTest.java | 0 .../FloatingPointArithmeticUnitTest.java | 0 .../com/baeldung/maths/RoundUnitTest.java | 3 - .../NumberOfDigitsIntegrationTest.java | 0 .../DifferentPairsUnitTest.java | 2 +- .../ExistingPairsUnitTest.java | 2 +- .../prime/PrimeGeneratorUnitTest.java | 4 +- .../baeldung/random}/JavaRandomUnitTest.java | 2 +- pom.xml | 1 + 41 files changed, 380 insertions(+), 188 deletions(-) delete mode 100644 algorithms/src/main/java/com/baeldung/algorithms/prime/PrimeGenerator.java delete mode 100644 algorithms/src/test/java/com/baeldung/algorithms/prime/PrimeGeneratorUnitTest.java delete mode 100644 core-java/src/main/java/com/baeldung/maths/BigDecimalImpl.java delete mode 100644 core-java/src/main/java/com/baeldung/maths/BigIntegerImpl.java create mode 100644 java-numbers/.gitignore create mode 100644 java-numbers/README.md create mode 100644 java-numbers/pom.xml rename {algorithms => java-numbers}/src/main/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeChecker.java (100%) rename {algorithms => java-numbers}/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java (83%) rename {algorithms => java-numbers}/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java (88%) rename {algorithms => java-numbers}/src/main/java/com/baeldung/algorithms/primechecker/PrimeChecker.java (100%) rename {algorithms => java-numbers}/src/main/java/com/baeldung/algorithms/primechecker/PrimesPrimeChecker.java (100%) rename {core-java => java-numbers}/src/main/java/com/baeldung/maths/FloatingPointArithmetic.java (100%) rename {core-java => java-numbers}/src/main/java/com/baeldung/maths/Round.java (100%) rename {core-java => java-numbers}/src/main/java/com/baeldung/nan/NaNExample.java (100%) rename {core-java => java-numbers}/src/main/java/com/baeldung/numberofdigits/Benchmarking.java (100%) rename {core-java => java-numbers}/src/main/java/com/baeldung/numberofdigits/NumberOfDigits.java (100%) rename {core-java => java-numbers}/src/main/java/com/baeldung/numberofdigits/NumberOfDigitsDriver.java (91%) rename {algorithms/src/main/java/com/baeldung/algorithms => java-numbers/src/main/java/com/baeldung}/pairsaddupnumber/DifferentPairs.java (93%) rename {algorithms/src/main/java/com/baeldung/algorithms => java-numbers/src/main/java/com/baeldung}/pairsaddupnumber/ExistingPairs.java (97%) rename {algorithms/src/main/java/com/baeldung/algorithms => java-numbers/src/main/java/com/baeldung}/pairsaddupnumber/FindPairs.java (98%) rename {core-java => java-numbers}/src/main/java/com/baeldung/pow/PowerExample.java (100%) rename {core-java-8 => java-numbers}/src/main/java/com/baeldung/prime/PrimeGenerator.java (100%) create mode 100644 java-numbers/src/main/resources/log4j.properties create mode 100644 java-numbers/src/main/resources/logback.xml rename {algorithms => java-numbers}/src/test/java/com/baeldung/algorithms/primechecker/PrimeCheckerUnitTest.java (85%) rename {core-java => java-numbers}/src/test/java/com/baeldung/maths/BigDecimalImplUnitTest.java (100%) rename {core-java => java-numbers}/src/test/java/com/baeldung/maths/BigIntegerImplUnitTest.java (100%) rename {core-java => java-numbers}/src/test/java/com/baeldung/maths/FloatingPointArithmeticUnitTest.java (100%) rename {core-java => java-numbers}/src/test/java/com/baeldung/maths/RoundUnitTest.java (95%) rename {core-java => java-numbers}/src/test/java/com/baeldung/numberofdigits/NumberOfDigitsIntegrationTest.java (100%) rename {algorithms/src/test/java/com/baeldung/algorithms => java-numbers/src/test/java/com/baeldung}/pairsaddupnumber/DifferentPairsUnitTest.java (95%) rename {algorithms/src/test/java/com/baeldung/algorithms => java-numbers/src/test/java/com/baeldung}/pairsaddupnumber/ExistingPairsUnitTest.java (94%) rename {core-java-8 => java-numbers}/src/test/java/com/baeldung/prime/PrimeGeneratorUnitTest.java (97%) rename {core-java/src/test/java/org/baeldung/java => java-numbers/src/test/java/com/baeldung/random}/JavaRandomUnitTest.java (99%) diff --git a/algorithms/README.md b/algorithms/README.md index 7e37ef3ec5..14ec7294e7 100644 --- a/algorithms/README.md +++ b/algorithms/README.md @@ -5,7 +5,6 @@ - [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization) - [Validating Input With Finite Automata in Java](http://www.baeldung.com/java-finite-automata) - [Introduction to Jenetics Library](http://www.baeldung.com/jenetics) -- [Check If a Number Is Prime in Java](http://www.baeldung.com/java-prime-numbers) - [Example of Hill Climbing Algorithm](http://www.baeldung.com/java-hill-climbing-algorithm) - [Monte Carlo Tree Search for Tic-Tac-Toe Game](http://www.baeldung.com/java-monte-carlo-tree-search) - [String Search Algorithms for Large Texts](http://www.baeldung.com/java-full-text-search-algorithms) @@ -21,7 +20,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) -- [Find All Pairs of Numbers in an Array That Add Up to a Given Sum](http://www.baeldung.com/java-algorithm-number-pairs-sum) - [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) - [Find the Middle Element of a Linked List](http://www.baeldung.com/java-linked-list-middle-element) diff --git a/algorithms/src/main/java/com/baeldung/algorithms/RunAlgorithm.java b/algorithms/src/main/java/com/baeldung/algorithms/RunAlgorithm.java index c82883425d..ce04d26db3 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/RunAlgorithm.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/RunAlgorithm.java @@ -6,7 +6,6 @@ import com.baeldung.algorithms.ga.annealing.SimulatedAnnealing; import com.baeldung.algorithms.ga.ant_colony.AntColonyOptimization; import com.baeldung.algorithms.ga.binary.SimpleGeneticAlgorithm; import com.baeldung.algorithms.slope_one.SlopeOne; -import com.baeldung.algorithms.pairsaddupnumber.FindPairs; public class RunAlgorithm { @@ -39,12 +38,6 @@ public class RunAlgorithm { case 5: System.out.println("Please run the DijkstraAlgorithmTest."); break; - case 6: - final FindPairs findPairs = new FindPairs(); - final int[] input = {1, 4, 3, 2, 1, 4, 4, 3, 3}; - final int sum = 6; - findPairs.execute(input, sum); - break; default: System.out.println("Unknown option"); break; diff --git a/algorithms/src/main/java/com/baeldung/algorithms/prime/PrimeGenerator.java b/algorithms/src/main/java/com/baeldung/algorithms/prime/PrimeGenerator.java deleted file mode 100644 index 48d51a8848..0000000000 --- a/algorithms/src/main/java/com/baeldung/algorithms/prime/PrimeGenerator.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.baeldung.algorithms.prime; - -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -public class PrimeGenerator { - public static List sieveOfEratosthenes(int n) { - final boolean prime[] = new boolean[n + 1]; - Arrays.fill(prime, true); - - for (int p = 2; p * p <= n; p++) { - if (prime[p]) { - for (int i = p * 2; i <= n; i += p) - prime[i] = false; - } - } - - final List primes = new LinkedList<>(); - for (int i = 2; i <= n; i++) { - if (prime[i]) - primes.add(i); - } - return primes; - } - - public static List primeNumbersBruteForce(int max) { - final List primeNumbers = new LinkedList(); - for (int i = 2; i <= max; i++) { - if (isPrimeBruteForce(i)) { - primeNumbers.add(i); - } - } - return primeNumbers; - } - - private static boolean isPrimeBruteForce(int x) { - for (int i = 2; i < x; i++) { - if (x % i == 0) { - return false; - } - } - return true; - } - - public static List primeNumbersTill(int max) { - return IntStream.rangeClosed(2, max) - .filter(x -> isPrime(x)) - .boxed() - .collect(Collectors.toList()); - } - - private static boolean isPrime(int x) { - return IntStream.rangeClosed(2, (int) (Math.sqrt(x))) - .allMatch(n -> x % n != 0); - } -} diff --git a/algorithms/src/test/java/com/baeldung/algorithms/prime/PrimeGeneratorUnitTest.java b/algorithms/src/test/java/com/baeldung/algorithms/prime/PrimeGeneratorUnitTest.java deleted file mode 100644 index ffa1404eac..0000000000 --- a/algorithms/src/test/java/com/baeldung/algorithms/prime/PrimeGeneratorUnitTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.algorithms.prime; - -import static com.baeldung.algorithms.prime.PrimeGenerator.*; - -import java.util.Arrays; -import java.util.List; -import org.junit.Test; -import static org.junit.Assert.*; - -public class PrimeGeneratorUnitTest { - @Test - public void whenBruteForced_returnsSuccessfully() { - final List primeNumbers = primeNumbersBruteForce(20); - assertEquals(Arrays.asList(new Integer[] { 2, 3, 5, 7, 11, 13, 17, 19 }), primeNumbers); - } - - @Test - public void whenOptimized_returnsSuccessfully() { - final List primeNumbers = primeNumbersTill(20); - assertEquals(Arrays.asList(new Integer[] { 2, 3, 5, 7, 11, 13, 17, 19 }), primeNumbers); - } - - @Test - public void whenSieveOfEratosthenes_returnsSuccessfully() { - final List primeNumbers = sieveOfEratosthenes(20); - assertEquals(Arrays.asList(new Integer[] { 2, 3, 5, 7, 11, 13, 17, 19 }), primeNumbers); - } -} diff --git a/core-java-8/README.md b/core-java-8/README.md index 7993bd93d8..dcf7b24ef8 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -32,7 +32,6 @@ - [“Stream has already been operated upon or closed” Exception in Java](http://www.baeldung.com/java-stream-operated-upon-or-closed-exception) - [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones) - [Copy a File with Java](http://www.baeldung.com/java-copy-file) -- [Generating Prime Numbers in Java](http://www.baeldung.com/java-generate-prime-numbers) - [Static and Default Methods in Interfaces in Java](http://www.baeldung.com/java-static-default-methods) - [Iterable to Stream in Java](http://www.baeldung.com/java-iterable-to-stream) - [Converting String to Stream of chars](http://www.baeldung.com/java-string-to-stream) diff --git a/core-java/README.md b/core-java/README.md index 6e50d3e458..185b3e4eb7 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -3,7 +3,6 @@ ## Core Java Cookbooks and Examples ### Relevant Articles: -- [Java – Random Long, Float, Integer and Double](http://www.baeldung.com/java-generate-random-long-float-integer-double) - [Java – Generate Random String](http://www.baeldung.com/java-random-string) - [Java Timer](http://www.baeldung.com/java-timer-and-timertask) - [How to Run a Shell Command in Java](http://www.baeldung.com/run-shell-command-in-java) @@ -38,7 +37,6 @@ - [A Quick JUnit vs TestNG Comparison](http://www.baeldung.com/junit-vs-testng) - [Java Primitive Conversions](http://www.baeldung.com/java-primitive-conversions) - [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency) -- [Using Math.pow in Java](http://www.baeldung.com/java-math-pow) - [Converting Strings to Enums in Java](http://www.baeldung.com/java-string-to-enum) - [Quick Guide to the Java StringTokenizer](http://www.baeldung.com/java-stringtokenizer) - [JVM Log Forging](http://www.baeldung.com/jvm-log-forging) @@ -49,7 +47,6 @@ - [How to Add a Single Element to a Stream](http://www.baeldung.com/java-stream-append-prepend) - [Iterating Over Enum Values in Java](http://www.baeldung.com/java-enum-iteration) - [Kotlin Java Interoperability](http://www.baeldung.com/kotlin-java-interoperability) -- [How to Round a Number to N Decimal Places in Java](http://www.baeldung.com/java-round-decimal-number) - [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params) - [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null) - [Changing the Order in a Sum Operation Can Produce Different Results?](http://www.baeldung.com/java-floating-point-sum-order) @@ -77,7 +74,6 @@ - [“Sneaky Throws” in Java](http://www.baeldung.com/java-sneaky-throws) - [OutOfMemoryError: GC Overhead Limit Exceeded](http://www.baeldung.com/java-gc-overhead-limit-exceeded) - [StringBuilder and StringBuffer in Java](http://www.baeldung.com/java-string-builder-string-buffer) -- [Number of Digits in an Integer in Java](http://www.baeldung.com/java-number-of-digits-in-int) - [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin) - [A Guide to the Static Keyword in Java](http://www.baeldung.com/java-static) - [Initializing Arrays in Java](http://www.baeldung.com/java-initialize-array) @@ -132,7 +128,6 @@ - [Find Sum and Average in a Java Array](http://www.baeldung.com/java-array-sum-average) - [Java List UnsupportedOperationException](http://www.baeldung.com/java-list-unsupported-operation-exception) - [Type Erasure in Java Explained](http://www.baeldung.com/java-type-erasure) -- [BigDecimal and BigInteger in Java](http://www.baeldung.com/java-bigdecimal-biginteger) - [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones) - [Join and Split Arrays and Collections in Java](http://www.baeldung.com/java-join-and-split) - [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality) @@ -147,7 +142,6 @@ - [Check If a String Is Numeric in Java](http://www.baeldung.com/java-check-string-number) - [Variable and Method Hiding in Java](http://www.baeldung.com/java-variable-method-hiding) - [Access Modifiers in Java](http://www.baeldung.com/java-access-modifiers) -- [NaN in Java](http://www.baeldung.com/java-not-a-number) - [Infinite Loops in Java](http://www.baeldung.com/infinite-loops-java) - [Why Use char[] Array Over a String for Storing Passwords in Java?](http://www.baeldung.com/java-storing-passwords) - [Introduction to Creational Design Patterns](http://www.baeldung.com/creational-design-patterns) diff --git a/core-java/pom.xml b/core-java/pom.xml index d7f700ff14..6ead63cfab 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -25,16 +25,6 @@ commons-lang3 ${commons-lang3.version} - - org.apache.commons - commons-math3 - ${commons-math3.version} - - - org.decimal4j - decimal4j - ${decimal4j.version} - org.bouncycastle bcprov-jdk15on @@ -393,6 +383,7 @@ 3.5 1.55 1.10 + 2.5 3.6.1 1.0.3 0.4 diff --git a/core-java/src/main/java/com/baeldung/maths/BigDecimalImpl.java b/core-java/src/main/java/com/baeldung/maths/BigDecimalImpl.java deleted file mode 100644 index 1472dd7d6d..0000000000 --- a/core-java/src/main/java/com/baeldung/maths/BigDecimalImpl.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.maths; - -import java.math.BigDecimal; -import java.math.RoundingMode; - -public class BigDecimalImpl { - - public static void main(String[] args) { - - BigDecimal serviceTax = new BigDecimal("56.0084578639"); - serviceTax = serviceTax.setScale(2, RoundingMode.CEILING); - - BigDecimal entertainmentTax = new BigDecimal("23.00689"); - entertainmentTax = entertainmentTax.setScale(2, RoundingMode.FLOOR); - - BigDecimal totalTax = serviceTax.add(entertainmentTax); - } -} diff --git a/core-java/src/main/java/com/baeldung/maths/BigIntegerImpl.java b/core-java/src/main/java/com/baeldung/maths/BigIntegerImpl.java deleted file mode 100644 index 9f46345e04..0000000000 --- a/core-java/src/main/java/com/baeldung/maths/BigIntegerImpl.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.maths; - -import java.math.BigInteger; - -public class BigIntegerImpl { - - public static void main(String[] args) { - - BigInteger numStarsMilkyWay = new BigInteger("8731409320171337804361260816606476"); - BigInteger numStarsAndromeda = new BigInteger("5379309320171337804361260816606476"); - - BigInteger totalStars = numStarsMilkyWay.add(numStarsAndromeda); - - } - -} diff --git a/java-numbers/.gitignore b/java-numbers/.gitignore new file mode 100644 index 0000000000..3de4cc647e --- /dev/null +++ b/java-numbers/.gitignore @@ -0,0 +1,26 @@ +*.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 +*.txt +backup-pom.xml +/bin/ +/temp + +#IntelliJ specific +.idea/ +*.iml \ No newline at end of file diff --git a/java-numbers/README.md b/java-numbers/README.md new file mode 100644 index 0000000000..6d6a279cc9 --- /dev/null +++ b/java-numbers/README.md @@ -0,0 +1,14 @@ +========= + +## Java Number Cookbooks and Examples + +### Relevant Articles: +- [Number of Digits in an Integer in Java](http://www.baeldung.com/java-number-of-digits-in-int) +- [NaN in Java](http://www.baeldung.com/java-not-a-number) +- [How to Round a Number to N Decimal Places in Java](http://www.baeldung.com/java-round-decimal-number) +- [Check If a Number Is Prime in Java](http://www.baeldung.com/java-prime-numbers) +- [Using Math.pow in Java](http://www.baeldung.com/java-math-pow) +- [Generating Prime Numbers in Java](http://www.baeldung.com/java-generate-prime-numbers) +- [BigDecimal and BigInteger in Java](http://www.baeldung.com/java-bigdecimal-biginteger) +- [Find All Pairs of Numbers in an Array That Add Up to a Given Sum](http://www.baeldung.com/java-algorithm-number-pairs-sum) +- [Java – Random Long, Float, Integer and Double](http://www.baeldung.com/java-generate-random-long-float-integer-double) diff --git a/java-numbers/pom.xml b/java-numbers/pom.xml new file mode 100644 index 0000000000..d1517fa57a --- /dev/null +++ b/java-numbers/pom.xml @@ -0,0 +1,286 @@ + + 4.0.0 + java-numbers + 0.1.0-SNAPSHOT + jar + java-numbers + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../parent-java + + + + log4j + log4j + ${log4j.version} + + + org.slf4j + slf4j-api + ${org.slf4j.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + org.openjdk.jmh + jmh-core + ${jmh-core.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh-generator-annprocess.version} + + + org.apache.commons + commons-math3 + ${commons-math3.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.decimal4j + decimal4j + ${decimal4j.version} + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + java-numbers + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IntegrationTest.java + + 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.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 + + + + **/*IntegrationTest.java + + + + + + + json + + + + + org.codehaus.mojo + exec-maven-plugin + + + + run-benchmarks + + none + + exec + + + test + java + + -classpath + + org.openjdk.jmh.Main + .* + + + + + + + + + + + + 3.6.1 + 1.0.3 + 3.5 + + 3.6.1 + + 1.7.21 + 1.1.7 + 1.19 + 1.19 + + 2.19.1 + 3.0.0-M1 + 3.0.2 + 1.4.4 + 3.1.1 + + diff --git a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeChecker.java b/java-numbers/src/main/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeChecker.java similarity index 100% rename from algorithms/src/main/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeChecker.java rename to java-numbers/src/main/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeChecker.java diff --git a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java b/java-numbers/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java similarity index 83% rename from algorithms/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java rename to java-numbers/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java index 47ffb3e224..68382c26ea 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java +++ b/java-numbers/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java @@ -1,16 +1,14 @@ package com.baeldung.algorithms.primechecker; import java.util.stream.IntStream; -import java.util.stream.LongStream; -public class BruteForcePrimeChecker implements PrimeChecker{ +public class BruteForcePrimeChecker implements PrimeChecker { @Override public boolean isPrime(Integer number) { - + return number > 2 ? IntStream.range(2, number) .noneMatch(n -> (number % n == 0)) : false; } - -} +} diff --git a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java b/java-numbers/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java similarity index 88% rename from algorithms/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java rename to java-numbers/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java index 06ae4acc7f..3dc372ad22 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java +++ b/java-numbers/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java @@ -1,9 +1,8 @@ package com.baeldung.algorithms.primechecker; import java.util.stream.IntStream; -import java.util.stream.LongStream; -public class OptimisedPrimeChecker implements PrimeChecker{ +public class OptimisedPrimeChecker implements PrimeChecker { @Override public boolean isPrime(Integer number) { @@ -11,5 +10,4 @@ public class OptimisedPrimeChecker implements PrimeChecker{ .noneMatch(n -> (number % n == 0)) : false; } - } diff --git a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimeChecker.java b/java-numbers/src/main/java/com/baeldung/algorithms/primechecker/PrimeChecker.java similarity index 100% rename from algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimeChecker.java rename to java-numbers/src/main/java/com/baeldung/algorithms/primechecker/PrimeChecker.java diff --git a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimesPrimeChecker.java b/java-numbers/src/main/java/com/baeldung/algorithms/primechecker/PrimesPrimeChecker.java similarity index 100% rename from algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimesPrimeChecker.java rename to java-numbers/src/main/java/com/baeldung/algorithms/primechecker/PrimesPrimeChecker.java diff --git a/core-java/src/main/java/com/baeldung/maths/FloatingPointArithmetic.java b/java-numbers/src/main/java/com/baeldung/maths/FloatingPointArithmetic.java similarity index 100% rename from core-java/src/main/java/com/baeldung/maths/FloatingPointArithmetic.java rename to java-numbers/src/main/java/com/baeldung/maths/FloatingPointArithmetic.java diff --git a/core-java/src/main/java/com/baeldung/maths/Round.java b/java-numbers/src/main/java/com/baeldung/maths/Round.java similarity index 100% rename from core-java/src/main/java/com/baeldung/maths/Round.java rename to java-numbers/src/main/java/com/baeldung/maths/Round.java diff --git a/core-java/src/main/java/com/baeldung/nan/NaNExample.java b/java-numbers/src/main/java/com/baeldung/nan/NaNExample.java similarity index 100% rename from core-java/src/main/java/com/baeldung/nan/NaNExample.java rename to java-numbers/src/main/java/com/baeldung/nan/NaNExample.java diff --git a/core-java/src/main/java/com/baeldung/numberofdigits/Benchmarking.java b/java-numbers/src/main/java/com/baeldung/numberofdigits/Benchmarking.java similarity index 100% rename from core-java/src/main/java/com/baeldung/numberofdigits/Benchmarking.java rename to java-numbers/src/main/java/com/baeldung/numberofdigits/Benchmarking.java diff --git a/core-java/src/main/java/com/baeldung/numberofdigits/NumberOfDigits.java b/java-numbers/src/main/java/com/baeldung/numberofdigits/NumberOfDigits.java similarity index 100% rename from core-java/src/main/java/com/baeldung/numberofdigits/NumberOfDigits.java rename to java-numbers/src/main/java/com/baeldung/numberofdigits/NumberOfDigits.java diff --git a/core-java/src/main/java/com/baeldung/numberofdigits/NumberOfDigitsDriver.java b/java-numbers/src/main/java/com/baeldung/numberofdigits/NumberOfDigitsDriver.java similarity index 91% rename from core-java/src/main/java/com/baeldung/numberofdigits/NumberOfDigitsDriver.java rename to java-numbers/src/main/java/com/baeldung/numberofdigits/NumberOfDigitsDriver.java index c3cc567eaa..4f98992e98 100755 --- a/core-java/src/main/java/com/baeldung/numberofdigits/NumberOfDigitsDriver.java +++ b/java-numbers/src/main/java/com/baeldung/numberofdigits/NumberOfDigitsDriver.java @@ -4,32 +4,32 @@ import org.apache.log4j.Logger; public class NumberOfDigitsDriver { private static NumberOfDigits numberOfDigits; - + private static Logger LOG = Logger.getLogger(NumberOfDigitsDriver.class); - + static { numberOfDigits = new NumberOfDigits(); } - + public static void main(String[] args) { LOG.info("Testing all methods..."); - + long length = numberOfDigits.stringBasedSolution(602); LOG.info("String Based Solution : " + length); - + length = numberOfDigits.logarithmicApproach(602); LOG.info("Logarithmic Approach : " + length); - + length = numberOfDigits.repeatedMultiplication(602); LOG.info("Repeated Multiplication : " + length); - + length = numberOfDigits.shiftOperators(602); LOG.info("Shift Operators : " + length); - + length = numberOfDigits.dividingWithPowersOf2(602); LOG.info("Dividing with Powers of 2 : " + length); - + length = numberOfDigits.divideAndConquer(602); LOG.info("Divide And Conquer : " + length); } -} +} \ No newline at end of file diff --git a/algorithms/src/main/java/com/baeldung/algorithms/pairsaddupnumber/DifferentPairs.java b/java-numbers/src/main/java/com/baeldung/pairsaddupnumber/DifferentPairs.java similarity index 93% rename from algorithms/src/main/java/com/baeldung/algorithms/pairsaddupnumber/DifferentPairs.java rename to java-numbers/src/main/java/com/baeldung/pairsaddupnumber/DifferentPairs.java index e86e1d5a22..b316957652 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/pairsaddupnumber/DifferentPairs.java +++ b/java-numbers/src/main/java/com/baeldung/pairsaddupnumber/DifferentPairs.java @@ -1,4 +1,4 @@ -package com.baeldung.algorithms.pairsaddupnumber; +package com.baeldung.pairsaddupnumber; import java.util.ArrayList; @@ -23,7 +23,7 @@ public class DifferentPairs { public static List findPairsWithForLoop(int[] input, int sum) { final List allDifferentPairs = new ArrayList<>(); // Aux. hash map - final Map pairs = new HashMap(); + final Map pairs = new HashMap<>(); for (int i : input) { if (pairs.containsKey(i)) { if (pairs.get(i) != null) { @@ -51,7 +51,7 @@ public class DifferentPairs { public static List findPairsWithStreamApi(int[] input, int sum) { final List allDifferentPairs = new ArrayList<>(); // Aux. hash map - final Map pairs = new HashMap(); + final Map pairs = new HashMap<>(); IntStream.range(0, input.length).forEach(i -> { if (pairs.containsKey(input[i])) { if (pairs.get(input[i]) != null) { diff --git a/algorithms/src/main/java/com/baeldung/algorithms/pairsaddupnumber/ExistingPairs.java b/java-numbers/src/main/java/com/baeldung/pairsaddupnumber/ExistingPairs.java similarity index 97% rename from algorithms/src/main/java/com/baeldung/algorithms/pairsaddupnumber/ExistingPairs.java rename to java-numbers/src/main/java/com/baeldung/pairsaddupnumber/ExistingPairs.java index 6b10c73bcf..82c2a54ae6 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/pairsaddupnumber/ExistingPairs.java +++ b/java-numbers/src/main/java/com/baeldung/pairsaddupnumber/ExistingPairs.java @@ -1,4 +1,4 @@ -package com.baeldung.algorithms.pairsaddupnumber; +package com.baeldung.pairsaddupnumber; import java.util.ArrayList; diff --git a/algorithms/src/main/java/com/baeldung/algorithms/pairsaddupnumber/FindPairs.java b/java-numbers/src/main/java/com/baeldung/pairsaddupnumber/FindPairs.java similarity index 98% rename from algorithms/src/main/java/com/baeldung/algorithms/pairsaddupnumber/FindPairs.java rename to java-numbers/src/main/java/com/baeldung/pairsaddupnumber/FindPairs.java index 4b309332ae..b990222b7e 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/pairsaddupnumber/FindPairs.java +++ b/java-numbers/src/main/java/com/baeldung/pairsaddupnumber/FindPairs.java @@ -1,4 +1,4 @@ -package com.baeldung.algorithms.pairsaddupnumber; +package com.baeldung.pairsaddupnumber; import java.util.ArrayList; import java.util.List; diff --git a/core-java/src/main/java/com/baeldung/pow/PowerExample.java b/java-numbers/src/main/java/com/baeldung/pow/PowerExample.java similarity index 100% rename from core-java/src/main/java/com/baeldung/pow/PowerExample.java rename to java-numbers/src/main/java/com/baeldung/pow/PowerExample.java diff --git a/core-java-8/src/main/java/com/baeldung/prime/PrimeGenerator.java b/java-numbers/src/main/java/com/baeldung/prime/PrimeGenerator.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/prime/PrimeGenerator.java rename to java-numbers/src/main/java/com/baeldung/prime/PrimeGenerator.java diff --git a/java-numbers/src/main/resources/log4j.properties b/java-numbers/src/main/resources/log4j.properties new file mode 100644 index 0000000000..621cf01735 --- /dev/null +++ b/java-numbers/src/main/resources/log4j.properties @@ -0,0 +1,6 @@ +log4j.rootLogger=DEBUG, A1 + +log4j.appender.A1=org.apache.log4j.ConsoleAppender + +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n \ No newline at end of file diff --git a/java-numbers/src/main/resources/logback.xml b/java-numbers/src/main/resources/logback.xml new file mode 100644 index 0000000000..f8ebaf1ebd --- /dev/null +++ b/java-numbers/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + \ No newline at end of file diff --git a/algorithms/src/test/java/com/baeldung/algorithms/primechecker/PrimeCheckerUnitTest.java b/java-numbers/src/test/java/com/baeldung/algorithms/primechecker/PrimeCheckerUnitTest.java similarity index 85% rename from algorithms/src/test/java/com/baeldung/algorithms/primechecker/PrimeCheckerUnitTest.java rename to java-numbers/src/test/java/com/baeldung/algorithms/primechecker/PrimeCheckerUnitTest.java index 9203131397..9f8ba8defd 100644 --- a/algorithms/src/test/java/com/baeldung/algorithms/primechecker/PrimeCheckerUnitTest.java +++ b/java-numbers/src/test/java/com/baeldung/algorithms/primechecker/PrimeCheckerUnitTest.java @@ -8,16 +8,16 @@ import static org.junit.Assert.assertTrue; public class PrimeCheckerUnitTest { private final BigIntegerPrimeChecker primeChecker = new BigIntegerPrimeChecker(); - + @Test - public void whenCheckIsPrime_thenTrue(){ + public void whenCheckIsPrime_thenTrue() { assertTrue(primeChecker.isPrime(13l)); assertTrue(primeChecker.isPrime(1009L)); assertTrue(primeChecker.isPrime(74207281L)); } - + @Test - public void whenCheckIsPrime_thenFalse(){ + public void whenCheckIsPrime_thenFalse() { assertTrue(!primeChecker.isPrime(50L)); assertTrue(!primeChecker.isPrime(1001L)); assertTrue(!primeChecker.isPrime(74207282L)); @@ -26,28 +26,27 @@ public class PrimeCheckerUnitTest { private final BruteForcePrimeChecker bfPrimeChecker = new BruteForcePrimeChecker(); @Test - public void whenBFCheckIsPrime_thenTrue(){ + public void whenBFCheckIsPrime_thenTrue() { assertTrue(bfPrimeChecker.isPrime(13)); assertTrue(bfPrimeChecker.isPrime(1009)); } @Test - public void whenBFCheckIsPrime_thenFalse(){ + public void whenBFCheckIsPrime_thenFalse() { assertFalse(bfPrimeChecker.isPrime(50)); assertFalse(bfPrimeChecker.isPrime(1001)); } - private final OptimisedPrimeChecker optimisedPrimeChecker = new OptimisedPrimeChecker(); @Test - public void whenOptCheckIsPrime_thenTrue(){ + public void whenOptCheckIsPrime_thenTrue() { assertTrue(optimisedPrimeChecker.isPrime(13)); assertTrue(optimisedPrimeChecker.isPrime(1009)); } @Test - public void whenOptCheckIsPrime_thenFalse(){ + public void whenOptCheckIsPrime_thenFalse() { assertFalse(optimisedPrimeChecker.isPrime(50)); assertFalse(optimisedPrimeChecker.isPrime(1001)); } @@ -65,5 +64,5 @@ public class PrimeCheckerUnitTest { assertFalse(primesPrimeChecker.isPrime(50)); assertFalse(primesPrimeChecker.isPrime(1001)); } - + } diff --git a/core-java/src/test/java/com/baeldung/maths/BigDecimalImplUnitTest.java b/java-numbers/src/test/java/com/baeldung/maths/BigDecimalImplUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/maths/BigDecimalImplUnitTest.java rename to java-numbers/src/test/java/com/baeldung/maths/BigDecimalImplUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/maths/BigIntegerImplUnitTest.java b/java-numbers/src/test/java/com/baeldung/maths/BigIntegerImplUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/maths/BigIntegerImplUnitTest.java rename to java-numbers/src/test/java/com/baeldung/maths/BigIntegerImplUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/maths/FloatingPointArithmeticUnitTest.java b/java-numbers/src/test/java/com/baeldung/maths/FloatingPointArithmeticUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/maths/FloatingPointArithmeticUnitTest.java rename to java-numbers/src/test/java/com/baeldung/maths/FloatingPointArithmeticUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/maths/RoundUnitTest.java b/java-numbers/src/test/java/com/baeldung/maths/RoundUnitTest.java similarity index 95% rename from core-java/src/test/java/com/baeldung/maths/RoundUnitTest.java rename to java-numbers/src/test/java/com/baeldung/maths/RoundUnitTest.java index f3c8e6e97a..7e3f5d6c63 100644 --- a/core-java/src/test/java/com/baeldung/maths/RoundUnitTest.java +++ b/java-numbers/src/test/java/com/baeldung/maths/RoundUnitTest.java @@ -5,9 +5,6 @@ import org.decimal4j.util.DoubleRounder; import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - public class RoundUnitTest { private double value = 2.03456d; private int places = 2; diff --git a/core-java/src/test/java/com/baeldung/numberofdigits/NumberOfDigitsIntegrationTest.java b/java-numbers/src/test/java/com/baeldung/numberofdigits/NumberOfDigitsIntegrationTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/numberofdigits/NumberOfDigitsIntegrationTest.java rename to java-numbers/src/test/java/com/baeldung/numberofdigits/NumberOfDigitsIntegrationTest.java diff --git a/algorithms/src/test/java/com/baeldung/algorithms/pairsaddupnumber/DifferentPairsUnitTest.java b/java-numbers/src/test/java/com/baeldung/pairsaddupnumber/DifferentPairsUnitTest.java similarity index 95% rename from algorithms/src/test/java/com/baeldung/algorithms/pairsaddupnumber/DifferentPairsUnitTest.java rename to java-numbers/src/test/java/com/baeldung/pairsaddupnumber/DifferentPairsUnitTest.java index 48fcfb871c..4f7c9b5a29 100644 --- a/algorithms/src/test/java/com/baeldung/algorithms/pairsaddupnumber/DifferentPairsUnitTest.java +++ b/java-numbers/src/test/java/com/baeldung/pairsaddupnumber/DifferentPairsUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.algorithms.pairsaddupnumber; +package com.baeldung.pairsaddupnumber; import org.junit.Test; diff --git a/algorithms/src/test/java/com/baeldung/algorithms/pairsaddupnumber/ExistingPairsUnitTest.java b/java-numbers/src/test/java/com/baeldung/pairsaddupnumber/ExistingPairsUnitTest.java similarity index 94% rename from algorithms/src/test/java/com/baeldung/algorithms/pairsaddupnumber/ExistingPairsUnitTest.java rename to java-numbers/src/test/java/com/baeldung/pairsaddupnumber/ExistingPairsUnitTest.java index ac6d6cc885..593db5b894 100644 --- a/algorithms/src/test/java/com/baeldung/algorithms/pairsaddupnumber/ExistingPairsUnitTest.java +++ b/java-numbers/src/test/java/com/baeldung/pairsaddupnumber/ExistingPairsUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.algorithms.pairsaddupnumber; +package com.baeldung.pairsaddupnumber; import org.junit.Test; import java.util.List; diff --git a/core-java-8/src/test/java/com/baeldung/prime/PrimeGeneratorUnitTest.java b/java-numbers/src/test/java/com/baeldung/prime/PrimeGeneratorUnitTest.java similarity index 97% rename from core-java-8/src/test/java/com/baeldung/prime/PrimeGeneratorUnitTest.java rename to java-numbers/src/test/java/com/baeldung/prime/PrimeGeneratorUnitTest.java index 0e7396c9dd..210bde076b 100644 --- a/core-java-8/src/test/java/com/baeldung/prime/PrimeGeneratorUnitTest.java +++ b/java-numbers/src/test/java/com/baeldung/prime/PrimeGeneratorUnitTest.java @@ -1,10 +1,10 @@ package com.baeldung.prime; -import static com.baeldung.prime.PrimeGenerator.*; - import java.util.Arrays; import java.util.List; import org.junit.Test; + +import static com.baeldung.prime.PrimeGenerator.*; import static org.junit.Assert.*; public class PrimeGeneratorUnitTest { diff --git a/core-java/src/test/java/org/baeldung/java/JavaRandomUnitTest.java b/java-numbers/src/test/java/com/baeldung/random/JavaRandomUnitTest.java similarity index 99% rename from core-java/src/test/java/org/baeldung/java/JavaRandomUnitTest.java rename to java-numbers/src/test/java/com/baeldung/random/JavaRandomUnitTest.java index f17531e744..2273dfda13 100644 --- a/core-java/src/test/java/org/baeldung/java/JavaRandomUnitTest.java +++ b/java-numbers/src/test/java/com/baeldung/random/JavaRandomUnitTest.java @@ -1,4 +1,4 @@ -package org.baeldung.java; +package com.baeldung.random; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.math3.random.RandomDataGenerator; diff --git a/pom.xml b/pom.xml index 51a62d929c..5ed7f7c33f 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,7 @@ persistence-modules/java-cassandra vavr java-lite + java-numbers java-rmi java-vavr-stream javax-servlets