You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2016/05/29 21:01:37 UTC
[12/32] [math] MATH-1366
MATH-1366
Functionality of "RandomAdaptor" replaced by "JDKRandomAdaptor" for the new RNG API.
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/cede12d4
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/cede12d4
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/cede12d4
Branch: refs/heads/develop
Commit: cede12d455fd0574315a12ec1584a6e3597d3fb7
Parents: 60c18b7
Author: Gilles <er...@apache.org>
Authored: Tue May 17 20:20:28 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 20:20:28 2016 +0200
----------------------------------------------------------------------
.../commons/math4/random/RandomAdaptor.java | 199 -------------------
.../commons/math4/random/RandomAdaptorTest.java | 126 ------------
2 files changed, 325 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/cede12d4/src/main/java/org/apache/commons/math4/random/RandomAdaptor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/random/RandomAdaptor.java b/src/main/java/org/apache/commons/math4/random/RandomAdaptor.java
deleted file mode 100644
index ea08bae..0000000
--- a/src/main/java/org/apache/commons/math4/random/RandomAdaptor.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * 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.math4.random;
-
-import java.util.Random;
-
-/**
- * Extension of <code>java.util.Random</code> wrapping a
- * {@link RandomGenerator}.
- *
- * @since 1.1
- */
-public class RandomAdaptor extends Random implements RandomGenerator {
-
- /** Serializable version identifier. */
- private static final long serialVersionUID = 2306581345647615033L;
-
- /** Wrapped randomGenerator instance */
- private final RandomGenerator randomGenerator;
-
- /**
- * Prevent instantiation without a generator argument
- */
- @SuppressWarnings("unused")
- private RandomAdaptor() { randomGenerator = null; }
-
- /**
- * Construct a RandomAdaptor wrapping the supplied RandomGenerator.
- *
- * @param randomGenerator the wrapped generator
- */
- public RandomAdaptor(RandomGenerator randomGenerator) {
- this.randomGenerator = randomGenerator;
- }
-
- /**
- * Factory method to create a <code>Random</code> using the supplied
- * <code>RandomGenerator</code>.
- *
- * @param randomGenerator wrapped RandomGenerator instance
- * @return a Random instance wrapping the RandomGenerator
- */
- public static Random createAdaptor(RandomGenerator randomGenerator) {
- return new RandomAdaptor(randomGenerator);
- }
-
- /**
- * Returns the next pseudorandom, uniformly distributed
- * <code>boolean</code> value from this random number generator's
- * sequence.
- *
- * @return the next pseudorandom, uniformly distributed
- * <code>boolean</code> value from this random number generator's
- * sequence
- */
- @Override
- public boolean nextBoolean() {
- return randomGenerator.nextBoolean();
- }
-
- /**
- * Generates random bytes and places them into a user-supplied
- * byte array. The number of random bytes produced is equal to
- * the length of the byte array.
- *
- * @param bytes the non-null byte array in which to put the
- * random bytes
- */
- @Override
- public void nextBytes(byte[] bytes) {
- randomGenerator.nextBytes(bytes);
- }
-
- /**
- * Returns the next pseudorandom, uniformly distributed
- * <code>double</code> value between <code>0.0</code> and
- * <code>1.0</code> from this random number generator's sequence.
- *
- * @return the next pseudorandom, uniformly distributed
- * <code>double</code> value between <code>0.0</code> and
- * <code>1.0</code> from this random number generator's sequence
- */
- @Override
- public double nextDouble() {
- return randomGenerator.nextDouble();
- }
-
- /**
- * Returns the next pseudorandom, uniformly distributed <code>float</code>
- * value between <code>0.0</code> and <code>1.0</code> from this random
- * number generator's sequence.
- *
- * @return the next pseudorandom, uniformly distributed <code>float</code>
- * value between <code>0.0</code> and <code>1.0</code> from this
- * random number generator's sequence
- */
- @Override
- public float nextFloat() {
- return randomGenerator.nextFloat();
- }
-
- /**
- * Returns the next pseudorandom, Gaussian ("normally") distributed
- * <code>double</code> value with mean <code>0.0</code> and standard
- * deviation <code>1.0</code> from this random number generator's sequence.
- *
- * @return the next pseudorandom, Gaussian ("normally") distributed
- * <code>double</code> value with mean <code>0.0</code> and
- * standard deviation <code>1.0</code> from this random number
- * generator's sequence
- */
- @Override
- public double nextGaussian() {
- return randomGenerator.nextGaussian();
- }
-
- /**
- * Returns the next pseudorandom, uniformly distributed <code>int</code>
- * value from this random number generator's sequence.
- * All 2<font size="-1"><sup>32</sup></font> possible {@code int} values
- * should be produced with (approximately) equal probability.
- *
- * @return the next pseudorandom, uniformly distributed <code>int</code>
- * value from this random number generator's sequence
- */
- @Override
- public int nextInt() {
- return randomGenerator.nextInt();
- }
-
- /**
- * Returns a pseudorandom, uniformly distributed {@code int} value
- * between 0 (inclusive) and the specified value (exclusive), drawn from
- * this random number generator's sequence.
- *
- * @param n the bound on the random number to be returned. Must be
- * positive.
- * @return a pseudorandom, uniformly distributed {@code int}
- * value between 0 (inclusive) and n (exclusive).
- * @throws IllegalArgumentException if n is not positive.
- */
- @Override
- public int nextInt(int n) {
- return randomGenerator.nextInt(n);
- }
-
- /**
- * Returns the next pseudorandom, uniformly distributed <code>long</code>
- * value from this random number generator's sequence. All
- * 2<font size="-1"><sup>64</sup></font> possible {@code long} values
- * should be produced with (approximately) equal probability.
- *
- * @return the next pseudorandom, uniformly distributed <code>long</code>
- *value from this random number generator's sequence
- */
- @Override
- public long nextLong() {
- return randomGenerator.nextLong();
- }
-
- /** {@inheritDoc} */
- @Override
- public void setSeed(int seed) {
- if (randomGenerator != null) { // required to avoid NPE in constructor
- randomGenerator.setSeed(seed);
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public void setSeed(int[] seed) {
- if (randomGenerator != null) { // required to avoid NPE in constructor
- randomGenerator.setSeed(seed);
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public void setSeed(long seed) {
- if (randomGenerator != null) { // required to avoid NPE in constructor
- randomGenerator.setSeed(seed);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/cede12d4/src/test/java/org/apache/commons/math4/random/RandomAdaptorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/random/RandomAdaptorTest.java b/src/test/java/org/apache/commons/math4/random/RandomAdaptorTest.java
deleted file mode 100644
index df8bdba..0000000
--- a/src/test/java/org/apache/commons/math4/random/RandomAdaptorTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.math4.random;
-
-import java.util.Random;
-
-import org.apache.commons.math4.random.RandomAdaptor;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Test cases for the RandomAdaptor class
- *
- */
-
-public class RandomAdaptorTest {
-
- @Test
- public void testAdaptor() {
- ConstantGenerator generator = new ConstantGenerator();
- Random random = RandomAdaptor.createAdaptor(generator);
- checkConstant(random);
- RandomAdaptor randomAdaptor = new RandomAdaptor(generator);
- checkConstant(randomAdaptor);
- }
-
- private void checkConstant(Random random) {
- byte[] bytes = new byte[] {0};
- random.nextBytes(bytes);
- Assert.assertEquals(0, bytes[0]);
- Assert.assertFalse(random.nextBoolean());
- Assert.assertEquals(0, random.nextDouble(), 0);
- Assert.assertEquals(0, random.nextFloat(), 0);
- Assert.assertEquals(0, random.nextGaussian(), 0);
- Assert.assertEquals(0, random.nextInt());
- Assert.assertEquals(0, random.nextInt(1));
- Assert.assertEquals(0, random.nextLong());
- random.setSeed(100);
- Assert.assertEquals(0, random.nextDouble(), 0);
- }
-
- /*
- * "Constant" generator to test Adaptor delegation.
- * "Powered by Eclipse ;-)"
- *
- */
- public static class ConstantGenerator implements RandomGenerator {
-
- private final double value;
-
- public ConstantGenerator() {
- value = 0;
- }
-
- public ConstantGenerator(double value) {
- this.value = value;
- }
-
- @Override
- public boolean nextBoolean() {
- return false;
- }
-
- @Override
- public void nextBytes(byte[] bytes) {
- }
-
- @Override
- public double nextDouble() {
- return value;
- }
-
- @Override
- public float nextFloat() {
- return (float) value;
- }
-
- @Override
- public double nextGaussian() {
- return value;
- }
-
- @Override
- public int nextInt() {
- return (int) value;
- }
-
- @Override
- public int nextInt(int n) {
- return (int) value;
- }
-
- @Override
- public long nextLong() {
- return (int) value;
- }
-
- @Override
- public void setSeed(int seed) {
- }
-
- @Override
- public void setSeed(int[] seed) {
- }
-
- @Override
- public void setSeed(long seed) {
- }
-
- }
-}