java.lang.Object
org.sentrysoftware.metricshub.engine.common.helpers.NumberHelper

public class NumberHelper extends Object
Helper class for number-related operations.
  • Field Details

    • INTEGER_DETECT_PATTERN

      public static final Pattern INTEGER_DETECT_PATTERN
      Pattern to detect integers with trailing zeros.
  • Method Details

    • parseDouble

      public static Double parseDouble(String value, Double defaultValue)
      Parse the given double value, if the parsing fails return the default value
      Parameters:
      value - The value we wish to parse
      defaultValue - The default value to return if the parsing fails
      Returns:
      Double value
    • parseInt

      public static Integer parseInt(String value, Integer defaultValue)
      Parse the given integer value, if the parsing fails return the default value
      Parameters:
      value - The value we wish to parse
      defaultValue - The default value to return if the parsing fails
      Returns:
      Integer value
    • round

      public static double round(double value, int places, RoundingMode roundingMode)
      Round the given double value using the specified decimal places
      Parameters:
      value - The value we wish to round
      places - The required decimal places expected as positive
      roundingMode - The rounding behavior used by the BigDecimal object for the numerical operations
      Returns:
      double value
    • cleanUpEnumInput

      public static String cleanUpEnumInput(String state)
      Removes the fractional part and the decimal point of the given state if the fractional part contains only 0 after the decimal point. The state is trimmed and converted to lower case
      Parameters:
      state - the value we wish to process
      Returns:
      String value
    • formatNumber

      public static String formatNumber(Number n, @NonNull @NonNull String format)
      Format the given value as String
      Parameters:
      n - numeric value to format
      format - string format used to format decimal parts
      Returns:
      String value
    • formatNumber

      public static String formatNumber(Number n)
      Format the given value as String
      Parameters:
      n - numeric value to format
      Returns:
      String value