@@ -653,7 +653,7 @@ private inline fun unaryFunction(
653
653
* - Short circuits UNSET and ERROR parameter to return ERROR.
654
654
* - Short circuits NULL [Value] parameter to return NULL [Value].
655
655
* - Extracts Boolean for [function] evaluation.
656
- * - All other [Value] types return ERROR.
656
+ * - All other parameter types return ERROR.
657
657
* - Catches evaluation exceptions and returns them as an ERROR.
658
658
*/
659
659
@JvmName(" unaryBooleanFunction" )
@@ -671,20 +671,22 @@ private inline fun unaryFunction(crossinline function: (Boolean) -> EvaluateResu
671
671
* - Short circuits NULL [Value] parameter to return NULL [Value].
672
672
* - Extracts Boolean for [function] evaluation.
673
673
* - Wraps the primitive String result as [EvaluateResult].
674
- * - All other [Value] types return ERROR.
674
+ * - All other parameter types return ERROR.
675
675
* - Catches evaluation exceptions and returns them as an ERROR.
676
676
*/
677
677
@JvmName(" unaryStringFunctionPrimitive" )
678
678
private inline fun unaryFunctionPrimitive (crossinline function : (String ) -> String ) =
679
- unaryFunction { s: String -> EvaluateResult .string(function(s)) }
679
+ unaryFunction { s: String ->
680
+ EvaluateResult .string(function(s))
681
+ }
680
682
681
683
/* *
682
684
* Unary String Function
683
685
* - Validates there is exactly 1 parameter.
684
686
* - Short circuits UNSET and ERROR parameter to return ERROR.
685
687
* - Short circuits NULL [Value] parameter to return NULL [Value].
686
688
* - Extracts String for [function] evaluation.
687
- * - All other [Value] types return ERROR.
689
+ * - All other parameter types return ERROR.
688
690
* - Catches evaluation exceptions and returns them as an ERROR.
689
691
*/
690
692
@JvmName(" unaryStringFunction" )
@@ -701,7 +703,7 @@ private inline fun unaryFunction(crossinline function: (String) -> EvaluateResul
701
703
* - Short circuits UNSET and ERROR parameter to return ERROR.
702
704
* - Short circuits NULL [Value] parameter to return NULL [Value].
703
705
* - Extracts String for [function] evaluation.
704
- * - All other [Value] types return ERROR.
706
+ * - All other parameter types return ERROR.
705
707
* - Catches evaluation exceptions and returns them as an ERROR.
706
708
*/
707
709
@JvmName(" unaryLongFunction" )
@@ -718,7 +720,7 @@ private inline fun unaryFunction(crossinline function: (Long) -> EvaluateResult)
718
720
* - Short circuits UNSET and ERROR parameter to return ERROR.
719
721
* - Short circuits NULL [Value] parameter to return NULL [Value].
720
722
* - Extracts Timestamp for [function] evaluation.
721
- * - All other [Value] types return ERROR.
723
+ * - All other parameter types return ERROR.
722
724
* - Catches evaluation exceptions and returns them as an ERROR.
723
725
*/
724
726
@JvmName(" unaryTimestampFunction" )
@@ -733,9 +735,10 @@ private inline fun unaryFunction(crossinline function: (Timestamp) -> EvaluateRe
733
735
* Unary Timestamp Function
734
736
* - Validates there is exactly 1 parameter.
735
737
* - Short circuits UNSET and ERROR parameter to return ERROR.
736
- * - Short circuits NULL [Value] parameter to return NULL [Value], however NULL [Value]s can appear inside of array.
738
+ * - Short circuits NULL [Value] parameter to return NULL [Value], however NULL [Value]s can appear
739
+ * inside of array.
737
740
* - Extracts Timestamp from [Value] for evaluation.
738
- * - All other [Value] types return ERROR.
741
+ * - All other parameter types return ERROR.
739
742
* - Catches evaluation exceptions and returns them as an ERROR.
740
743
*/
741
744
@JvmName(" unaryArrayFunction" )
@@ -751,9 +754,9 @@ private inline fun unaryFunction(crossinline longOp: (List<Value>) -> EvaluateRe
751
754
* - Validates there is exactly 1 parameter.
752
755
* - Short circuits UNSET and ERROR parameter to return ERROR.
753
756
* - Short circuits NULL [Value] parameter to return NULL [Value].
754
- * - Depending on [Value] type, either the Timestamp or String is extracted and evaluated by
755
- * either [byteOp] or [stringOp].
756
- * - All other [Value] types return ERROR.
757
+ * - Depending on [Value] type, either the Timestamp or String is extracted and evaluated by either
758
+ * [byteOp] or [stringOp].
759
+ * - All other parameter types return ERROR.
757
760
* - Catches evaluation exceptions and returns them as an ERROR.
758
761
*/
759
762
private inline fun unaryFunction (
@@ -775,7 +778,7 @@ private inline fun unaryFunction(
775
778
* - Short circuits UNSET and ERROR parameter to return ERROR.
776
779
* - Short circuits NULL [Value] parameter to return NULL [Value].
777
780
* - If [Value] type is [valueTypeCase] then use [valueExtractor] for [function] evaluation.
778
- * - All other [Value] types return ERROR.
781
+ * - All other parameter types return ERROR.
779
782
* - Catches evaluation exceptions and returns them as an ERROR.
780
783
*/
781
784
private inline fun <T > unaryFunctionType (
@@ -800,7 +803,7 @@ private inline fun <T> unaryFunctionType(
800
803
* - Short circuits NULL [Value] parameter to return NULL [Value].
801
804
* - If [Value] type is [valueTypeCase1] then use [valueExtractor1] for [function1] evaluation.
802
805
* - If [Value] type is [valueTypeCase2] then use [valueExtractor2] for [function2] evaluation.
803
- * - All other [Value] types return ERROR.
806
+ * - All other parameter types return ERROR.
804
807
* - Catches evaluation exceptions and returns them as an ERROR.
805
808
*/
806
809
private inline fun <T1 , T2 > unaryFunctionType (
@@ -852,9 +855,10 @@ private inline fun binaryFunction(
852
855
* Binary (Map, String) Function
853
856
* - Validates there is exactly 2 parameters.
854
857
* - First, short circuits UNSET and ERROR parameters to return ERROR.
855
- * - Second short circuits NULL [Value] parameters to return NULL [Value], however NULL [Value]s can appear inside of Map.
858
+ * - Second short circuits NULL [Value] parameters to return NULL [Value], however NULL [Value]s can
859
+ * appear inside of Map.
856
860
* - Extracts Map and String for [function] evaluation.
857
- * - All other [Value] types return ERROR.
861
+ * - All other parameter types return ERROR.
858
862
* - Catches evaluation exceptions and returns them as an ERROR.
859
863
*/
860
864
@JvmName(" binaryMapStringFunction" )
@@ -873,9 +877,10 @@ private inline fun binaryFunction(
873
877
* Binary (Value, Array) Function
874
878
* - Validates there is exactly 2 parameters.
875
879
* - First, short circuits UNSET and ERROR parameters to return ERROR.
876
- * - Second short circuits NULL [Value] parameters to return NULL [Value], however NULL [Value]s can appear inside of Array.
880
+ * - Second short circuits NULL [Value] parameters to return NULL [Value], however NULL [Value]s can
881
+ * appear inside of Array.
877
882
* - Extracts Value and Array for [function] evaluation.
878
- * - All other [Value] types return ERROR.
883
+ * - All other parameter types return ERROR.
879
884
* - Catches evaluation exceptions and returns them as an ERROR.
880
885
*/
881
886
@JvmName(" binaryValueArrayFunction" )
@@ -889,9 +894,10 @@ private inline fun binaryFunction(
889
894
* Binary (Array, Value) Function
890
895
* - Validates there is exactly 2 parameters.
891
896
* - First, short circuits UNSET and ERROR parameters to return ERROR.
892
- * - Second short circuits NULL [Value] parameters to return NULL [Value], however NULL [Value]s can appear inside of Array.
897
+ * - Second short circuits NULL [Value] parameters to return NULL [Value], however NULL [Value]s can
898
+ * appear inside of Array.
893
899
* - Extracts Array and Value for [function] evaluation.
894
- * - All other [Value] types return ERROR.
900
+ * - All other parameter types return ERROR.
895
901
* - Catches evaluation exceptions and returns them as an ERROR.
896
902
*/
897
903
@JvmName(" binaryArrayValueFunction" )
@@ -907,7 +913,7 @@ private inline fun binaryFunction(
907
913
* - First, short circuits UNSET and ERROR parameters to return ERROR.
908
914
* - Second short circuits NULL [Value] parameters to return NULL [Value].
909
915
* - Extracts String and String for [function] evaluation.
910
- * - All other [Value] types return ERROR.
916
+ * - All other parameter types return ERROR.
911
917
* - Catches evaluation exceptions and returns them as an ERROR.
912
918
*/
913
919
@JvmName(" binaryStringStringFunction" )
@@ -927,7 +933,7 @@ private inline fun binaryFunction(crossinline function: (String, String) -> Eval
927
933
* - First, short circuits UNSET and ERROR parameters to return ERROR.
928
934
* - Second short circuits NULL [Value] parameters to return NULL [Value].
929
935
* - Extracts String and Regex via [patternConstructor] for [function] evaluation.
930
- * - All other [Value] types return ERROR.
936
+ * - All other parameter types return ERROR.
931
937
* - Catches evaluation exceptions and returns them as an ERROR.
932
938
*/
933
939
@JvmName(" binaryStringPatternConstructorFunction" )
@@ -955,7 +961,7 @@ private inline fun binaryPatternConstructorFunction(
955
961
* - Second short circuits NULL [Value] parameters to return NULL [Value].
956
962
* - Extracts String and Regex for [function] evaluation.
957
963
* - Caches previously seen Regex to avoid compilation overhead.
958
- * - All other [Value] types return ERROR.
964
+ * - All other parameter types return ERROR.
959
965
* - Catches evaluation exceptions and returns them as an ERROR.
960
966
*/
961
967
@JvmName(" binaryStringPatternFunction" )
@@ -971,9 +977,7 @@ private inline fun binaryPatternFunction(crossinline function: (Pattern, String)
971
977
function
972
978
)
973
979
974
- /* *
975
- * Simple one entry cache.
976
- */
980
+ /* * Simple one entry cache. */
977
981
private inline fun <T > cache (crossinline ifAbsent : (String ) -> T ): (String ) -> T ? {
978
982
var cache: Pair <String ?, T ?> = Pair (null , null )
979
983
return block@{ s: String ->
@@ -990,9 +994,10 @@ private inline fun <T> cache(crossinline ifAbsent: (String) -> T): (String) -> T
990
994
* Binary (Array, Array) Function
991
995
* - Validates there is exactly 2 parameters.
992
996
* - First, short circuits UNSET and ERROR parameters to return ERROR.
993
- * - Second short circuits NULL [Value] parameters to return NULL [Value], however NULL [Value]s can appear inside of Array.
997
+ * - Second short circuits NULL [Value] parameters to return NULL [Value], however NULL [Value]s can
998
+ * appear inside of Array.
994
999
* - Extracts Array and Array for [function] evaluation.
995
- * - All other [Value] types return ERROR.
1000
+ * - All other parameter types return ERROR.
996
1001
* - Catches evaluation exceptions and returns them as an ERROR.
997
1002
*/
998
1003
@JvmName(" binaryArrayArrayFunction" )
@@ -1015,7 +1020,7 @@ private inline fun binaryFunction(
1015
1020
* - First parameter must be [Value] of [valueTypeCase1].
1016
1021
* - Second parameter must be [Value] of [valueTypeCase2].
1017
1022
* - Extract parameter values via [valueExtractor1] and [valueExtractor2] for [function] evaluation.
1018
- * - All other [Value] types return ERROR.
1023
+ * - All other parameter types return ERROR.
1019
1024
* - Catches evaluation exceptions and returns them as an ERROR.
1020
1025
*/
1021
1026
private inline fun <T1 , T2 > binaryFunctionType (
@@ -1057,7 +1062,7 @@ private inline fun <T1, T2> binaryFunctionType(
1057
1062
* - First parameter must be [Value] of [valueTypeCase1].
1058
1063
* - Second parameter must be [Value] of [valueTypeCase2].
1059
1064
* - Extract parameter values via [valueExtractor1] and [valueExtractor2] for [function] evaluation.
1060
- * - All other [Value] types return ERROR.
1065
+ * - All other parameter types return ERROR.
1061
1066
* - Catches evaluation exceptions and returns them as an ERROR.
1062
1067
*/
1063
1068
private inline fun <T1 , T2 > binaryFunctionConstructorType (
@@ -1118,7 +1123,7 @@ private inline fun ternaryLazyFunction(
1118
1123
* - If 2nd parameter is NULL, short circuit and return ERROR.
1119
1124
* - If 1st or 3rd parameter is NULL, short circuit and return NULL.
1120
1125
* - Extracts Timestamp, String and Long for [function] evaluation.
1121
- * - All other [Value] types return ERROR.
1126
+ * - All other parameter types return ERROR.
1122
1127
* - Catches evaluation exceptions and returns them as an ERROR.
1123
1128
*/
1124
1129
private inline fun ternaryTimestampFunction (
@@ -1190,7 +1195,7 @@ private inline fun variadicNullableValueFunction(
1190
1195
* - First short circuits UNSET and ERROR parameters to return ERROR.
1191
1196
* - Second short circuits NULL [Value] parameters to return NULL [Value].
1192
1197
* - Extract String parameters into List for [function] evaluation.
1193
- * - All other [Value] types return ERROR.
1198
+ * - All other parameter types return ERROR.
1194
1199
* - Catches evaluation exceptions and returns them as an ERROR.
1195
1200
*/
1196
1201
@JvmName(" variadicStringFunction" )
@@ -1205,7 +1210,7 @@ private inline fun variadicFunction(
1205
1210
* - Second short circuits NULL [Value] parameters to return NULL [Value].
1206
1211
* - Parameter must be [Value] of [valueTypeCase].
1207
1212
* - Extract parameter values via [valueExtractor] into List for [function] evaluation.
1208
- * - All other [Value] types return ERROR.
1213
+ * - All other parameter types return ERROR.
1209
1214
* - Catches evaluation exceptions and returns them as an ERROR.
1210
1215
*/
1211
1216
private inline fun <T > variadicFunctionType (
@@ -1233,7 +1238,7 @@ private inline fun <T> variadicFunctionType(
1233
1238
* - First short circuits UNSET and ERROR parameters to return ERROR.
1234
1239
* - Second short circuits NULL [Value] parameters to return NULL [Value].
1235
1240
* - Extract String parameters into BooleanArray for [function] evaluation.
1236
- * - All other [Value] types return ERROR.
1241
+ * - All other parameter types return ERROR.
1237
1242
* - Catches evaluation exceptions and returns them as an ERROR.
1238
1243
*/
1239
1244
@JvmName(" variadicBooleanFunction" )
@@ -1270,6 +1275,17 @@ private inline fun comparison(crossinline f: (Value, Value) -> Boolean?): Evalua
1270
1275
else EvaluateResult .boolean(f(p1, p2))
1271
1276
}
1272
1277
1278
+ /* *
1279
+ * Unary (Number) Arithmetic Function
1280
+ * - Validates there is exactly 1 parameter.
1281
+ * - Short circuits UNSET and ERROR parameter to return ERROR.
1282
+ * - Short circuits NULL [Value] parameter to return NULL [Value].
1283
+ * - If parameter type is Integer then [intOp] will be used for evaluation.
1284
+ * - If parameter type is Double then [doubleOp] will be used for evaluation.
1285
+ * - All other parameter types return ERROR.
1286
+ * - Primitive result is wrapped as EvaluateResult.
1287
+ * - Catches evaluation exceptions and returns them as an ERROR.
1288
+ */
1273
1289
private inline fun arithmeticPrimitive (
1274
1290
crossinline intOp : (Long ) -> Long ,
1275
1291
crossinline doubleOp : (Double ) -> Double
@@ -1279,6 +1295,18 @@ private inline fun arithmeticPrimitive(
1279
1295
{ x: Double -> EvaluateResult .double(doubleOp(x)) }
1280
1296
)
1281
1297
1298
+ /* *
1299
+ * Binary Arithmetic Function
1300
+ * - Validates there is exactly 2 parameter.
1301
+ * - Short circuits UNSET and ERROR parameter to return ERROR.
1302
+ * - Short circuits NULL [Value] parameter to return NULL [Value].
1303
+ * - If both parameter types are Integer then [intOp] will be used for evaluation.
1304
+ * - Otherwise if both parameters are either Integer or Double, then the values are converted to
1305
+ * Double, and then [doubleOp] will be used for evaluation.
1306
+ * - All other parameter types return ERROR.
1307
+ * - Primitive result is wrapped as EvaluateResult.
1308
+ * - Catches evaluation exceptions and returns them as an ERROR.
1309
+ */
1282
1310
private inline fun arithmeticPrimitive (
1283
1311
crossinline intOp : (Long , Long ) -> Long ,
1284
1312
crossinline doubleOp : (Double , Double ) -> Double
@@ -1288,13 +1316,43 @@ private inline fun arithmeticPrimitive(
1288
1316
{ x: Double , y: Double -> EvaluateResult .double(doubleOp(x, y)) }
1289
1317
)
1290
1318
1319
+ /* *
1320
+ * Binary Arithmetic Function
1321
+ * - Validates there is exactly 2 parameter.
1322
+ * - Short circuits UNSET and ERROR parameter to return ERROR.
1323
+ * - Short circuits NULL [Value] parameter to return NULL [Value].
1324
+ * - If any of parameters are Integer, they will be converted to Double.
1325
+ * - After conversion, if both parameters are Double, the [doubleOp] will be used for evaluation.
1326
+ * - All other parameter types return ERROR.
1327
+ * - Catches evaluation exceptions and returns them as an ERROR.
1328
+ */
1291
1329
private inline fun arithmeticPrimitive (
1292
1330
crossinline doubleOp : (Double , Double ) -> Double
1293
1331
): EvaluateFunction = arithmetic { x: Double , y: Double -> EvaluateResult .double(doubleOp(x, y)) }
1294
1332
1295
- private inline fun arithmetic (crossinline doubleOp : (Double ) -> EvaluateResult ): EvaluateFunction =
1296
- arithmetic({ n: Long -> doubleOp(n.toDouble()) }, doubleOp)
1333
+ /* *
1334
+ * Unary Arithmetic Function
1335
+ * - Validates there is exactly 1 parameter.
1336
+ * - Short circuits UNSET and ERROR parameter to return ERROR.
1337
+ * - Short circuits NULL [Value] parameter to return NULL [Value].
1338
+ * - If parameter is Integer, it will be converted to Double.
1339
+ * - After conversion, if parameter is Double, the [function] will be used for evaluation.
1340
+ * - All other parameter types return ERROR.
1341
+ * - Catches evaluation exceptions and returns them as an ERROR.
1342
+ */
1343
+ private inline fun arithmetic (crossinline function : (Double ) -> EvaluateResult ): EvaluateFunction =
1344
+ arithmetic({ n: Long -> function(n.toDouble()) }, function)
1297
1345
1346
+ /* *
1347
+ * Unary Arithmetic Function
1348
+ * - Validates there is exactly 1 parameter.
1349
+ * - Short circuits UNSET and ERROR parameter to return ERROR.
1350
+ * - Short circuits NULL [Value] parameter to return NULL [Value].
1351
+ * - If [Value] type is Integer then [intOp] will be used for evaluation.
1352
+ * - If [Value] type is Double then [doubleOp] will be used for evaluation.
1353
+ * - All other parameter types return ERROR.
1354
+ * - Catches evaluation exceptions and returns them as an ERROR.
1355
+ */
1298
1356
private inline fun arithmetic (
1299
1357
crossinline intOp : (Long ) -> EvaluateResult ,
1300
1358
crossinline doubleOp : (Double ) -> EvaluateResult
@@ -1308,6 +1366,17 @@ private inline fun arithmetic(
1308
1366
doubleOp,
1309
1367
)
1310
1368
1369
+ /* *
1370
+ * Binary Arithmetic Function
1371
+ * - Validates there is exactly 2 parameter.
1372
+ * - Short circuits UNSET and ERROR parameter to return ERROR.
1373
+ * - Short circuits NULL [Value] parameter to return NULL [Value].
1374
+ * - Second parameter is expected to be Long.
1375
+ * - If first parameter type is Integer then [intOp] will be used for evaluation.
1376
+ * - If first parameter type is Double then [doubleOp] will be used for evaluation.
1377
+ * - All other parameter types return ERROR.
1378
+ * - Catches evaluation exceptions and returns them as an ERROR.
1379
+ */
1311
1380
@JvmName(" arithmeticNumberLong" )
1312
1381
private inline fun arithmetic (
1313
1382
crossinline intOp : (Long , Long ) -> EvaluateResult ,
@@ -1322,6 +1391,17 @@ private inline fun arithmetic(
1322
1391
else EvaluateResultError
1323
1392
}
1324
1393
1394
+ /* *
1395
+ * Binary Arithmetic Function
1396
+ * - Validates there is exactly 2 parameter.
1397
+ * - Short circuits UNSET and ERROR parameter to return ERROR.
1398
+ * - Short circuits NULL [Value] parameter to return NULL [Value].
1399
+ * - If both parameter types are Integer then [intOp] will be used for evaluation.
1400
+ * - Otherwise if both parameters are either Integer or Double, then the values are converted to
1401
+ * Double, and then [doubleOp] will be used for evaluation.
1402
+ * - All other parameter types return ERROR.
1403
+ * - Catches evaluation exceptions and returns them as an ERROR.
1404
+ */
1325
1405
private inline fun arithmetic (
1326
1406
crossinline intOp : (Long , Long ) -> EvaluateResult ,
1327
1407
crossinline doubleOp : (Double , Double ) -> EvaluateResult
@@ -1343,8 +1423,18 @@ private inline fun arithmetic(
1343
1423
}
1344
1424
}
1345
1425
1426
+ /* *
1427
+ * Binary Arithmetic Function
1428
+ * - Validates there is exactly 2 parameter.
1429
+ * - Short circuits UNSET and ERROR parameter to return ERROR.
1430
+ * - Short circuits NULL [Value] parameter to return NULL [Value].
1431
+ * - If any of parameters are Integer, they will be converted to Double.
1432
+ * - After conversion, if both parameters are Double, the [function] will be used for evaluation.
1433
+ * - All other parameter types return ERROR.
1434
+ * - Catches evaluation exceptions and returns them as an ERROR.
1435
+ */
1346
1436
private inline fun arithmetic (
1347
- crossinline op : (Double , Double ) -> EvaluateResult
1437
+ crossinline function : (Double , Double ) -> EvaluateResult
1348
1438
): EvaluateFunction = binaryFunction { p1: Value , p2: Value ->
1349
1439
val v1: Double =
1350
1440
when (p1.valueTypeCase) {
@@ -1358,5 +1448,5 @@ private inline fun arithmetic(
1358
1448
ValueTypeCase .DOUBLE_VALUE -> p2.doubleValue
1359
1449
else -> return @binaryFunction EvaluateResultError
1360
1450
}
1361
- op (v1, v2)
1451
+ function (v1, v2)
1362
1452
}
0 commit comments