code for BAEL-747 after incorporating review comments (#1560)

This commit is contained in:
Mohamed Sanaulla 2017-04-01 22:51:12 +03:00 committed by maibin
parent 15a4a23099
commit 0b17547d20
10 changed files with 29 additions and 12 deletions

View File

@ -10,9 +10,15 @@
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
<exec-maven-plugin.version>1.5.0</exec-maven-plugin.version>
<lombok.version>1.16.12</lombok.version>
<commons-math3.version>3.6.1</commons-math3.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>${commons-math3.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

View File

@ -1,4 +1,4 @@
package com.baeldung.primechecker;
package com.baeldung.algorithms.primechecker;
import java.math.BigInteger;

View File

@ -1,4 +1,4 @@
package com.baeldung.primechecker;
package com.baeldung.algorithms.primechecker;
import java.util.stream.IntStream;
@ -6,7 +6,7 @@ public class BruteForcePrimeChecker implements PrimeChecker{
@Override
public boolean isPrime(int number) {
return IntStream.range(2, number).filter(n -> (number % n == 0)).count() == 0;
return IntStream.range(2, number).noneMatch(n -> (number % n == 0));
}

View File

@ -1,4 +1,4 @@
package com.baeldung.primechecker;
package com.baeldung.algorithms.primechecker;
import java.util.stream.IntStream;
@ -7,8 +7,7 @@ public class OptimisedPrimeChecker implements PrimeChecker{
@Override
public boolean isPrime(int number) {
return IntStream.range(2, (int)Math.sqrt(number) + 1)
.filter(n -> (number % n == 0))
.count() == 0;
.noneMatch(n -> (number % n == 0));
}

View File

@ -1,4 +1,4 @@
package com.baeldung.primechecker;
package com.baeldung.algorithms.primechecker;
public interface PrimeChecker {

View File

@ -1,4 +1,4 @@
package com.baeldung.primechecker;
package com.baeldung.algorithms.primechecker;
import org.apache.commons.math3.primes.Primes;

View File

@ -1,9 +1,12 @@
package com.baeldung.primechecker;
package com.baeldung.algorithms.primechecker;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.baeldung.algorithms.primechecker.BigIntegerPrimeChecker;
import com.baeldung.algorithms.primechecker.PrimeChecker;
public class BigIntegerPrimeCheckerTest {
PrimeChecker primeChecker = new BigIntegerPrimeChecker();

View File

@ -1,6 +1,9 @@
package com.baeldung.primechecker;
package com.baeldung.algorithms.primechecker;
import org.junit.Test;
import com.baeldung.algorithms.primechecker.BruteForcePrimeChecker;
import static org.junit.Assert.*;
public class BruteForcePrimeCheckerTest {

View File

@ -1,9 +1,12 @@
package com.baeldung.primechecker;
package com.baeldung.algorithms.primechecker;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.baeldung.algorithms.primechecker.OptimisedPrimeChecker;
import com.baeldung.algorithms.primechecker.PrimeChecker;
public class OptimisedPrimeCheckerTest {
PrimeChecker primeChecker = new OptimisedPrimeChecker();

View File

@ -1,9 +1,12 @@
package com.baeldung.primechecker;
package com.baeldung.algorithms.primechecker;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.baeldung.algorithms.primechecker.PrimeChecker;
import com.baeldung.algorithms.primechecker.PrimesPrimeChecker;
public class PrimesPrimeCheckerTest {
PrimeChecker primeChecker = new PrimesPrimeChecker();