Class DecimalUtils

java.lang.Object
tools.jackson.databind.ext.javatime.util.DecimalUtils

public final class DecimalUtils extends Object
Utilities to aid in the translation of decimal types to/from multiple parts.
  • Constructor Details

    • DecimalUtils

      private DecimalUtils()
  • Method Details

    • toDecimal

      public static String toDecimal(long seconds, int nanoseconds)
    • toBigDecimal

      public static BigDecimal toBigDecimal(long seconds, int nanoseconds)
      Factory method for constructing BigDecimal out of second, nano-second components.
      Parameters:
      seconds - Seconds component
      nanoseconds - Nanoseconds component
      Returns:
      BigDecimal representation
      Throws:
      ArithmeticException - if the calculation overflows or produces invalid results
    • extractSecondsAndNanos

      public static <T> T extractSecondsAndNanos(BigDecimal seconds, BiFunction<Long,Integer,T> convert, boolean negativeAdjustment)
      Extracts the seconds and nanoseconds component of seconds as long and int values, passing them to the given converter. The implementation avoids latency issues present on some JRE releases.
      Type Parameters:
      T - The return type of the converter function
      Parameters:
      seconds - The decimal seconds value to extract components from
      convert - Function to convert the extracted seconds and nanoseconds into result type
      negativeAdjustment - Whether to adjust negative nanoseconds
      Returns:
      The result of applying the converter function
      Throws:
      ArithmeticException - if the calculation overflows or produces invalid results
      Since:
      2.19