Skip to content

Commit

Permalink
Update versions of Maven plugins and dependencies; use primes code in…
Browse files Browse the repository at this point in the history
… Commons Math instead of old custom code

git-svn-id: https://svn.apache.org/repos/asf/mahout/trunk@1465367 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
srowen committed Apr 7, 2013
1 parent 17270d8 commit 46ed1c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 91 deletions.
43 changes: 4 additions & 39 deletions math/src/main/java/org/apache/mahout/common/RandomUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@
import java.util.WeakHashMap;

import com.google.common.primitives.Longs;
import org.apache.commons.math3.primes.Primes;

/**
* <p>
* The source of random stuff for the whole project. This lets us make all randomness in the project
* predictable, if desired, for when we run unit tests, which should be repeatable.
* </p>
*
* <p>
* This class is increasingly incorrectly named as it also includes other mathematical utility methods.
* </p>
*/
public final class RandomUtils {

Expand Down Expand Up @@ -93,43 +90,11 @@ public static int nextTwinPrime(int n) {
if (n <= 3) {
return 5;
}
int next = nextPrime(n);
while (isNotPrime(next + 2)) {
next = nextPrime(next + 4);
int next = Primes.nextPrime(n);
while (!Primes.isPrime(next + 2)) {
next = Primes.nextPrime(next + 4);
}
return next + 2;
}

/**
* <p>
* Finds smallest prime p such that p is greater than or equal to n.
* </p>
*/
public static int nextPrime(int n) {
if (n <= 2) {
return 2;
}
// Make sure the number is odd. Is this too clever?
n |= 0x1;
// There is no problem with overflow since Integer.MAX_INT is prime, as it happens
while (isNotPrime(n)) {
n += 2;
}
return n;
}

/** @return {@code true} iff n is not a prime */
public static boolean isNotPrime(int n) {
if (n < 2 || (n & 0x1) == 0) { // < 2 or even
return n != 2;
}
int max = 1 + (int) Math.sqrt(n);
for (int d = 3; d <= max; d += 2) {
if (n % d == 0) {
return true;
}
}
return false;
}

}
26 changes: 0 additions & 26 deletions math/src/test/java/org/apache/mahout/common/RandomUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,6 @@ public void testHashFloat() {
assertEquals(new Float(Float.NaN).hashCode(), RandomUtils.hashFloat(Float.NaN));
}

@Test
public void testIsNotPrime() {
assertTrue(RandomUtils.isNotPrime(Integer.MIN_VALUE));
assertTrue(RandomUtils.isNotPrime(-1));
assertTrue(RandomUtils.isNotPrime(0));
assertTrue(RandomUtils.isNotPrime(1));
assertTrue(!RandomUtils.isNotPrime(2));
assertTrue(!RandomUtils.isNotPrime(3));
assertTrue(RandomUtils.isNotPrime(4));
assertTrue(!RandomUtils.isNotPrime(5));
assertTrue(RandomUtils.isNotPrime(Integer.MAX_VALUE - 1));
assertTrue(!RandomUtils.isNotPrime(Integer.MAX_VALUE)); // 2^31 - 1
}

@Test
public void testNextPrime() {
assertEquals(2, RandomUtils.nextPrime(-1));
assertEquals(2, RandomUtils.nextPrime(1));
assertEquals(2, RandomUtils.nextPrime(2));
assertEquals(3, RandomUtils.nextPrime(3));
assertEquals(5, RandomUtils.nextPrime(4));
assertEquals(5, RandomUtils.nextPrime(5));
assertEquals(7, RandomUtils.nextPrime(6));
assertEquals(Integer.MAX_VALUE, RandomUtils.nextPrime(Integer.MAX_VALUE - 1));
}

@Test
public void testNextTwinPrime() {
assertEquals(5, RandomUtils.nextTwinPrime(-1));
Expand Down
52 changes: 26 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<skipTests>false</skipTests>
<maven.clover.multiproject>true</maven.clover.multiproject>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hadoop.version>1.1.1</hadoop.version>
<hadoop.version>1.1.2</hadoop.version>
<lucene.version>4.2.0</lucene.version>
</properties>
<issueManagement>
Expand Down Expand Up @@ -334,12 +334,12 @@
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.11</version>
<version>1.9.12</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.11</version>
<version>1.9.12</version>
</dependency>

<dependency>
Expand All @@ -357,12 +357,12 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jcl</artifactId>
<version>1.7.2</version>
<version>1.7.5</version>
<scope>test</scope>
</dependency>

Expand All @@ -381,7 +381,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.1.1</version>
<version>3.2</version>
</dependency>

<dependency>
Expand All @@ -393,7 +393,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0.1</version>
<version>14.0.1</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -425,7 +425,7 @@
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>2.5.1</versionRange>
<versionRange>2.7</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
Expand Down Expand Up @@ -481,7 +481,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -491,7 +491,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -546,7 +546,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4</version>
<version>2.4.1</version>
<configuration>
<useReleaseProfile>true</useReleaseProfile>
<releaseProfiles>release,mahout_release</releaseProfiles>
Expand All @@ -570,7 +570,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<version>2.10</version>
<dependencies>
<dependency>
<groupId>org.apache.mahout</groupId>
Expand Down Expand Up @@ -601,7 +601,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<version>3.0.1</version>
<dependencies>
<dependency>
<groupId>org.apache.mahout</groupId>
Expand Down Expand Up @@ -635,7 +635,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<version>2.14</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -660,7 +660,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<version>1.8</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down Expand Up @@ -691,7 +691,7 @@
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>3.1.7</version>
<version>3.1.10.1</version>
</plugin>
</plugins>
<resources>
Expand Down Expand Up @@ -804,12 +804,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<version>2.10</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<version>3.0.1</version>
</plugin>
</plugins>
</build>
Expand Down Expand Up @@ -860,13 +860,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.13</version>
<version>2.14</version>
</plugin>
<!-- checkstyle -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<version>2.10</version>
<configuration>
<configLocation>${project.build.directory}/../../buildtools/src/main/resources/mahout-checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
Expand All @@ -876,7 +876,7 @@
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>3.1.7</version>
<version>3.1.10.1</version>
<configuration>
<generateHistorical>true</generateHistorical>
<licenseLocation>buildtools/clover.license</licenseLocation>
Expand All @@ -895,7 +895,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<version>3.0.1</version>
<configuration>
<rulesets>
<ruleset>../buildtools/src/main/resources/mahout-pmd-ruleset.xml</ruleset>
Expand Down Expand Up @@ -940,7 +940,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changes-plugin</artifactId>
<version>2.8</version>
<version>2.9</version>
<configuration>
<onlyCurrentVersion>true</onlyCurrentVersion>
<columnNames>Type,Key,Summary,Status,Resolution,Assignee</columnNames>
Expand All @@ -957,7 +957,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.13</version>
<version>2.14</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -967,7 +967,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.5.1</version>
<version>2.6</version>
<reportSets>
<reportSet>
<reports>
Expand All @@ -982,7 +982,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down

0 comments on commit 46ed1c0

Please sign in to comment.