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


The following commit(s) were added to refs/heads/master by this push:
     new 7eb3645  Updated examples-sampling to picocli for the command line 
application.
7eb3645 is described below

commit 7eb3645f53ec8b52b6a590a62e849ea0bce80a6d
Author: aherbert <[email protected]>
AuthorDate: Mon May 20 16:57:28 2019 +0100

    Updated examples-sampling to picocli for the command line application.
---
 commons-rng-examples/examples-sampling/pom.xml     |  58 ++++++-
 .../sampling/ExamplesSamplingApplication.java      |  52 +++++++
 .../examples/sampling/ExamplesSamplingCommand.java |  48 ++++++
 .../examples/sampling/ManifestVersionProvider.java |  77 ++++++++++
 ...=> ProbabilityDensityApproximationCommand.java} | 166 +++++++++++++++------
 .../rng/examples/sampling/StandardOptions.java     |  35 +++++
 ...java => UniformSamplingVisualCheckCommand.java} |  62 ++++++--
 commons-rng-examples/examples-stress/pom.xml       |   3 -
 commons-rng-examples/pom.xml                       |   9 +-
 9 files changed, 440 insertions(+), 70 deletions(-)

diff --git a/commons-rng-examples/examples-sampling/pom.xml 
b/commons-rng-examples/examples-sampling/pom.xml
index 6133ed7..955fd1c 100644
--- a/commons-rng-examples/examples-sampling/pom.xml
+++ b/commons-rng-examples/examples-sampling/pom.xml
@@ -29,14 +29,15 @@
   <groupId>org.apache.commons</groupId>
   <artifactId>commons-rng-examples-sampling</artifactId>
   <version>1.3-SNAPSHOT</version>
-  <name>Sampling example</name>
+  <!-- This name is used in the shaded jar to provide the application title 
for the version information. -->
+  <name>Apache Commons RNG Examples Sampling Utilities</name>
 
   <description>Contains examples of output from the samplers.
   Code in this module is not part of the public API.</description>
 
   <properties>
-    <maven.compiler.source>1.7</maven.compiler.source>
-    <maven.compiler.target>1.7</maven.compiler.target>
+    <maven.compiler.source>1.8</maven.compiler.source>
+    <maven.compiler.target>1.8</maven.compiler.target>
 
     <!-- OSGi -->
     
<commons.osgi.symbolicName>org.apache.commons.rng.examples.sampling</commons.osgi.symbolicName>
@@ -45,6 +46,9 @@
     
<commons.automatic.module.name>org.apache.commons.rng.examples.sampling</commons.automatic.module.name>
     <!-- Workaround to avoid duplicating config files. -->
     <rng.parent.dir>${basedir}/../..</rng.parent.dir>
+
+    <uberjar.name>examples-sampling</uberjar.name>
+    
<project.mainClass>org.apache.commons.rng.examples.sampling.ExamplesSamplingApplication</project.mainClass>
   </properties>
 
   <dependencies>
@@ -52,11 +56,57 @@
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-rng-simple</artifactId>
     </dependency>
-
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-rng-sampling</artifactId>
     </dependency>
+    <dependency>
+      <groupId>info.picocli</groupId>
+      <artifactId>picocli</artifactId>
+    </dependency>
   </dependencies>
 
+  <profiles>
+    <profile>
+      <id>examples-sampling</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-shade-plugin</artifactId>
+            <executions>
+              <execution>
+                <phase>package</phase>
+                <goals>
+                  <goal>shade</goal>
+                </goals>
+                <configuration>
+                  <finalName>${uberjar.name}</finalName>
+                  <minimizeJar>true</minimizeJar>
+                  <transformers>
+                    <transformer
+                      
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                      <mainClass>${project.mainClass}</mainClass>
+                    </transformer>
+                  </transformers>
+                  <filters>
+                    <filter>
+                      <!-- Shading signed JARs will fail without this. 
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
 -->
