Class NumberUtils

java.lang.Object
org.instancio.internal.util.NumberUtils

public final class NumberUtils extends Object
  • Method Details

    • getMinValue

      public static <T extends Number & Comparable<T>> T getMinValue(Class<?> klass)
    • getMaxValue

      public static <T extends Number & Comparable<T>> T getMaxValue(Class<?> klass)
    • getToLongConverter

      public static <T extends Number> Function<Long,T> getToLongConverter(Class<?> klass)
    • calculateNewMin

      public static <T extends Number & Comparable<T>> T calculateNewMin(@Nullable T curMin, T newMax, int percentage)
      Calculate a new minimum given the new maximum.

      If the new maximum is less than the current minimum, returns a new minimum value that is less than the nex maximum by the specified percentage. Otherwise, returns the current minimum.

      Type Parameters:
      T - number type
      Parameters:
      curMin - current minimum
      newMax - new maximum
      percentage - to adjust by
      Returns:
      new minimum if current minimum is greater than the new maximum
    • calculateNewMax

      public static <T extends Number & Comparable<T>> T calculateNewMax(@Nullable T curMax, T newMin, int percentage)
      Calculate a new maximum given the new minimum.

      If the new minimum is greater than the current maximum, returns a new maximum value that is higher than the new minimum by the specified percentage. Otherwise, returns the current maximum.

      Type Parameters:
      T - number type
      Parameters:
      curMax - current maximum
      newMin - new minimum
      percentage - to adjust by
      Returns:
      new maximum if current maximum is less than the new minimum