Java BigDecimal Compare compareTo(final BigDecimal b0, final BigDecimal b1)

Here you can find the source of compareTo(final BigDecimal b0, final BigDecimal b1)

Description

Null safe compareTo of two BigDecimal s.

License

Open Source License

Parameter

Parameter Description
b0 the first BigDecimal .
b1 the second BigDecimal .

Return

equal, more little or greater.

Declaration

public static int compareTo(final BigDecimal b0, final BigDecimal b1) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013, 2014, 2015 QPark Consulting  S.a r.l.
 * /*from  w w  w  .  j a v a 2s  .  c om*/
 * This program and the accompanying materials are made available under the 
 * terms of the Eclipse Public License v1.0. 
 * The Eclipse Public License is available at 
 * http://www.eclipse.org/legal/epl-v10.html.
 ******************************************************************************/

import java.math.BigDecimal;

public class Main {
    /**
     * Null safe compareTo of two {@link BigDecimal}s.
     *
     * @param b0
     *            the first {@link BigDecimal}.
     * @param b1
     *            the second {@link BigDecimal}.
     * @return equal, more little or greater.
     * @see BigDecimal#compareTo(Object)
     */
    public static int compareTo(final BigDecimal b0, final BigDecimal b1) {
        if (b0 == b1) {
            return 0;
        } else if (b0 == null) {
            return 1;
        } else if (b1 == null) {
            return -1;
        } else {
            return b0.compareTo(b1);
        }
    }

    /**
     * Null safe compareTo of two {@link BigDecimal}s.
     *
     * @param d0
     *            the first {@link BigDecimal}.
     * @param d1
     *            the second {@link BigDecimal}.
     * @return equal, more little or greater.
     * @see BigDecimal#compareTo(Object)
     */
    public static int compareTo(final Double d0, final Double d1) {
        if (d0 == d1) {
            return 0;
        } else if (d0 == null) {
            return 1;
        } else if (d1 == null) {
            return -1;
        } else {
            return d0.compareTo(d1);
        }
    }
}

Related

  1. compare(BigDecimal one, BigDecimal other)
  2. compare(BigDecimal v1, BigDecimal v2)
  3. compareBigDecimal(BigDecimal bigDecimal, BigDecimal bigDecimal2, boolean desc)
  4. compareBigDecimals(java.math.BigDecimal one, java.math.BigDecimal two)
  5. compareTo(BigDecimal b1, BigDecimal b2)
  6. compareTo(final BigDecimal v1, final BigDecimal v2)
  7. compareToOne(BigDecimal x)
  8. compareToZeroOrNull(BigDecimal value)
  9. greaterThan(BigDecimal decimal, double number)