Class NumberUtil

java.lang.Object
org.drasyl.util.NumberUtil

public final class NumberUtil extends Object
Utility class for number-related operations.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    max(double... numbers)
    Returns the largest given number.
    static double
    max(double a, double b)
    Returns the largest given number.
    static double
    max(double a, double b, double c)
    Returns the largest given number.
    static int
    max(int... numbers)
    Returns the largest given number.
    static int
    max(int a, int b)
    Returns the largest given number.
    static int
    max(int a, int b, int c)
    Returns the largest given number.
    static long
    max(long... numbers)
    Returns the largest given number.
    static long
    max(long a, long b)
    Returns the largest given number.
    static long
    max(long a, long b, long c)
    Returns the largest given number.
    static double
    min(double... numbers)
    Returns the smallest given number.
    static double
    min(double a, double b)
    Returns the smallest given number.
    static double
    min(double a, double b, double c)
    Returns the smallest given number.
    static int
    min(int... numbers)
    Returns the smallest given number.
    static int
    min(int a, int b)
    Returns the smallest given number.
    static int
    min(int a, int b, int c)
    Returns the smallest given number.
    static long
    min(long... numbers)
    Returns the smallest given number.
    static long
    min(long a, long b)
    Returns the smallest given number.
    static long
    min(long a, long b, long c)
    Returns the smallest given number.
    static String
    Takes a Number with bytes and returns it as a formatted SI (metric) multiple-byte number.
    static String
    numberToHumanData(Number number, short precision)
    Takes a Number with bytes and returns it as a formatted SI (metric) multiple-byte number.
    static String
    numberToHumanData(Number number, short precision, Locale locale)
    Takes a Number with bytes and returns it as a formatted SI (metric) multiple-byte number.
    static String
    numberToHumanData(Number number, Locale locale)
    Takes a Number with bytes and returns it as a formatted SI (metric) multiple-byte number.
    static String
    Takes a Number with bytes and returns it as a formatted SI (metric) data-rate.
    static String
    numberToHumanDataRate(Number number, short precision)
    Takes a Number with bytes and returns it as a formatted SI (metric) data-rate.
    static String
    numberToHumanDataRate(Number number, short precision, Locale locale)
    Takes a Number with bytes and returns it as a formatted SI (metric) data-rate.
    static String
    Takes a Number with bytes and returns it as a formatted SI (metric) data-rate.
    static double
    sampleStandardDeviation(double... values)
    Returns the corrected sample standard deviation of given values.
    static double
    sampleVariance(double... values)
    Returns the unbiased sample variance of given values.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • numberToHumanData

      public static String numberToHumanData(Number number, short precision, Locale locale)
      Takes a Number with bytes and returns it as a formatted SI (metric) multiple-byte number.

      Inspired by https://stackoverflow.com/a/3758880/1074188.

      Parameters:
      number - number containing size in bytes
      precision - Sets the precision of the number. Value -1 has a special meaning here: an absolute formatted number less then 10 results in precision 2; an absolute formatted number less then 100 results in precision 1; all other absolute formatted numbers result in precision 0
      locale - The locale to apply during formatting. If locale is null then no localization is applied.
      Returns:
      the formatted SI (metric) multiple-byte number
      Throws:
      IllegalArgumentException - if precision is less than -1
    • numberToHumanData

      public static String numberToHumanData(Number number, short precision)
      Takes a Number with bytes and returns it as a formatted SI (metric) multiple-byte number.
      Parameters:
      number - number containing size in bytes
      precision - Sets the precision of the number. Value -1 has a special meaning here: an absolute formatted number less then 10 results in precision 2; an absolute formatted number less then 100 results in precision 1; all other absolute formatted numbers result in precision 0
      Returns:
      the formatted SI (metric) multiple-byte number
      Throws:
      IllegalArgumentException - if precision is less than -1
    • numberToHumanData

      public static String numberToHumanData(Number number, Locale locale)
      Takes a Number with bytes and returns it as a formatted SI (metric) multiple-byte number.
      Parameters:
      number - number containing size in bytes
      locale - The locale to apply during formatting. If locale is null then no localization is applied.
      Returns:
      the formatted SI (metric) multiple-byte number
      Throws:
      IllegalArgumentException - if precision is less than -1
    • numberToHumanData

      public static String numberToHumanData(Number number)
      Takes a Number with bytes and returns it as a formatted SI (metric) multiple-byte number.
      Parameters:
      number - number containing size in bytes
      Returns:
      the formatted SI (metric) multiple-byte number
      Throws:
      IllegalArgumentException - if precision is less than -1
    • numberToHumanDataRate

      public static String numberToHumanDataRate(Number number, short precision, Locale locale)
      Takes a Number with bytes and returns it as a formatted SI (metric) data-rate.

      Inspired by https://stackoverflow.com/a/3758880/1074188.

      Parameters:
      number - number containing size in bytes
      precision - Sets the precision of the number. Value -1 has a special meaning here: an absolute formatted number less than 10 results in precision 2; an absolute formatted number less than 100 results in precision 1; all other absolute formatted numbers result in precision 0
      locale - The locale to apply during formatting. If locale is null then no localization is applied.
      Returns:
      the formatted SI (metric) data-rate
      Throws:
      IllegalArgumentException - if precision is less than -1
    • numberToHumanDataRate

      public static String numberToHumanDataRate(Number number, short precision)
      Takes a Number with bytes and returns it as a formatted SI (metric) data-rate.
      Parameters:
      number - number containing size in bytes
      precision - Sets the precision of the number. Value -1 has a special meaning here: an absolute formatted number less than 10 results in precision 2; an absolute formatted number less than 100 results in precision 1; all other absolute formatted numbers result in precision 0
      Returns:
      the formatted SI (metric) data-rate
      Throws:
      IllegalArgumentException - if precision is less than -1
    • numberToHumanDataRate

      public static String numberToHumanDataRate(Number number, Locale locale)
      Takes a Number with bytes and returns it as a formatted SI (metric) data-rate.
      Parameters:
      number - number containing size in bytes
      locale - The locale to apply during formatting. If locale is null then no localization is applied.
      Returns:
      the formatted SI (metric) data-rate
      Throws:
      IllegalArgumentException - if precision is less than -1
    • numberToHumanDataRate

      public static String numberToHumanDataRate(Number number)
      Takes a Number with bytes and returns it as a formatted SI (metric) data-rate.
      Parameters:
      number - number containing size in bytes
      Returns:
      the formatted SI (metric) data-rate
      Throws:
      IllegalArgumentException - if precision is less than -1
    • sampleVariance

      public static double sampleVariance(double... values)
      Returns the unbiased sample variance of given values.
    • sampleStandardDeviation

      public static double sampleStandardDeviation(double... values)
      Returns the corrected sample standard deviation of given values.
    • min

      public static int min(int a, int b)
      Returns the smallest given number.
      Returns:
      the smallest number in numbers.
    • min

      public static int min(int a, int b, int c)
      Returns the smallest given number.
      Returns:
      the smallest number in numbers.
    • min

      public static int min(int... numbers)
      Returns the smallest given number.
      Returns:
      the smallest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • min

      public static long min(long a, long b)
      Returns the smallest given number.
      Returns:
      the smallest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • min

      public static long min(long a, long b, long c)
      Returns the smallest given number.
      Returns:
      the smallest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • min

      public static long min(long... numbers)
      Returns the smallest given number.
      Returns:
      the smallest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • min

      public static double min(double a, double b)
      Returns the smallest given number.
      Returns:
      the smallest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • min

      public static double min(double a, double b, double c)
      Returns the smallest given number.
      Returns:
      the smallest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • min

      public static double min(double... numbers)
      Returns the smallest given number.
      Returns:
      the smallest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • max

      public static int max(int a, int b)
      Returns the largest given number.
      Returns:
      the largest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • max

      public static int max(int a, int b, int c)
      Returns the largest given number.
      Returns:
      the largest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • max

      public static int max(int... numbers)
      Returns the largest given number.
      Returns:
      the largest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • max

      public static long max(long a, long b)
      Returns the largest given number.
      Returns:
      the largest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • max

      public static long max(long a, long b, long c)
      Returns the largest given number.
      Returns:
      the largest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • max

      public static long max(long... numbers)
      Returns the largest given number.
      Returns:
      the largest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • max

      public static double max(double a, double b)
      Returns the largest given number.
      Returns:
      the largest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • max

      public static double max(double a, double b, double c)
      Returns the largest given number.
      Returns:
      the largest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given
    • max

      public static double max(double... numbers)
      Returns the largest given number.
      Returns:
      the largest number in numbers.
      Throws:
      NoSuchElementException - if no numbers were given