Klasse NumberUtil

java.lang.Object
com.github.hypfvieh.util.NumberUtil

public final class NumberUtil extends Object
Helper class to convert different types of strings to double/BigDecimal.
BigDecimals are usually created with a scale of BIGDECIMAL_DEFAULT_FRACTIONS, if not specified otherwise.
  • Felddetails

    • BIGDECIMAL_DEFAULT_FRACTIONS

      public static final int BIGDECIMAL_DEFAULT_FRACTIONS
      Siehe auch:
    • NEGATIVE_ONE

      public static final BigDecimal NEGATIVE_ONE
    • ONE_HUNDRED

      public static final BigDecimal ONE_HUNDRED
  • Methodendetails

    • convertNumberToBigDecimal

      public static BigDecimal convertNumberToBigDecimal(Number _num)
      Converts a Number to a BigDecimal using BIGDECIMAL_DEFAULT_FRACTIONS maximum fraction digits.
      Parameter:
      _num - number to convert
      Gibt zurück:
      BigDecimal or null if input was null
    • convertNumberToBigDecimal

      public static BigDecimal convertNumberToBigDecimal(Number _num, int _fractionDigits)
      Converts a Number to a BigDecimal using given fraction digits as scale.
      Parameter:
      _num - number to convert
      Gibt zurück:
      BigDecimal or null if input was null
    • isLess

      public static boolean isLess(BigDecimal _v1, BigDecimal _v2)
      Compares v1 vs. v2 and will return true if v1 is smaller than v2.
      This comparison ignores the scale of the BigDecimal.
      Will return false if any (or both) parameter is null
      Parameter:
      _v1 - first value
      _v2 - second value
      Gibt zurück:
      true if first value smaller than second
    • isGreater

      public static boolean isGreater(BigDecimal _v1, BigDecimal _v2)
      Compares v1 vs. v2 and will return true if v1 is bigger than v2.
      This comparison ignores the scale of the BigDecimal.
      Will return false if any (or both) parameter is null
      Parameter:
      _v1 - first value
      _v2 - second value
      Gibt zurück:
      true if first value bigger than second
    • isEqual

      public static boolean isEqual(BigDecimal _v1, BigDecimal _v2)
      Compares v1 vs. v2 and will return true if they are equal.
      This comparison ignores the scale of the BigDecimal, which will be done when BigDecimal.equals(Object) is used.
      Will return false if any (or both) parameter is null
      Parameter:
      _v1 - first value
      _v2 - second value
      Gibt zurück:
      true if equal
    • isZero

      public static boolean isZero(BigDecimal _val)
      Checks if the given BigDecimal is zero. This comparison ignores the scale of the BigDecimal. Will return false if the input value is null.
      Parameter:
      _val - the value to check
      Gibt zurück:
      true if the value is zero, false otherwise
    • isGreaterOrEqual

      public static boolean isGreaterOrEqual(BigDecimal _v1, BigDecimal _v2)
      Compares v1 vs. v2 and will return true if they are equal or v1 is bigger than v2.
      This comparison ignores the scale of the BigDecimal, which will be done when BigDecimal.equals(Object) is used.
      Will return false if any (or both) parameter is null
      Parameter:
      _v1 - first value
      _v2 - second value
      Gibt zurück:
      true if bigger or equal
    • isLessOrEqual

      public static boolean isLessOrEqual(BigDecimal _v1, BigDecimal _v2)
      Compares v1 vs. v2 and will return true if they are equal or v1 is smaller than v2.
      This comparison ignores the scale of the BigDecimal, which will be done when BigDecimal.equals(Object) is used.
      Will return false if any (or both) parameter is null
      Parameter:
      _v1 - first value
      _v2 - second value
      Gibt zurück:
      true if smaller or equal
    • isNegative

      public static boolean isNegative(BigDecimal _bd)
      Checks if given BigDecimal is negative.
      Parameter:
      _bd - value
      Gibt zurück:
      true if negative
    • invert

      public static BigDecimal invert(BigDecimal _bd)
      Inverts a BigDecimal. This means, if given value was negative, the positive representation is returned and vice versa.
      Parameter:
      _bd - value
      Gibt zurück:
      inverted BigDecimal or null if input was null
    • sumBigDecimals

      public static BigDecimal sumBigDecimals(BigDecimal... _add)
      Sums the given BigDecimals. Will return null if any of the given objects is null.
      Parameter:
      _add - var args containing BigDecimals to sum
      Gibt zurück:
      BigDecimal, BigDecimal.ZERO when no or null input is given
    • sumBigDecimals

      public static BigDecimal sumBigDecimals(Collection<BigDecimal> _add)
      Sums the given collection of BigDecimals.
      Will ignore any null value in collection.
      When a null collection is given, zero is returned.
      Parameter:
      _add - collection of bigdecimals
      Gibt zurück:
      BigDecimal, never null