Java BigDecimal Min min(final BigDecimal v1, final BigDecimal v2)

Here you can find the source of min(final BigDecimal v1, final BigDecimal v2)

Description

min

License

Apache License

Return

return the min amount

Declaration

public static BigDecimal min(final BigDecimal v1, final BigDecimal v2) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.math.BigDecimal;

public class Main {
    /**//from w  w  w .j  a v a 2 s  .c o m
     * @return return the min amount
     */
    public static BigDecimal min(final BigDecimal v1, final BigDecimal v2) {
        if (v1 == null) {
            return v2;
        } else if (v2 == null) {
            return v1;
        }
        return v1.compareTo(v2) <= 0 ? v1 : v2;
    }

    /**
     * @return 1 if v1 &gt; v2 or v2==null and v2!=null
     * @return 0 if v1 == v2 or v1==null and v2==null
     * @return -1 if v1 &lt; v2 or v1==null and v2!=null
     */
    public static int compareTo(final BigDecimal v1, final BigDecimal v2) {
        int ret = 1;
        if (v1 != null && v2 != null) {
            ret = v1.compareTo(v2);
        } else if (v1 == null && v2 == null) {
            ret = 0;
        } else if (v1 == null) {
            ret = -1;
        }
        return ret;
    }
}

Related

  1. min(BigDecimal a, BigDecimal b)
  2. min(BigDecimal b1, BigDecimal b2)
  3. min(BigDecimal one, BigDecimal other)
  4. min(BigDecimal... amounts)
  5. min(final BigDecimal bd1, final BigDecimal bd2)
  6. min(List numbers)
  7. minimum(BigDecimal... decimals)
  8. minimum(BigDecimal... values)
  9. minus(BigDecimal a, BigDecimal b)