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 d22daa5c3a608bc90a69a4eac764733c3949b4e8
Author: aherbert <[email protected]>
AuthorDate: Fri Sep 27 12:55:35 2019 +0100

    Drop commons-codec dependency and extract the Hex encoding function.
    
    This reduces the shaded jar size by 135K (>25%).
---
 commons-rng-examples/examples-stress/pom.xml       |  5 ----
 .../commons/rng/examples/stress/RNGUtils.java      | 32 ++++++++++++++++++++++
 .../rng/examples/stress/StressTestCommand.java     |  3 +-
 3 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/commons-rng-examples/examples-stress/pom.xml 
b/commons-rng-examples/examples-stress/pom.xml
index 04f315b..3c01926 100644
--- a/commons-rng-examples/examples-stress/pom.xml
+++ b/commons-rng-examples/examples-stress/pom.xml
@@ -64,11 +64,6 @@
       <groupId>info.picocli</groupId>
       <artifactId>picocli</artifactId>
     </dependency>
-    <dependency>
-      <groupId>commons-codec</groupId>
-      <artifactId>commons-codec</artifactId>
-      <version>1.13</version>
-    </dependency>
   </dependencies>
 
   <build>
diff --git 
a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/RNGUtils.java
 
b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/RNGUtils.java
index d5d4f79..a82a393 100644
--- 
a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/RNGUtils.java
+++ 
b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/RNGUtils.java
@@ -25,6 +25,13 @@ import java.util.concurrent.ThreadLocalRandom;
  * Utility methods for a {@link UniformRandomProvider}.
  */
 final class RNGUtils {
+    /**
+     * Used to build 4-bit numbers as Hex.
+     */
+    private static final char[] HEX_DIGITS = {
+        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 
'e', 'f'
+    };
+
     /** No public construction. */
     private RNGUtils() {}
 
@@ -180,4 +187,29 @@ final class RNGUtils {
             throw new ApplicationException("Failed to parse RandomSource 
argument: " + argument, ex);
         }
     }
+
+    /**
+     * Converts an array of bytes into an array of characters representing the 
hexadecimal
+     * values of each byte in order. The returned array will be double the 
length of the
+     * passed array, as it takes two characters to represent any given byte.
+     *
+     * <p>This can be used to encode byte array seeds into a text 
representation.</p>
+     *
+     * <p>Adapted from commons-codec.</p>
+     *
+     * @param data a byte[] to convert to Hex characters
+     * @return A char[] containing the lower-case Hex representation
+     */
+    static char[] encodeHex(final byte[] data) {
+        final int l = data.length;
+        final char[] out = new char[l << 1];
+        // Two characters form the hex value
+        for (int i = 0; i < l; i++) {
+            // Upper 4-bits
+            out[2 * i]     = HEX_DIGITS[(0xf0 & data[i]) >>> 4];
+            // Lower 4-bits
+            out[2 * i + 1] = HEX_DIGITS[ 0x0f & data[i]];
+        }
+        return out;
+    }
 }
diff --git 
a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/StressTestCommand.java
 
b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/StressTestCommand.java
index 32d9082..9eaa405 100644
--- 
a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/StressTestCommand.java
+++ 
b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/StressTestCommand.java
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.rng.examples.stress;
 
-import org.apache.commons.codec.binary.Hex;
 import org.apache.commons.rng.UniformRandomProvider;
 import org.apache.commons.rng.simple.RandomSource;
 
@@ -629,7 +628,7 @@ class StressTestCommand implements Callable<Void> {
             sb.append(C).append(N);
             sb.append(C).append("RandomSource: 
").append(randomSource.name()).append(N);
             sb.append(C).append("RNG: ").append(rng.toString()).append(N);
-            sb.append(C).append("Seed: ").append(Hex.encodeHexString(seed, 
true)).append(N);
+            sb.append(C).append("Seed: 
").append(RNGUtils.encodeHex(seed)).append(N);
             sb.append(C).append(N);
 
             // Match the output of 'java -version', e.g.

Reply via email to