Package org.bardframework.commons.utils
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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doublegetDouble(Object object)remove all non-digit character form string, if remain string not empty, return double value of that, else return 0static LonggetLastDigit(long number, int countOfLastDigit)static Set<Long>getNumbers(String string)static LonggetNumeric(Object num)static LonggetNumeric(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 0static Set<Long>getNumeric(Collection<String> collection)static inttoInt(String str, int defaultValue)Convert aStringto aint, returning a default value if the conversion fails.static longtoLong(String str, long defaultValue)Convert aStringto along, returning a default value if the conversion fails.
-
-
-
Method Detail
-
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
Stringto along, 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 nulldefaultValue- 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
Stringto aint, 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 nulldefaultValue- the default value- Returns:
- the int represented by the string, or the default if conversion fails
-
-