Class NumberUtils

java.lang.Object
org.bardframework.commons.utils.NumberUtils

public final class NumberUtils extends Object
Created by Vahid Zafari on 8/12/2016.
  • Method Details

    • getLastDigit

      public static Long getLastDigit(long number, int countOfLastDigit)
      Returns:
      count of last digit from number
    • getNumeric

      public static Long getNumeric(String num)
      remove all non-digit character (not minus in start if string '-') form string, if remain string not empty, return long value of that, else return 0
    • getNumeric

      public static Long getNumeric(Object num)
      Returns:
      remove all non-digit character form string, if remain string not empty, return long value of that, else return 0
    • getNumeric

      public static Set<Long> getNumeric(Collection<String> collection)
      Returns:
      Numeric list of given string collection
    • getDouble

      public static double getDouble(Object object)
      remove all non-digit character form string, if remain string not empty, return double value of that, else return 0
    • getNumbers

      public static Set<Long> getNumbers(String string)
      Returns:
      list of numbers in given string
    • toLong

      public static long toLong(String str, long defaultValue)

      Convert a String to a long, returning a default value if the conversion fails.

      If the string is null, the default value is returned.

         NumberUtils.toLong(null, 1L) = 1L
         NumberUtils.toLong("", 1L)   = 1L
         NumberUtils.toLong("1", 0L)  = 1L
       
      Parameters:
      str - the string to convert, may be null
      defaultValue - the default value
      Returns:
      the long represented by the string, or the default if conversion fails
    • toInt

      public static int toInt(String str, int defaultValue)

      Convert a String to a int, returning a default value if the conversion fails.

      If the string is null, the default value is returned.

         NumberUtils.toInt(null, 1) = 1
         NumberUtils.toInt("", 1)   = 1
         NumberUtils.toInt("1", 0)  = 1
       
      Parameters:
      str - the string to convert, may be null
      defaultValue - the default value
      Returns:
      the int represented by the string, or the default if conversion fails