Search code examples
javamvel

Dealing with collections in MVEL


I have the following field:

List<Map<String, Long>> vehicles;

where each map contains 2 pairs:

"id" -> N
"order" -> M

How can I find a map by id and extract the corresponsing order in MVEL?

In Java it looks like:

vehicles.stream().find(m -> m.get("id") == N).findAny().map(m -> m.get("order")).orElse(0);

Solution

  • It turns out one can iterate over list of maps, filter them and extract value in the following way:

    order: Number() from accumulate(
     Map(this["id"] == N, $ord: this["order"]) from vehicles, max($ord)
    )