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
This commit is contained in:
parent
de2afd7da8
commit
b44883b364
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Integer> 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<Integer> primes = new LinkedList<>();
|
||||
for (int i = 2; i <= n; i++) {
|
||||
if (prime[i])
|
||||
primes.add(i);
|
||||
}
|
||||
return primes;
|
||||
}
|
||||
|
||||
public static List<Integer> primeNumbersBruteForce(int max) {
|
||||
final List<Integer> primeNumbers = new LinkedList<Integer>();
|
||||
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<Integer> 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);
|
||||
}
|
||||
}
|
|
@ -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<Integer> primeNumbers = primeNumbersBruteForce(20);
|
||||
assertEquals(Arrays.asList(new Integer[] { 2, 3, 5, 7, 11, 13, 17, 19 }), primeNumbers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOptimized_returnsSuccessfully() {
|
||||
final List<Integer> primeNumbers = primeNumbersTill(20);
|
||||
assertEquals(Arrays.asList(new Integer[] { 2, 3, 5, 7, 11, 13, 17, 19 }), primeNumbers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSieveOfEratosthenes_returnsSuccessfully() {
|
||||
final List<Integer> primeNumbers = sieveOfEratosthenes(20);
|
||||
assertEquals(Arrays.asList(new Integer[] { 2, 3, 5, 7, 11, 13, 17, 19 }), primeNumbers);
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -25,16 +25,6 @@
|
|||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
<version>${commons-math3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.decimal4j</groupId>
|
||||
<artifactId>decimal4j</artifactId>
|
||||
<version>${decimal4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
|
@ -393,6 +383,7 @@
|
|||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<bouncycastle.version>1.55</bouncycastle.version>
|
||||
<commons-codec.version>1.10</commons-codec.version>
|
||||
<commons-io.version>2.5</commons-io.version>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<decimal4j.version>1.0.3</decimal4j.version>
|
||||
<unix4j.version>0.4</unix4j.version>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
|
@ -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)
|
|
@ -0,0 +1,286 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>java-numbers</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>java-numbers</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-java</relativePath>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh-generator-annprocess.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
<version>${commons-math3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.decimal4j</groupId>
|
||||
<artifactId>decimal4j</artifactId>
|
||||
<version>${decimal4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>java-numbers</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
</excludes>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/libs</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>${maven-jar-plugin.version}</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>libs/</classpathPrefix>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>${maven-shade-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>com.jolira</groupId>
|
||||
<artifactId>onejar-maven-plugin</artifactId>
|
||||
<version>${onejar-maven-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<configuration>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
<attachToBuild>true</attachToBuild>
|
||||
<filename>${project.build.finalName}-onejar.${project.packaging}</filename>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>one-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<mainClass>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</mainClass>
|
||||
<arguments>
|
||||
<argument>-Xmx300m</argument>
|
||||
<argument>-XX:+UseParallelGC</argument>
|
||||
<argument>-classpath</argument>
|
||||
<classpath />
|
||||
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>${maven-javadoc-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>integration</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*IntegrationTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<test.mime>json</test.mime>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>run-benchmarks</id>
|
||||
<!-- <phase>integration-test</phase> -->
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classpathScope>test</classpathScope>
|
||||
<executable>java</executable>
|
||||
<arguments>
|
||||
<argument>-classpath</argument>
|
||||
<classpath />
|
||||
<argument>org.openjdk.jmh.Main</argument>
|
||||
<argument>.*</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<decimal4j.version>1.0.3</decimal4j.version>
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
|
||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
||||
<logback.version>1.1.7</logback.version>
|
||||
<jmh-core.version>1.19</jmh-core.version>
|
||||
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
|
||||
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||
<onejar-maven-plugin.version>1.4.4</onejar-maven-plugin.version>
|
||||
<maven-shade-plugin.version>3.1.1</maven-shade-plugin.version>
|
||||
</properties>
|
||||
</project>
|
|
@ -1,9 +1,8 @@
|
|||
package com.baeldung.algorithms.primechecker;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
public class BruteForcePrimeChecker implements PrimeChecker<Integer>{
|
||||
public class BruteForcePrimeChecker implements PrimeChecker<Integer> {
|
||||
|
||||
@Override
|
||||
public boolean isPrime(Integer number) {
|
||||
|
@ -12,5 +11,4 @@ public class BruteForcePrimeChecker implements PrimeChecker<Integer>{
|
|||
.noneMatch(n -> (number % n == 0)) : false;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
package com.baeldung.algorithms.primechecker;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
public class OptimisedPrimeChecker implements PrimeChecker<Integer>{
|
||||
public class OptimisedPrimeChecker implements PrimeChecker<Integer> {
|
||||
|
||||
@Override
|
||||
public boolean isPrime(Integer number) {
|
||||
|
@ -11,5 +10,4 @@ public class OptimisedPrimeChecker implements PrimeChecker<Integer>{
|
|||
.noneMatch(n -> (number % n == 0)) : false;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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<Integer> findPairsWithForLoop(int[] input, int sum) {
|
||||
final List<Integer> allDifferentPairs = new ArrayList<>();
|
||||
// Aux. hash map
|
||||
final Map<Integer, Integer> pairs = new HashMap();
|
||||
final Map<Integer, Integer> 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<Integer> findPairsWithStreamApi(int[] input, int sum) {
|
||||
final List<Integer> allDifferentPairs = new ArrayList<>();
|
||||
// Aux. hash map
|
||||
final Map<Integer, Integer> pairs = new HashMap();
|
||||
final Map<Integer, Integer> pairs = new HashMap<>();
|
||||
IntStream.range(0, input.length).forEach(i -> {
|
||||
if (pairs.containsKey(input[i])) {
|
||||
if (pairs.get(input[i]) != null) {
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.algorithms.pairsaddupnumber;
|
||||
package com.baeldung.pairsaddupnumber;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.algorithms.pairsaddupnumber;
|
||||
package com.baeldung.pairsaddupnumber;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
|
@ -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
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>web - %date [%thread] %-5level %logger{36} - %message%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
|
@ -10,14 +10,14 @@ 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));
|
||||
}
|
|
@ -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;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.algorithms.pairsaddupnumber;
|
||||
package com.baeldung.pairsaddupnumber;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.algorithms.pairsaddupnumber;
|
||||
package com.baeldung.pairsaddupnumber;
|
||||
|
||||
import org.junit.Test;
|
||||
import java.util.List;
|
|
@ -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 {
|
|
@ -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;
|
Loading…
Reference in New Issue