You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2015/10/17 11:13:28 UTC

[1/4] [lang] Add sugar to RandomIUtils

Repository: commons-lang
Updated Branches:
  refs/heads/master 881c5fa3d -> c9cae602e


Add sugar to RandomIUtils


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/31466db6
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/31466db6
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/31466db6

Branch: refs/heads/master
Commit: 31466db6ecd115aa74616e14a75721b45c0f59f9
Parents: 00fafe7
Author: Vincent Potucek <vi...@1und1.de>
Authored: Mon Oct 12 09:47:40 2015 +0200
Committer: Vincent Potucek <vi...@1und1.de>
Committed: Mon Oct 12 09:47:40 2015 +0200

----------------------------------------------------------------------
 .../org/apache/commons/lang3/RandomUtils.java   | 45 +++++++++++++++++---
 .../apache/commons/lang3/RandomUtilsTest.java   | 43 ++++++++++++++++++-
 2 files changed, 81 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/31466db6/src/main/java/org/apache/commons/lang3/RandomUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/RandomUtils.java b/src/main/java/org/apache/commons/lang3/RandomUtils.java
index 6bba274..16188c6 100644
--- a/src/main/java/org/apache/commons/lang3/RandomUtils.java
+++ b/src/main/java/org/apache/commons/lang3/RandomUtils.java
@@ -90,6 +90,15 @@ public class RandomUtils {
         
         return startInclusive + RANDOM.nextInt(endExclusive - startInclusive);
     }
+
+    /**
+     * <p> Returns a random int within 0 - Integer.MAX_VALUE </p>
+     *
+     * @see #nextInt()
+     */
+    public static int nextInt() {
+        return nextInt(0, Integer.MAX_VALUE);
+    }
     
     /**
      * <p>
@@ -115,8 +124,16 @@ public class RandomUtils {
         }
 
         return (long) nextDouble(startInclusive, endExclusive);
-    }    
-    
+    }
+
+    /**
+     * <p> Returns a random long within 0 - Long.MAX_VALUE </p>
+     *
+     * @see #nextLong()
+     */
+    public static long nextLong() {
+        return nextLong(0, Long.MAX_VALUE);
+    }
     
     /**
      * <p> 
@@ -136,14 +153,23 @@ public class RandomUtils {
         Validate.isTrue(endInclusive >= startInclusive,
                 "Start value must be smaller or equal to end value.");
         Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative.");
-        
+
         if (startInclusive == endInclusive) {
             return startInclusive;
         }
         
         return startInclusive + ((endInclusive - startInclusive) * RANDOM.nextDouble());
     }
-    
+
+    /**
+     * <p> Returns a random double within 0 - Double.MAX_VALUE </p>
+     *
+     * @see #nextDouble()
+     */
+    public static double nextDouble() {
+        return nextDouble(0, Double.MAX_VALUE);
+    }
+
     /**
      * <p>
      * Returns a random float within the specified range.
@@ -168,5 +194,14 @@ public class RandomUtils {
         }
         
         return startInclusive + ((endInclusive - startInclusive) * RANDOM.nextFloat());
-    }    
+    }
+
+    /**
+     * <p> Returns a random float within 0 - Float.MAX_VALUE </p>
+     *
+     * @see #nextFloat()
+     */
+    public static float nextFloat() {
+        return nextFloat(0, Float.MAX_VALUE);
+    }
 }

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/31466db6/src/test/java/org/apache/commons/lang3/RandomUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/RandomUtilsTest.java b/src/test/java/org/apache/commons/lang3/RandomUtilsTest.java
index a2aa063..e1108e5 100644
--- a/src/test/java/org/apache/commons/lang3/RandomUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/RandomUtilsTest.java
@@ -111,6 +111,16 @@ public class RandomUtilsTest {
         final int result = RandomUtils.nextInt(33, 42);
         assertTrue(result >= 33 && result < 42);
     }
