maximum of list

271 views
Skip to first unread message

vijay yadav

unread,
Aug 23, 2017, 2:14:09 AM8/23/17
to Drools Usage
I have a field of type list

private java.util.list<java.lang.Double> income

How can I get max of this list using guided rule?

Collections.max(income) is not working.
can it be done using from accumulate?


Regards
Vijay

José Filipe Neis

unread,
Aug 24, 2017, 8:53:56 AM8/24/17
to Drools Usage

vijay yadav

unread,
Aug 28, 2017, 3:18:00 AM8/28/17
to Drools Usage
None of these are working.
I have a class named "Test" which contains this list type object. Now I need to get the maximum of this list.
I think Accumulate iterates over all the objects and return max of all of these objects. but I have only one object with a field of type list and I need to get max of this.

José Filipe Neis

unread,
Aug 28, 2017, 9:37:59 AM8/28/17
to Drools Usage
Do you need max on LHS or RHS of the rule?

--
You received this message because you are subscribed to a topic in the Google Groups "Drools Usage" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/drools-usage/MOIMOXCbczc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/7cae8520-5e78-4b93-8030-bae3440458c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vijay yadav

unread,
Aug 29, 2017, 1:24:55 AM8/29/17
to Drools Usage
Would you please tell me how can I do it in LHS?


On Wednesday, August 23, 2017 at 11:44:09 AM UTC+5:30, vijay yadav wrote:

José Filipe Neis

unread,
Aug 29, 2017, 8:34:41 AM8/29/17
to Drools Usage
Vljay,

Writing the rules will follow the same kind of pattern you used in your example, but remember that now you have a List. What does this influence? That Drools will match your objects if they are equals (and list.equals(list) is not a trivial thing to match).

If I would give you any advice right now is: avoid using a List as a session object, but I really don't know your business requirements as you didn't talk about them at all so far.

Anyway, to write a rule that matches a property a list inside another object, you can use contains/memberof or a condition like the one exposed on this SO question:

rule "some rule name"
when
$a
: A($bset : bset)
$b
: B(x == "hello") from $bset
then
//you will have one activation for each of the B objects matching //the second pattern end

In this example I understand that A would be your test class and bset/B your list type.

Filipe

José Filipe Neis

unread,
Aug 29, 2017, 8:40:08 AM8/29/17
to Drools Usage
Sorry, I answered your question thinking about another question in the group. No contains/memberof applies to your case.

What you need to do is something like a showed, but use a accumulate function then:

rule "some rule name"
when
$a
: A($bset : bset)
accumulate(
$b: B from $bset;
...
)

then
Reply all
Reply to author
Forward
0 new messages