Example usage for org.apache.commons.math3.exception NumberIsTooLargeException NumberIsTooLargeException

List of usage examples for org.apache.commons.math3.exception NumberIsTooLargeException NumberIsTooLargeException

Introduction

In this page you can find the example usage for org.apache.commons.math3.exception NumberIsTooLargeException NumberIsTooLargeException.

Prototype

public NumberIsTooLargeException(Localizable specific, Number wrong, Number max, boolean boundIsAllowed) 

Source Link

Document

Construct the exception with a specific context.

Usage

From source file:org.apache.kylin.cube.cuboid.algorithm.generic.lib.ListPopulation.java

/**
 * Creates a new ListPopulation instance.
 * <p>/*from  w  ww  .j a  v a 2s.  co m*/
 * Note: the chromosomes of the specified list are added to the population.
 *
 * @param chromosomes list of chromosomes to be added to the population
 * @param populationLimit maximal size of the population
 * @throws NullArgumentException if the list of chromosomes is {@code null}
 * @throws NotPositiveException if the population limit is not a positive number (&lt; 1)
 * @throws NumberIsTooLargeException if the list of chromosomes exceeds the population limit
 */
public ListPopulation(final List<Chromosome> chromosomes, final int populationLimit)
        throws NullArgumentException, NotPositiveException, NumberIsTooLargeException {

    if (chromosomes == null) {
        throw new NullArgumentException();
    }
    if (populationLimit <= 0) {
        throw new NotPositiveException(LocalizedFormats.POPULATION_LIMIT_NOT_POSITIVE, populationLimit);
    }
    if (chromosomes.size() > populationLimit) {
        throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE,
                chromosomes.size(), populationLimit, false);
    }
    this.populationLimit = populationLimit;
    this.chromosomes = new ArrayList<Chromosome>(populationLimit);
    this.chromosomes.addAll(chromosomes);
}

From source file:org.apache.kylin.cube.cuboid.algorithm.generic.lib.ListPopulation.java

/**
 * Add a {@link Collection} of chromosomes to this {@link Population}.
 * @param chromosomeColl a {@link Collection} of chromosomes
 * @throws NumberIsTooLargeException if the population would exceed the population limit when
 * adding this chromosome//w  ww. j  a v a  2s.c  om
 * @since 3.1
 */
public void addChromosomes(final Collection<Chromosome> chromosomeColl) throws NumberIsTooLargeException {
    if (chromosomes.size() + chromosomeColl.size() > populationLimit) {
        throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE,
                chromosomes.size(), populationLimit, false);
    }
    this.chromosomes.addAll(chromosomeColl);
}

From source file:org.apache.kylin.cube.cuboid.algorithm.generic.lib.ListPopulation.java

/**
 * Sets the list of chromosomes.//from  w  ww.  j av  a2s  .  c  om
 * <p>
 * Note: this method removes all existing chromosomes in the population and adds all chromosomes
 * of the specified list to the population.
 *
 * @param chromosomes the list of chromosomes
 * @throws NullArgumentException if the list of chromosomes is {@code null}
 * @throws NumberIsTooLargeException if the list of chromosomes exceeds the population limit
 * @deprecated use {@link #addChromosomes(Collection)} instead
 */
@Deprecated
public void setChromosomes(final List<Chromosome> chromosomes)
        throws NullArgumentException, NumberIsTooLargeException {

    if (chromosomes == null) {
        throw new NullArgumentException();
    }
    if (chromosomes.size() > populationLimit) {
        throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE,
                chromosomes.size(), populationLimit, false);
    }
    this.chromosomes.clear();
    this.chromosomes.addAll(chromosomes);
}

From source file:org.apache.kylin.cube.cuboid.algorithm.generic.lib.ListPopulation.java

/**
 * Add the given chromosome to the population.
 *
 * @param chromosome the chromosome to add.
 * @throws NumberIsTooLargeException if the population would exceed the {@code populationLimit} after
 *   adding this chromosome/* w  w  w. j a  va2  s  .c o  m*/
 */
public void addChromosome(final Chromosome chromosome) throws NumberIsTooLargeException {
    if (chromosomes.size() >= populationLimit) {
        throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE,
                chromosomes.size(), populationLimit, false);
    }
    this.chromosomes.add(chromosome);
}

From source file:org.deeplearning4j.nn.conf.distribution.UniformDistribution.java

/**
 * Create a uniform real distribution using the given lower and upper
 * bounds./*from  www  .j av a 2  s.  co m*/
 *
 * @param lower Lower bound of this distribution (inclusive).
 * @param upper Upper bound of this distribution (exclusive).
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
@JsonCreator
public UniformDistribution(@JsonProperty("lower") double lower, @JsonProperty("upper") double upper)
        throws NumberIsTooLargeException {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper,
                false);
    }
    this.lower = lower;
    this.upper = upper;
}