+
+    /**
+     * Tests next double range, random result.
+     */
+    @Test
+    public void testNextIntRandomResult() {
+        int randomResult = RandomUtils.nextInt();
+        assertTrue(randomResult > 0);
+        assertTrue(randomResult < Integer.MAX_VALUE);
+    }
     
     /**
      * Test next double range with minimal range.
@@ -136,6 +146,16 @@ public class RandomUtilsTest {
         final double result = RandomUtils.nextDouble(33d, 42d);
         assertTrue(result >= 33d && result <= 42d);
     }
+
+    /**
+     * Tests next double range, random result.
+     */
+    @Test
+    public void testNextDoubleRandomResult() {
+        double randomResult = RandomUtils.nextDouble();
+        assertTrue(randomResult > 0);
+        assertTrue(randomResult < Double.MAX_VALUE);
+    }
     
     /**
      * Tests next float range.
@@ -144,7 +164,17 @@ public class RandomUtilsTest {
     public void testNextFloat() {
         final double result = RandomUtils.nextFloat(33f, 42f);
         assertTrue(result >= 33f && result <= 42f);
-    }    
+    }
+
+    /**
+     * Tests next float range, random result.
+     */
+    @Test
+    public void testNextFloatRandomResult() {
+        float randomResult = RandomUtils.nextFloat();
+        assertTrue(randomResult > 0);
+        assertTrue(randomResult < Float.MAX_VALUE);
+    }
 
     /**
      * Test next long range with minimal range.
@@ -162,7 +192,16 @@ public class RandomUtilsTest {
         final long result = RandomUtils.nextLong(33L, 42L);
         assertTrue(result >= 33L && result < 42L);
     }
-    
+
+    /**
+     * Tests next long range, random result.
+     */
+    @Test
+    public void testNextLongRandomResult() {
+        long randomResult = RandomUtils.nextLong();
+        assertTrue(randomResult > 0);
+        assertTrue(randomResult < Long.MAX_VALUE);
+    }
     
     /**
      * Tests extreme range.


[3/4] [lang] Add LANG-1174 to changes.xml

Posted by br...@apache.org.
Add LANG-1174 to changes.xml


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/19f9893d
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/19f9893d
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/19f9893d

Branch: refs/heads/master
Commit: 19f9893de0459412b11830b2798584c9669e5e2d
Parents: 69383a2
Author: Benedikt Ritter <br...@apache.org>
Authored: Sat Oct 17 11:12:07 2015 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Sat Oct 17 11:12:07 2015 +0200

----------------------------------------------------------------------
 src/changes/changes.xml | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/19f9893d/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ae6ed76..4a5c143 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -22,6 +22,7 @@
   <body>
 
   <release version="3.5" date="tba" description="tba">
+    <action issue="LANG-1174" type="add" dev="britter" dute-to="Punkratz312">Add sugar to RandomUtils</action>
     <action issue="LANG-1057" type="update" dev="chas" dute-to="Otávio Santana">Replace StringBuilder with String concatenation for better optimization</action>
     <action issue="LANG-1075" type="update" dev="chas">Deprecate SystemUtils.FILE_SEPARATOR and SystemUtils.PATH_SEPARATOR</action>
     <action issue="LANG-1154" type="add" dev="chas" due-to="Gary Gregory">FastDateFormat APIs that use a StringBuilder</action>


[4/4] [lang] Merge branch 'LANG-1174'

Posted by br...@apache.org.
Merge branch 'LANG-1174'

LANG-1174: Add sugar to RandomUtils.
This closes 111 from github. Thanks to github user Punkratz312.


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/c9cae602
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/c9cae602
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/c9cae602

Branch: refs/heads/master
Commit: c9cae602ec96ac1fb0b738801d919705db60f03e
Parents: 881c5fa 19f9893
Author: Benedikt Ritter <br...@apache.org>
Authored: Sat Oct 17 11:12:19 2015 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Sat Oct 17 11:12:19 2015 +0200

----------------------------------------------------------------------
 src/changes/changes.xml                         |  1 +
 .../org/apache/commons/lang3/RandomUtils.java   | 53 ++++++++++++++++++--
 .../apache/commons/lang3/RandomUtilsTest.java   | 43 +++++++++++++++-
 3 files changed, 90 insertions(+), 7 deletions(-)
----------------------------------------------------------------------



[2/4] [lang] Better JavaDoc

Posted by br...@apache.org.
Better JavaDoc


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/69383a2b
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/69383a2b
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/69383a2b

Branch: refs/heads/master
Commit: 69383a2babea381e7e114d2e7bb8b44eb4b14ca5
Parents: 31466db
Author: Benedikt Ritter <br...@apache.org>
Authored: Sat Oct 17 11:10:54 2015 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Sat Oct 17 11:10:54 2015 +0200

----------------------------------------------------------------------
 .../java/org/apache/commons/lang3/RandomUtils.java    | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/69383a2b/src/main/java/org/apache/commons/lang3/RandomUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/RandomUtils.java b/src/main/java/org/apache/commons/lang3/RandomUtils.java
index 16188c6..594fe3f 100644
--- a/src/main/java/org/apache/commons/lang3/RandomUtils.java
+++ b/src/main/java/org/apache/commons/lang3/RandomUtils.java
@@ -94,7 +94,9 @@ public class RandomUtils {
     /**
      * <p> Returns a random int within 0 - Integer.MAX_VALUE </p>
      *
-     * @see #nextInt()
+     * @return the random integer
+     * @see #nextInt(int, int)
+     * @since 3.5
      */
     public static int nextInt() {
         return nextInt(0, Integer.MAX_VALUE);
@@ -129,7 +131,9 @@ public class RandomUtils {
     /**
      * <p> Returns a random long within 0 - Long.MAX_VALUE </p>
      *
-     * @see #nextLong()
+     * @return the random long
+     * @see #nextLong(long, long)
+     * @since 3.5
      */
     public static long nextLong() {
         return nextLong(0, Long.MAX_VALUE);
@@ -164,7 +168,9 @@ public class RandomUtils {
     /**
      * <p> Returns a random double within 0 - Double.MAX_VALUE </p>
      *
-     * @see #nextDouble()
+     * @return the random double
+     * @see #nextDouble(double, double)
+     * @since 3.5
      */
     public static double nextDouble() {
         return nextDouble(0, Double.MAX_VALUE);
@@ -199,7 +205,9 @@ public class RandomUtils {
     /**
      * <p> Returns a random float within 0 - Float.MAX_VALUE </p>
      *
+     * @return the random float
      * @see #nextFloat()
+     * @since 3.5
      */
     public static float nextFloat() {
         return nextFloat(0, Float.MAX_VALUE);