Skip to content
Permalink
Browse files
Use Objects.requireNonNull
  • Loading branch information
aherbert committed Aug 13, 2021
1 parent d04082e commit 15afa3328890b2e47ab8eb872c369872968b0417
Showing 1 changed file with 4 additions and 24 deletions.
@@ -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 @@ private static class SharedStateDiscreteProbabilitySampler implements SharedStat
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 @@ S createSampler(DiscreteSampler discreteSampler,
*/
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 Builder<S> add(S sampler, double weight) {
*/
@Override
public Builder<S> setFactory(DiscreteProbabilitySamplerFactory samplerFactory) {
this.factory = requireNonNull(samplerFactory, "factory");
this.factory = Objects.requireNonNull(samplerFactory, "factory");
return this;
}

@@ -1054,27 +1055,6 @@ public static Builder<SharedStateLongSampler> newSharedStateLongSamplerBuilder()
SamplerBuilder.Specialisation.SHARED_STATE_SAMPLER, SharedStateLongSamplerFactory.INSTANCE);
}

/**
* 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.

0 comments on commit 15afa33

Please sign in to comment.