类 FieldParser
java.lang.Object
org.apache.pulsar.common.util.FieldParser
Generic value converter.
Use examples
String o1 = String.valueOf(1); ; Integer i = FieldParser.convert(o1, Integer.class); System.out.println(i); // 1
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static StringbooleanToString(Boolean value) Converts Boolean to String.static <T> TConvert the given object value to the given class.static StringintegerToString(Integer value) Converts Integer to String.static <T> voidsetEmptyValue(String strValue, Field field, T obj) Sets the empty/null value if field is allowed to be set empty.static BooleanstringToBoolean(String value) Converts String to Boolean.static DoublestringToDouble(String val) Converts String to Double.static FloatstringToFloat(String val) Converts String to float.static IntegerstringToInteger(String val) Converts String to Integer.static <T> List<T>stringToList(String val, Class<T> type) Converts comma separated string to List.static LongstringToLong(String val) Converts String to Long.static <T> Set<T>stringToSet(String val, Class<T> type) Converts comma separated string to Set.static <T> voidUpdate given Object attribute by reading it from provided map properties.static ObjectConverts value as per appropriate DataType of the field.
-
构造器详细资料
-
FieldParser
public FieldParser()
-
-
方法详细资料
-
convert
Convert the given object value to the given class.- 参数:
from- The object value to be converted.to- The type class which the given object should be converted to.- 返回:
- The converted object value.
- 抛出:
UnsupportedOperationException- If no suitable converter can be found.RuntimeException- If conversion failed somehow. This can be caused by at least an ExceptionInInitializerError, IllegalAccessException or InvocationTargetException.
-
update
Update given Object attribute by reading it from provided map properties.- 参数:
properties- which key-value pair of properties to assign those values to given objectobj- object which needs to be updated- 抛出:
IllegalArgumentException- if the properties key-value contains incorrect value type
-
value
Converts value as per appropriate DataType of the field.- 参数:
strValue- : string value of the objectfield- : field of the attribute- 返回:
-
setEmptyValue
public static <T> void setEmptyValue(String strValue, Field field, T obj) throws IllegalArgumentException, IllegalAccessException Sets the empty/null value if field is allowed to be set empty.- 参数:
strValue-field-obj-- 抛出:
IllegalArgumentExceptionIllegalAccessException
-
stringToInteger
Converts String to Integer.- 参数:
val- The String to be converted.- 返回:
- The converted Integer value.
-
stringToLong
Converts String to Long.- 参数:
val- The String to be converted.- 返回:
- The converted Long value.
-
stringToDouble
Converts String to Double.- 参数:
val- The String to be converted.- 返回:
- The converted Double value.
-
stringToFloat
Converts String to float.- 参数:
val- The String to be converted.- 返回:
- The converted Double value.
-
stringToList
Converts comma separated string to List.- 类型参数:
T- type of list- 参数:
val- comma separated values.- 返回:
- The converted list with type
<T>.
-
stringToSet
Converts comma separated string to Set.- 类型参数:
T- type of set- 参数:
val- comma separated values.- 返回:
- The converted set with type
<T>.
-
integerToString
Converts Integer to String.- 参数:
value- The Integer to be converted.- 返回:
- The converted String value.
-
booleanToString
Converts Boolean to String.- 参数:
value- The Boolean to be converted.- 返回:
- The converted String value.
-
stringToBoolean
Converts String to Boolean.- 参数:
value- The String to be converted.- 返回:
- The converted Boolean value.
-