Class NumberUtils


  • public class NumberUtils
    extends Object
    • Method Detail

      • getInstance

        public static NumberUtils getInstance()
      • randomNonNegativeLong

        public static long randomNonNegativeLong()
      • min

        public static int min​(int a,
                              int b)
      • max

        public static int max​(int a,
                              int b)
      • round

        public static double round​(double val,
                                   int places)
      • round

        public static float round​(float val,
                                  int places)
      • padWithZeroes

        public static String padWithZeroes​(Number value,
                                           int numberOfZeroes)
      • createDoubleQuietly

        @Nullable
        public static @Nullable Double createDoubleQuietly​(@Nullable
                                                           @Nullable String s)
        see NumberUtils.createDouble(String). Returns null instead of throwing an exception.
      • unlocalizedStringToDouble

        public static double unlocalizedStringToDouble​(@Nullable
                                                       @Nullable String s)
        Convert string to double value. Method expects non-localized input (as produced by Double.toString(double)). If the input cannot be parsed method would log this and return 0. This method is intended to be used from FreeMarker code.
        Parameters:
        s - input string containing representation of a double value.
        Returns:
        parsed value or 0 if there was error during parsing
      • stringToLong

        public static long stringToLong​(String s)
      • stringToInt

        public static int stringToInt​(String s)
      • max

        public static <T extends Comparable<? super T>> T max​(@NotNull
                                                              @NotNull Collection<T> collection)
      • isPositiveInteger

        public static boolean isPositiveInteger​(@Nullable
                                                @Nullable String input)
      • arrayStore

        public static void arrayStore​(int number,
                                      @NotNull
                                      @org.jetbrains.annotations.NotNull byte[] array,
                                      int startIndex)
      • arrayStore

        public static void arrayStore​(long number,
                                      @NotNull
                                      @org.jetbrains.annotations.NotNull byte[] array,
                                      int startIndex)
      • valueOf

        public static long valueOf​(Long l,
                                   long defaultValue)
        Null-safe unboxing of Long
        Parameters:
        l - value to unbox
        defaultValue - default value to return if l is null
      • toInteger

        @Nullable
        public static @Nullable Integer toInteger​(@Nullable
                                                  @Nullable Number number)