Java BigDecimal Max max(final BigDecimal bd1, final BigDecimal bd2)

Here you can find the source of max(final BigDecimal bd1, final BigDecimal bd2)

Description

Selects the higher of two BigDecimals, preferring the non-null value if one is null.

License

Open Source License

Parameter

Parameter Description
bd1 First value.
bd2 Second value.

Return

Max of the two values or the non-null reference or null if both inputs are null.

Declaration

public static BigDecimal max(final BigDecimal bd1, final BigDecimal bd2) 

Method Source Code


//package com.java2s;
/* Copyright (c) 2011-2014 Pushing Inertia
 * All rights reserved.  http://pushinginertia.com
 *
 * 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
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.//  w ww.  j a  va2s  .  co  m
 */

import java.math.BigDecimal;

public class Main {
    /**
     * Selects the higher of two BigDecimals, preferring the non-null value if one is null.
     * @param bd1 First value.
     * @param bd2 Second value.
     * @return Max of the two values or the non-null reference or null if both inputs are null.
     */
    public static BigDecimal max(final BigDecimal bd1, final BigDecimal bd2) {
        if (bd1 == null) {
            return bd2;
        }
        if (bd2 == null) {
            return bd1;
        }
        if (bd1.compareTo(bd2) > 0) {
            return bd1;
        }
        return bd2;
    }
}

Related

  1. max(BigDecimal a, BigDecimal b)
  2. max(BigDecimal b1, BigDecimal b2)
  3. max(BigDecimal one, BigDecimal other)
  4. max(BigDecimal... amounts)
  5. max(BigDecimal... values)
  6. max(final List list)
  7. max(List numbers)
  8. maximum(BigDecimal... decimals)
  9. maximum(BigDecimal... values)