-
Notifications
You must be signed in to change notification settings - Fork 0
Computing Functions ForCollections
These functions take a collection as a parameter and perform some calculations by it.
Count | Calc count not null values in path |
Max | Detect max value |
Min | Detect minimal value |
SubList | Returning a subarray from an incoming array |
TrimTo | Removes all values from the array, starting from the beginning and ending with the given value |
TrimAfter | Removes all values from the array from the given value `lastValue` to the end |
Calc count not null values in a path or collection.
collection
path or collection where required to count the number of rows
Count of rows, type : int
count(null) -> 0
count(2) -> 1
count((1,1,1)) -> 3
List<String> list = new ArrayList<>();
list.add("one");
list.add("two");
list.add(null);
list.add("three");
int cnt = (int) engine.calc("count(.)", list);
assertEquals(3, cnt);
Detect max value.
collection
path or collection where required to find the max value or several values, among which you need to find the max value.
max value
max(null) -> null
max(1) -> 1
max(1,2) -> 2
max((1,2)) -> 2
LList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
Object max = engine.calc("max(.)", list);
assertEquals(2, max);
Detect minimal value
collection
path or collection where required to find the minimal value or several values, among which you need to find the max value.
max value
min(null) -> null
min(1) -> 1
min(1,2) -> 1
min((2,1)) -> 1
LList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
Object min= engine.calc("min(.)", list);
assertEquals(1, min);
Returning a subarray from an incoming array.
Subarray, starts with indexFrom
and ends with indexTo
.
By default indexFrom
and indexTo
are included in the subarray
subList(collection, indexFrom, indexTo)
subList(collection, indexFrom, indexTo, includeFirstValue)
subList(collection, indexFrom, indexTo, includeFirstValue, includeLastValue)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
collection | List | Yes | Incoming collection | |
indexFrom | int | Yes | The starting index in array which the subarray will be taken. If it less than zero, then it will be counted from the end of the array. | |
indexTo | String | Yes | The ending index in the array from which the subarray will be taken. If it is less than zero, then it will be counted from the end of the array. |
|
includeFirstValue | boolean | No | Include first value to subarray | true |
includeLastValue | boolean | No | Include last value to subarray | true |
Type: java.util.List
Subarray.
assertEquals("[2, 3, 4]", engine.calc(new Formula("subList( (1,2,3,4,5), 1, 3 )")).toString());
assertEquals("[1, 2, 3, 4, 5]", engine.calc(new Formula("subList( (1,2,3,4,5), 0, 4 )")).toString());
assertEquals("[5]", engine.calc(new Formula("subList( (1,2,3,4,5), 100, 4 )")).toString());
assertEquals("[2, 3, 4, 5]", engine.calc(new Formula("subList( (1,2,3,4,5), -3, 4 )")).toString());
assertEquals("[1, 2, 3, 4, 5]", engine.calc(new Formula("subList( (1,2,3,4,5), -100, 4 )")).toString());
assertEquals("[2, 3, 4, 5]", engine.calc(new Formula("subList( (1,2,3,4,5), 1, 40 )")).toString());
assertEquals("[1, 2]", engine.calc(new Formula("subList( (1,2,3,4,5), 1, 0 )")).toString());
assertEquals("[2, 3, 4]", engine.calc(new Formula("subList( (1,2,3,4,5), 1, -1 )")).toString());
assertEquals("[1, 2]", engine.calc(new Formula("subList( (1,2,3,4,5), 1, -100)")).toString());
assertEquals("[]", engine.calc(new Formula("subList( null, 1, 3 )")).toString());
assertEquals("[]", engine.calc(new Formula("subList( toList(), 1, 3 )")).toString());
assertEquals("[]", engine.calc(new Formula("subList( (1,2,3,4,5), 100, 100)")).toString());
Removes all values from the array, starting from the beginning and ending with the given value firstValue
.
The optional leaveFirstValue
parameter allows you to leave the specified value firstValue
in the array.
By default, it is true
.
trimTo(collection, firstValue)
trimTo(collection, firstValue, leaveFirstValue)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
collection | List | Yes | Incoming collection | |
firstValue | Object | Yes | Value as border to trim. | |
leaveFirstValue | boolean | No | Leave the specified value in the array | true |
Type: java.util.List
Trimmed array.
assertEquals("[3, 4, 5]", engine.calc(new Formula("trimTo( (1,2,3,4,5), 3 )")).toString());
assertEquals("[4, 5]", engine.calc(new Formula("trimTo( (1,2,3,4,5), 3, false)")).toString());
assertEquals("[]", engine.calc(new Formula("trimTo( (1,2,3,4,5), 6 )")).toString());
assertEquals("[1, 2, 3, 4, 5]", engine.calc(new Formula("trimTo( (1,2,3,4,5), 1 )")).toString());
assertEquals("[5]", engine.calc(new Formula("trimTo( (1,2,3,4,5), 5 )")).toString());
assertEquals("[]", engine.calc(new Formula("trimTo( (1,2,3,4,5), 5, false)")).toString());
assertEquals("[]", engine.calc(new Formula("trimTo( (1,2,3,4,5), null )")).toString());
assertEquals("[]", engine.calc(new Formula("trimTo( null, 5 )")).toString());
Removes all values from the array from the given value lastValue
to the end.
The optional leaveLastValue
parameter allows you to leave the specified value lastValue
in the array.
By default, it is true
.
trimAfter(collection, lastValue)
trimAfter(collection, lastValue, leaveLastValue)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
collection | List | Yes | Incoming collection | |
lastValue | Object | Yes | Value as border to trim. | |
leaveLastValue | boolean | No | Leave the specified value in the array | true |
Type: java.util.List
Trimmed array.
assertEquals("[1, 2, 3]", engine.calc(new Formula("trimAfter( (1,2,3,4,5), 3 )")).toString());
assertEquals("[1, 2]", engine.calc(new Formula("trimAfter( (1,2,3,4,5), 3, false)")).toString());
assertEquals("[]", engine.calc(new Formula("trimAfter( (1,2,3,4,5), 6 )")).toString());
assertEquals("[]", engine.calc(new Formula("trimAfter( (1,2,3,4,5), 6, false)")).toString());
assertEquals("[1]", engine.calc(new Formula("trimAfter( (1,2,3,4,5), 1 )")).toString());
assertEquals("[]", engine.calc(new Formula("trimAfter( (1,2,3,4,5), 1, false)")).toString());
assertEquals("[1, 2, 3, 4, 5]", engine.calc(new Formula("trimAfter( (1,2,3,4,5), 5 )")).toString());
assertEquals("[1, 2, 3, 4]", engine.calc(new Formula("trimAfter( (1,2,3,4,5), 5, false)")).toString());
assertEquals("[]", engine.calc(new Formula("trimAfter( (1,2,3,4,5), null )")).toString());
assertEquals("[]", engine.calc(new Formula("trimAfter( null, 5 )")).toString());
- Home
- Extendable Query Language
- Computing
- Simple Usage
- Own Value Extraction
- Functions
- What is Type
- Known Types
- Add Own Type
- Data conversion
- Generate SQL Query
- Find files