Class TypeConversionUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanconvertToBoolean(Object value, boolean do_i18n) Convert a value to a boolean.static booleanconvertToBoolean_JythonRules(Object value, boolean do_i18n) Convert a value to a boolean by Jython rules.static doubleconvertToDouble(Object value, boolean do_i18n) Convert a value to a double.static doubleconvertToDouble(Object value, boolean do_i18n, boolean checkAll, boolean throwOnError) Convert a value to a double.static doubleconvertToDouble(Object value, boolean do_i18n, boolean checkAll, boolean throwOnError, boolean warnOnError) Convert a value to a double.static longconvertToLong(Object value) Convert a value to a long.static longconvertToLong(Object value, boolean checkAll, boolean throwOnError) Convert a value to a long.static longconvertToLong(Object value, boolean checkAll, boolean throwOnError, boolean warnOnError) Convert a value to a long.static StringconvertToString(Object value, boolean do_i18n) Convert a value to a String.static booleanisFloatingNumber(Object object) Is this object an integer or a floating point number?static booleanisIntegerNumber(Object object) Is this object an integer number?static booleanIs this object a String?
-
Constructor Details
-
TypeConversionUtil
public TypeConversionUtil()
-
-
Method Details
-
isIntegerNumber
Is this object an integer number?The method returns true if the object is any of these classes:
- AtomicInteger
- AtomicLong
- BigInteger
- Byte
- Short
- Integer
- Long
- Parameters:
object- the object to check- Returns:
- true if the object is an object that is an integer, false otherwise
-
isFloatingNumber
Is this object an integer or a floating point number?The method returns true if the object is any of these classes:
- AtomicInteger
- AtomicLong
- BigInteger
- Byte
- Short
- Integer
- Long
- BigDecimal
- Float
- Double
- Parameters:
object- the object to check- Returns:
- true if the object is an object that is either an integer or a float, false otherwise
-
isString
Is this object a String?- Parameters:
object- the object to check- Returns:
- true if the object is a String, false otherwise
-
convertToBoolean
Convert a value to a boolean.Rules: "0" string is converted to false "0.000" string is converted to false, if the number of decimals is > 0 An integer number is converted to false if the number is 0 A floating number is converted to false if the number is -0.5 < x < 0.5 The string "true" (case insensitive) returns true. The string "false" (case insensitive) returns false. A Reportable is first converted to a string using toReportString() and then treated as a string. A JSON TextNode is first converted to a string using asText() and then treated as a string. Everything else throws an exception.
For objects that implement the Reportable interface, the value is fetched from the method toReportString().
- Parameters:
value- the value to convertdo_i18n- true if internationalization should be done, false otherwise- Returns:
- the boolean value
-
convertToBoolean_JythonRules
Convert a value to a boolean by Jython rules.Rules: null is converted to false empty string is converted to false "0" string is converted to false "0.000" string is converted to false, if the number of decimals is > 0 empty map is converted to false empty collection is converted to false An integer number is converted to false if the number is 0 A floating number is converted to false if the number is -0.5 < x < 0.5 Everything else is converted to true
For objects that implement the Reportable interface, the value is fetched from the method toReportString().
- Parameters:
value- the value to convertdo_i18n- true if internationalization should be done, false otherwise- Returns:
- the boolean value
-
convertToLong
Convert a value to a long.Rules: null is converted to 0 empty string is converted to 0 empty collection is converted to 0 an instance of the interface Number is converted to the number a string that can be parsed as a number is converted to that number. a string that doesn't start with a digit is converted to 0
For objects that implement the Reportable interface, the value is fetched from the method toReportString() before doing the conversion.
- Parameters:
value- the value to convert- Returns:
- the long value
-
convertToLong
public static long convertToLong(@CheckForNull Object value, boolean checkAll, boolean throwOnError) Convert a value to a long.Rules: null is converted to 0 empty string is converted to 0 empty collection is converted to 0 an instance of the interface Number is converted to the number a string that can be parsed as a number is converted to that number. a string that doesn't start with a digit is converted to 0
For objects that implement the Reportable interface, the value is fetched from the method toReportString() before doing the conversion.
- Parameters:
value- the value to convertcheckAll- true if the whole string should be checked, false otherwisethrowOnError- true if a NumberFormatException should be thrown on error, false otherwise- Returns:
- the long value
- Throws:
NumberFormatException- on error if throwOnError is true
-
convertToLong
public static long convertToLong(@CheckForNull Object value, boolean checkAll, boolean throwOnError, boolean warnOnError) throws NumberFormatException Convert a value to a long.Rules: null is converted to 0 empty string is converted to 0 empty collection is converted to 0 an instance of the interface Number is converted to the number a string that can be parsed as a number is converted to that number. a string that doesn't start with a digit is converted to 0
For objects that implement the Reportable interface, the value is fetched from the method toReportString() before doing the conversion.
- Parameters:
value- the value to convertcheckAll- true if the whole string should be checked, false otherwisethrowOnError- true if a NumberFormatException should be thrown on error, false otherwisewarnOnError- true if a warning message should be logged on error- Returns:
- the long value
- Throws:
NumberFormatException- on error if throwOnError is true
-
convertToDouble
Convert a value to a double.Rules: null is converted to 0 empty string is converted to 0 empty collection is converted to 0 an instance of the interface Number is converted to the number a string that can be parsed as a number is converted to that number. if a string starts with a number AND do_i18n is false, it's converted to that number a string that doesn't start with a digit is converted to 0
For objects that implement the Reportable interface, the value is fetched from the method toReportString() before doing the conversion.
- Parameters:
value- the value to convertdo_i18n- true if internationalization should be done, false otherwise- Returns:
- the double value
-
convertToDouble
public static double convertToDouble(@CheckForNull Object value, boolean do_i18n, boolean checkAll, boolean throwOnError) Convert a value to a double.Rules: null is converted to 0 empty string is converted to 0 empty collection is converted to 0 an instance of the interface Number is converted to the number a string that can be parsed as a number is converted to that number. if a string starts with a number AND do_i18n is false, it's converted to that number a string that doesn't start with a digit is converted to 0
For objects that implement the Reportable interface, the value is fetched from the method toReportString() before doing the conversion.
- Parameters:
value- the value to convertdo_i18n- true if internationalization should be done, false otherwisecheckAll- true if the whole string should be checked, false otherwisethrowOnError- true if a NumberFormatException should be thrown on error, false otherwise- Returns:
- the double value
- Throws:
NumberFormatException- on error if throwOnError is true
-
convertToDouble
public static double convertToDouble(@CheckForNull Object value, boolean do_i18n, boolean checkAll, boolean throwOnError, boolean warnOnError) Convert a value to a double.Rules: null is converted to 0 empty string is converted to 0 empty collection is converted to 0 an instance of the interface Number is converted to the number a string that can be parsed as a number is converted to that number. if a string starts with a number AND do_i18n is false, it's converted to that number a string that doesn't start with a digit is converted to 0
For objects that implement the Reportable interface, the value is fetched from the method toReportString() before doing the conversion.
- Parameters:
value- the value to convertdo_i18n- true if internationalization should be done, false otherwisecheckAll- true if the whole string should be checked, false otherwisethrowOnError- true if a NumberFormatException should be thrown on error, false otherwisewarnOnError- true if a warning message should be logged on error- Returns:
- the double value
- Throws:
NumberFormatException- on error if throwOnError is true
-
convertToString
Convert a value to a String.- Parameters:
value- the value to convertdo_i18n- true if internationalization should be done, false otherwise- Returns:
- the String value
-