/** * Check that all entries of the input array are >= 0. * * @param in Array to be tested * @throws NotPositiveException if any array entries are less than 0. * @since 3.1 */ public static void checkNonNegative(final long[] in) throws NotPositiveException { for (int i = 0; i < in.length; i++) { if (in[i] < 0) { throw new NotPositiveException(in[i]); } } }
/** * Creates a new instance of a DBSCANClusterer. * * @param eps maximum radius of the neighborhood to be considered * @param minPts minimum number of points needed for a cluster * @throws NotPositiveException if {@code eps < 0.0} or {@code minPts < 0} */ public DBSCANClusterer(final double eps, final int minPts) throws NotPositiveException { if (eps < 0.0d) { throw new NotPositiveException(eps); } if (minPts < 0) { throw new NotPositiveException(minPts); } this.eps = eps; this.minPts = minPts; }
/** * Check all entries of the input array are >= 0. * * @param in Array to be tested * @throws NotPositiveException if any array entries are less than 0. * @since 3.1 */ public static void checkNonNegative(final long[][] in) throws NotPositiveException { for (int i = 0; i < in.length; i ++) { for (int j = 0; j < in[i].length; j++) { if (in[i][j] < 0) { throw new NotPositiveException(in[i][j]); } } } }
/** * Creates a new instance of a DBSCANClusterer. * * @param eps maximum radius of the neighborhood to be considered * @param minPts minimum number of points needed for a cluster * @param measure the distance measure to use * @throws NotPositiveException if {@code eps < 0.0} or {@code minPts < 0} */ public DBSCANClusterer(final double eps, final int minPts, final DistanceMeasure measure) throws NotPositiveException { super(measure); if (eps < 0.0d) { throw new NotPositiveException(eps); } if (minPts < 0) { throw new NotPositiveException(minPts); } this.eps = eps; this.minPts = minPts; }
/** * Raise a BigInteger to an int power. * * @param k Number to raise. * @param e Exponent (must be positive or zero). * @return k<sup>e</sup> * @throws NotPositiveException if {@code e < 0}. */ public static BigInteger pow(final BigInteger k, int e) throws NotPositiveException { if (e < 0) { throw new NotPositiveException(LocalizedFormats.EXPONENT, e); } return k.pow(e); }
/** * Create a microsphere interpolator. * * @param microsphere Microsphere. * @param exponent Exponent used in the power law that computes the * weights (distance dimming factor) of the sample data. * @param sharedSphere Whether the sphere can be shared among the * interpolating function instances. If {@code true}, the instances * will share the same data, and thus will <em>not</em> be thread-safe. * @param noInterpolationTolerance When the distance between an * interpolated point and one of the sample points is less than this * value, no interpolation will be performed (the value of the sample * will be returned). * @throws NotPositiveException if {@code exponent < 0}. */ public MicrosphereProjectionInterpolator(InterpolatingMicrosphere microsphere, double exponent, boolean sharedSphere, double noInterpolationTolerance) throws NotPositiveException { if (exponent < 0) { throw new NotPositiveException(exponent); } this.microsphere = microsphere; this.exponent = exponent; this.sharedSphere = sharedSphere; this.noInterpolationTolerance = noInterpolationTolerance; }
/** * Raise an int to a long power. * * @param k Number to raise. * @param e Exponent (must be positive or zero). * @return k<sup>e</sup> * @throws NotPositiveException if {@code e < 0}. * @deprecated As of 3.3. Please use {@link #pow(int,int)} instead. */ @Deprecated public static int pow(final int k, long e) throws NotPositiveException { if (e < 0) { throw new NotPositiveException(LocalizedFormats.EXPONENT, e); } int result = 1; int k2p = k; while (e != 0) { if ((e & 0x1) != 0) { result *= k2p; } k2p *= k2p; e >>= 1; } return result; }
/** * Raise a long to a long power. * * @param k Number to raise. * @param e Exponent (must be positive or zero). * @return k<sup>e</sup> * @throws NotPositiveException if {@code e < 0}. * @deprecated As of 3.3. Please use {@link #pow(long,int)} instead. */ @Deprecated public static long pow(final long k, long e) throws NotPositiveException { if (e < 0) { throw new NotPositiveException(LocalizedFormats.EXPONENT, e); } long result = 1l; long k2p = k; while (e != 0) { if ((e & 0x1) != 0) { result *= k2p; } k2p *= k2p; e >>= 1; } return result; }
/** * Raise a BigInteger to a long power. * * @param k Number to raise. * @param e Exponent (must be positive or zero). * @return k<sup>e</sup> * @throws NotPositiveException if {@code e < 0}. */ public static BigInteger pow(final BigInteger k, long e) throws NotPositiveException { if (e < 0) { throw new NotPositiveException(LocalizedFormats.EXPONENT, e); } BigInteger result = BigInteger.ONE; BigInteger k2p = k; while (e != 0) { if ((e & 0x1) != 0) { result = result.multiply(k2p); } k2p = k2p.multiply(k2p); e >>= 1; } return result; }
/** * @param s Sigma values. * @throws NotPositiveException if any of the array entries is smaller * than zero. */ public Sigma(double[] s) throws NotPositiveException { for (int i = 0; i < s.length; i++) { if (s[i] < 0) { throw new NotPositiveException(s[i]); } } sigma = s.clone(); }
/** * @param s Sigma values. * @throws NotPositiveException if any of the array entries is smaller * than zero. */ public Sigma(double[] s) throws NotPositiveException { for (int i = 0; i < s.length; i++) { if (s[i] < 0) { throw new NotPositiveException(s[i]); } } sigma = s.clone(); }
/** * Sets the maximal population size. * @param populationLimit maximal population size. * @throws NotPositiveException if the population limit is not a positive number (< 1) * @throws NumberIsTooSmallException if the new population size is smaller than the current number * of chromosomes in the population */ public void setPopulationLimit(final int populationLimit) throws NotPositiveException, NumberIsTooSmallException { if (populationLimit <= 0) { throw new NotPositiveException(LocalizedFormats.POPULATION_LIMIT_NOT_POSITIVE, populationLimit); } if (populationLimit < chromosomes.size()) { throw new NumberIsTooSmallException(populationLimit, chromosomes.size(), true); } this.populationLimit = populationLimit; }
/** * Check binomial preconditions. * * @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); } } }
/** * Creates a binomial distribution. * * @param rng Random number generator. * @param trials Number of trials. * @param p Probability of success. * @throws org.apache.commons.math3.exception.NotPositiveException if {@code trials < 0}. * @throws org.apache.commons.math3.exception.OutOfRangeException if {@code p < 0} or {@code p > 1}. * @since 3.1 */ public BinomialDistribution(Random rng, int trials, double p) { super(rng); if (trials < 0) { throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS, trials); } if (p < 0 || p > 1) { throw new OutOfRangeException(p, 0, 1); } probabilityOfSuccess = p; numberOfTrials = trials; }
/** Create a microsphere interpolator. * @param elements Number of surface elements of the microsphere. * @param exponent Exponent used in the power law that computes the * weights (distance dimming factor) of the sample data. * @throws NotPositiveException if {@code exponent < 0}. * @throws NotStrictlyPositiveException if {@code elements <= 0}. */ public MicrosphereInterpolator(final int elements, final int exponent) throws NotPositiveException, NotStrictlyPositiveException { if (exponent < 0) { throw new NotPositiveException(exponent); } if (elements <= 0) { throw new NotStrictlyPositiveException(elements); } microsphereElements = elements; brightnessExponent = exponent; }
/** * Creates a binomial distribution. * * @param rng Random number generator. * @param trials Number of trials. * @param p Probability of success. * @throws NotPositiveException if {@code trials < 0}. * @throws OutOfRangeException if {@code p < 0} or {@code p > 1}. * @since 3.1 */ public BinomialDistribution(RandomGenerator rng, int trials, double p) { super(rng); if (trials < 0) { throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS, trials); } if (p < 0 || p > 1) { throw new OutOfRangeException(p, 0, 1); } probabilityOfSuccess = p; numberOfTrials = trials; }
/** * Raise a BigInteger to a BigInteger power. * * @param k Number to raise. * @param e Exponent (must be positive or zero). * @return k<sup>e</sup> * @throws NotPositiveException if {@code e < 0}. */ public static BigInteger pow(final BigInteger k, BigInteger e) throws NotPositiveException { if (e.compareTo(BigInteger.ZERO) < 0) { throw new NotPositiveException(LocalizedFormats.EXPONENT, e); } BigInteger result = BigInteger.ONE; BigInteger k2p = k; while (!BigInteger.ZERO.equals(e)) { if (e.testBit(0)) { result = result.multiply(k2p); } k2p = k2p.multiply(k2p); e = e.shiftRight(1); } return result; }
/** * Set the data array. The input array is copied, not referenced. * * @param values data array to store * @param begin the index of the first element to include * @param length the number of elements to include * @throws MathIllegalArgumentException if values is null or the indices * are not valid * @see #evaluate() */ public void setData(final double[] values, final int begin, final int length) throws MathIllegalArgumentException { if (values == null) { throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (begin < 0) { throw new NotPositiveException(LocalizedFormats.START_POSITION, begin); } if (length < 0) { throw new NotPositiveException(LocalizedFormats.LENGTH, length); } if (begin + length > values.length) { throw new NumberIsTooLargeException(LocalizedFormats.SUBARRAY_ENDS_AFTER_ARRAY_END, begin + length, values.length, true); } storedData = new double[length]; System.arraycopy(values, begin, storedData, 0, length); }
throw new NotPositiveException(LocalizedFormats.START_POSITION, Integer.valueOf(begin)); throw new NotPositiveException(LocalizedFormats.LENGTH, Integer.valueOf(length));
throw new NotPositiveException(LocalizedFormats.FACTORIAL_NEGATIVE_PARAMETER, n);