/** * Modify the denominator format. * @param format the new denominator format value. * @throws NullArgumentException if {@code format} is {@code null}. */ public void setDenominatorFormat(final NumberFormat format) { if (format == null) { throw new NullArgumentException(LocalizedFormats.DENOMINATOR_FORMAT); } this.denominatorFormat = format; }
/** * Modify the whole format. * @param format The new whole format value. * @throws NullArgumentException if {@code format} is {@code null}. */ public void setWholeFormat(final NumberFormat format) { if (format == null) { throw new NullArgumentException(LocalizedFormats.WHOLE_FORMAT); } this.wholeFormat = format; } }
/** * Modify the numerator format. * @param format the new numerator format value. * @throws NullArgumentException if {@code format} is {@code null}. */ public void setNumeratorFormat(final NumberFormat format) { if (format == null) { throw new NullArgumentException(LocalizedFormats.NUMERATOR_FORMAT); } this.numeratorFormat = format; }
/** * Modify the whole format. * @param format The new whole format value. * @throws NullArgumentException if {@code format} is {@code null}. */ public void setWholeFormat(NumberFormat format) { if (format == null) { throw new NullArgumentException(LocalizedFormats.WHOLE_FORMAT); } this.wholeFormat = format; } }
/** * Checks that an object is not null. * * @param o Object to be checked. * @throws NullArgumentException if {@code o} is {@code null}. */ public static void checkNotNull(Object o) throws NullArgumentException { if (o == null) { throw new NullArgumentException(); } } }
/** * Create an instance with a custom number format for both real and * imaginary parts. * @param format the custom format for both real and imaginary parts. * @throws NullArgumentException if {@code realFormat} is {@code null}. */ public ComplexFormat(NumberFormat format) throws NullArgumentException { if (format == null) { throw new NullArgumentException(LocalizedFormats.IMAGINARY_FORMAT); } this.imaginaryCharacter = DEFAULT_IMAGINARY_CHARACTER; this.imaginaryFormat = format; this.realFormat = format; }
/** * Checks that an object is not null. * * @param o Object to be checked. * @param pattern Message pattern. * @param args Arguments to replace the placeholders in {@code pattern}. * @throws NullArgumentException if {@code o} is {@code null}. */ public static void checkNotNull(Object o, Localizable pattern, Object ... args) throws NullArgumentException { if (o == null) { throw new NullArgumentException(pattern, args); } }
/** * Defines a maximal count and a callback method to be triggered at * counter exhaustion. * * @param max Maximal count. * @param cb Function to be called when the maximal count has been reached. * @throws NullArgumentException if {@code cb} is {@code null} */ public Incrementor(int max, MaxCountExceededCallback cb) throws NullArgumentException { if (cb == null){ throw new NullArgumentException(); } maximalCount = max; maxCountCallback = cb; }
/** * Create an instance with a custom number format for the real part and a * custom number format for the imaginary part. * @param realFormat the custom format for the real part. * @param imaginaryFormat the custom format for the imaginary part. * @throws NullArgumentException if {@code imaginaryFormat} is {@code null}. * @throws NullArgumentException if {@code realFormat} is {@code null}. */ public ComplexFormat(NumberFormat realFormat, NumberFormat imaginaryFormat) throws NullArgumentException { if (imaginaryFormat == null) { throw new NullArgumentException(LocalizedFormats.IMAGINARY_FORMAT); } if (realFormat == null) { throw new NullArgumentException(LocalizedFormats.REAL_FORMAT); } this.imaginaryCharacter = DEFAULT_IMAGINARY_CHARACTER; this.imaginaryFormat = imaginaryFormat; this.realFormat = realFormat; }
/** * Creates a {@link RealVector} using the data from the input array. * * @param data the input data * @return a data.length RealVector * @throws NoDataException if {@code data} is empty. * @throws NullArgumentException if {@code data} is {@code null}. */ public static RealVector createRealVector(double[] data) throws NoDataException, NullArgumentException { if (data == null) { throw new NullArgumentException(); } return new ArrayRealVector(data, true); }
/** * Verifies that {@code array} has length at least 2. * * @param array array to test * @throws NullArgumentException if array is null * @throws InsufficientDataException if array is too short */ private void checkArray(double[] array) { if (array == null) { throw new NullArgumentException(LocalizedFormats.NULL_NOT_ALLOWED); } if (array.length < 2) { throw new InsufficientDataException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, array.length, 2); } }
/** * This default implementation just calls {@link #increment} in a loop over * the input array. * <p> * Throws IllegalArgumentException if the input values array is null.</p> * * @param values values to add * @throws MathIllegalArgumentException if values is null * @see org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic#incrementAll(double[]) */ public void incrementAll(double[] values) throws MathIllegalArgumentException { if (values == null) { throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } incrementAll(values, 0, values.length); }
/** * Ensures that the provided arrays fulfills the assumptions. * * @param x first sample * @param y second sample * @throws NullArgumentException if {@code x} or {@code y} are {@code null}. * @throws NoDataException if {@code x} or {@code y} are zero-length. */ private void ensureDataConformance(final double[] x, final double[] y) throws NullArgumentException, NoDataException { if (x == null || y == null) { throw new NullArgumentException(); } if (x.length == 0 || y.length == 0) { throw new NoDataException(); } }
/** * <p> * Multiplies the value of this fraction by the passed * <code>BigInteger</code>, returning the result in reduced form. * </p> * * @param bg the {@code BigInteger} to multiply by. * @return a {@code BigFraction} instance with the resulting values. * @throws NullArgumentException if {@code bg} is {@code null}. */ public BigFraction multiply(final BigInteger bg) { if (bg == null) { throw new NullArgumentException(); } if (numerator.signum() == 0 || bg.signum() == 0) { return ZERO; } return new BigFraction(bg.multiply(numerator), denominator); }
/** * Check sample data. * * @param data Sample data. * @throws NullArgumentException if {@code data} is {@code null}. * @throws NumberIsTooSmallException if there is not enough sample data. */ private void checkSampleData(final double[] data) throws NullArgumentException, NumberIsTooSmallException { if (data == null) { throw new NullArgumentException(); } if (data.length < 2) { throw new NumberIsTooSmallException( LocalizedFormats.INSUFFICIENT_DATA_FOR_T_STATISTIC, data.length, 2, true); } }
/** * Construct a vector from part of a array. * * @param d Array. * @param pos Position of first entry. * @param size Number of entries to copy. * @throws NullArgumentException if {@code d} is {@code null}. * @throws NumberIsTooLargeException if the size of {@code d} is less * than {@code pos + size}. */ public ArrayRealVector(double[] d, int pos, int size) throws NullArgumentException, NumberIsTooLargeException { if (d == null) { throw new NullArgumentException(); } if (d.length < pos + size) { throw new NumberIsTooLargeException(pos + size, d.length, true); } data = new double[size]; System.arraycopy(d, pos, data, 0, size); }
/** * Create a new ArrayRealVector using the input array as the underlying * data array. * If an array is built specially in order to be embedded in a * ArrayRealVector and not used directly, the {@code copyArray} may be * set to {@code false}. This will prevent the copying and improve * performance as no new array will be built and no data will be copied. * * @param d Data for the new vector. * @param copyArray if {@code true}, the input array will be copied, * otherwise it will be referenced. * @throws NullArgumentException if {@code d} is {@code null}. * @see #ArrayRealVector(double[]) */ public ArrayRealVector(double[] d, boolean copyArray) throws NullArgumentException { if (d == null) { throw new NullArgumentException(); } data = copyArray ? d.clone() : d; }
/** * Validates parameters to ensure they are appropriate for the evaluation of * the {@link #value(double,double[])} and {@link #gradient(double,double[])} * methods. * * @param param Values for lower and higher bounds. * @throws NullArgumentException if {@code param} is {@code null}. * @throws DimensionMismatchException if the size of {@code param} is * not 2. */ private void validateParameters(double[] param) throws NullArgumentException, DimensionMismatchException { if (param == null) { throw new NullArgumentException(); } if (param.length != 2) { throw new DimensionMismatchException(param.length, 2); } } }
/** * Validates parameters to ensure they are appropriate for the evaluation of * the {@link #value(double,double[])} and {@link #gradient(double,double[])} * methods. * * @param param Values of norm, mean and standard deviation. * @throws NullArgumentException if {@code param} is {@code null}. * @throws DimensionMismatchException if the size of {@code param} is * not 3. */ private void validateParameters(double[] param) throws NullArgumentException, DimensionMismatchException { if (param == null) { throw new NullArgumentException(); } if (param.length != 3) { throw new DimensionMismatchException(param.length, 3); } } }
/** * Returns the sample mode(s). The mode is the most frequently occurring * value in the sample. If there is a unique value with maximum frequency, * this value is returned as the only element of the output array. Otherwise, * the returned array contains the maximum frequency elements in increasing * order. For example, if {@code sample} is {0, 12, 5, 6, 0, 13, 5, 17}, * the returned array will have length two, with 0 in the first element and * 5 in the second. * * <p>NaN values are ignored when computing the mode - i.e., NaNs will never * appear in the output array. If the sample includes only NaNs or has * length 0, an empty array is returned.</p> * * @param sample input data * @return array of array of the most frequently occurring element(s) sorted in ascending order. * @throws MathIllegalArgumentException if the indices are invalid or the array is null * @since 3.3 */ public static double[] mode(double[] sample) throws MathIllegalArgumentException { if (sample == null) { throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } return getMode(sample, 0, sample.length); }