类 ConvertUtils
java.lang.Object
com.alibaba.nacos.common.utils.ConvertUtils
Value Convert Utils.
- 作者:
- liaochuntao
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static booleanConverts a String to a boolean (optimised for performance).static booleanConvert String value to boolean value if parameter value is legal.static BooleantoBooleanObject(String str)Converts a String to a Boolean.static intConvert String value to int value if parameter value is legal.static intConvert String value to int value if parameter value is legal.static longConvert Object value to long value if parameter value is legal.static longConvert String value to long value if parameter value is legal.static longConvert String value to long value if parameter value is legal.
-
构造器详细资料
-
ConvertUtils
public ConvertUtils()
-
-
方法详细资料
-
toInt
Convert String value to int value if parameter value is legal. And it automatically defaults to 0 if parameter value is null or blank str.- 参数:
val- String value which need to be converted to int value.- 返回:
- Converted int value and its default value is 0.
-
toInt
Convert String value to int value if parameter value is legal. And return default value if parameter value is null or blank str.- 参数:
val- valuedefaultValue- default value- 返回:
- int value if input value is legal, otherwise default value
-
toLong
Convert Object value to long value if parameter value is legal. And it automatically defaults to 0 if parameter value is null or other object.- 参数:
val- object value- 返回:
- Converted long value and its default value is 0.
-
toLong
Convert String value to long value if parameter value is legal. And it automatically defaults to 0 if parameter value is null or blank str.- 参数:
val- String value which need to be converted to int value.- 返回:
- Converted long value and its default value is 0.
-
toLong
Convert String value to long value if parameter value is legal. And return default value if parameter value is null or blank str.- 参数:
val- valuedefaultValue- default value- 返回:
- long value if input value is legal, otherwise default value
-
toBoolean
Convert String value to boolean value if parameter value is legal. And return default value if parameter value is null or blank str.- 参数:
val- valuedefaultValue- default value- 返回:
- boolean value if input value is legal, otherwise default value
-
toBoolean
Converts a String to a boolean (optimised for performance).
'true','on','y','t'or'yes'(case insensitive) will returntrue. Otherwise,falseis returned.This method performs 4 times faster (JDK1.4) than
Boolean.valueOf(String). However, this method accepts 'on' and 'yes', 't', 'y' as true values.BooleanUtils.toBoolean(null) = false BooleanUtils.toBoolean("true") = true BooleanUtils.toBoolean("TRUE") = true BooleanUtils.toBoolean("tRUe") = true BooleanUtils.toBoolean("on") = true BooleanUtils.toBoolean("yes") = true BooleanUtils.toBoolean("false") = false BooleanUtils.toBoolean("x gti") = false BooleanUtils.toBooleanObject("y") = true BooleanUtils.toBooleanObject("n") = false BooleanUtils.toBooleanObject("t") = true BooleanUtils.toBooleanObject("f") = false- 参数:
str- the String to check- 返回:
- the boolean value of the string,
falseif no match or the String is null
-
toBooleanObject
Converts a String to a Boolean.
'true','on','y','t'or'yes'(case insensitive) will returntrue.'false','off','n','f'or'no'(case insensitive) will returnfalse. Otherwise,nullis returned.NOTE: This returns null and will throw a NullPointerException if autoboxed to a boolean.
// N.B. case is not significant BooleanUtils.toBooleanObject(null) = null BooleanUtils.toBooleanObject("true") = Boolean.TRUE BooleanUtils.toBooleanObject("T") = Boolean.TRUE // i.e. T[RUE] BooleanUtils.toBooleanObject("false") = Boolean.FALSE BooleanUtils.toBooleanObject("f") = Boolean.FALSE // i.e. f[alse] BooleanUtils.toBooleanObject("No") = Boolean.FALSE BooleanUtils.toBooleanObject("n") = Boolean.FALSE // i.e. n[o] BooleanUtils.toBooleanObject("on") = Boolean.TRUE BooleanUtils.toBooleanObject("ON") = Boolean.TRUE BooleanUtils.toBooleanObject("off") = Boolean.FALSE BooleanUtils.toBooleanObject("oFf") = Boolean.FALSE BooleanUtils.toBooleanObject("yes") = Boolean.TRUE BooleanUtils.toBooleanObject("Y") = Boolean.TRUE // i.e. Y[ES] BooleanUtils.toBooleanObject("blue") = null BooleanUtils.toBooleanObject("true ") = null // trailing space (too long) BooleanUtils.toBooleanObject("ono") = null // does not match on or no- 参数:
str- the String to check; upper and lower case are treated as the same- 返回:
- the Boolean value of the string,
nullif no match ornullinput
-