[rules-users] How to write constraint about a Map inside a Map?

Yang Song starsy at gmail.com
Tue Jul 24 23:54:47 EDT 2007


Hi, Felipe,

Try this:

     $mf: MyFact( $map : map  )
     eval($map.get("innerKey") == "innerValue");

or you can have a try on the new MVEL diaglect.

Yang


On 7/25/07, Felipe Piccolini <felipe.piccolini at bluesoft.cl> wrote:
>
> Suppouse I have a Map attribute and one of the values is another Map...how
> can I check a member of the inner Map?
>
> class MyFact{
>      Map map;
>      public MyFact(){
>            this.map = new HashMap();
>      }
>
>
>      ....setter and getter...
>
>
> }
>
>
> -- test --
> MyFact myFact = new MyFact();
>
>
> Map innerMap = new HashMap();
> innerMap.put("innerKey", new String("InnerValue"));
>
>
> Map map = new HashMap();
> map.put("mapKey", innerMap);
>
>
> myFact.setMap(map);
>
>
> .... set the RuleBase and insert myFact as a fact for the WorkingMemory...
>
>
> -------
>
>
> Now... how should I write the rule to check the innerKey ??
>
>
> rule "test InnerMap"
>      when
>            $mf: MyFact( map['mapKey']['innerKey'] == "InnerValue" ) //
> doesnt work...
>     ....
>
>
>            $mf: MyFact( map['mapKey'].this['innerKey'] == "InnerValue" )
> // doesnt work...
>    $mf: MyFact( map['mapKey'].['innerKey'] == "InnerValue" ) // doesnt
> work...
>    $mf: MyFact( $innerMap: map['mapKey'], $innerMap['innerKey'] ==
> "InnerValue" ) // doesnt work...
>            $mf: MyFact( $innerMap: map['mapKey'] -> ($innerMap['innerKey']
> == "InnerValue" )) // doesnt work...
>
>
>
>
> Thanks.
>
> *Felipe Piccolini M.*
> felipe.piccolini at bluesoft.cl
>
>
>
>
>
>
>
>
> _______________________________________________
> 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/20070725/a80b0220/attachment.html 


More information about the rules-users mailing list