Package org.apache.pulsar.common.util
Class 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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.
-
Constructor Details
-
FieldParser
public FieldParser()
-
-
Method Details
-
convert
Convert the given object value to the given class.- Parameters:
from- The object value to be converted.to- The type class which the given object should be converted to.- Returns:
- The converted object value.
- Throws:
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.- Parameters:
properties- which key-value pair of properties to assign those values to given objectobj- object which needs to be updated- Throws:
IllegalArgumentException- if the properties key-value contains incorrect value type
-
value
Converts value as per appropriate DataType of the field.- Parameters:
strValue- : string value of the objectfield- : field of the attribute- Returns:
-
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.- Parameters:
strValue-field-obj-- Throws:
IllegalArgumentExceptionIllegalAccessException
-
stringToInteger
Converts String to Integer.- Parameters:
val- The String to be converted.- Returns:
- The converted Integer value.
-
stringToLong
Converts String to Long.- Parameters:
val- The String to be converted.- Returns:
- The converted Long value.
-
stringToDouble
Converts String to Double.- Parameters:
val- The String to be converted.- Returns:
- The converted Double value.
-
stringToFloat
Converts String to float.- Parameters:
val- The String to be converted.- Returns:
- The converted Double value.
-
stringToList
Converts comma separated string to List.- Type Parameters:
T- type of list- Parameters:
val- comma separated values.- Returns:
- The converted list with type
<T>.
-
stringToSet
Converts comma separated string to Set.- Type Parameters:
T- type of set- Parameters:
val- comma separated values.- Returns:
- The converted set with type
<T>.
-
integerToString
Converts Integer to String.- Parameters:
value- The Integer to be converted.- Returns:
- The converted String value.
-
booleanToString
Converts Boolean to String.- Parameters:
value- The Boolean to be converted.- Returns:
- The converted String value.
-
stringToBoolean
Converts String to Boolean.- Parameters:
value- The String to be converted.- Returns:
- The converted Boolean value.
-