Java BigDecimal Max max(BigDecimal b1, BigDecimal b2)

Here you can find the source of max(BigDecimal b1, BigDecimal b2)

Description

Return max value of @param b1 and @param b2

License

Open Source License

Parameter

Parameter Description
b1 <code>java.math.BigDecimal</code>
b2 <code>java.math.BigDecimal</code>

Return

java.math.BigDecimal

Declaration

public static BigDecimal max(BigDecimal b1, BigDecimal b2) 

Method Source Code


//package com.java2s;
/*//  ww  w. j av a  2s.  com
 * File: $RCSfile$
 *
 * Copyright (c) 2005 Wincor Nixdorf International GmbH,
 * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Wincor Nixdorf ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Wincor Nixdorf.
 */

import java.math.BigDecimal;

public class Main {
    public static final BigDecimal ZERO = new BigDecimal((double) 0);

    /**
     * Return max value of @param b1 and @param b2
     *
     * @param b1 <code>java.math.BigDecimal</code>
     * @param b2 <code>java.math.BigDecimal</code>
     * @return <code>java.math.BigDecimal</code>
     */
    public static BigDecimal max(BigDecimal b1, BigDecimal b2) {
        if (b1 == null && b2 == null) {
            return null;
        }
        if (b1 == null) {
            b1 = ZERO;
        }
        if (b2 == null) {
            b2 = ZERO;
        }
        if (b1.compareTo(b2) >= 0) {
            return b1;
        }
        return b2;
    }

    /**
     * Compare to b1 with b2
     *
     * @param b1 <code>java.math.BigDecimal</code>
     * @param b2 <code>java.math.BigDecimal</code>
     * @return if b1 and b2 ==null return 0, else @see java.math.BigDecimal#compareTo
     */
    public static int compareTo(BigDecimal b1, BigDecimal b2) {
        if (b1 == null && b2 == null) {
            return 0;
        }
        if (b1 == null) {
            b1 = ZERO;
        }
        if (b2 == null) {
            b2 = ZERO;
        }
        return b1.compareTo(b2);
    }
}

Related

  1. max(BigDecimal a, BigDecimal b)
  2. max(BigDecimal one, BigDecimal other)
  3. max(BigDecimal... amounts)
  4. max(BigDecimal... values)
  5. max(final BigDecimal bd1, final BigDecimal bd2)