diff --git a/docs/Changelog.md b/docs/Changelog.md index 6d866ce0c72..75c8cdfc60d 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -34,18 +34,6 @@ * [#6807](https://github.com/TouK/nussknacker/pull/6807) Add conversion functions to primitives to: `#CONV`: * toNumberOrNull * toString - * toBoolean - * toBooleanOrNull - * toInteger - * toIntegerOrNull - * toLong - * toLongOrNull - * toDouble - * toDoubleOrNull - * toBigInteger - * toBigIntegerOrNull - * toBigDecimal - * toBigDecimalOrNull * [#6995](https://github.com/TouK/nussknacker/pull/6995) Add `toJson` and `toJsonString` conversions (in the `#CONV` helper) * [#6995](https://github.com/TouK/nussknacker/pull/6995) Add `#BASE64` helper to decode/encode Base64 values * [#6826](https://github.com/TouK/nussknacker/pull/6826) Security fix: added validation of expression used inside @@ -76,6 +64,11 @@ * [#6958](https://github.com/TouK/nussknacker/pull/6958) Add message size limit in the "Kafka" exceptionHandler * [#6988](https://github.com/TouK/nussknacker/pull/6988) Remove unused API classes: `MultiMap`, `TimestampedEvictableStateFunction` * [#7000](https://github.com/TouK/nussknacker/pull/7000) Show all possible options for dictionary editor on open. +* [#7061]https://github.com/TouK/nussknacker/pull/7061 SpeL: add conversion to primitives extension methods: + * isBoolean/toBoolean/toBooleanOrNull + * isLong/toLong/toLongOrNull + * isDouble/toDouble/toDoubleOrNull + * isBigDecimal/toBigDecimal/toBigDecimalOrNull ## 1.17 diff --git a/engine/flink/management/dev-model/src/test/resources/extractedTypes/devCreator.json b/engine/flink/management/dev-model/src/test/resources/extractedTypes/devCreator.json index 9d98ae655e8..be53e0450ee 100644 --- a/engine/flink/management/dev-model/src/test/resources/extractedTypes/devCreator.json +++ b/engine/flink/management/dev-model/src/test/resources/extractedTypes/devCreator.json @@ -824,6 +824,36 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "longValue": [ { "name": "longValue", @@ -842,6 +872,66 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -1191,6 +1281,26 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isInfinite": [ { "name": "isInfinite", @@ -1200,6 +1310,16 @@ } } ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isNaN": [ { "name": "isNaN", @@ -1236,6 +1356,66 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -1574,6 +1754,26 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isInfinite": [ { "name": "isInfinite", @@ -1583,6 +1783,16 @@ } } ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isNaN": [ { "name": "isNaN", @@ -1619,6 +1829,66 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -1948,6 +2218,36 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "longValue": [ { "name": "longValue", @@ -1966,6 +2266,66 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -2484,12 +2844,42 @@ } } ], - "longValue": [ + "isBigDecimal": [ { - "name": "longValue", + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", "signature": { "noVarArgs": [], - "result": {"refClazzName": "java.lang.Long"} + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "longValue": [ + { + "name": "longValue", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} } } ], @@ -2502,6 +2892,66 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -3031,6 +3481,36 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "longValue": [ { "name": "longValue", @@ -3049,6 +3529,66 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -3106,6 +3646,126 @@ ] } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isBoolean": [ + { + "description": "Check whether can be convert to a Boolean", + "name": "isBoolean", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBoolean": [ + { + "description": "Convert to Boolean or throw exception in case of failure", + "name": "toBoolean", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "toBooleanOrNull": [ + { + "description": "Convert to Boolean or null in case of failure", + "name": "toBooleanOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -3123,75 +3783,165 @@ "methods": { "byteValue": [ { - "name": "byteValue", + "name": "byteValue", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Byte"} + } + } + ], + "compareTo": [ + { + "name": "compareTo", + "signature": { + "noVarArgs": [ + {"name": "arg0", "refClazz": {"refClazzName": "java.lang.Short"}} + ], + "result": {"refClazzName": "java.lang.Integer"} + } + }, + { + "name": "compareTo", + "signature": { + "noVarArgs": [ + {"name": "arg0", "refClazz": {"type": "Unknown"}} + ], + "result": {"refClazzName": "java.lang.Integer"} + } + } + ], + "doubleValue": [ + { + "name": "doubleValue", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "floatValue": [ + { + "name": "floatValue", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Float"} + } + } + ], + "intValue": [ + { + "name": "intValue", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Integer"} + } + } + ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "longValue": [ + { + "name": "longValue", "signature": { "noVarArgs": [], - "result": {"refClazzName": "java.lang.Byte"} + "result": {"refClazzName": "java.lang.Long"} } } ], - "compareTo": [ + "shortValue": [ { - "name": "compareTo", + "name": "shortValue", "signature": { - "noVarArgs": [ - {"name": "arg0", "refClazz": {"refClazzName": "java.lang.Short"}} - ], - "result": {"refClazzName": "java.lang.Integer"} + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Short"} } - }, + } + ], + "toBigDecimal": [ { - "name": "compareTo", + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", "signature": { - "noVarArgs": [ - {"name": "arg0", "refClazz": {"type": "Unknown"}} - ], - "result": {"refClazzName": "java.lang.Integer"} + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} } } ], - "doubleValue": [ + "toBigDecimalOrNull": [ { - "name": "doubleValue", + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", "signature": { "noVarArgs": [], - "result": {"refClazzName": "java.lang.Double"} + "result": {"refClazzName": "java.math.BigDecimal"} } } ], - "floatValue": [ + "toDouble": [ { - "name": "floatValue", + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", "signature": { "noVarArgs": [], - "result": {"refClazzName": "java.lang.Float"} + "result": {"refClazzName": "java.lang.Double"} } } ], - "intValue": [ + "toDoubleOrNull": [ { - "name": "intValue", + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", "signature": { "noVarArgs": [], - "result": {"refClazzName": "java.lang.Integer"} + "result": {"refClazzName": "java.lang.Double"} } } ], - "longValue": [ + "toLong": [ { - "name": "longValue", + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", "signature": { "noVarArgs": [], "result": {"refClazzName": "java.lang.Long"} } } ], - "shortValue": [ + "toLongOrNull": [ { - "name": "shortValue", + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", "signature": { "noVarArgs": [], - "result": {"refClazzName": "java.lang.Short"} + "result": {"refClazzName": "java.lang.Long"} } } ], @@ -3521,6 +4271,16 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isBlank": [ { "name": "isBlank", @@ -3530,6 +4290,26 @@ } } ], + "isBoolean": [ + { + "description": "Check whether can be convert to a Boolean", + "name": "isBoolean", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isEmpty": [ { "name": "isEmpty", @@ -3539,6 +4319,16 @@ } } ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "lastIndexOf": [ { "name": "lastIndexOf", @@ -3755,6 +4545,86 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBoolean": [ + { + "description": "Convert to Boolean or throw exception in case of failure", + "name": "toBoolean", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "toBooleanOrNull": [ + { + "description": "Convert to Boolean or null in case of failure", + "name": "toBooleanOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toLowerCase": [ { "name": "toLowerCase", @@ -4112,6 +4982,36 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "longValue": [ { "name": "longValue", @@ -4412,6 +5312,26 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], "toBigInteger": [ { "name": "toBigInteger", @@ -4430,6 +5350,26 @@ } } ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], "toEngineeringString": [ { "name": "toEngineeringString", @@ -4439,6 +5379,26 @@ } } ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toPlainString": [ { "name": "toPlainString", @@ -4819,6 +5779,36 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isProbablePrime": [ { "name": "isProbablePrime", @@ -5094,6 +6084,26 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], "toByteArray": [ { "name": "toByteArray", @@ -5113,6 +6123,46 @@ } } ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", diff --git a/engine/flink/tests/src/test/resources/extractedTypes/defaultModel.json b/engine/flink/tests/src/test/resources/extractedTypes/defaultModel.json index c12d863707c..cb9a7394157 100644 --- a/engine/flink/tests/src/test/resources/extractedTypes/defaultModel.json +++ b/engine/flink/tests/src/test/resources/extractedTypes/defaultModel.json @@ -344,6 +344,36 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "longValue": [ { "name": "longValue", @@ -362,6 +392,66 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -778,6 +868,26 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isInfinite": [ { "name": "isInfinite", @@ -787,6 +897,16 @@ } } ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isNaN": [ { "name": "isNaN", @@ -823,6 +943,66 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -1161,6 +1341,26 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isInfinite": [ { "name": "isInfinite", @@ -1170,6 +1370,16 @@ } } ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isNaN": [ { "name": "isNaN", @@ -1206,6 +1416,66 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -1535,56 +1805,146 @@ } } ], - "longValue": [ + "isBigDecimal": [ { - "name": "longValue", + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", "signature": { "noVarArgs": [], - "result": {"refClazzName": "java.lang.Long"} + "result": {"refClazzName": "java.lang.Boolean"} } } ], - "shortValue": [ + "isDouble": [ { - "name": "shortValue", + "description": "Check whether can be convert to a Double", + "name": "isDouble", "signature": { "noVarArgs": [], - "result": {"refClazzName": "java.lang.Short"} + "result": {"refClazzName": "java.lang.Boolean"} } } ], - "toString": [ + "isLong": [ { - "name": "toString", + "description": "Check whether can be convert to a Long", + "name": "isLong", "signature": { "noVarArgs": [], - "result": {"refClazzName": "java.lang.String"} + "result": {"refClazzName": "java.lang.Boolean"} } } - ] - }, - "staticMethods": { - "BYTES": [ + ], + "longValue": [ { - "name": "BYTES", + "name": "longValue", "signature": { "noVarArgs": [], - "result": {"refClazzName": "java.lang.Integer"} + "result": {"refClazzName": "java.lang.Long"} } } ], - "MAX_VALUE": [ + "shortValue": [ { - "name": "MAX_VALUE", + "name": "shortValue", "signature": { "noVarArgs": [], - "result": {"refClazzName": "java.lang.Integer"} + "result": {"refClazzName": "java.lang.Short"} } } ], - "MIN_VALUE": [ + "toBigDecimal": [ { - "name": "MIN_VALUE", + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toString": [ + { + "name": "toString", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.String"} + } + } + ] + }, + "staticMethods": { + "BYTES": [ + { + "name": "BYTES", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Integer"} + } + } + ], + "MAX_VALUE": [ + { + "name": "MAX_VALUE", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Integer"} + } + } + ], + "MIN_VALUE": [ + { + "name": "MIN_VALUE", "signature": { "noVarArgs": [], "result": {"refClazzName": "java.lang.Integer"} @@ -2071,6 +2431,36 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "longValue": [ { "name": "longValue", @@ -2089,6 +2479,66 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -2618,6 +3068,36 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "longValue": [ { "name": "longValue", @@ -2636,6 +3116,66 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -2693,38 +3233,158 @@ ] } ], - "toString": [ + "isBigDecimal": [ { - "name": "toString", + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", "signature": { "noVarArgs": [], - "result": {"refClazzName": "java.lang.String"} + "result": {"refClazzName": "java.lang.Boolean"} } } - ] - }, - "staticMethods": {} - }, - { - "clazzName": {"refClazzName": "java.lang.Short"}, - "methods": { - "byteValue": [ + ], + "isBoolean": [ { - "name": "byteValue", + "description": "Check whether can be convert to a Boolean", + "name": "isBoolean", "signature": { "noVarArgs": [], - "result": {"refClazzName": "java.lang.Byte"} + "result": {"refClazzName": "java.lang.Boolean"} } } ], - "compareTo": [ + "isDouble": [ { - "name": "compareTo", + "description": "Check whether can be convert to a Double", + "name": "isDouble", "signature": { - "noVarArgs": [ - {"name": "arg0", "refClazz": {"refClazzName": "java.lang.Short"}} - ], - "result": {"refClazzName": "java.lang.Integer"} + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBoolean": [ + { + "description": "Convert to Boolean or throw exception in case of failure", + "name": "toBoolean", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "toBooleanOrNull": [ + { + "description": "Convert to Boolean or null in case of failure", + "name": "toBooleanOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toString": [ + { + "name": "toString", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.String"} + } + } + ] + }, + "staticMethods": {} + }, + { + "clazzName": {"refClazzName": "java.lang.Short"}, + "methods": { + "byteValue": [ + { + "name": "byteValue", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Byte"} + } + } + ], + "compareTo": [ + { + "name": "compareTo", + "signature": { + "noVarArgs": [ + {"name": "arg0", "refClazz": {"refClazzName": "java.lang.Short"}} + ], + "result": {"refClazzName": "java.lang.Integer"} } }, { @@ -2764,6 +3424,36 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "longValue": [ { "name": "longValue", @@ -2782,6 +3472,66 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -3108,6 +3858,16 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isBlank": [ { "name": "isBlank", @@ -3117,6 +3877,26 @@ } } ], + "isBoolean": [ + { + "description": "Check whether can be convert to a Boolean", + "name": "isBoolean", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isEmpty": [ { "name": "isEmpty", @@ -3126,6 +3906,16 @@ } } ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "lastIndexOf": [ { "name": "lastIndexOf", @@ -3342,6 +4132,86 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBoolean": [ + { + "description": "Convert to Boolean or throw exception in case of failure", + "name": "toBoolean", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "toBooleanOrNull": [ + { + "description": "Convert to Boolean or null in case of failure", + "name": "toBooleanOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toLowerCase": [ { "name": "toLowerCase", @@ -3699,6 +4569,36 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "longValue": [ { "name": "longValue", @@ -3999,6 +4899,26 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], "toBigInteger": [ { "name": "toBigInteger", @@ -4017,6 +4937,26 @@ } } ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], "toEngineeringString": [ { "name": "toEngineeringString", @@ -4026,6 +4966,26 @@ } } ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toPlainString": [ { "name": "toPlainString", @@ -4406,6 +5366,36 @@ } } ], + "isBigDecimal": [ + { + "description": "Check whether can be convert to a BigDecimal", + "name": "isBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isDouble": [ + { + "description": "Check whether can be convert to a Double", + "name": "isDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], + "isLong": [ + { + "description": "Check whether can be convert to a Long", + "name": "isLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Boolean"} + } + } + ], "isProbablePrime": [ { "name": "isProbablePrime", @@ -4681,6 +5671,26 @@ } } ], + "toBigDecimal": [ + { + "description": "Convert to BigDecimal or throw exception in case of failure", + "name": "toBigDecimal", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], + "toBigDecimalOrNull": [ + { + "description": "Convert to BigDecimal or null in case of failure", + "name": "toBigDecimalOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.math.BigDecimal"} + } + } + ], "toByteArray": [ { "name": "toByteArray", @@ -4700,6 +5710,46 @@ } } ], + "toDouble": [ + { + "description": "Convert to Double or throw exception in case of failure", + "name": "toDouble", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toDoubleOrNull": [ + { + "description": "Convert to Double or null in case of failure", + "name": "toDoubleOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Double"} + } + } + ], + "toLong": [ + { + "description": "Convert to Long or throw exception in case of failure", + "name": "toLong", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], + "toLongOrNull": [ + { + "description": "Convert to Long or null in case of failure", + "name": "toLongOrNull", + "signature": { + "noVarArgs": [], + "result": {"refClazzName": "java.lang.Long"} + } + } + ], "toString": [ { "name": "toString", @@ -14141,126 +15191,6 @@ } } ], - "toBigDecimal": [ - { - "description": "Convert any value to BigDecimal or throw exception in case of failure", - "name": "toBigDecimal", - "signature": { - "noVarArgs": [ - {"name": "value", "refClazz": {"type": "Unknown"}} - ], - "result": {"refClazzName": "java.math.BigDecimal"} - } - } - ], - "toBigDecimalOrNull": [ - { - "description": "Convert any value to BigDecimal or null in case of failure", - "name": "toBigDecimalOrNull", - "signature": { - "noVarArgs": [ - {"name": "value", "refClazz": {"type": "Unknown"}} - ], - "result": {"refClazzName": "java.math.BigDecimal"} - } - } - ], - "toBigInteger": [ - { - "description": "Convert any value to BigInteger or throw exception in case of failure", - "name": "toBigInteger", - "signature": { - "noVarArgs": [ - {"name": "value", "refClazz": {"type": "Unknown"}} - ], - "result": {"refClazzName": "java.math.BigInteger"} - } - } - ], - "toBigIntegerOrNull": [ - { - "description": "Convert any value to BigInteger or null in case of failure", - "name": "toBigIntegerOrNull", - "signature": { - "noVarArgs": [ - {"name": "value", "refClazz": {"type": "Unknown"}} - ], - "result": {"refClazzName": "java.math.BigInteger"} - } - } - ], - "toBoolean": [ - { - "description": "Convert any value to Boolean or throw exception in case of failure", - "name": "toBoolean", - "signature": { - "noVarArgs": [ - {"name": "value", "refClazz": {"type": "Unknown"}} - ], - "result": {"refClazzName": "java.lang.Boolean"} - } - } - ], - "toBooleanOrNull": [ - { - "description": "Convert any value to Boolean or throw exception in case of failure", - "name": "toBooleanOrNull", - "signature": { - "noVarArgs": [ - {"name": "value", "refClazz": {"type": "Unknown"}} - ], - "result": {"refClazzName": "java.lang.Boolean"} - } - } - ], - "toDouble": [ - { - "description": "Convert any value to Double or throw exception in case of failure", - "name": "toDouble", - "signature": { - "noVarArgs": [ - {"name": "value", "refClazz": {"type": "Unknown"}} - ], - "result": {"refClazzName": "java.lang.Double"} - } - } - ], - "toDoubleOrNull": [ - { - "description": "Convert any value to Double or null in case of failure", - "name": "toDoubleOrNull", - "signature": { - "noVarArgs": [ - {"name": "value", "refClazz": {"type": "Unknown"}} - ], - "result": {"refClazzName": "java.lang.Double"} - } - } - ], - "toInteger": [ - { - "description": "Convert any value to Integer or throw exception in case of failure", - "name": "toInteger", - "signature": { - "noVarArgs": [ - {"name": "value", "refClazz": {"type": "Unknown"}} - ], - "result": {"refClazzName": "java.lang.Integer"} - } - } - ], - "toIntegerOrNull": [ - { - "description": "Convert any value to Integer or null in case of failure", - "name": "toIntegerOrNull", - "signature": { - "noVarArgs": [ - {"name": "value", "refClazz": {"type": "Unknown"}} - ], - "result": {"refClazzName": "java.lang.Integer"} - } - } - ], "toJson": [ { "description": "Convert String value to JSON", @@ -14297,30 +15227,6 @@ } } ], - "toLong": [ - { - "description": "Convert any value to Long or throw exception in case of failure", - "name": "toLong", - "signature": { - "noVarArgs": [ - {"name": "value", "refClazz": {"type": "Unknown"}} - ], - "result": {"refClazzName": "java.lang.Long"} - } - } - ], - "toLongOrNull": [ - { - "description": "Convert any value to Long or null in case of failure", - "name": "toLongOrNull", - "signature": { - "noVarArgs": [ - {"name": "value", "refClazz": {"type": "Unknown"}} - ], - "result": {"refClazzName": "java.lang.Long"} - } - } - ], "toNumber": [ { "description": "Parse string to number", diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/extension/BooleanConversionExt.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/extension/BooleanConversionExt.scala new file mode 100644 index 00000000000..c6d6f6e6261 --- /dev/null +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/extension/BooleanConversionExt.scala @@ -0,0 +1,78 @@ +package pl.touk.nussknacker.engine.extension + +import pl.touk.nussknacker.engine.api.generics.MethodTypeInfo +import pl.touk.nussknacker.engine.api.typed.typing.Typed +import pl.touk.nussknacker.engine.definition.clazz.{ClassDefinitionSet, MethodDefinition, StaticMethodDefinition} + +import java.lang.{Boolean => JBoolean} + +class BooleanConversionExt(target: Any) { + private lazy val cannotConvertException = new IllegalArgumentException(s"Cannot convert: $target to Boolean") + + def isBoolean(): JBoolean = convertToBoolean(target).isRight + + def toBoolean(): JBoolean = convertToBoolean(target) match { + case Right(value) => value + case Left(ex) => throw ex + } + + def toBooleanOrNull(): JBoolean = convertToBoolean(target) match { + case Right(value) => value + case Left(_) => null + } + + private def convertToBoolean(value: Any): Either[Throwable, JBoolean] = value match { + case s: String => + stringToBoolean(s).toRight(cannotConvertException) + case b: JBoolean => Right(b) + case _ => Left(cannotConvertException) + } + + private def stringToBoolean(value: String): Option[JBoolean] = + if ("true".equalsIgnoreCase(value)) { + Some(true) + } else if ("false".equalsIgnoreCase(value)) { + Some(false) + } else { + None + } + +} + +object BooleanConversionExt extends ExtensionMethodsHandler { + private val stringClass = classOf[String] + private val unknownClass = classOf[Object] + private val allowedClassesForDefinitions: Set[Class[_]] = Set(stringClass, unknownClass) + private val booleanTyping = Typed.typedClass[JBoolean] + + private val definition = StaticMethodDefinition( + signature = MethodTypeInfo( + noVarArgs = Nil, + varArg = None, + result = booleanTyping + ), + name = "", + description = None + ) + + private val definitions = List( + definition.copy(name = "isBoolean", description = Some("Check whether can be convert to a Boolean")), + definition.copy(name = "toBoolean", description = Some("Convert to Boolean or throw exception in case of failure")), + definition.copy(name = "toBooleanOrNull", description = Some("Convert to Boolean or null in case of failure")), + ).groupBy(_.name) + + override type ExtensionMethodInvocationTarget = BooleanConversionExt + override val invocationTargetClass: Class[BooleanConversionExt] = classOf[BooleanConversionExt] + + override def createConverter( + classLoader: ClassLoader, + set: ClassDefinitionSet + ): ToExtensionMethodInvocationTargetConverter[BooleanConversionExt] = + (target: Any) => new BooleanConversionExt(target) + + override def extractDefinitions(clazz: Class[_], set: ClassDefinitionSet): Map[String, List[MethodDefinition]] = + if (allowedClassesForDefinitions.contains(clazz)) definitions + else Map.empty + + override def applies(clazz: Class[_]): Boolean = true +} diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/extension/ExtensionMethods.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/extension/ExtensionMethods.scala index 750ccfbcc28..68db0905e58 100644 --- a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/extension/ExtensionMethods.scala +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/extension/ExtensionMethods.scala @@ -41,6 +41,8 @@ object ExtensionMethods { val extensionMethodsHandlers: List[ExtensionMethodsHandler] = List( Cast, ArrayExt, + NumericConversionExt, + BooleanConversionExt, ) def enrichWithExtensionMethods(set: ClassDefinitionSet): ClassDefinitionSet = { diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/extension/NumericConversionExt.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/extension/NumericConversionExt.scala new file mode 100644 index 00000000000..9a4e5c45e64 --- /dev/null +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/extension/NumericConversionExt.scala @@ -0,0 +1,153 @@ +package pl.touk.nussknacker.engine.extension + +import pl.touk.nussknacker.engine.api.generics.MethodTypeInfo +import pl.touk.nussknacker.engine.api.typed.typing.{Typed, TypingResult} +import pl.touk.nussknacker.engine.definition.clazz.{ClassDefinitionSet, MethodDefinition, StaticMethodDefinition} +import pl.touk.nussknacker.engine.util.classes.Extensions.ClassExtensions + +import scala.util.{Success, Try} +import java.lang.{Boolean => JBoolean, Double => JDouble, Long => JLong, Number => JNumber} +import java.math.{BigDecimal => JBigDecimal, BigInteger => JBigInteger} + +class NumericConversionExt(target: Any) { + + def isLong(): JBoolean = toLongEither.isRight + + def toLong(): JLong = toLongEither match { + case Right(value) => value + case Left(ex) => throw ex + } + + def toLongOrNull(): JLong = toLongEither match { + case Right(value) => value + case Left(_) => null + } + + def isDouble(): JBoolean = toDoubleEither.isRight + + def toDouble(): JDouble = toDoubleEither match { + case Right(value) => value + case Left(ex) => throw ex + } + + def toDoubleOrNull(): JDouble = toDoubleEither match { + case Right(value) => value + case Left(_) => null + } + + def isBigDecimal(): JBoolean = toBigDecimalEither.isRight + + def toBigDecimal(): JBigDecimal = toBigDecimalEither match { + case Right(value) => value + case Left(ex) => throw ex + } + + def toBigDecimalOrNull(): JBigDecimal = toBigDecimalEither match { + case Right(value) => value + case Left(_) => null + } + + private def toLongEither: Either[Throwable, JLong] = { + target match { + case v: String => Try(JLong.valueOf(toNumber(v).longValue())).toEither + case v: Number => Right(v.longValue()) + case _ => Left(new IllegalArgumentException(s"Cannot convert: $target to Long")) + } + } + + private def toDoubleEither: Either[Throwable, JDouble] = { + target match { + case v: String => Try(JDouble.valueOf(toNumber(v).doubleValue())).toEither + case v: Number => Right(v.doubleValue()) + case _ => Left(new IllegalArgumentException(s"Cannot convert: $target to Double")) + } + } + + private def toBigDecimalEither: Either[Throwable, JBigDecimal] = { + target match { + case v: String => Try(new JBigDecimal(v)).toEither + case v: JBigInteger => Right(new JBigDecimal(v)) + case v: JBigDecimal => Right(v) + case v: Number => Try(new JBigDecimal(v.toString)).toEither + case _ => Left(new IllegalArgumentException(s"Cannot convert: $target to BigDecimal")) + } + } + + private def toNumber(stringOrNumber: Any): JNumber = stringOrNumber match { + case s: CharSequence => + val ss = s.toString + // we pick the narrowest type as possible to reduce the amount of memory and computations overheads + val tries: List[Try[JNumber]] = List( + Try(java.lang.Integer.parseInt(ss)), + Try(java.lang.Long.parseLong(ss)), + Try(java.lang.Double.parseDouble(ss)), + Try(new JBigDecimal(ss)), + Try(new JBigInteger(ss)) + ) + + tries + .collectFirst { case Success(value) => + value + } + .getOrElse(new JBigDecimal(ss)) + + case n: JNumber => n + } + +} + +object NumericConversionExt extends ExtensionMethodsHandler { + private val numberClass = classOf[JNumber] + private val stringClass = classOf[String] + private val unknownClass = classOf[Object] + + private val definitions = List( + definition(Typed.typedClass[JBoolean], "isLong", Some("Check whether can be convert to a Long")), + definition(Typed.typedClass[JLong], "toLong", Some("Convert to Long or throw exception in case of failure")), + definition(Typed.typedClass[JLong], "toLongOrNull", Some("Convert to Long or null in case of failure")), + definition(Typed.typedClass[JBoolean], "isDouble", Some("Check whether can be convert to a Double")), + definition(Typed.typedClass[JDouble], "toDouble", Some("Convert to Double or throw exception in case of failure")), + definition(Typed.typedClass[JDouble], "toDoubleOrNull", Some("Convert to Double or null in case of failure")), + definition(Typed.typedClass[JBoolean], "isBigDecimal", Some("Check whether can be convert to a BigDecimal")), + definition( + Typed.typedClass[JBigDecimal], + "toBigDecimal", + Some("Convert to BigDecimal or throw exception in case of failure") + ), + definition( + Typed.typedClass[JBigDecimal], + "toBigDecimalOrNull", + Some("Convert to BigDecimal or null in case of failure") + ), + ).groupBy(_.name) + + override type ExtensionMethodInvocationTarget = NumericConversionExt + override val invocationTargetClass: Class[NumericConversionExt] = classOf[NumericConversionExt] + + override def createConverter( + classLoader: ClassLoader, + set: ClassDefinitionSet + ): ToExtensionMethodInvocationTargetConverter[NumericConversionExt] = + (target: Any) => new NumericConversionExt(target) + + override def extractDefinitions(clazz: Class[_], set: ClassDefinitionSet): Map[String, List[MethodDefinition]] = { + if (clazz.isAOrChildOf(numberClass) || clazz == stringClass || clazz == unknownClass) { + definitions + } else { + Map.empty + } + } + + override def applies(clazz: Class[_]): Boolean = true + + private def definition(result: TypingResult, methodName: String, desc: Option[String]) = StaticMethodDefinition( + signature = MethodTypeInfo( + noVarArgs = Nil, + varArg = None, + result = result + ), + name = methodName, + description = desc + ) + +} diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/util/classes/Extensions.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/util/classes/Extensions.scala index 94706b5b950..440fbe6a539 100644 --- a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/util/classes/Extensions.scala +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/util/classes/Extensions.scala @@ -12,6 +12,9 @@ object Extensions { clazz != targetClazz && targetClazz.isAssignableFrom(clazz) + def isAOrChildOf(targetClazz: Class[_]): Boolean = + targetClazz.isAssignableFrom(clazz) + def isNotFromNuUtilPackage(): Boolean = { val name = clazz.getName !(name.contains("nussknacker") && name.contains("util")) diff --git a/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/extension/ExtensionMethodsSpec.scala b/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/extension/ExtensionMethodsSpec.scala index 6bd07bfcf2b..4dfa5966a0e 100644 --- a/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/extension/ExtensionMethodsSpec.scala +++ b/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/extension/ExtensionMethodsSpec.scala @@ -27,11 +27,45 @@ class ExtensionMethodsSpec extends AnyFunSuite with Matchers { ) val definitionsSet = ClassDefinitionSet(Set(stringDefinition, unknownDefinition)) - ExtensionMethods.enrichWithExtensionMethods( - definitionsSet - ).classDefinitionsMap.map(e => e._1.getName -> e._2.methods.keys) shouldBe Map( - "java.lang.String" -> Set("toUpperCase"), - "java.lang.Object" -> Set("toString", "canCastTo", "castTo", "castToOrNull"), + ExtensionMethods + .enrichWithExtensionMethods( + definitionsSet + ) + .classDefinitionsMap + .map(e => e._1.getName -> e._2.methods.keys) shouldBe Map( + "java.lang.String" -> Set( + "isBigDecimal", + "toBigDecimal", + "toBigDecimalOrNull", + "isBoolean", + "toBoolean", + "toBooleanOrNull", + "isDouble", + "toDouble", + "toDoubleOrNull", + "isLong", + "toLong", + "toLongOrNull", + "toUpperCase", + ), + "java.lang.Object" -> Set( + "isBigDecimal", + "toBigDecimal", + "toBigDecimalOrNull", + "isBoolean", + "toBoolean", + "toBooleanOrNull", + "isDouble", + "toDouble", + "toDoubleOrNull", + "isLong", + "toLong", + "toLongOrNull", + "toString", + "canCastTo", + "castTo", + "castToOrNull" + ), ) } diff --git a/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/spel/SpelExpressionSpec.scala b/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/spel/SpelExpressionSpec.scala index eb99bd47d53..8652dfddfc0 100644 --- a/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/spel/SpelExpressionSpec.scala +++ b/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/spel/SpelExpressionSpec.scala @@ -52,7 +52,8 @@ import pl.touk.nussknacker.engine.spel.SpelExpressionParser.{Flavour, Standard} import pl.touk.nussknacker.engine.testing.ModelDefinitionBuilder import pl.touk.nussknacker.test.ValidatedValuesDetailedMessage -import java.math.{BigDecimal, BigInteger} +import java.lang.{Boolean => JBoolean, Double => JDouble, Long => JLong} +import java.math.{BigDecimal => JBigDecimal, BigInteger => JBigInteger} import java.nio.charset.Charset import java.time.chrono.ChronoLocalDate import java.time.{LocalDate, LocalDateTime} @@ -241,8 +242,8 @@ class SpelExpressionSpec extends AnyFunSuite with Matchers with ValidatedValuesD ClassDefinitionTestUtils.createDefinitionForClassesWithExtensions(typesFromGlobalVariables ++ customClasses: _*) } - private def evaluate[T: TypeTag](expr: String): T = - parse[T](expr = expr, context = ctx).validExpression.evaluateSync[T](ctx) + private def evaluate[T: TypeTag](expr: String, context: Context = ctx): T = + parse[T](expr = expr, context = context).validExpression.evaluateSync[T](context) test("parsing first selection on array") { parse[Any]("{1,2,3,4,5,6,7,8,9,10}.^[(#this%2==0)]").validExpression @@ -306,11 +307,11 @@ class SpelExpressionSpec extends AnyFunSuite with Matchers with ValidatedValuesD } test("blocking excluded in runtime, without previous static validation, allowed class and package") { - parse[BigInteger]( + parse[JBigInteger]( "T(java.math.BigInteger).valueOf(1L)", staticMethodInvocationsChecking = false, methodExecutionForUnknownAllowed = true - ).validExpression.evaluateSync[BigInteger](ctx) should equal(BigInteger.ONE) + ).validExpression.evaluateSync[JBigInteger](ctx) should equal(JBigInteger.ONE) } test("blocking excluded in runtime, allowed reference") { @@ -1508,6 +1509,113 @@ class SpelExpressionSpec extends AnyFunSuite with Matchers with ValidatedValuesD ) shouldBe List("unknown", "unknown", true).asJava } + test("should convert unknown to a given type") { + val customCtx = ctx + .withVariable("unknownBoolean", ContainerOfUnknown(false)) + .withVariable("unknownInteger", ContainerOfUnknown(1)) + val longTyping = Typed.typedClass[JLong] + val doubleTyping = Typed.typedClass[JDouble] + val bigDecimalTyping = Typed.typedClass[JBigDecimal] + val booleanTyping = Typed.typedClass[JBoolean] + forAll( + Table( + ("expression", "expectedType", "expectedResult"), + ("1.toLong()", longTyping, 1), + ("1.1.toLong()", longTyping, 1), + ("'1'.toLong()", longTyping, 1), + ("1.toLongOrNull()", longTyping, 1), + ("1.1.toLongOrNull()", longTyping, 1), + ("'1'.toLongOrNull()", longTyping, 1), + ("'a'.toLongOrNull()", longTyping, null), + ("#unknownBoolean.value.toLongOrNull()", longTyping, null), + ("1.toDouble()", doubleTyping, 1.0), + ("1.1.toDouble()", doubleTyping, 1.1), + ("'1'.toDouble()", doubleTyping, 1.0), + ("1.toDoubleOrNull()", doubleTyping, 1.0), + ("1.1.toDoubleOrNull()", doubleTyping, 1.1), + ("'1'.toDoubleOrNull()", doubleTyping, 1.0), + ("'a'.toDoubleOrNull()", doubleTyping, null), + ("#unknownBoolean.value.toDoubleOrNull()", doubleTyping, null), + ("1.toBigDecimal()", bigDecimalTyping, BigDecimal(1).bigDecimal), + ("1.1.toBigDecimal()", bigDecimalTyping, BigDecimal(1.1).bigDecimal), + ("'1'.toBigDecimal()", bigDecimalTyping, BigDecimal(1).bigDecimal), + ("1.toBigDecimalOrNull()", bigDecimalTyping, BigDecimal(1).bigDecimal), + ("1.1.toBigDecimalOrNull()", bigDecimalTyping, BigDecimal(1.1).bigDecimal), + ("'1'.toBigDecimalOrNull()", bigDecimalTyping, BigDecimal(1).bigDecimal), + ("'a'.toBigDecimalOrNull()", bigDecimalTyping, null), + ("#unknownBoolean.value.toBigDecimalOrNull()", bigDecimalTyping, null), + ("'true'.toBoolean()", booleanTyping, true), + ("#unknownInteger.value.toBooleanOrNull()", booleanTyping, null), + ("'a'.toBooleanOrNull()", booleanTyping, null), + ("'true'.toBooleanOrNull()", booleanTyping, true), + ("#unknownBoolean.value.toBoolean()", booleanTyping, false), + ) + ) { (expression, expectedType, expectedResult) => + val parsed = parse[Any](expr = expression, context = customCtx).validValue + parsed.returnType.withoutValue shouldBe expectedType + parsed.expression.evaluateSync[Any](customCtx) shouldBe expectedResult + } + } + + test("should check if unknown can be converted to a given type") { + val customCtx = ctx + .withVariable("unknownBoolean", ContainerOfUnknown(true)) + .withVariable("unknownBooleanString", ContainerOfUnknown("false")) + .withVariable("unknownLong", ContainerOfUnknown(11L)) + .withVariable("unknownLongString", ContainerOfUnknown("11")) + .withVariable("unknownDouble", ContainerOfUnknown(1.1)) + .withVariable("unknownDoubleString", ContainerOfUnknown("1.1")) + .withVariable("unknownBigDecimal", ContainerOfUnknown(BigDecimal(2.1).bigDecimal)) + .withVariable("unknownBigDecimalString", ContainerOfUnknown("2.1")) + forAll( + Table( + ("expression", "result"), + ("#unknownBoolean.value.isBoolean()", true), + ("#unknownBooleanString.value.isBoolean()", true), + ("#unknownString.value.isBoolean()", false), + ("#unknownLong.value.isLong()", true), + ("#unknownLongString.value.isLong()", true), + ("#unknownString.value.isLong()", false), + ("#unknownDouble.value.isDouble()", true), + ("#unknownDoubleString.value.isDouble()", true), + ("#unknownString.value.isDouble()", false), + ("#unknownBigDecimal.value.isBigDecimal()", true), + ("#unknownBigDecimalString.value.isBigDecimal()", true), + ("#unknownString.value.isBigDecimal()", false), + ) + ) { (expression, result) => + evaluate[Any](expression, customCtx) shouldBe result + } + } + + test("should throw exception if a value cannot be converted to primitive") { + val customCtx = ctx + .withVariable("unknownBoolean", ContainerOfUnknown(true)) + .withVariable("unknownLong", ContainerOfUnknown(11L)) + .withVariable("unknownDouble", ContainerOfUnknown(1.1)) + .withVariable("unknownBigDecimal", ContainerOfUnknown(BigDecimal(2.1).bigDecimal)) + Table( + "expression", + "#unknownDouble.value.toBoolean()", + "#unknownLong.value.toBoolean()", + "#unknownString.value.toBoolean()", + "#unknownString.value.toLong()", + "#unknownBoolean.value.toLong()", + "#unknownString.value.toDouble()", + "#unknownBoolean.value.toDouble()", + "#unknownBoolean.value.toBigDecimal()", + "#unknownString.value.toBigDecimal()", + ).forEvery { expression => + val caught = intercept[SpelExpressionEvaluationException] { + evaluate[Any](expression, customCtx) + } + caught.getCause.getMessage should ( + include("Cannot convert:") or + include("is neither a decimal digit number") + ) + } + } + } case class SampleObject(list: java.util.List[SampleValue]) diff --git a/utils/default-helpers/src/main/scala/pl/touk/nussknacker/engine/util/functions/conversion.scala b/utils/default-helpers/src/main/scala/pl/touk/nussknacker/engine/util/functions/conversion.scala index 52350def8a0..22af90e4d15 100644 --- a/utils/default-helpers/src/main/scala/pl/touk/nussknacker/engine/util/functions/conversion.scala +++ b/utils/default-helpers/src/main/scala/pl/touk/nussknacker/engine/util/functions/conversion.scala @@ -2,7 +2,6 @@ package pl.touk.nussknacker.engine.util.functions import pl.touk.nussknacker.engine.api.generics.GenericType import pl.touk.nussknacker.engine.api.{Documentation, HideToString, ParamName} -import pl.touk.nussknacker.engine.util.functions.ConversionUtils.{stringToBigInteger, stringToBoolean} import pl.touk.nussknacker.engine.util.functions.NumericUtils.ToNumberTypingFunction import pl.touk.nussknacker.engine.util.json.{JsonUtils, ToJsonEncoder} @@ -38,107 +37,6 @@ trait ConversionUtils extends HideToString { case v => v.toString } - @Documentation(description = "Convert any value to Boolean or throw exception in case of failure") - def toBoolean(@ParamName("value") value: Any): java.lang.Boolean = value match { - case v: String => - stringToBoolean(v).getOrElse { - throw new IllegalArgumentException(s"Cannot convert: $value to Boolean") - } - case v: java.lang.Boolean => v - case null => null - case _ => throw new IllegalArgumentException(s"Cannot convert: $value to Boolean") - } - - @Documentation(description = "Convert any value to Boolean or throw exception in case of failure") - def toBooleanOrNull(@ParamName("value") value: Any): java.lang.Boolean = value match { - case v: String => stringToBoolean(v).orNull - case v: java.lang.Boolean => v - case _ => null - } - - @Documentation(description = "Convert any value to Integer or throw exception in case of failure") - def toInteger(@ParamName("value") value: Any): java.lang.Integer = value match { - case v: String => Integer.valueOf(numeric.toNumber(v).intValue()) - case v: Number => v.intValue() - case null => null - case _ => throw new IllegalArgumentException(s"Cannot convert: $value to Integer") - } - - @Documentation(description = "Convert any value to Integer or null in case of failure") - def toIntegerOrNull(@ParamName("value") value: Any): java.lang.Integer = value match { - case v: String => Try(Integer.valueOf(numeric.toNumber(v).intValue())).getOrElse(null) - case v: Number => v.intValue() - case _ => null - } - - @Documentation(description = "Convert any value to Long or throw exception in case of failure") - def toLong(@ParamName("value") value: Any): java.lang.Long = value match { - case v: String => java.lang.Long.valueOf(numeric.toNumber(v).longValue()) - case v: Number => v.longValue() - case null => null - case _ => throw new IllegalArgumentException(s"Cannot convert: $value to Long") - } - - @Documentation(description = "Convert any value to Long or null in case of failure") - def toLongOrNull(@ParamName("value") value: Any): java.lang.Long = value match { - case v: String => Try(java.lang.Long.valueOf(numeric.toNumber(v).longValue())).getOrElse(null) - case v: Number => v.longValue() - case _ => null - } - - @Documentation(description = "Convert any value to Double or throw exception in case of failure") - def toDouble(@ParamName("value") value: Any): java.lang.Double = value match { - case v: String => java.lang.Double.valueOf(numeric.toNumber(v).doubleValue()) - case v: Number => v.doubleValue() - case null => null - case _ => throw new IllegalArgumentException(s"Cannot convert: $value to Double") - } - - @Documentation(description = "Convert any value to Double or null in case of failure") - def toDoubleOrNull(@ParamName("value") value: Any): java.lang.Double = value match { - case v: String => Try(java.lang.Double.valueOf(numeric.toNumber(v).doubleValue())).getOrElse(null) - case v: Number => v.doubleValue() - case _ => null - } - - @Documentation(description = "Convert any value to BigInteger or throw exception in case of failure") - def toBigInteger(@ParamName("value") value: Any): java.math.BigInteger = value match { - case v: String => stringToBigInteger(v) - case v: java.math.BigInteger => v - case v: java.math.BigDecimal => v.toBigInteger - case v: Number => java.math.BigInteger.valueOf(v.longValue()) - case null => null - case _ => throw new IllegalArgumentException(s"Cannot convert: $value to BigInteger") - } - - @Documentation(description = "Convert any value to BigInteger or null in case of failure") - def toBigIntegerOrNull(@ParamName("value") value: Any): java.math.BigInteger = value match { - case v: String => Try(stringToBigInteger(v)).getOrElse(null) - case v: java.math.BigInteger => v - case v: java.math.BigDecimal => v.toBigInteger - case v: Number => java.math.BigInteger.valueOf(v.longValue()) - case _ => null - } - - @Documentation(description = "Convert any value to BigDecimal or throw exception in case of failure") - def toBigDecimal(@ParamName("value") value: Any): java.math.BigDecimal = value match { - case v: String => new java.math.BigDecimal(v) - case v: java.math.BigInteger => new java.math.BigDecimal(v) - case v: java.math.BigDecimal => v - case v: Number => new java.math.BigDecimal(v.toString) - case null => null - case _ => throw new IllegalArgumentException(s"Cannot convert: $value to BigDecimal") - } - - @Documentation(description = "Convert any value to BigDecimal or null in case of failure") - def toBigDecimalOrNull(@ParamName("value") value: Any): java.math.BigDecimal = value match { - case v: String => Try(new java.math.BigDecimal(v)).getOrElse(null) - case v: java.math.BigInteger => new java.math.BigDecimal(v) - case v: java.math.BigDecimal => v - case v: Number => Try(new java.math.BigDecimal(v.toString)).getOrElse(null) - case _ => null - } - @Documentation(description = "Convert String value to JSON") def toJson(@ParamName("value") value: String): Any = { toJsonEither(value).toTry.get @@ -164,22 +62,3 @@ trait ConversionUtils extends HideToString { private lazy val jsonEncoder = new ToJsonEncoder(true, this.getClass.getClassLoader) } - -object ConversionUtils { - - private def stringToBigInteger(value: String): java.math.BigInteger = - numeric.toNumber(value) match { - case n: java.math.BigInteger => n - case n => java.math.BigInteger.valueOf(n.longValue()) - } - - private def stringToBoolean(value: String): Option[java.lang.Boolean] = - if ("true".equalsIgnoreCase(value)) { - Some(true) - } else if ("false".equalsIgnoreCase(value)) { - Some(false) - } else { - None - } - -} diff --git a/utils/default-helpers/src/test/scala/pl/touk/nussknacker/engine/util/functions/ConversionUtilsSpec.scala b/utils/default-helpers/src/test/scala/pl/touk/nussknacker/engine/util/functions/ConversionUtilsSpec.scala index 54ab7ac6263..0bf30560994 100644 --- a/utils/default-helpers/src/test/scala/pl/touk/nussknacker/engine/util/functions/ConversionUtilsSpec.scala +++ b/utils/default-helpers/src/test/scala/pl/touk/nussknacker/engine/util/functions/ConversionUtilsSpec.scala @@ -24,70 +24,6 @@ class ConversionUtilsSpec extends AnyFunSuite with BaseSpelSpec with Matchers { ("#CONV.toString('a')", "a"), ("#CONV.toString(null)", null), ("#CONV.toString(true)", "true"), - ("#CONV.toBoolean(null)", null), - ("#CONV.toBoolean(true)", true), - ("#CONV.toBoolean('true')", true), - ("#CONV.toBooleanOrNull(1)", null), - ("#CONV.toBooleanOrNull(1.1)", null), - ("#CONV.toBooleanOrNull('a')", null), - ("#CONV.toBooleanOrNull(null)", null), - ("#CONV.toBooleanOrNull(true)", true), - ("#CONV.toBooleanOrNull('true')", true), - ("#CONV.toInteger(1)", 1), - ("#CONV.toInteger(1.1)", 1), - ("#CONV.toInteger('1')", 1), - ("#CONV.toInteger(null)", null), - ("#CONV.toIntegerOrNull(1)", 1), - ("#CONV.toIntegerOrNull(1.1)", 1), - ("#CONV.toIntegerOrNull('1')", 1), - ("#CONV.toIntegerOrNull('a')", null), - ("#CONV.toIntegerOrNull(null)", null), - ("#CONV.toIntegerOrNull(true)", null), - ("#CONV.toIntegerOrNull('true')", null), - ("#CONV.toLong(1)", 1), - ("#CONV.toLong(1.1)", 1), - ("#CONV.toLong('1')", 1), - ("#CONV.toLong(null)", null), - ("#CONV.toLongOrNull(1)", 1), - ("#CONV.toLongOrNull(1.1)", 1), - ("#CONV.toLongOrNull('1')", 1), - ("#CONV.toLongOrNull('a')", null), - ("#CONV.toLongOrNull(null)", null), - ("#CONV.toLongOrNull(true)", null), - ("#CONV.toLongOrNull('true')", null), - ("#CONV.toDouble(1)", 1.0), - ("#CONV.toDouble(1.1)", 1.1), - ("#CONV.toDouble('1')", 1.0), - ("#CONV.toDouble(null)", null), - ("#CONV.toDoubleOrNull(1)", 1.0), - ("#CONV.toDoubleOrNull(1.1)", 1.1), - ("#CONV.toDoubleOrNull('1')", 1.0), - ("#CONV.toDoubleOrNull('a')", null), - ("#CONV.toDoubleOrNull(null)", null), - ("#CONV.toDoubleOrNull(true)", null), - ("#CONV.toDoubleOrNull('true')", null), - ("#CONV.toBigInteger(1)", BigInt(1).bigInteger), - ("#CONV.toBigInteger(1.1)", BigInt(1).bigInteger), - ("#CONV.toBigInteger('1')", BigInt(1).bigInteger), - ("#CONV.toBigInteger(null)", null), - ("#CONV.toBigIntegerOrNull(1)", BigInt(1).bigInteger), - ("#CONV.toBigIntegerOrNull(1.1)", BigInt(1).bigInteger), - ("#CONV.toBigIntegerOrNull('1')", BigInt(1).bigInteger), - ("#CONV.toBigIntegerOrNull('a')", null), - ("#CONV.toBigIntegerOrNull(null)", null), - ("#CONV.toBigIntegerOrNull(true)", null), - ("#CONV.toBigIntegerOrNull('true')", null), - ("#CONV.toBigDecimal(1)", BigDecimal(1).bigDecimal), - ("#CONV.toBigDecimal(1.1)", BigDecimal(1.1).bigDecimal), - ("#CONV.toBigDecimal('1')", BigDecimal(1).bigDecimal), - ("#CONV.toBigDecimal(null)", null), - ("#CONV.toBigDecimalOrNull(1)", BigDecimal(1).bigDecimal), - ("#CONV.toBigDecimalOrNull(1.1)", BigDecimal(1.1).bigDecimal), - ("#CONV.toBigDecimalOrNull('1')", BigDecimal(1).bigDecimal), - ("#CONV.toBigDecimalOrNull('a')", null), - ("#CONV.toBigDecimalOrNull(null)", null), - ("#CONV.toBigDecimalOrNull(true)", null), - ("#CONV.toBigDecimalOrNull('true')", null), ).forEvery { (expression, expected) => evaluateAny(expression) shouldBe expected } @@ -96,56 +32,11 @@ class ConversionUtilsSpec extends AnyFunSuite with BaseSpelSpec with Matchers { ("expression", "expected"), ("#CONV.toNumberOrNull(1)", "Number"), ("#CONV.toString(1)", "String"), - ("#CONV.toBoolean('true')", "Boolean"), - ("#CONV.toBooleanOrNull('true')", "Boolean"), - ("#CONV.toInteger('true')", "Integer"), - ("#CONV.toIntegerOrNull('true')", "Integer"), - ("#CONV.toLong('true')", "Long"), - ("#CONV.toLongOrNull('true')", "Long"), - ("#CONV.toDouble('true')", "Double"), - ("#CONV.toDoubleOrNull('true')", "Double"), - ("#CONV.toBigInteger('true')", "BigInteger"), - ("#CONV.toBigIntegerOrNull('true')", "BigInteger"), - ("#CONV.toBigDecimal('true')", "BigDecimal"), - ("#CONV.toBigDecimalOrNull('true')", "BigDecimal"), ).forEvery { (expression, expected) => evaluateType(expression, types = Map.empty) shouldBe expected.valid } } - test("should throw exception if a value cannot be converted to primitive") { - Table( - "expression", - "#CONV.toBoolean('a')", - "#CONV.toBoolean(1)", - "#CONV.toBoolean(1.1)", - "#CONV.toInteger('a')", - "#CONV.toInteger(true)", - "#CONV.toInteger('true')", - "#CONV.toLong('a')", - "#CONV.toLong(true)", - "#CONV.toLong('true')", - "#CONV.toDouble('a')", - "#CONV.toDouble(true)", - "#CONV.toDouble('true')", - "#CONV.toBigInteger('a')", - "#CONV.toBigInteger(true)", - "#CONV.toBigInteger('true')", - "#CONV.toBigDecimal('a')", - "#CONV.toBigDecimal(true)", - "#CONV.toBigDecimal('true')", - ).forEvery { expression => - val caught = intercept[SpelExpressionEvaluationException] { - evaluateAny(expression, Map.empty) - } - caught.getMessage should ( - include("Cannot convert:") or - include("is neither a decimal digit number") or - include("For input string:") - ) - } - } - test("parse JSON") { Table( ("expression", "expected"),