当前位置: 首页>>代码示例>>Java>>正文


Java LocalizedFormats.LENGTH属性代码示例

本文整理汇总了Java中org.apache.commons.math3.exception.util.LocalizedFormats.LENGTH属性的典型用法代码示例。如果您正苦于以下问题:Java LocalizedFormats.LENGTH属性的具体用法?Java LocalizedFormats.LENGTH怎么用?Java LocalizedFormats.LENGTH使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.commons.math3.exception.util.LocalizedFormats的用法示例。


在下文中一共展示了LocalizedFormats.LENGTH属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setData

/**
 * 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);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:31,代码来源:AbstractUnivariateStatistic.java

示例2: verifyValues

/**
 * This method is used
 * 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;

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:48,代码来源:MathArrays.java

示例3: nextHexString

/**
 * {@inheritDoc}
 * <p>
 * <strong>Algorithm Description:</strong> hex strings are generated using a
 * 2-step process.
 * <ol>
 * <li>{@code len / 2 + 1} binary bytes are generated using the underlying
 * Random</li>
 * <li>Each binary byte is translated into 2 hex digits</li>
 * </ol>
 * </p>
 *
 * @param len the desired string length.
 * @return the random string.
 * @throws NotStrictlyPositiveException if {@code len <= 0}.
 */
public String nextHexString(int len) throws NotStrictlyPositiveException {
    if (len <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.LENGTH, len);
    }

    // Get a random number generator
    RandomGenerator ran = getRandomGenerator();

    // Initialize output buffer
    StringBuilder outBuffer = new StringBuilder();

    // Get int(len/2)+1 random bytes
    byte[] randomBytes = new byte[(len / 2) + 1];
    ran.nextBytes(randomBytes);

    // Convert each byte to 2 hex digits
    for (int i = 0; i < randomBytes.length; i++) {
        Integer c = Integer.valueOf(randomBytes[i]);

        /*
         * Add 128 to byte value to make interval 0-255 before doing hex
         * conversion. This guarantees <= 2 hex digits from toHexString()
         * toHexString would otherwise add 2^32 to negative arguments.
         */
        String hex = Integer.toHexString(c.intValue() + 128);

        // Make sure we add 2 hex digits for each byte
        if (hex.length() == 1) {
            hex = "0" + hex;
        }
        outBuffer.append(hex);
    }
    return outBuffer.toString().substring(0, len);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:50,代码来源:RandomDataGenerator.java

示例4: mode

/**
 * 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
 * @param begin index (0-based) of the first array element to include
 * @param length the number of elements to include
 *
 * @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, final int begin, final int length) {
    if (sample == 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));
    }

    return getMode(sample, begin, length);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:36,代码来源:StatUtils.java

示例5: nextSecureHexString

/**
 * {@inheritDoc}
 * <p>
 * <strong>Algorithm Description:</strong> hex strings are generated in
 * 40-byte segments using a 3-step process.
 * <ol>
 * <li>
 * 20 random bytes are generated using the underlying
 * <code>SecureRandom</code>.</li>
 * <li>
 * SHA-1 hash is applied to yield a 20-byte binary digest.</li>
 * <li>
 * Each byte of the binary digest is converted to 2 hex digits.</li>
 * </ol>
 * </p>
 * @throws NotStrictlyPositiveException if {@code len <= 0}
 */
public String nextSecureHexString(int len) throws NotStrictlyPositiveException {
    if (len <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.LENGTH, len);
    }

    // Get SecureRandom and setup Digest provider
    final RandomGenerator secRan = getSecRan();
    MessageDigest alg = null;
    try {
        alg = MessageDigest.getInstance("SHA-1");
    } catch (NoSuchAlgorithmException ex) {
        // this should never happen
        throw new MathInternalError(ex);
    }
    alg.reset();

    // Compute number of iterations required (40 bytes each)
    int numIter = (len / 40) + 1;

    StringBuilder outBuffer = new StringBuilder();
    for (int iter = 1; iter < numIter + 1; iter++) {
        byte[] randomBytes = new byte[40];
        secRan.nextBytes(randomBytes);
        alg.update(randomBytes);

        // Compute hash -- will create 20-byte binary hash
        byte[] hash = alg.digest();

        // Loop over the hash, converting each byte to 2 hex digits
        for (int i = 0; i < hash.length; i++) {
            Integer c = Integer.valueOf(hash[i]);

            /*
             * Add 128 to byte value to make interval 0-255 This guarantees
             * <= 2 hex digits from toHexString() toHexString would
             * otherwise add 2^32 to negative arguments
             */
            String hex = Integer.toHexString(c.intValue() + 128);

            // Keep strings uniform length -- guarantees 40 bytes
            if (hex.length() == 1) {
                hex = "0" + hex;
            }
            outBuffer.append(hex);
        }
    }
    return outBuffer.toString().substring(0, len);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:65,代码来源:RandomDataGenerator.java


注:本文中的org.apache.commons.math3.exception.util.LocalizedFormats.LENGTH属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。