You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2019/06/06 08:00:22 UTC

[commons-rng] 09/11: RNG-75: Renamed local and class level constructor variables.

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit e84b889c114e0dc470cafd9b0f9a30de8d192f98
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Wed Jun 5 23:40:34 2019 +0100

    RNG-75: Renamed local and class level constructor variables.
---
 .../commons/rng/simple/internal/ProviderBuilder.java  | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/ProviderBuilder.java b/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/ProviderBuilder.java
index 9bf0967..704c940 100644
--- a/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/ProviderBuilder.java
+++ b/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/ProviderBuilder.java
@@ -232,9 +232,9 @@ public final class ProviderBuilder {
         private final NativeSeedType nativeSeedType;
         /**
          * The constructor.
-         * This is discovered using the constructor parameter types and cached.
+         * This is discovered using the constructor parameter types and stored for re-use.
          */
-        private Constructor<?> constructor;
+        private Constructor<?> rngConstructor;
 
         /**
          * Create a new instance.
@@ -367,7 +367,6 @@ public final class ProviderBuilder {
             return nativeSeedType.createSeed(nativeSeedSize);
         }
 
-
         /**
          * Converts a seed from any of the supported seed types to a native seed.
          *
@@ -398,12 +397,16 @@ public final class ProviderBuilder {
          * @return the RNG constructor.
          */
         private Constructor<?> getConstructor() {
-            Constructor<?> con = constructor;
-            if (con == null) {
-                con = createConstructor();
-                constructor = con;
+            // The constructor never changes so it is stored for re-use.
+            Constructor<?> constructor = rngConstructor;
+            if (constructor == null) {
+                // If null this is either the first attempt to find it or
+                // look-up previously failed and this method will throw
+                // upon each invocation.
+                constructor = createConstructor();
+                rngConstructor = constructor;
             }
-            return con;
+            return constructor;
         }
         /**
          * Creates a constructor.