Java BigDecimal Min minimum(BigDecimal... values)

Here you can find the source of minimum(BigDecimal... values)

Description

Calculate the minimum value from an array of values.

License

Apache License

Parameter

Parameter Description
values Array of values.

Return

minimum value of the provided set.

Declaration

public static BigDecimal minimum(BigDecimal... values) 

Method Source Code

//package com.java2s;
/**//w w  w  .  j ava 2  s .  co  m
 * Useful Math utilities
 *
 * @author John DeRegnaucourt (john@cedarsoftware.com)
 *         <br>
 *         Copyright (c) Cedar Software LLC
 *         <br><br>
 *         Licensed under the Apache License, Version 2.0 (the "License");
 *         you may not use this file except in compliance with the License.
 *         You may obtain a copy of the License at
 *         <br><br>
 *         http://www.apache.org/licenses/LICENSE-2.0
 *         <br><br>
 *         Unless required by applicable law or agreed to in writing, software
 *         distributed under the License is distributed on an "AS IS" BASIS,
 *         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *         See the License for the specific language governing permissions and
 *         limitations under the License.
 */

import java.math.BigDecimal;
import java.math.BigInteger;

public class Main {
    /**
     * Calculate the minimum value from an array of values.
     *
     * @param values Array of values.
     * @return minimum value of the provided set.
     */
    public static long minimum(long... values) {
        int len = values.length;
        long current = values[0];

        for (int i = 1; i < len; i++) {
            current = Math.min(values[i], current);
        }

        return current;
    }

    /**
     * Calculate the minimum value from an array of values.
     *
     * @param values Array of values.
     * @return minimum value of the provided set.
     */
    public static double minimum(double... values) {
        int len = values.length;
        double current = values[0];

        for (int i = 1; i < len; i++) {
            current = Math.min(values[i], current);
        }

        return current;
    }

    /**
     * Calculate the minimum value from an array of values.
     *
     * @param values Array of values.
     * @return minimum value of the provided set.
     */
    public static BigInteger minimum(BigInteger... values) {
        int len = values.length;
        if (len == 1) {
            if (values[0] == null) {
                throw new IllegalArgumentException("Cannot passed null BigInteger entry to minimum()");
            }
            return values[0];
        }
        BigInteger current = values[0];

        for (int i = 1; i < len; i++) {
            if (values[i] == null) {
                throw new IllegalArgumentException("Cannot passed null BigInteger entry to minimum()");
            }
            current = values[i].min(current);
        }

        return current;
    }

    /**
     * Calculate the minimum value from an array of values.
     *
     * @param values Array of values.
     * @return minimum value of the provided set.
     */
    public static BigDecimal minimum(BigDecimal... values) {
        int len = values.length;
        if (len == 1) {
            if (values[0] == null) {
                throw new IllegalArgumentException("Cannot passed null BigDecimal entry to minimum()");
            }
            return values[0];
        }
        BigDecimal current = values[0];

        for (int i = 1; i < len; i++) {
            if (values[i] == null) {
                throw new IllegalArgumentException("Cannot passed null BigDecimal entry to minimum()");
            }
            current = values[i].min(current);
        }

        return current;
    }
}

Related

  1. min(BigDecimal... amounts)
  2. min(final BigDecimal bd1, final BigDecimal bd2)
  3. min(final BigDecimal v1, final BigDecimal v2)
  4. min(List numbers)
  5. minimum(BigDecimal... decimals)
  6. minus(BigDecimal a, BigDecimal b)
  7. minus(BigDecimal decimal)
  8. minus(BigDecimal num1, BigDecimal num2)
  9. minusMultiply(BigDecimal num)