Class MathUtil

java.lang.Object
org.seppiko.commons.utils.MathUtil

public class MathUtil
extends java.lang.Object
Math Util
Author:
Leonard Woo
  • Constructor Summary

    Constructors
    Constructor Description
    MathUtil()  
  • Method Summary

    Modifier and Type Method Description
    static double avgDecimal​(java.util.List<java.math.BigDecimal> nums)
    BigDecimal list avg number
    static java.math.BigDecimal avgDecimal​(java.util.List<java.math.BigDecimal> nums, java.math.RoundingMode roundingMode)
    BigDecimal list avg number
    static java.math.BigDecimal avgInteger​(java.util.List<java.math.BigInteger> nums, java.math.RoundingMode roundingMode)
    BigInteger list avg number
    static java.lang.String convertDecimalTo​(int num, char[] alphabet)
    Convert decimal to alphabet number
    static java.lang.Integer convertToDecimal​(java.lang.CharSequence num, char[] alphabet)
    Convert any base to decimal
    static java.lang.String format​(java.lang.String precisionPattern, double number)
    Double format
    static java.math.BigDecimal maxDecimal​(java.util.List<java.math.BigDecimal> nums)
    BigDecimal list max number
    static java.math.BigInteger maxInteger​(java.util.List<java.math.BigInteger> nums)
    BigInteger list max number
    static java.math.BigDecimal minDecimal​(java.util.List<java.math.BigDecimal> nums)
    BigDecimal list min number
    static java.math.BigInteger minInteger​(java.util.List<java.math.BigInteger> nums)
    BigInteger list min number

    Methods inherited from class java.lang.Object

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

    • MathUtil

      public MathUtil()
  • Method Details

    • maxDecimal

      public static java.math.BigDecimal maxDecimal​(java.util.List<java.math.BigDecimal> nums) throws java.util.NoSuchElementException
      BigDecimal list max number
      Parameters:
      nums - number list
      Returns:
      maximum
      Throws:
      java.util.NoSuchElementException - list is null
    • maxInteger

      public static java.math.BigInteger maxInteger​(java.util.List<java.math.BigInteger> nums) throws java.util.NoSuchElementException
      BigInteger list max number
      Parameters:
      nums - number list
      Returns:
      maximum
      Throws:
      java.util.NoSuchElementException - list is null
    • minDecimal

      public static java.math.BigDecimal minDecimal​(java.util.List<java.math.BigDecimal> nums) throws java.util.NoSuchElementException
      BigDecimal list min number
      Parameters:
      nums - number list
      Returns:
      minimum
      Throws:
      java.util.NoSuchElementException - list is null
    • minInteger

      public static java.math.BigInteger minInteger​(java.util.List<java.math.BigInteger> nums) throws java.util.NoSuchElementException
      BigInteger list min number
      Parameters:
      nums - number list
      Returns:
      minimum
      Throws:
      java.util.NoSuchElementException - list is null
    • avgDecimal

      public static java.math.BigDecimal avgDecimal​(java.util.List<java.math.BigDecimal> nums, java.math.RoundingMode roundingMode)
      BigDecimal list avg number
      Parameters:
      nums - number list
      roundingMode - RoundingMode
      Returns:
      average
    • avgDecimal

      public static double avgDecimal​(java.util.List<java.math.BigDecimal> nums) throws java.util.NoSuchElementException
      BigDecimal list avg number
      Parameters:
      nums - number list
      Returns:
      average double
      Throws:
      java.util.NoSuchElementException - list is null
    • avgInteger

      public static java.math.BigDecimal avgInteger​(java.util.List<java.math.BigInteger> nums, java.math.RoundingMode roundingMode)
      BigInteger list avg number
      Parameters:
      nums - number list
      roundingMode - RoundingMode
      Returns:
      average
    • format

      public static java.lang.String format​(java.lang.String precisionPattern, double number)
      Double format
      Parameters:
      precisionPattern - precision pattern, e.g. 0.00
      number - double number
      Returns:
      formatted string
    • convertDecimalTo

      public static java.lang.String convertDecimalTo​(int num, char[] alphabet)
      Convert decimal to alphabet number
      Parameters:
      num - number (greater than 0)
      alphabet - alphabet
      Returns:
      alphabet base
    • convertToDecimal

      public static java.lang.Integer convertToDecimal​(java.lang.CharSequence num, char[] alphabet)
      Convert any base to decimal
      Parameters:
      num - number
      alphabet - base
      Returns:
      if null num parser failed