+                      <artifact>*:*</artifact>
+                      <excludes>
+                        <exclude>META-INF/*.SF</exclude>
+                        <exclude>META-INF/*.DSA</exclude>
+                        <exclude>META-INF/*.RSA</exclude>
+                      </excludes>
+                    </filter>
+                  </filters>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+
 </project>
diff --git 
a/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ExamplesSamplingApplication.java
 
b/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ExamplesSamplingApplication.java
new file mode 100644
index 0000000..391ac02
--- /dev/null
+++ 
b/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ExamplesSamplingApplication.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rng.examples.sampling;
+
+import picocli.CommandLine;
+import picocli.CommandLine.RunLast;
+
+/**
+ * Executes testing utilities for the samplers in the Commons RNG library.
+ *
+ * <p>Functionality includes:</p>
+ *
+ * <ul>
+ *   <li>Outputting data from a random generator
+ * </ul>
+ */
+public class ExamplesSamplingApplication {
+    /** No public constructor. */
+    private ExamplesSamplingApplication() {}
+
+    /**
+     * Run the RNG examples stress command line application.
+     *
+     * @param args Application's arguments.
+     */
+    public static void main(String[] args)
+    {
+        // Build the command line manually so we can configure options.
+        final CommandLine cmd = new CommandLine(new ExamplesSamplingCommand())
+                .addSubcommand("density", new 
ProbabilityDensityApproximationCommand())
+                .addSubcommand("visual", new 
UniformSamplingVisualCheckCommand())
+                // Call last to apply to all sub-commands
+                .setCaseInsensitiveEnumValuesAllowed(true);
+
+        // Parse the command line and invokes the Callable program
+        cmd.parseWithHandler(new RunLast(), args);
+    }
+}
diff --git 
a/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ExamplesSamplingCommand.java
 
b/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ExamplesSamplingCommand.java
new file mode 100644
index 0000000..fa3fafc
--- /dev/null
+++ 
b/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ExamplesSamplingCommand.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rng.examples.sampling;
+
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Mixin;
+import picocli.CommandLine.Model.CommandSpec;
+import picocli.CommandLine.Spec;
+
+import java.util.concurrent.Callable;
+
+/**
+ * Specification for the top-level command in the examples sampling 
application.
+ *
+ * <p>This command is will print the top-level help message.</p>
+ */
+@Command(name = "examples-sampling",
+         description = "Apache Commons RNG Examples Stress Utilities.")
+class ExamplesSamplingCommand implements Callable<Void> {
+    /** The command specification. Used to print the usage built by Picocli. */
+    @Spec
+    private CommandSpec spec;
+
+    /** The standard options. */
+    @Mixin
+    private StandardOptions reusableOptions;
+
+    @Override
+    public Void call() {
+        // All work is done in sub-commands so just print the usage
+        spec.commandLine().usage(System.out);
+        return null;
+    }
+}
diff --git 
a/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ManifestVersionProvider.java
 
b/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ManifestVersionProvider.java
new file mode 100644
index 0000000..f20d99c
--- /dev/null
+++ 
b/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ManifestVersionProvider.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rng.examples.sampling;
+
+import picocli.CommandLine.IVersionProvider;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+/**
+ * {@link IVersionProvider} implementation that returns version information 
from
+ * the package jar file's {@code /META-INF/MANIFEST.MF} file.
+ *
+ * @see <a
+ * 
href="https://github.com/remkop/picocli/blob/master/picocli-examples/src/main/java/picocli/examples/VersionProviderDemo2.java";>PicoCLI
+ * version provider demo</a>
+ */
+class ManifestVersionProvider implements IVersionProvider {
+    /** {@inheritDoc} */
+    @Override
+    public String[] getVersion() throws Exception {
+        final Enumeration<URL> resources = 
ManifestVersionProvider.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
+        while (resources.hasMoreElements()) {
+            final URL url = resources.nextElement();
+            try {
+                final Manifest manifest = new Manifest(url.openStream());
+                if (isApplicableManifest(manifest)) {
+                    final Attributes attr = manifest.getMainAttributes();
+                    return new String[] { get(attr, "Implementation-Title") + 
" version \"" +
+                            get(attr, "Implementation-Version") + "\"" };
+                }
+            } catch (final IOException ex) {
+                return new String[] { "Unable to read from " + url + ". " + ex 
};
+            }
+        }
+        return new String[0];
+    }
+
+    /**
+     * Checks if this is the applicable manifest for the package.
+     *
+     * @param manifest The manifest.
+     * @return true if is the applicable manifest
+     */
+    private static boolean isApplicableManifest(Manifest manifest) {
+        final Attributes attributes = manifest.getMainAttributes();
+        return 
"org.apache.commons.rng.examples.sampling".equals(get(attributes, 
"Automatic-Module-Name"));
+    }
+
+    /**
+     * Gets the named object from the attributes using the key.
+     *
+     * @param attributes The attributes.
+     * @param key The key.
+     * @return the object
+     */
+    private static Object get(Attributes attributes, String key) {
+        return attributes.get(new Attributes.Name(key));
+    }
+}
diff --git 
a/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ProbabilityDensityApproximation.java
 
