Package org.bardframework.commons.utils
Class NumberUtils
java.lang.Object
org.bardframework.commons.utils.NumberUtils
Created by Vahid Zafari on 8/12/2016.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleremove all non-digit character form string, if remain string not empty, return double value of that, else return 0static LonggetLastDigit(long number, int countOfLastDigit) 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 0getNumeric(Collection<String> collection) static intConvert aStringto aint, returning a default value if the conversion fails.static longConvert aStringto along, returning a default value if the conversion fails.
-
Constructor Details
-
NumberUtils
public NumberUtils()
-
-
Method Details
-
getLastDigit
- Returns:
- count of last digit from number
-
getNumeric
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
- Returns:
- remove all non-digit character form string, if remain string not empty, return long value of that, else return 0
-
getNumeric
- Returns:
- Numeric list of given string collection
-
getDouble
remove all non-digit character form string, if remain string not empty, return double value of that, else return 0 -
getNumbers
- Returns:
- list of numbers in given string
-
toLong
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
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
-