类 ConvertUtils
- java.lang.Object
-
- com.alibaba.nacos.common.utils.ConvertUtils
-
public final class ConvertUtils extends java.lang.ObjectValue Convert Utils.- 作者:
- liaochuntao
-
-
构造器概要
构造器 构造器 说明 ConvertUtils()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static booleantoBoolean(java.lang.String str)Converts a String to a boolean (optimised for performance).static booleantoBoolean(java.lang.String val, boolean defaultValue)Convert String value to boolean value if parameter value is legal.static java.lang.BooleantoBooleanObject(java.lang.String str)Converts a String to a Boolean.static inttoInt(java.lang.String val)Convert String value to int value if parameter value is legal.static inttoInt(java.lang.String val, int defaultValue)Convert String value to int value if parameter value is legal.static longtoLong(java.lang.Object val)Convert Object value to long value if parameter value is legal.static longtoLong(java.lang.String val)Convert String value to long value if parameter value is legal.static longtoLong(java.lang.String val, long defaultValue)Convert String value to long value if parameter value is legal.
-
-
-
字段详细资料
-
NULL_STR
private static final java.lang.String NULL_STR
- 另请参阅:
- 常量字段值
-
TRUE_SET
public static final java.util.Set<java.lang.String> TRUE_SET
-
FALSE_SET
public static final java.util.Set<java.lang.String> FALSE_SET
-
-
方法详细资料
-
toInt
public static int toInt(java.lang.String val)
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
public static int toInt(java.lang.String val, int defaultValue)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
public static long toLong(java.lang.Object val)
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
public static long toLong(java.lang.String val)
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
public static long toLong(java.lang.String val, long defaultValue)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
public static boolean toBoolean(java.lang.String val, boolean defaultValue)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
public static boolean toBoolean(java.lang.String str)
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
public static java.lang.Boolean toBooleanObject(java.lang.String str)
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
-
-