b/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ProbabilityDensityApproximationCommand.java
similarity index 57%
rename from 
commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ProbabilityDensityApproximation.java
rename to 
commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ProbabilityDensityApproximationCommand.java
index 348bc75..85151bd 100644
--- 
a/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ProbabilityDensityApproximation.java
+++ 
b/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/ProbabilityDensityApproximationCommand.java
@@ -18,9 +18,16 @@
 package org.apache.commons.rng.examples.sampling;
 
 import java.io.PrintWriter;
+import java.util.EnumSet;
+import java.util.concurrent.Callable;
 import java.io.IOException;
 import org.apache.commons.rng.UniformRandomProvider;
 import org.apache.commons.rng.simple.RandomSource;
+
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Mixin;
+import picocli.CommandLine.Option;
+
 import 
org.apache.commons.rng.sampling.distribution.ZigguratNormalizedGaussianSampler;
 import 
org.apache.commons.rng.sampling.distribution.MarsagliaNormalizedGaussianSampler;
 import 
org.apache.commons.rng.sampling.distribution.BoxMullerNormalizedGaussianSampler;
@@ -36,22 +43,65 @@ import 
org.apache.commons.rng.sampling.distribution.ContinuousSampler;
 /**
  * Approximation of the probability density by the histogram of the sampler 
output.
  */
