Java BigDecimal Value Check isNotSameAbsValue(final BigDecimal v1, final BigDecimal v2)

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

Description

is Not Same Abs Value

License

Apache License

Return

false if the ABS value match!

Declaration

public static boolean isNotSameAbsValue(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  . java  2  s.  c om*/
     * @return false if the ABS value match!
     */
    public static boolean isNotSameAbsValue(final BigDecimal v1, final BigDecimal v2) {
        return !isSameAbsValue(v1, v2);
    }

    /**
     * @return true if the ABS value match!
     */
    public static boolean isSameAbsValue(final BigDecimal v1, final BigDecimal v2) {
        return isSameValue(abs(v1), abs(v2));
    }

    /**
     * @return true if val1 == val2 (ignoring scale and null are treated as 0)
     */
    public static boolean isSameValue(final BigDecimal val1, final BigDecimal val2) {
        return val1 == null && val2 == null || val1 != null && val2 != null && val1.compareTo(val2) == 0;
    }

    /**
     * Returns the ABS of the value, handles null.
     */
    public static BigDecimal abs(final BigDecimal value) {
        return value != null ? value.abs() : null;
    }

    /**
     * @return 1 if v1 > v2 or v2==null and v2!=null
     * @return 0 if v1 == v2 or v1==null and v2==null
     * @return -1 if v1 < 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. isMaximumDecimalValue(BigDecimal maxValue)
  2. isMoreThanZero(BigDecimal decimal)
  3. isNegative(BigDecimal amount)
  4. isNegative(BigDecimal inValue)
  5. isNotNullOrZero(final BigDecimal number)
  6. isNotZero(final BigDecimal value)
  7. isNotZeroPositive(BigDecimal value)
  8. isNull(BigDecimal bdg)
  9. isNull(final BigDecimal s)