From source file:org.gitools.analysis.groupcomparison.format.math33Preview.CombinatoricsUtils.java

/**
 * Check binomial preconditions.// w w  w.j a v  a  2  s .  c om
 *
 * @param n Size of the set.
 * @param k Size of the subsets to be counted.
 * @throws NotPositiveException      if {@code n < 0}.
 * @throws NumberIsTooLargeException if {@code k > n}.
 */
public static void checkBinomial(final int n, final int k)
        throws NumberIsTooLargeException, NotPositiveException {
    if (n < k) {
        throw new NumberIsTooLargeException(LocalizedFormats.BINOMIAL_INVALID_PARAMETERS_ORDER, k, n, true);
    }
    if (n < 0) {
        throw new NotPositiveException(LocalizedFormats.BINOMIAL_NEGATIVE_PARAMETER, n);
    }
}

From source file:org.gitools.analysis.groupcomparison.format.math33Preview.MathArrays.java

/**
 * This method is used/*from  www.  ja v  a  2  s .co m*/
 * to verify that the input parameters designate a subarray of positive length.
 * <p>
 * <ul>
 * <li>returns <code>true</code> iff the parameters designate a subarray of
 * non-negative length</li>
 * <li>throws <code>IllegalArgumentException</code> if the array is null or
 * or the indices are invalid</li>
 * <li>returns <code>false</li> if the array is non-null, but
 * <code>length</code> is 0 unless <code>allowEmpty</code> is <code>true</code>
 * </ul></p>
 *
 * @param values     the input array
 * @param begin      index of the first array element to include
 * @param length     the number of elements to include
 * @param allowEmpty if <code>true</code> then zero length arrays are allowed
 * @return true if the parameters are valid
 * @throws MathIllegalArgumentException if the indices are invalid or the array is null
 * @since 3.3
 */
public static boolean verifyValues(final double[] values, final int begin, final int length,
        final boolean allowEmpty) throws MathIllegalArgumentException {

    if (values == null) {
        throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
    }

    if (begin < 0) {
        throw new NotPositiveException(LocalizedFormats.START_POSITION, Integer.valueOf(begin));
    }

    if (length < 0) {
        throw new NotPositiveException(LocalizedFormats.LENGTH, Integer.valueOf(length));
    }

    if (begin + length > values.length) {
        throw new NumberIsTooLargeException(LocalizedFormats.SUBARRAY_ENDS_AFTER_ARRAY_END,
                Integer.valueOf(begin + length), Integer.valueOf(values.length), true);
    }

    if (length == 0 && !allowEmpty) {
        return false;
    }

    return true;

}

From source file:org.nd4j.linalg.api.rng.distribution.BaseDistribution.java

/**
 * For a random variable {@code X} whose values are distributed according
 * to this distribution, this method returns {@code P(x0 < X <= x1)}.
 *
 * @param x0 Lower bound (excluded).//w w  w .  j ava 2  s. c  o  m
 * @param x1 Upper bound (included).
 * @return the probability that a random variable with this distribution
 * takes a value between {@code x0} and {@code x1}, excluding the lower
 * and including the upper endpoint.
 * @throws org.apache.commons.math3.exception.NumberIsTooLargeException if {@code x0 > x1}.
 *                                                                      <p/>
 *                                                                      The default implementation uses the identity
 *                                                                      {@code P(x0 < X <= x1) = P(X <= x1) - P(X <= x0)}
 * @since 3.1
 */

public double probability(double x0, double x1) {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1, true);
    }
    return cumulativeProbability(x1) - cumulativeProbability(x0);
}

From source file:org.nd4j.linalg.api.rng.distribution.impl.LogNormalDistribution.java

/**
 * {@inheritDoc}//w  w  w.  j  av  a  2  s .c o  m
 */
@Override
public double probability(double x0, double x1) throws NumberIsTooLargeException {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1, true);
    }
    final double denom = standardDeviation * SQRT2;
    final double v0 = (x0 - mean) / denom;
    final double v1 = (x1 - mean) / denom;
    return 0.5 * Erf.erf(v0, v1);
}

From source file:org.nd4j.linalg.api.rng.distribution.impl.UniformDistribution.java

/**
 * Creates a uniform distribution./*w  w w  .  ja v a  2 s .  c o m*/
 *
 * @param rng   Random number generator.
 * @param lower Lower bound of this distribution (inclusive).
 * @param upper Upper bound of this distribution (exclusive).
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 * @since 3.1
 */
public UniformDistribution(org.nd4j.linalg.api.rng.Random rng, double lower, double upper)
        throws NumberIsTooLargeException {
    super(rng);
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper,
                false);
    }

    this.lower = lower;
    this.upper = upper;
}