Example usage for org.apache.commons.math3.exception.util LocalizedFormats LENGTH

List of usage examples for org.apache.commons.math3.exception.util LocalizedFormats LENGTH

Introduction

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

Prototype

LocalizedFormats LENGTH

To view the source code for org.apache.commons.math3.exception.util LocalizedFormats LENGTH.

Click Source Link

Usage

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

/**
 * This method is used// w  w w . j a  v  a2  s  .c om
 * 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;

}