Skip to content

Computing Functions IntoCollection

anymaker edited this page Apr 3, 2021 · 2 revisions

This functions working into collection for each row.

Distinct Return true if this row is encountered for the first time
First Return true is current row is first
Last Return true is current row is last
MaxInRows Detect max value in path by all rows
RowNum Return number of current row in collection. Starting from 0.
RowsCount Return the number of rows in this collection

Distinct

Return true if this row is encountered for the first time.

Incoming parameters

no parameters

Output

if this row is first, type : boolean

Examples

List<String> list = new ArrayList<>();
list.add("one");
list.add("one");
list.add(null);
list.add("two");
list.add("two");
list.add("three");

List result = engine.calc("  .(distinct)  ", list, List.class);
assertEquals(4, result.size());
assertEquals("[one, null, two, three]", result.toString());

First

Return true is current row is first.

Incoming parameters

no parameters

Output

row is first, type : boolean

Examples

List<String> list = new ArrayList<>();
list.add("one");
list.add(null);
list.add("two");
list.add("three");

String result = engine.calc(".(first)", list, String.class);
assertEquals("one", result);));

Last

Return true is current row is last.

Incoming parameters

no parameters

Output

row is last, type : boolean

Examples

List<String> list = new ArrayList<>();
list.add("one");
list.add(null);
list.add("two");
list.add("three");

String result = engine.calc(".(last)", list, String.class);
assertEquals("three", result);

MaxInRows

Determine the max value in the path across all rows.
Unlike the similar function "max", this function looks for the largest value in all rows processed by the filter.

Incoming parameters

path path to find value

Output

Maximum value, type : Object

Examples

List<Object> list = new ArrayList<>();

Map<String, Object> map = new HashMap<>();
map.put("name", "AAA");
map.put("value", 1);
list.add(map);

map = new HashMap<>();
map.put("name", "BBB");
map.put("value", 2);
list.add(map);

map = new HashMap<>();
map.put("name", "CCC");
map.put("value", 5);
list.add(map);

map = new HashMap<>();
map.put("name", "DDD");
map.put("value", 3);
list.add(map);

String result = engine.calc("   .(.value = maxInRows(.value)).name   ", list, String.class);
assertEquals("CCC", result);

RowNum

Return number of current row in collection. Starting from 0.

Incoming parameters

no parameters

Output

row number, type : int

Examples

List<String> list = new ArrayList<>();
list.add("one");
list.add(null);
list.add("two");
list.add("three");

String result = engine.calc("   .(rownum = 3)   ", list, String.class);
assertEquals("three", result);

RowsCount

Return the number of rows in this collection

Incoming parameters

no parameters

Output

rows count, type : int

Examples

List<String> list = new ArrayList<>();
list.add("one");
list.add(null);
list.add("two");
list.add("three");

String result = engine.calc("   .(rownum = rowscount-2)   ", list, String.class);
assertEquals("two", result);
Clone this wiki locally