@fincity/kirun-js 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +9 -0
- package/__tests__/engine/function/system/array/AddFirstTest.ts +235 -0
- package/__tests__/engine/function/system/array/AddTest.ts +126 -0
- package/__tests__/engine/function/system/array/BinarySearchTest.ts +135 -0
- package/__tests__/engine/function/system/array/CompareTest.ts +48 -0
- package/__tests__/engine/function/system/array/CopyTest.ts +86 -0
- package/__tests__/engine/function/system/array/DeleteFirstTest.ts +103 -0
- package/__tests__/engine/function/system/array/DeleteFromTest.ts +232 -0
- package/__tests__/engine/function/system/array/DeleteLastTest.ts +103 -0
- package/__tests__/engine/function/system/array/DeleteTest.ts +110 -0
- package/__tests__/engine/function/system/array/DisjointTest.ts +184 -0
- package/__tests__/engine/function/system/array/Equals.ts +67 -0
- package/__tests__/engine/function/system/array/FillTest.ts +36 -0
- package/__tests__/engine/function/system/array/FrequencyTest.ts +97 -0
- package/__tests__/engine/function/system/array/IndexOfArrayTest.ts +347 -0
- package/__tests__/engine/function/system/array/IndexOfTest.ts +267 -0
- package/__tests__/engine/function/system/array/InsertTest.ts +229 -0
- package/__tests__/engine/function/system/array/LastIndexOfArrayTest.ts +213 -0
- package/__tests__/engine/function/system/array/LastIndexOfTest.ts +253 -0
- package/__tests__/engine/function/system/array/MaxTest.ts +98 -0
- package/__tests__/engine/function/system/array/MinTest.ts +99 -0
- package/__tests__/engine/function/system/array/MisMatchTest.ts +215 -0
- package/__tests__/engine/function/system/array/ReverseTest.ts +235 -0
- package/__tests__/engine/function/system/array/RotateTest.ts +137 -0
- package/__tests__/engine/function/system/array/ShuffleTest.ts +154 -0
- package/__tests__/engine/function/system/array/SortTest.ts +130 -0
- package/__tests__/engine/function/system/array/SubArrayTest.ts +236 -0
- package/__tests__/engine/function/system/math/AddTest.ts +12 -0
- package/__tests__/engine/function/system/string/ConcatenateTest.ts +46 -0
- package/__tests__/engine/function/system/string/DeleteForGivenLengthTest.ts +38 -0
- package/__tests__/engine/function/system/string/InsertAtGivenPositionTest.ts +53 -0
- package/__tests__/engine/function/system/string/PostPadTest.ts +54 -0
- package/__tests__/engine/function/system/string/PrePadTest.ts +54 -0
- package/__tests__/engine/function/system/string/RegionMatchesTest.ts +78 -0
- package/__tests__/engine/function/system/string/ReverseTest.ts +36 -0
- package/__tests__/engine/function/system/string/SplitTest.ts +61 -0
- package/__tests__/engine/function/system/string/StringFunctionRepoTest2.ts +126 -0
- package/__tests__/engine/function/system/string/StringFunctionRepoTest3.ts +54 -0
- package/__tests__/engine/function/system/string/StringFunctionRepositoryTest.ts +146 -0
- package/__tests__/engine/function/system/string/ToStringTest.ts +43 -0
- package/__tests__/engine/function/system/string/TrimToTest.ts +28 -0
- package/__tests__/engine/json/schema/validator/SchemaValidatorTest.ts +26 -0
- package/__tests__/engine/runtime/KIRuntimeTest.ts +351 -0
- package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +128 -0
- package/__tests__/engine/runtime/expression/ExpressionTest.ts +33 -0
- package/__tests__/engine/runtime/expression/tokenextractor/OutputMapTokenValueExtractorTest.ts +44 -0
- package/__tests__/engine/runtime/expression/tokenextractor/TokenValueExtractorTest.ts +72 -0
- package/__tests__/engine/util/LinkedListTest.ts +29 -0
- package/__tests__/engine/util/string/StringFormatterTest.ts +17 -0
- package/__tests__/indexTest.ts +33 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/module.js +2 -0
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +430 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +54 -0
- package/src/engine/HybridRepository.ts +18 -0
- package/src/engine/Repository.ts +3 -0
- package/src/engine/constant/KIRunConstants.ts +7 -0
- package/src/engine/exception/ExecutionException.ts +12 -0
- package/src/engine/exception/KIRuntimeException.ts +12 -0
- package/src/engine/function/AbstractFunction.ts +76 -0
- package/src/engine/function/Function.ts +13 -0
- package/src/engine/function/system/GenerateEvent.ts +76 -0
- package/src/engine/function/system/If.ts +40 -0
- package/src/engine/function/system/array/AbstractArrayFunction.ts +158 -0
- package/src/engine/function/system/array/Add.ts +31 -0
- package/src/engine/function/system/array/AddFirst.ts +44 -0
- package/src/engine/function/system/array/BinarySearch.ts +66 -0
- package/src/engine/function/system/array/Compare.ts +150 -0
- package/src/engine/function/system/array/Copy.ts +56 -0
- package/src/engine/function/system/array/Delete.ts +63 -0
- package/src/engine/function/system/array/DeleteFirst.ts +22 -0
- package/src/engine/function/system/array/DeleteFrom.ts +51 -0
- package/src/engine/function/system/array/DeleteLast.ts +23 -0
- package/src/engine/function/system/array/Disjoint.ts +85 -0
- package/src/engine/function/system/array/Equals.ts +36 -0
- package/src/engine/function/system/array/Fill.ts +51 -0
- package/src/engine/function/system/array/Frequency.ts +68 -0
- package/src/engine/function/system/array/IndexOf.ts +56 -0
- package/src/engine/function/system/array/IndexOfArray.ts +67 -0
- package/src/engine/function/system/array/Insert.ts +48 -0
- package/src/engine/function/system/array/LastIndexOf.ts +62 -0
- package/src/engine/function/system/array/LastIndexOfArray.ts +70 -0
- package/src/engine/function/system/array/Max.ts +31 -0
- package/src/engine/function/system/array/Min.ts +32 -0
- package/src/engine/function/system/array/MisMatch.ts +66 -0
- package/src/engine/function/system/array/Reverse.ts +50 -0
- package/src/engine/function/system/array/Rotate.ts +43 -0
- package/src/engine/function/system/array/Shuffle.ts +31 -0
- package/src/engine/function/system/array/Sort.ts +70 -0
- package/src/engine/function/system/array/SubArray.ts +48 -0
- package/src/engine/function/system/context/Create.ts +73 -0
- package/src/engine/function/system/context/Get.ts +55 -0
- package/src/engine/function/system/context/SetFunction.ts +244 -0
- package/src/engine/function/system/loop/CountLoop.ts +55 -0
- package/src/engine/function/system/loop/RangeLoop.ts +120 -0
- package/src/engine/function/system/math/Add.ts +34 -0
- package/src/engine/function/system/math/GenericMathFunction.ts +80 -0
- package/src/engine/function/system/math/Hypotenuse.ts +57 -0
- package/src/engine/function/system/math/MathFunctionRepository.ts +63 -0
- package/src/engine/function/system/math/Maximum.ts +38 -0
- package/src/engine/function/system/math/Minimum.ts +38 -0
- package/src/engine/function/system/math/Random.ts +27 -0
- package/src/engine/function/system/string/AbstractStringFunction.ts +409 -0
- package/src/engine/function/system/string/Concatenate.ts +57 -0
- package/src/engine/function/system/string/DeleteForGivenLength.ts +82 -0
- package/src/engine/function/system/string/InsertAtGivenPosition.ts +72 -0
- package/src/engine/function/system/string/PostPad.ts +83 -0
- package/src/engine/function/system/string/PrePad.ts +73 -0
- package/src/engine/function/system/string/RegionMatches.ts +119 -0
- package/src/engine/function/system/string/ReplaceAtGivenPosition.ts +101 -0
- package/src/engine/function/system/string/Reverse.ts +62 -0
- package/src/engine/function/system/string/Split.ts +53 -0
- package/src/engine/function/system/string/StringFunctionRepository.ts +60 -0
- package/src/engine/function/system/string/ToString.ts +45 -0
- package/src/engine/function/system/string/TrimTo.ts +55 -0
- package/src/engine/json/JsonExpression.ts +11 -0
- package/src/engine/json/schema/Schema.ts +670 -0
- package/src/engine/json/schema/SchemaUtil.ts +145 -0
- package/src/engine/json/schema/array/ArraySchemaType.ts +44 -0
- package/src/engine/json/schema/object/AdditionalPropertiesType.ts +32 -0
- package/src/engine/json/schema/string/StringFormat.ts +7 -0
- package/src/engine/json/schema/type/MultipleType.ts +28 -0
- package/src/engine/json/schema/type/SchemaType.ts +11 -0
- package/src/engine/json/schema/type/SingleType.ts +23 -0
- package/src/engine/json/schema/type/Type.ts +6 -0
- package/src/engine/json/schema/type/TypeUtil.ts +25 -0
- package/src/engine/json/schema/validator/AnyOfAllOfOneOfValidator.ts +108 -0
- package/src/engine/json/schema/validator/ArrayValidator.ts +145 -0
- package/src/engine/json/schema/validator/BooleanValidator.ts +24 -0
- package/src/engine/json/schema/validator/NullValidator.ts +17 -0
- package/src/engine/json/schema/validator/NumberValidator.ts +115 -0
- package/src/engine/json/schema/validator/ObjectValidator.ts +184 -0
- package/src/engine/json/schema/validator/SchemaValidator.ts +141 -0
- package/src/engine/json/schema/validator/StringValidator.ts +97 -0
- package/src/engine/json/schema/validator/TypeValidator.ts +49 -0
- package/src/engine/json/schema/validator/exception/SchemaReferenceException.ts +19 -0
- package/src/engine/json/schema/validator/exception/SchemaValidationException.ts +22 -0
- package/src/engine/model/AbstractStatement.ts +29 -0
- package/src/engine/model/Argument.ts +36 -0
- package/src/engine/model/Event.ts +62 -0
- package/src/engine/model/EventResult.ts +34 -0
- package/src/engine/model/FunctionDefinition.ts +69 -0
- package/src/engine/model/FunctionOutput.ts +37 -0
- package/src/engine/model/FunctionOutputGenerator.ts +5 -0
- package/src/engine/model/FunctionSignature.ts +67 -0
- package/src/engine/model/Parameter.ts +97 -0
- package/src/engine/model/ParameterReference.ts +57 -0
- package/src/engine/model/ParameterReferenceType.ts +4 -0
- package/src/engine/model/ParameterType.ts +4 -0
- package/src/engine/model/Position.ts +40 -0
- package/src/engine/model/Statement.ts +101 -0
- package/src/engine/model/StatementGroup.ts +37 -0
- package/src/engine/namespaces/Namespaces.ts +11 -0
- package/src/engine/repository/KIRunFunctionRepository.ts +37 -0
- package/src/engine/repository/KIRunSchemaRepository.ts +24 -0
- package/src/engine/runtime/ContextElement.ts +28 -0
- package/src/engine/runtime/FunctionExecutionParameters.ts +74 -0
- package/src/engine/runtime/KIRuntime.ts +653 -0
- package/src/engine/runtime/StatementExecution.ts +61 -0
- package/src/engine/runtime/StatementMessage.ts +30 -0
- package/src/engine/runtime/StatementMessageType.ts +5 -0
- package/src/engine/runtime/expression/Expression.ts +330 -0
- package/src/engine/runtime/expression/ExpressionEvaluator.ts +305 -0
- package/src/engine/runtime/expression/ExpressionToken.ts +15 -0
- package/src/engine/runtime/expression/ExpressionTokenValue.ts +23 -0
- package/src/engine/runtime/expression/Operation.ts +190 -0
- package/src/engine/runtime/expression/exception/ExpressionEvaluationException.ts +15 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticAdditionOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticDivisionOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticInetgerDivisionOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticModulusOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticMultiplicationOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticSubtractionOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArrayOperator.ts +31 -0
- package/src/engine/runtime/expression/operators/binary/BinaryOperator.ts +15 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseAndOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseLeftShiftOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseOrOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseRightShiftOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseUnsignedRightShiftOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseXorOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/LogicalAndOperator.ts +25 -0
- package/src/engine/runtime/expression/operators/binary/LogicalEqualOperator.ts +13 -0
- package/src/engine/runtime/expression/operators/binary/LogicalGreaterThanEqualOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/binary/LogicalGreaterThanOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/binary/LogicalLessThanEqualOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/binary/LogicalLessThanOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/binary/LogicalNotEqualOperator.ts +13 -0
- package/src/engine/runtime/expression/operators/binary/LogicalOrOperator.ts +25 -0
- package/src/engine/runtime/expression/operators/binary/ObjectOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/unary/ArithmeticUnaryMinusOperator.ts +13 -0
- package/src/engine/runtime/expression/operators/unary/ArithmeticUnaryPlusOperator.ts +13 -0
- package/src/engine/runtime/expression/operators/unary/BitwiseComplementOperator.ts +22 -0
- package/src/engine/runtime/expression/operators/unary/LogicalNotOperator.ts +22 -0
- package/src/engine/runtime/expression/operators/unary/UnaryOperator.ts +15 -0
- package/src/engine/runtime/expression/tokenextractor/LiteralTokenValueExtractor.ts +64 -0
- package/src/engine/runtime/expression/tokenextractor/TokenValueExtractor.ts +136 -0
- package/src/engine/runtime/graph/ExecutionGraph.ts +81 -0
- package/src/engine/runtime/graph/GraphVertex.ts +118 -0
- package/src/engine/runtime/graph/GraphVertexType.ts +4 -0
- package/src/engine/runtime/tokenextractor/ArgumentsTokenValueExtractor.ts +22 -0
- package/src/engine/runtime/tokenextractor/ContextTokenValueExtractor.ts +37 -0
- package/src/engine/runtime/tokenextractor/OutputMapTokenValueExtractor.ts +32 -0
- package/src/engine/util/ArrayUtil.ts +23 -0
- package/src/engine/util/LinkedList.ts +229 -0
- package/src/engine/util/MapUtil.ts +86 -0
- package/src/engine/util/NullCheck.ts +3 -0
- package/src/engine/util/Tuples.ts +43 -0
- package/src/engine/util/primitive/PrimitiveUtil.ts +143 -0
- package/src/engine/util/string/StringBuilder.ts +59 -0
- package/src/engine/util/string/StringFormatter.ts +25 -0
- package/src/engine/util/string/StringUtil.ts +48 -0
- package/src/index.ts +13 -0
- package/tsconfig.json +6 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
2
|
+
import { EventResult } from '../../../model/EventResult';
|
|
3
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
5
|
+
import { MapUtil } from '../../../util/MapUtil';
|
|
6
|
+
import { isNullValue } from '../../../util/NullCheck';
|
|
7
|
+
import { StringFormatter } from '../../../util/string/StringFormatter';
|
|
8
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
9
|
+
|
|
10
|
+
export class Copy extends AbstractArrayFunction {
|
|
11
|
+
public constructor() {
|
|
12
|
+
super(
|
|
13
|
+
'Copy',
|
|
14
|
+
[
|
|
15
|
+
Copy.PARAMETER_ARRAY_SOURCE,
|
|
16
|
+
Copy.PARAMETER_INT_SOURCE_FROM,
|
|
17
|
+
Copy.PARAMETER_INT_LENGTH,
|
|
18
|
+
Copy.PARAMETER_BOOLEAN_DEEP_COPY,
|
|
19
|
+
],
|
|
20
|
+
Copy.EVENT_RESULT_ARRAY,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
25
|
+
var source = context?.getArguments()?.get(Copy.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
26
|
+
var srcfrom = context
|
|
27
|
+
?.getArguments()
|
|
28
|
+
?.get(Copy.PARAMETER_INT_SOURCE_FROM.getParameterName());
|
|
29
|
+
var length = context?.getArguments()?.get(Copy.PARAMETER_INT_LENGTH.getParameterName());
|
|
30
|
+
|
|
31
|
+
if (length == -1) length = source.length - srcfrom;
|
|
32
|
+
|
|
33
|
+
if (srcfrom + length > source.length)
|
|
34
|
+
throw new KIRuntimeException(
|
|
35
|
+
StringFormatter.format(
|
|
36
|
+
'Array has no elements from $ to $ as the array size is $',
|
|
37
|
+
srcfrom,
|
|
38
|
+
srcfrom + length,
|
|
39
|
+
source.length,
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
var deep = context
|
|
44
|
+
?.getArguments()
|
|
45
|
+
?.get(Copy.PARAMETER_BOOLEAN_DEEP_COPY.getParameterName());
|
|
46
|
+
|
|
47
|
+
const ja: any[] = new Array(length);
|
|
48
|
+
|
|
49
|
+
for (let i = srcfrom; i < srcfrom + length; i++) {
|
|
50
|
+
if (!isNullValue(source[i]))
|
|
51
|
+
ja[i - srcfrom] = deep ? JSON.parse(JSON.stringify(source[i])) : source[i];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return new FunctionOutput([EventResult.outputOf(MapUtil.of(Copy.EVENT_RESULT_NAME, ja))]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
2
|
+
import { EventResult } from '../../../model/EventResult';
|
|
3
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
5
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
6
|
+
|
|
7
|
+
export class Delete extends AbstractArrayFunction {
|
|
8
|
+
public constructor() {
|
|
9
|
+
super(
|
|
10
|
+
'Delete',
|
|
11
|
+
[
|
|
12
|
+
AbstractArrayFunction.PARAMETER_ARRAY_SOURCE_PRIMITIVE,
|
|
13
|
+
AbstractArrayFunction.PARAMETER_ARRAY_SECOND_SOURCE,
|
|
14
|
+
],
|
|
15
|
+
AbstractArrayFunction.EVENT_RESULT_EMPTY,
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
20
|
+
let source: any[] = context
|
|
21
|
+
?.getArguments()
|
|
22
|
+
?.get(Delete.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName());
|
|
23
|
+
|
|
24
|
+
let deletable: any[] = context
|
|
25
|
+
?.getArguments()
|
|
26
|
+
?.get(Delete.PARAMETER_ARRAY_SECOND_SOURCE.getParameterName());
|
|
27
|
+
|
|
28
|
+
if (source.length == 0 || deletable.length == 0 || deletable.length > source.length)
|
|
29
|
+
throw new KIRuntimeException(
|
|
30
|
+
'Expected a source or deletable for an array but not found any or the deletable size of the array is more than the source array',
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
let deletableSize: number = deletable.length;
|
|
34
|
+
|
|
35
|
+
let index: number = -1;
|
|
36
|
+
|
|
37
|
+
for (let i = 0; i < source.length; i++) {
|
|
38
|
+
let j: number = 0;
|
|
39
|
+
if (source[i] !== null && deletable[j] !== null && source[i] == deletable[j]) {
|
|
40
|
+
while (j < deletableSize) {
|
|
41
|
+
if (
|
|
42
|
+
source[i] == null ||
|
|
43
|
+
deletable[j] == null ||
|
|
44
|
+
source[i + j] != deletable[j]
|
|
45
|
+
) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
j++;
|
|
49
|
+
}
|
|
50
|
+
if (j == deletableSize) {
|
|
51
|
+
index = i;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (index != -1) {
|
|
58
|
+
source.splice(index, deletableSize);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return new FunctionOutput([EventResult.outputOf(new Map([]))]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
2
|
+
import { EventResult } from '../../../model/EventResult';
|
|
3
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
5
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
6
|
+
|
|
7
|
+
export class DeleteFirst extends AbstractArrayFunction {
|
|
8
|
+
public constructor() {
|
|
9
|
+
super('DeleteFirst', [DeleteFirst.PARAMETER_ARRAY_SOURCE], DeleteFirst.EVENT_RESULT_EMPTY);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
13
|
+
let source: any[] = context
|
|
14
|
+
?.getArguments()
|
|
15
|
+
?.get(DeleteFirst.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
16
|
+
|
|
17
|
+
if (source.length == 0) throw new KIRuntimeException('Given source array is empty');
|
|
18
|
+
|
|
19
|
+
source.shift();
|
|
20
|
+
return new FunctionOutput([EventResult.outputOf(new Map([]))]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
2
|
+
import { EventResult } from '../../../model/EventResult';
|
|
3
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
5
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
6
|
+
|
|
7
|
+
export class DeleteFrom extends AbstractArrayFunction {
|
|
8
|
+
public constructor() {
|
|
9
|
+
super(
|
|
10
|
+
'DeleteFrom',
|
|
11
|
+
[
|
|
12
|
+
DeleteFrom.PARAMETER_ARRAY_SOURCE,
|
|
13
|
+
DeleteFrom.PARAMETER_INT_SOURCE_FROM,
|
|
14
|
+
DeleteFrom.PARAMETER_INT_LENGTH,
|
|
15
|
+
],
|
|
16
|
+
DeleteFrom.EVENT_RESULT_EMPTY,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
21
|
+
let source: any[] = context
|
|
22
|
+
?.getArguments()
|
|
23
|
+
?.get(DeleteFrom.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
24
|
+
|
|
25
|
+
let start: number = context
|
|
26
|
+
?.getArguments()
|
|
27
|
+
?.get(DeleteFrom.PARAMETER_INT_SOURCE_FROM.getParameterName());
|
|
28
|
+
|
|
29
|
+
let len: number = context
|
|
30
|
+
?.getArguments()
|
|
31
|
+
?.get(DeleteFrom.PARAMETER_INT_LENGTH.getParameterName());
|
|
32
|
+
|
|
33
|
+
if (source.length == 0) throw new KIRuntimeException('There are no elements to be deleted');
|
|
34
|
+
|
|
35
|
+
if (start >= source.length || start < 0)
|
|
36
|
+
throw new KIRuntimeException(
|
|
37
|
+
'The int source for the array should be in between 0 and length of the array ',
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
if (len == -1) len = source.length - start;
|
|
41
|
+
|
|
42
|
+
if (start + len > source.length)
|
|
43
|
+
throw new KIRuntimeException(
|
|
44
|
+
'Requested length to be deleted is more than the size of array ',
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
source.splice(start, len);
|
|
48
|
+
|
|
49
|
+
return new FunctionOutput([EventResult.outputOf(new Map([]))]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
2
|
+
import { EventResult } from '../../../model/EventResult';
|
|
3
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
5
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
6
|
+
|
|
7
|
+
export class DeleteLast extends AbstractArrayFunction {
|
|
8
|
+
public constructor() {
|
|
9
|
+
super('DeleteLast', [DeleteLast.PARAMETER_ARRAY_SOURCE], DeleteLast.EVENT_RESULT_EMPTY);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
13
|
+
let source: any[] = context
|
|
14
|
+
?.getArguments()
|
|
15
|
+
?.get(DeleteLast.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
16
|
+
|
|
17
|
+
if (source.length == 0) throw new KIRuntimeException('Given source array is empty');
|
|
18
|
+
|
|
19
|
+
source.pop();
|
|
20
|
+
|
|
21
|
+
return new FunctionOutput([EventResult.outputOf(new Map([]))]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
2
|
+
import { EventResult } from '../../../model/EventResult';
|
|
3
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
5
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
6
|
+
|
|
7
|
+
export class Disjoint extends AbstractArrayFunction {
|
|
8
|
+
public constructor() {
|
|
9
|
+
super(
|
|
10
|
+
'Disjoint',
|
|
11
|
+
[
|
|
12
|
+
Disjoint.PARAMETER_ARRAY_SOURCE,
|
|
13
|
+
Disjoint.PARAMETER_INT_SOURCE_FROM,
|
|
14
|
+
Disjoint.PARAMETER_ARRAY_SECOND_SOURCE,
|
|
15
|
+
Disjoint.PARAMETER_INT_SECOND_SOURCE_FROM,
|
|
16
|
+
Disjoint.PARAMETER_INT_LENGTH,
|
|
17
|
+
],
|
|
18
|
+
Disjoint.EVENT_RESULT_ARRAY,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
23
|
+
let firstSource: any[] = context
|
|
24
|
+
?.getArguments()
|
|
25
|
+
?.get(Disjoint.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
26
|
+
|
|
27
|
+
let first: number = context
|
|
28
|
+
?.getArguments()
|
|
29
|
+
?.get(Disjoint.PARAMETER_INT_SOURCE_FROM.getParameterName());
|
|
30
|
+
|
|
31
|
+
let secondSource: any[] = context
|
|
32
|
+
?.getArguments()
|
|
33
|
+
?.get(Disjoint.PARAMETER_ARRAY_SECOND_SOURCE.getParameterName());
|
|
34
|
+
|
|
35
|
+
let second: number = context
|
|
36
|
+
?.getArguments()
|
|
37
|
+
?.get(Disjoint.PARAMETER_INT_SECOND_SOURCE_FROM.getParameterName());
|
|
38
|
+
|
|
39
|
+
let len: number = context
|
|
40
|
+
?.getArguments()
|
|
41
|
+
?.get(Disjoint.PARAMETER_INT_LENGTH.getParameterName());
|
|
42
|
+
|
|
43
|
+
if (len == -1)
|
|
44
|
+
len =
|
|
45
|
+
firstSource.length <= secondSource.length
|
|
46
|
+
? firstSource.length - first
|
|
47
|
+
: secondSource.length - second;
|
|
48
|
+
|
|
49
|
+
if (
|
|
50
|
+
len > firstSource.length ||
|
|
51
|
+
len > secondSource.length ||
|
|
52
|
+
first + len > firstSource.length ||
|
|
53
|
+
second + len > secondSource.length
|
|
54
|
+
)
|
|
55
|
+
throw new KIRuntimeException(
|
|
56
|
+
'The length which was being requested is more than than the size either source array or second source array',
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
let set1: Set<any> = new Set<any>();
|
|
60
|
+
let set2: Set<any> = new Set<any>();
|
|
61
|
+
|
|
62
|
+
for (let i: number = 0; i < len; i++) set1.add(firstSource[i + first]);
|
|
63
|
+
|
|
64
|
+
for (let i: number = 0; i < len; i++) set2.add(secondSource[i + second]);
|
|
65
|
+
|
|
66
|
+
let set3: Set<any> = new Set<any>();
|
|
67
|
+
|
|
68
|
+
set1.forEach((element) => {
|
|
69
|
+
if (set2.has(element)) set2.delete(element);
|
|
70
|
+
else set3.add(element);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
set2.forEach((element) => {
|
|
74
|
+
if (!set1.has(element)) set3.add(element);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
let disjointArray: any[] = [];
|
|
78
|
+
|
|
79
|
+
set3.forEach((element) => disjointArray.push(element));
|
|
80
|
+
|
|
81
|
+
return new FunctionOutput([
|
|
82
|
+
EventResult.outputOf(new Map([[Disjoint.EVENT_RESULT_ARRAY.getName(), disjointArray]])),
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EventResult } from '../../../model/EventResult';
|
|
2
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
3
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
4
|
+
import { MapUtil } from '../../../util/MapUtil';
|
|
5
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
6
|
+
import { Compare } from './Compare';
|
|
7
|
+
|
|
8
|
+
export class Equals extends AbstractArrayFunction {
|
|
9
|
+
public constructor() {
|
|
10
|
+
super(
|
|
11
|
+
'Equals',
|
|
12
|
+
[
|
|
13
|
+
Equals.PARAMETER_ARRAY_SOURCE,
|
|
14
|
+
Equals.PARAMETER_INT_SOURCE_FROM,
|
|
15
|
+
Equals.PARAMETER_ARRAY_FIND,
|
|
16
|
+
Equals.PARAMETER_INT_FIND_FROM,
|
|
17
|
+
Equals.PARAMETER_INT_LENGTH,
|
|
18
|
+
],
|
|
19
|
+
Equals.EVENT_RESULT_BOOLEAN,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
24
|
+
let compare: Compare = new Compare();
|
|
25
|
+
|
|
26
|
+
let fo: FunctionOutput = compare.execute(context);
|
|
27
|
+
|
|
28
|
+
let resultMap: Map<string, any> = fo.allResults()[0].getResult();
|
|
29
|
+
|
|
30
|
+
let v: number = resultMap.get(Equals.EVENT_RESULT_NAME);
|
|
31
|
+
|
|
32
|
+
return new FunctionOutput([
|
|
33
|
+
EventResult.outputOf(MapUtil.of(Equals.EVENT_RESULT_NAME, v == 0)),
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
2
|
+
import { EventResult } from '../../../model/EventResult';
|
|
3
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
5
|
+
import { MapUtil } from '../../../util/MapUtil';
|
|
6
|
+
import { isNullValue } from '../../../util/NullCheck';
|
|
7
|
+
import { StringFormatter } from '../../../util/string/StringFormatter';
|
|
8
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
9
|
+
|
|
10
|
+
export class Fill extends AbstractArrayFunction {
|
|
11
|
+
public constructor() {
|
|
12
|
+
super(
|
|
13
|
+
'Fill',
|
|
14
|
+
[
|
|
15
|
+
Fill.PARAMETER_ARRAY_SOURCE,
|
|
16
|
+
Fill.PARAMETER_INT_SOURCE_FROM,
|
|
17
|
+
Fill.PARAMETER_INT_LENGTH,
|
|
18
|
+
Fill.PARAMETER_ANY,
|
|
19
|
+
],
|
|
20
|
+
Fill.EVENT_RESULT_EMPTY,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
25
|
+
var source = context?.getArguments()?.get(Fill.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
26
|
+
var srcfrom = context
|
|
27
|
+
?.getArguments()
|
|
28
|
+
?.get(Fill.PARAMETER_INT_SOURCE_FROM.getParameterName());
|
|
29
|
+
var length = context?.getArguments()?.get(Fill.PARAMETER_INT_LENGTH.getParameterName());
|
|
30
|
+
var element = context?.getArguments()?.get(Fill.PARAMETER_ANY.getParameterName());
|
|
31
|
+
|
|
32
|
+
if (srcfrom < 0)
|
|
33
|
+
throw new KIRuntimeException(
|
|
34
|
+
StringFormatter.format('Arrays out of bound trying to access $ index', srcfrom),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (length == -1) length = source.length - srcfrom;
|
|
38
|
+
|
|
39
|
+
let add = srcfrom + length - source.length;
|
|
40
|
+
|
|
41
|
+
if (add > 0) {
|
|
42
|
+
for (let i = 0; i < add; i++) source.push();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (let i = srcfrom; i < srcfrom + length; i++) {
|
|
46
|
+
source[i] = isNullValue(element) ? element : JSON.parse(JSON.stringify(element));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return new FunctionOutput([EventResult.outputOf(MapUtil.of())]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
2
|
+
import { EventResult } from '../../../model/EventResult';
|
|
3
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
5
|
+
import { isNullValue } from '../../../util/NullCheck';
|
|
6
|
+
import { PrimitiveUtil } from '../../../util/primitive/PrimitiveUtil';
|
|
7
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
8
|
+
|
|
9
|
+
export class Frequency extends AbstractArrayFunction {
|
|
10
|
+
FunctionOutput: any;
|
|
11
|
+
|
|
12
|
+
public constructor() {
|
|
13
|
+
super(
|
|
14
|
+
'Frequency',
|
|
15
|
+
[
|
|
16
|
+
Frequency.PARAMETER_ARRAY_SOURCE,
|
|
17
|
+
Frequency.PARAMETER_ANY,
|
|
18
|
+
Frequency.PARAMETER_INT_SOURCE_FROM,
|
|
19
|
+
Frequency.PARAMETER_INT_LENGTH,
|
|
20
|
+
],
|
|
21
|
+
Frequency.EVENT_RESULT_INTEGER,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
26
|
+
let source: any[] = context
|
|
27
|
+
?.getArguments()
|
|
28
|
+
?.get(Frequency.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
29
|
+
|
|
30
|
+
let find: any = context?.getArguments()?.get(Frequency.PARAMETER_ANY.getParameterName());
|
|
31
|
+
|
|
32
|
+
let start: number = context
|
|
33
|
+
?.getArguments()
|
|
34
|
+
?.get(Frequency.PARAMETER_INT_SOURCE_FROM.getParameterName());
|
|
35
|
+
|
|
36
|
+
let length: number = context
|
|
37
|
+
?.getArguments()
|
|
38
|
+
?.get(Frequency.PARAMETER_INT_LENGTH.getParameterName());
|
|
39
|
+
|
|
40
|
+
if (source.length == 0)
|
|
41
|
+
return new FunctionOutput([
|
|
42
|
+
EventResult.outputOf(new Map([[Frequency.EVENT_RESULT_INTEGER.getName(), 0]])),
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
if (start > source.length)
|
|
46
|
+
throw new KIRuntimeException('Given start point is more than the size of source');
|
|
47
|
+
|
|
48
|
+
if (isNullValue(find))
|
|
49
|
+
throw new KIRuntimeException('Given find was null. Hence cannot be found in the array');
|
|
50
|
+
|
|
51
|
+
let end: number = start + length;
|
|
52
|
+
|
|
53
|
+
if (length == -1) end = source.length - start;
|
|
54
|
+
|
|
55
|
+
if (end > source.length)
|
|
56
|
+
throw new KIRuntimeException('Given length is more than the size of source');
|
|
57
|
+
|
|
58
|
+
let frequency: number = 0;
|
|
59
|
+
|
|
60
|
+
for (let i: number = start; i < end && i < source.length; i++) {
|
|
61
|
+
if (PrimitiveUtil.compare(source[i], find) == 0) frequency++;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return new FunctionOutput([
|
|
65
|
+
EventResult.outputOf(new Map([[Frequency.EVENT_RESULT_INTEGER.getName(), frequency]])),
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
2
|
+
import { EventResult } from '../../../model/EventResult';
|
|
3
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
5
|
+
import { isNullValue } from '../../../util/NullCheck';
|
|
6
|
+
import { PrimitiveUtil } from '../../../util/primitive/PrimitiveUtil';
|
|
7
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
8
|
+
|
|
9
|
+
export class IndexOf extends AbstractArrayFunction {
|
|
10
|
+
public constructor() {
|
|
11
|
+
super(
|
|
12
|
+
'IndexOf',
|
|
13
|
+
[
|
|
14
|
+
IndexOf.PARAMETER_ARRAY_SOURCE,
|
|
15
|
+
IndexOf.PARAMETER_ANY_NOT_NULL,
|
|
16
|
+
IndexOf.PARAMETER_INT_FIND_FROM,
|
|
17
|
+
],
|
|
18
|
+
IndexOf.EVENT_RESULT_INTEGER,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
23
|
+
let source: any[] = context
|
|
24
|
+
?.getArguments()
|
|
25
|
+
?.get(IndexOf.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
26
|
+
|
|
27
|
+
var find = context?.getArguments()?.get(IndexOf.PARAMETER_ANY_NOT_NULL.getParameterName());
|
|
28
|
+
|
|
29
|
+
let len: number = context
|
|
30
|
+
?.getArguments()
|
|
31
|
+
?.get(IndexOf.PARAMETER_INT_FIND_FROM.getParameterName());
|
|
32
|
+
|
|
33
|
+
if (source.length == 0)
|
|
34
|
+
return new FunctionOutput([
|
|
35
|
+
EventResult.outputOf(new Map([[IndexOf.EVENT_RESULT_INTEGER.getName(), -1]])),
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
if (len < 0 || len > source.length)
|
|
39
|
+
throw new KIRuntimeException(
|
|
40
|
+
'The size of the search index of the array is greater than the size of the array',
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
let index: number = -1;
|
|
44
|
+
|
|
45
|
+
for (let i: number = len; i < source.length; i++) {
|
|
46
|
+
if (PrimitiveUtil.compare(source[i], find) == 0) {
|
|
47
|
+
index = i;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return new FunctionOutput([
|
|
53
|
+
EventResult.outputOf(new Map([[IndexOf.EVENT_RESULT_INTEGER.getName(), index]])),
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
2
|
+
import { EventResult } from '../../../model/EventResult';
|
|
3
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
5
|
+
import { PrimitiveUtil } from '../../../util/primitive/PrimitiveUtil';
|
|
6
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
7
|
+
|
|
8
|
+
export class IndexOfArray extends AbstractArrayFunction {
|
|
9
|
+
public constructor() {
|
|
10
|
+
super(
|
|
11
|
+
'IndexOfArray',
|
|
12
|
+
[
|
|
13
|
+
IndexOfArray.PARAMETER_ARRAY_SOURCE,
|
|
14
|
+
IndexOfArray.PARAMETER_ARRAY_SECOND_SOURCE,
|
|
15
|
+
IndexOfArray.PARAMETER_INT_FIND_FROM,
|
|
16
|
+
],
|
|
17
|
+
IndexOfArray.EVENT_RESULT_INTEGER,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
22
|
+
let source: any[] = context
|
|
23
|
+
?.getArguments()
|
|
24
|
+
?.get(IndexOfArray.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
25
|
+
|
|
26
|
+
let secondSource: any[] = context
|
|
27
|
+
?.getArguments()
|
|
28
|
+
?.get(IndexOfArray.PARAMETER_ARRAY_SECOND_SOURCE.getParameterName());
|
|
29
|
+
|
|
30
|
+
let from: number = context
|
|
31
|
+
?.getArguments()
|
|
32
|
+
?.get(IndexOfArray.PARAMETER_INT_FIND_FROM.getParameterName());
|
|
33
|
+
|
|
34
|
+
if (source.length == 0 || secondSource.length == 0)
|
|
35
|
+
return new FunctionOutput([
|
|
36
|
+
EventResult.outputOf(new Map([[IndexOfArray.EVENT_RESULT_INTEGER.getName(), -1]])),
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
if (from < 0 || from > source.length || source.length < secondSource.length)
|
|
40
|
+
throw new KIRuntimeException(
|
|
41
|
+
'Given from second source is more than the size of the source array',
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
let secondSourceSize: number = secondSource.length;
|
|
45
|
+
let index: number = -1;
|
|
46
|
+
|
|
47
|
+
for (let i: number = from; i < source.length; i++) {
|
|
48
|
+
let j: number = 0;
|
|
49
|
+
if (PrimitiveUtil.compare(source[i], secondSource[j]) == 0) {
|
|
50
|
+
while (j < secondSourceSize) {
|
|
51
|
+
if (PrimitiveUtil.compare(source[i + j], secondSource[j]) != 0) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
j++;
|
|
55
|
+
}
|
|
56
|
+
if (j == secondSourceSize) {
|
|
57
|
+
index = i;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return new FunctionOutput([
|
|
64
|
+
EventResult.outputOf(new Map([[IndexOfArray.EVENT_RESULT_INTEGER.getName(), index]])),
|
|
65
|
+
]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
2
|
+
import { EventResult } from '../../../model/EventResult';
|
|
3
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
5
|
+
import { isNullValue } from '../../../util/NullCheck';
|
|
6
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
7
|
+
|
|
8
|
+
export class Insert extends AbstractArrayFunction {
|
|
9
|
+
public constructor() {
|
|
10
|
+
super(
|
|
11
|
+
'Insert',
|
|
12
|
+
[Insert.PARAMETER_ARRAY_SOURCE, Insert.PARAMETER_INT_OFFSET, Insert.PARAMETER_ANY],
|
|
13
|
+
Insert.EVENT_RESULT_EMPTY,
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
18
|
+
let source: any[] = context
|
|
19
|
+
?.getArguments()
|
|
20
|
+
?.get(Insert.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
21
|
+
|
|
22
|
+
let offset: number = context
|
|
23
|
+
?.getArguments()
|
|
24
|
+
?.get(Insert.PARAMETER_INT_OFFSET.getParameterName());
|
|
25
|
+
|
|
26
|
+
var output = context?.getArguments()?.get(Insert.PARAMETER_ANY.getParameterName());
|
|
27
|
+
|
|
28
|
+
if (isNullValue(output) || isNullValue(offset) || offset > source.length)
|
|
29
|
+
throw new KIRuntimeException('Please valid resouces to insert at the correct location');
|
|
30
|
+
|
|
31
|
+
if (source.length == 0) {
|
|
32
|
+
if (offset == 0) source.push(output);
|
|
33
|
+
return new FunctionOutput([EventResult.outputOf(new Map([]))]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
source.push(output);
|
|
37
|
+
let len: number = source.length - 1;
|
|
38
|
+
offset++; // to insert at that point
|
|
39
|
+
|
|
40
|
+
while (len >= offset) {
|
|
41
|
+
let temp: any = source[len - 1];
|
|
42
|
+
source[len - 1] = source[len];
|
|
43
|
+
source[len--] = temp;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return new FunctionOutput([EventResult.outputOf(new Map([]))]);
|
|
47
|
+
}
|
|
48
|
+
}
|