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 2021/08/13 19:32:05 UTC
[commons-rng] 05/12: Use Objects.requireNonNull
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 15afa3328890b2e47ab8eb872c369872968b0417
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Fri Aug 13 19:34:01 2021 +0100
Use Objects.requireNonNull
---
.../commons/rng/sampling/CompositeSamplers.java | 28 ++++------------------
1 file changed, 4 insertions(+), 24 deletions(-)
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/CompositeSamplers.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/CompositeSamplers.java
index 7de1acf..b8941ee 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/CompositeSamplers.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/CompositeSamplers.java
@@ -18,6 +18,7 @@
package org.apache.commons.rng.sampling;
import java.util.List;
+import java.util.Objects;
import java.util.ArrayList;
import org.apache.commons.rng.UniformRandomProvider;
@@ -141,7 +142,7 @@ public final class CompositeSamplers {
SharedStateDiscreteProbabilitySampler(DiscreteSampler sampler,
DiscreteProbabilitySamplerFactory factory,
double[] probabilities) {
- this.sampler = requireNonNull(sampler, "discrete sampler");
+ this.sampler = Objects.requireNonNull(sampler, "discrete sampler");
// Assume the factory and probabilities are not null
this.factory = factory;
this.probabilities = probabilities;
@@ -308,7 +309,7 @@ public final class CompositeSamplers {
*/
WeightedSampler(double weight, S sampler) {
this.weight = requirePositiveFinite(weight, "weight");
- this.sampler = requireNonNull(sampler, "sampler");
+ this.sampler = Objects.requireNonNull(sampler, "sampler");
}
/**
@@ -382,7 +383,7 @@ public final class CompositeSamplers {
*/
@Override
public Builder<S> setFactory(DiscreteProbabilitySamplerFactory samplerFactory) {
- this.factory = requireNonNull(samplerFactory, "factory");
+ this.factory = Objects.requireNonNull(samplerFactory, "factory");
return this;
}
@@ -1055,27 +1056,6 @@ public final class CompositeSamplers {
}
/**
- * Checks that the specified object reference is not {@code null} and throws a
- * customized {@link NullPointerException} if it is.
- *
- * <P>Note: This method is to be replaced with
- * {@code java.util.Objects.requireNonNull} when the source requires Java 8.
- *
- * @param obj the object reference to check for nullity
- * @param message detail message to be used in the event that a {@code
- * NullPointerException} is thrown
- * @param <T> the type of the reference
- * @return {@code obj} if not {@code null}
- * @throws NullPointerException if {@code obj} is {@code null}
- */
- private static <T> T requireNonNull(T obj, String message) {
- if (obj == null) {
- throw new NullPointerException(message);
- }
- return obj;
- }
-
- /**
* Create a copy instance of each sampler in the list of samplers using the given
* uniform random provider as the source of randomness.
*