-public class ProbabilityDensityApproximation {
+@Command(name = "density",
+         description = {"Approximate the probability density of samplers."})
+class ProbabilityDensityApproximationCommand  implements Callable<Void> {
+    /** The standard options. */
+    @Mixin
+    private StandardOptions reusableOptions;
+
     /** Number of (equal-width) bins in the histogram. */
-    private final int numBins;
+    @Option(names = {"-b", "--bins"},
+            description = "The number of bins in the histogram (default: 
${DEFAULT-VALUE}).")
+    private int numBins = 25000;
+
     /** Number of samples to be generated. */
-    private final long numSamples;
+    @Option(names = {"-n", "--samples"},
+            description = "The number of samples in the histogram (default: 
${DEFAULT-VALUE}).")
+    private long numSamples = 1000000000;
+
+    /** The samplers. */
+    @Option(names = {"-s", "--samplers"},
+            split = ",",
+            description = {"The samplers (comma-delimited for multiple 
options).",
+                          "Valid values: ${COMPLETION-CANDIDATES}."})
+    private EnumSet<Sampler> samplers = EnumSet.noneOf(Sampler.class);
+
+    /** Flag to output all samplers. */
+    @Option(names = {"-a", "--all"},
+            description = "Output all samplers")
+    private boolean allSamplers = false;
 
     /**
-     * Application.
-     *
-     * @param numBins Number of "equal-width" bins.
-     * @param numSamples Number of samples.
+     * The sampler. This enum uses lower case for clarity when matching the 
distribution name.
      */
-    private ProbabilityDensityApproximation(int numBins,
-                                            long numSamples) {
-        this.numBins = numBins;
-        this.numSamples = numSamples;
+    enum Sampler {
+        /** The Ziggurat gaussian sampler. */
+        ZigguratGaussianSampler,
+        /** The Marsaglia gaussian sampler. */
+        MarsagliaGaussianSampler,
+        /** The Box muller gaussian sampler. */
+        BoxMullerGaussianSampler,
+        /** The Cheng beta sampler case 1. */
+        ChengBetaSamplerCase1,
+        /** The Cheng beta sampler case 2. */
+        ChengBetaSamplerCase2,
+        /** The Ahrens dieter exponential sampler. */
+        AhrensDieterExponentialSampler,
+        /** The Ahrens dieter marsaglia tsang gamma sampler small gamma. */
+        AhrensDieterMarsagliaTsangGammaSamplerCase1,
+        /** The Ahrens dieter marsaglia tsang gamma sampler large gamma. */
+        AhrensDieterMarsagliaTsangGammaSamplerCase2,
+        /** The Inverse transform pareto sampler. */
+        InverseTransformParetoSampler,
+        /** The Continuous uniform sampler. */
+        ContinuousUniformSampler,
+        /** The Log normal ziggurat gaussian sampler. */
+        LogNormalZigguratGaussianSampler,
+        /** The Log normal marsaglia gaussian sampler. */
+        LogNormalMarsagliaGaussianSampler,
+        /** The Log normal box muller gaussian sampler. */
+        LogNormalBoxMullerGaussianSampler,
     }
 
     /**
@@ -117,18 +167,16 @@ public class ProbabilityDensityApproximation {
     /**
      * Program entry point.
      *
-     * @param args Argument. They must be provided, in the following order:
-     * <ol>
-     *  <li>Number of "equal-width" bins.</li>
-     *  <li>Number of samples.</li>
-     * </ol>
      * @throws IOException if failure occurred while writing to files.
      */
-    public static void main(String[] args)
-        throws IOException {
-        final int numBins = Integer.parseInt(args[0]);
-        final long numSamples = Long.parseLong(args[1]);
-        final ProbabilityDensityApproximation app = new 
ProbabilityDensityApproximation(numBins, numSamples);
+    @Override
+    public Void call() throws IOException {
+        if (allSamplers) {
+            samplers = EnumSet.allOf(Sampler.class);
+        } else if (samplers.isEmpty()) {
+            System.err.println("ERROR: No samplers specified");
+            System.exit(1);
+        }
 
         final UniformRandomProvider rng = 
RandomSource.create(RandomSource.XOR_SHIFT_1024_S_PHI);
 
@@ -136,68 +184,96 @@ public class ProbabilityDensityApproximation {
         final double gaussSigma = 2;
         final double gaussMin = -9;
         final double gaussMax = 11;
-        app.createDensity(new GaussianSampler(new 
ZigguratNormalizedGaussianSampler(rng),
+        if (samplers.contains(Sampler.ZigguratGaussianSampler)) {
+            createDensity(new GaussianSampler(new 
ZigguratNormalizedGaussianSampler(rng),
                                               gaussMean, gaussSigma),
                           gaussMin, gaussMax, "gauss.ziggurat.txt");
-        app.createDensity(new GaussianSampler(new 
MarsagliaNormalizedGaussianSampler(rng),
+        }
+        if (samplers.contains(Sampler.MarsagliaGaussianSampler)) {
+            createDensity(new GaussianSampler(new 
MarsagliaNormalizedGaussianSampler(rng),
                                               gaussMean, gaussSigma),
                           gaussMin, gaussMax, "gauss.marsaglia.txt");
-        app.createDensity(new GaussianSampler(new 
BoxMullerNormalizedGaussianSampler(rng),
+        }
+        if (samplers.contains(Sampler.BoxMullerGaussianSampler)) {
+            createDensity(new GaussianSampler(new 
BoxMullerNormalizedGaussianSampler(rng),
                                               gaussMean, gaussSigma),
                           gaussMin, gaussMax, "gauss.boxmuller.txt");
+        }
 
-        final double alphaBeta = 4.3;
-        final double betaBeta = 2.1;
         final double betaMin = 0;
         final double betaMax = 1;
-        app.createDensity(new ChengBetaSampler(rng, alphaBeta, betaBeta),
+        if (samplers.contains(Sampler.ChengBetaSamplerCase1)) {
+            final double alphaBeta = 4.3;
+            final double betaBeta = 2.1;
+            createDensity(new ChengBetaSampler(rng, alphaBeta, betaBeta),
                           betaMin, betaMax, "beta.case1.txt");
-        final double alphaBetaAlt = 0.5678;
-        final double betaBetaAlt = 0.1234;
-        app.createDensity(new ChengBetaSampler(rng, alphaBetaAlt, betaBetaAlt),
+        }
+        if (samplers.contains(Sampler.ChengBetaSamplerCase2)) {
+            final double alphaBetaAlt = 0.5678;
+            final double betaBetaAlt = 0.1234;
+            createDensity(new ChengBetaSampler(rng, alphaBetaAlt, betaBetaAlt),
                           betaMin, betaMax, "beta.case2.txt");
+        }
 
-        final double meanExp = 3.45;
-        final double expMin = 0;
-        final double expMax = 60;
-        app.createDensity(new AhrensDieterExponentialSampler(rng, meanExp),
+        if (samplers.contains(Sampler.AhrensDieterExponentialSampler)) {
+            final double meanExp = 3.45;
+            final double expMin = 0;
+            final double expMax = 60;
+            createDensity(new AhrensDieterExponentialSampler(rng, meanExp),
                           expMin, expMax, "exp.txt");
+        }
 
-        final double thetaGammaSmallerThanOne = 0.1234;
-        final double alphaGamma = 3.456;
         final double gammaMin = 0;
         final double gammaMax1 = 40;
-        app.createDensity(new AhrensDieterMarsagliaTsangGammaSampler(rng, 
alphaGamma, thetaGammaSmallerThanOne),
+        final double alphaGamma = 3.456;
+        if 
(samplers.contains(Sampler.AhrensDieterMarsagliaTsangGammaSamplerCase1)) {
+            final double thetaGammaSmallerThanOne = 0.1234;
+            createDensity(new AhrensDieterMarsagliaTsangGammaSampler(rng, 
alphaGamma, thetaGammaSmallerThanOne),
                           gammaMin, gammaMax1, "gamma.case1.txt");
-        final double thetaGammaLargerThanOne = 2.345;
-        final double gammaMax2 = 70;
-        app.createDensity(new AhrensDieterMarsagliaTsangGammaSampler(rng, 
alphaGamma, thetaGammaLargerThanOne),
+        }
+        if 
(samplers.contains(Sampler.AhrensDieterMarsagliaTsangGammaSamplerCase2)) {
+            final double thetaGammaLargerThanOne = 2.345;
+            final double gammaMax2 = 70;
+            createDensity(new AhrensDieterMarsagliaTsangGammaSampler(rng, 
alphaGamma, thetaGammaLargerThanOne),
                           gammaMin, gammaMax2, "gamma.case2.txt");
+        }
 
         final double scalePareto = 23.45;
         final double shapePareto = 0.789;
         final double paretoMin = 23;
         final double paretoMax = 400;
-        app.createDensity(new InverseTransformParetoSampler(rng, scalePareto, 
shapePareto),
+        if (samplers.contains(Sampler.InverseTransformParetoSampler)) {
+            createDensity(new InverseTransformParetoSampler(rng, scalePareto, 
shapePareto),
                           paretoMin, paretoMax, "pareto.txt");
+        }
 
         final double loUniform = -9.876;
         final double hiUniform = 5.432;
-        app.createDensity(new ContinuousUniformSampler(rng, loUniform, 
hiUniform),
+        if (samplers.contains(Sampler.ContinuousUniformSampler)) {
+            createDensity(new ContinuousUniformSampler(rng, loUniform, 
hiUniform),
                           loUniform, hiUniform, "uniform.txt");
+        }
 
         final double scaleLogNormal = 2.345;
         final double shapeLogNormal = 0.1234;
         final double logNormalMin = 5;
         final double logNormalMax = 25;
-        app.createDensity(new LogNormalSampler(new 
ZigguratNormalizedGaussianSampler(rng),
+        if (samplers.contains(Sampler.LogNormalZigguratGaussianSampler)) {
+            createDensity(new LogNormalSampler(new 
ZigguratNormalizedGaussianSampler(rng),
                                                scaleLogNormal, shapeLogNormal),
                           logNormalMin, logNormalMax, 
"lognormal.ziggurat.txt");
-        app.createDensity(new LogNormalSampler(new 
MarsagliaNormalizedGaussianSampler(rng),
+        }
+        if (samplers.contains(Sampler.LogNormalMarsagliaGaussianSampler)) {
+            createDensity(new LogNormalSampler(new 
MarsagliaNormalizedGaussianSampler(rng),
                                                scaleLogNormal, shapeLogNormal),
                           logNormalMin, logNormalMax, 
"lognormal.marsaglia.txt");
-        app.createDensity(new LogNormalSampler(new 
BoxMullerNormalizedGaussianSampler(rng),
+        }
+        if (samplers.contains(Sampler.LogNormalBoxMullerGaussianSampler)) {
+            createDensity(new LogNormalSampler(new 
BoxMullerNormalizedGaussianSampler(rng),
                                                scaleLogNormal, shapeLogNormal),
                           logNormalMin, logNormalMax, 
"lognormal.boxmuller.txt");
+        }
+
+        return null;
     }
 }
diff --git 
a/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/StandardOptions.java
 
b/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/StandardOptions.java
new file mode 100644
index 0000000..6342863
--- /dev/null
+++ 
b/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/StandardOptions.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rng.examples.sampling;
+
+import picocli.CommandLine.Command;
+
+/**
+ * Standard options for all commands. This sets the formatting for usage 
messages and
+ * adds common parameters (help, version).
+ */
+@Command(sortOptions = true,
+         mixinStandardHelpOptions = true,
+         versionProvider      = ManifestVersionProvider.class,
+         synopsisHeading      = "%n",
+         descriptionHeading   = "%n",
+         parameterListHeading = "%nParameters:%n",
+         optionListHeading    = "%nOptions:%n",
+         commandListHeading   = "%nCommands:%n")
+class StandardOptions {
+    // Empty class used for annotations
+}
diff --git 
a/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/UniformSamplingVisualCheck.java
 
b/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/UniformSamplingVisualCheckCommand.java
similarity index 60%
rename from 
commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/UniformSamplingVisualCheck.java
rename to 
commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/UniformSamplingVisualCheckCommand.java
index a912791..c22b5e4 100644
--- 
a/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/UniformSamplingVisualCheck.java
+++ 
b/commons-rng-examples/examples-sampling/src/main/java/org/apache/commons/rng/examples/sampling/UniformSamplingVisualCheckCommand.java
@@ -19,6 +19,13 @@ package org.apache.commons.rng.examples.sampling;
 
 import org.apache.commons.rng.UniformRandomProvider;
 import org.apache.commons.rng.simple.RandomSource;
+
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Mixin;
+import picocli.CommandLine.Option;
+
+import java.util.concurrent.Callable;
+
 import 
org.apache.commons.rng.sampling.distribution.ZigguratNormalizedGaussianSampler;
 import 
org.apache.commons.rng.sampling.distribution.MarsagliaNormalizedGaussianSampler;
 import 
org.apache.commons.rng.sampling.distribution.BoxMullerNormalizedGaussianSampler;
@@ -31,7 +38,28 @@ import 
org.apache.commons.rng.sampling.distribution.ContinuousSampler;
  * accuracy, e.g. when porting C code based on 32-bits "float" to
  * "Commons RNG" that uses Java "double" (64-bits).
  */
-public class UniformSamplingVisualCheck {
+@Command(name = "visual",
+         description = "Show output from a tiny region of the sampler.")
+class UniformSamplingVisualCheckCommand implements Callable<Void> {
+    /** The standard options. */
+    @Mixin
+    private StandardOptions reusableOptions;
+
+    /** The lower bound of the tiny range. */
+    @Option(names = {"-l", "--low"},
+            description = "The lower bound (default: ${DEFAULT-VALUE}).")
+    private float lo = 0.1f;
+
+    /** The number of bands of the tiny range. */
+    @Option(names = {"-b", "--bands"},
+            description = "The number of bands for the range (default: 
${DEFAULT-VALUE}).")
+    private int bands = 2;
+
+    /** Number of samples to be generated. */
+    @Option(names = {"-s", "--samples"},
+        description = "The number of samples in the tiny range (default: 
${DEFAULT-VALUE}).")
+    private int numSamples = 50;
+
     /** RNG. */
     private final UniformRandomProvider rng = 
RandomSource.create(RandomSource.XOR_SHIFT_1024_S_PHI);
     /** Samplers. */
@@ -45,40 +73,42 @@ public class UniformSamplingVisualCheck {
     // CHECKSTYLE: stop RegexpCheck
 
     /**
-     * Program entry point.
-     *
-     * @param args Unused.
+     * Prints a template generators list to stdout.
      */
-    public static void main(String[] args) {
-        final float lo = 0.1f;
-        final int bands = 2;
+    @Override
+    public Void call() {
         float hi = lo;
         for (int i = 0; i < bands; i++) {
             hi = Math.nextUp(hi);
         }
-        System.out.printf("# lo=%.10e hi=%.10e", lo, hi);
-        System.out.println();
+        System.out.printf("# lower=%.16e%n", lo);
+        System.out.printf("# upper=%.16e%n", hi);
 
-        final UniformSamplingVisualCheck app = new 
UniformSamplingVisualCheck();
+        for (int i = 0; i < samplers.length; i++) {
+            System.out.printf("# [%d] %s%n", i, 
samplers[i].getClass().getSimpleName());
+        }
 
-        while (true) {
-            System.out.printf("%.16e\t", app.rng.nextDouble());
+        int n = 0;
+        while (++n < numSamples) {
+            System.out.printf("[%d]", n, rng.nextDouble());
 
-            for (ContinuousSampler s : app.samplers) {
+            for (ContinuousSampler s : samplers) {
                 while (true) {
                     final double r = s.sample();
                     if (r < lo ||
                         r > hi) {
                         // Discard numbers outside the tiny region.
-                         continue;
-                     }
+                        continue;
+                    }
 
-                    System.out.printf("%.16e ", r);
+                    System.out.printf("\t%.16e", r);
                     break;
                 }
             }
 
             System.out.println();
         }
+
+        return null;
     }
 }
diff --git a/commons-rng-examples/examples-stress/pom.xml 
b/commons-rng-examples/examples-stress/pom.xml
index d652bab..29480e2 100644
--- a/commons-rng-examples/examples-stress/pom.xml
+++ b/commons-rng-examples/examples-stress/pom.xml
@@ -49,8 +49,6 @@
 
     <uberjar.name>examples-stress</uberjar.name>
     
<project.mainClass>org.apache.commons.rng.examples.stress.ExamplesStressApplication</project.mainClass>
-
-    <rng.picocli.version>3.9.5</rng.picocli.version>
   </properties>
 
   <dependencies>
@@ -65,7 +63,6 @@
     <dependency>
       <groupId>info.picocli</groupId>
       <artifactId>picocli</artifactId>
-      <version>${rng.picocli.version}</version>
     </dependency>
   </dependencies>
 
diff --git a/commons-rng-examples/pom.xml b/commons-rng-examples/pom.xml
index 7e37120..c63e546 100644
--- a/commons-rng-examples/pom.xml
+++ b/commons-rng-examples/pom.xml
@@ -48,6 +48,8 @@
     
<commons.automatic.module.name>org.apache.commons.rng.examples</commons.automatic.module.name>
     <!-- Workaround to avoid duplicating config files. -->
     <rng.parent.dir>${basedir}/..</rng.parent.dir>
+
+    <rng.picocli.version>3.9.5</rng.picocli.version>
   </properties>
 
   <dependencyManagement>
@@ -57,18 +59,21 @@
         <artifactId>commons-rng-simple</artifactId>
         <version>1.3-SNAPSHOT</version>
       </dependency>
-
       <dependency>
         <groupId>org.apache.commons</groupId>
         <artifactId>commons-rng-sampling</artifactId>
         <version>1.3-SNAPSHOT</version>
       </dependency>
-
       <dependency>
         <groupId>org.apache.commons</groupId>
         <artifactId>commons-rng-client-api</artifactId>
         <version>1.3-SNAPSHOT</version>
       </dependency>
+      <dependency>
+        <groupId>info.picocli</groupId>
+        <artifactId>picocli</artifactId>
+        <version>${rng.picocli.version}</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>
 

Reply via email to