[rules-users] check list size

Michael Anstis michael.anstis at gmail.com
Mon Jul 14 07:28:51 EDT 2014


I had a look, but was able to use a List without problem (6.1.CR2):

1) Made a Maven-ized JAR containing the following class:

package org.anstis;

import java.util.List;

public class MyListClass {

    private List myList;

    public List getMyList() {
        return myList;
    }

    public void setMyList( List myList ) {
        this.myList = myList;
    }
}

2) Uploaded JAR to the workbench's Artifact Repository

3) Added a project dependency on this artifact

4) Added an Import Suggestion for java.util.List

5) Created a new Guided Rule

6) Imported MyListClass and java.util.List (Config tab)

7) Created the following rule:

package org.mortgages;

import java.lang.Number;
import java.util.List;
import org.anstis.MyListClass;

rule "r1"
  dialect "mvel"
when
  MyListClass( myList.size() < 5 )
then
end

You need to use an "Expression" to use the "size()" method call (as it is
not a field, but a method call). Fields are "getXXX" or "setYYY" or public
members.

With kind regards,

Mike

On 11 July 2014 15:14, Sumit Dhaniya <sumitdhaniya at gmail.com> wrote:

> I have a class which contains some lists, I want to apply rules on size of
> list and want to use functions like first(), last() but list objects which
> are in my class are identified as collections and only collection related
> functions are shown.
>
> For eg.
>
> class A {
> java.util.List bList = new ArrayList();
> }
>
> now it shows bList as collection type and it doesn't shows size and related
> list function instead shows collection functions like contains etc.
>
> Can't I use it like both a collection as well as List?
>
> I tried importing java.util.List but it still don't recognize my List
> objects as List
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/check-list-size-tp4030303.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20140714/061c0f00/attachment-0001.html 


More information about the rules-users mailing list