Using from

View: New views
4 Messages — Rating Filter:   Alert me  

Using from

by Aziz Boxwala :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
I have the following class structure.

Class GrandFather {
  List<Father> fathers;
  public List<Father> getFathers() {return fathers;}
}

Class Father {
   int age;
  List<Son> sons;
  public int getAge() {return age;}
  public List<Son> getSons() {return sons;}
}

Class Son {
 int age;
  public int getAge() {return age;}
}

I'd like to write a rule that finds all the Fathers who have age > 45 and have Sons where the son's age is greater than 5. But I can't figure out how to use "from" to iterate over father first and then over son.

Any help will be greatly appreciated.

Thanks,
--Aziz



_______________________________________________
rules-users mailing list
rules-users@...
https://lists.jboss.org/mailman/listinfo/rules-users

Re: Using from

by Marcus Ilgner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Aziz,

On Thu, Jul 17, 2008 at 8:26 PM, Aziz Boxwala <boxwala@...> wrote:

> I have the following class structure.
>
> Class GrandFather {
>   List<Father> fathers;
>   public List<Father> getFathers() {return fathers;}
> }
>
> Class Father {
>    int age;
>   List<Son> sons;
>   public int getAge() {return age;}
>   public List<Son> getSons() {return sons;}
> }
>
> Class Son {
>  int age;
>   public int getAge() {return age;}
> }
>
> I'd like to write a rule that finds all the Fathers who have age > 45 and
> have Sons where the son's age is greater than 5. But I can't figure out how
> to use "from" to iterate over father first and then over son.
>
> Any help will be greatly appreciated.
>
> Thanks,
> --Aziz

Something like this?

rule "FatherAndSon
when
  $father : Father(age > 45)
  $son : Son(age > 5) from $father.sons
then
// do something
end

Best regards
Marcus
_______________________________________________
rules-users mailing list
rules-users@...
https://lists.jboss.org/mailman/listinfo/rules-users

Re: Using from

by Edson Tirelli-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


   Hey Aziz,

  Try like this:

when
    $f : Father( age > 45 )
    exists( Son( age > 5 ) from $f.sons )
then
   // $f is older than 45 and has at least one son older than 5
end

   Happy drooling,

   []s
   Edson


2008/7/17 Aziz Boxwala <boxwala@...>:
I have the following class structure.

Class GrandFather {
  List<Father> fathers;
  public List<Father> getFathers() {return fathers;}
}

Class Father {
   int age;
  List<Son> sons;
  public int getAge() {return age;}
  public List<Son> getSons() {return sons;}
}

Class Son {
 int age;
  public int getAge() {return age;}
}

I'd like to write a rule that finds all the Fathers who have age > 45 and have Sons where the son's age is greater than 5. But I can't figure out how to use "from" to iterate over father first and then over son.

Any help will be greatly appreciated.

Thanks,
--Aziz



_______________________________________________
rules-users mailing list
rules-users@...
https://lists.jboss.org/mailman/listinfo/rules-users




--
Edson Tirelli
JBoss Drools Core Development
JBoss, a division of Red Hat @ www.jboss.com

_______________________________________________
rules-users mailing list
rules-users@...
https://lists.jboss.org/mailman/listinfo/rules-users

Parent Message unknown Re: Using from

by Aziz Boxwala :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Marcus,

Thank you very much. I am trying that out.

--Aziz

----- Original Message ----
From: Marcus Ilgner <marcus.ilgner@...>
To: Rules Users List <rules-users@...>
Sent: Thursday, July 17, 2008 2:35:55 PM
Subject: Re: [rules-users] Using from

Hi Aziz,

On Thu, Jul 17, 2008 at 8:26 PM, Aziz Boxwala <boxwala@...> wrote:

> I have the following class structure.
>
> Class GrandFather {
>  List<Father> fathers;
>  public List<Father> getFathers() {return fathers;}
> }
>
> Class Father {
>    int age;
>  List<Son> sons;
>  public int getAge() {return age;}
>  public List<Son> getSons() {return sons;}
> }
>
> Class Son {
>  int age;
>  public int getAge() {return age;}
> }
>
> I'd like to write a rule that finds all the Fathers who have age > 45 and
> have Sons where the son's age is greater than 5. But I can't figure out how
> to use "from" to iterate over father first and then over son.
>
> Any help will be greatly appreciated.
>
> Thanks,
> --Aziz

Something like this?

rule "FatherAndSon
when
  $father : Father(age > 45)
  $son : Son(age > 5) from $father.sons
then
// do something
end

Best regards
Marcus
_______________________________________________
rules-users mailing list
rules-users@...
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
rules-users@...
https://lists.jboss.org/mailman/listinfo/rules-users
LightInTheBox - Buy quality products at wholesale price