<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<STYLE type=text/css>DIV {
        MARGIN: 0px
}
</STYLE>

<META content="MSHTML 6.00.2900.3132" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=448075808-02112007><FONT face=Arial 
color=#0000ff size=2>IMHO you should still think about putting the Map values 
into working memory.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=448075808-02112007><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=448075808-02112007><FONT face=Arial 
color=#0000ff size=2>This would both simplify your rules and make their 
execution faster (eval cannot be indexed, if I remember 
correctly).</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=448075808-02112007><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=448075808-02112007><FONT face=Arial 
color=#0000ff size=2>You might need to adapt your data model representation into 
one that is more efficient for use in a RETE network.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=448075808-02112007><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=448075808-02112007><FONT face=Arial 
color=#0000ff size=2>Can you explain your use case to help understand? Unless 
you have very good reason to keep the facts in the Map your life will be more 
difficult than it need be.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=448075808-02112007><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=448075808-02112007><FONT face=Arial 
color=#0000ff size=2>An "eval" returns a boolean indiciating whether the 
"pattern" matched and therefore, whilst you can reference other bound LHS facts, 
you cannot bind other objects to variables.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=448075808-02112007><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=448075808-02112007><FONT face=Arial 
color=#0000ff size=2>Thanks,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=448075808-02112007><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=448075808-02112007><FONT face=Arial 
color=#0000ff size=2>Mike</FONT></SPAN></DIV><BR>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
  <HR tabIndex=-1>
  <FONT face=Tahoma size=2><B>From:</B> rules-users-bounces@lists.jboss.org 
  [mailto:rules-users-bounces@lists.jboss.org] <B>On Behalf Of 
  </B>shaz<BR><B>Sent:</B> 02 November 2007 02:32<BR><B>To:</B> Rules Users 
  List<BR><B>Subject:</B> Re: [rules-users] Accessing maps (hashmaps) keys and 
  values in rules<BR></FONT><BR></DIV>
  <DIV></DIV>
  <DIV style="FONT-SIZE: 10pt; FONT-FAMILY: arial,helvetica,sans-serif">
  <DIV style="FONT-SIZE: 10pt; FONT-FAMILY: arial,helvetica,sans-serif">Hi, 
  <BR><BR>I am placing objects in the Hashmap that were retrieved from the 
  database. There are currently a hundred objects that I'm storing in the 
  HashMap. I just made a simple example earlier :) . What works for me now is 
  putting the getting of the values in the eval(). However, I don't know how to 
  assign the values that I've taken from the Map.<BR><BR>eval( ( 
  (MyClass)mapOfObj.get("keyOfObj")).getId() &gt; 30);<BR><BR>How do I assign 
  (MyClass)mapOfObj.get("keyOfObj") to a 
  variable?<BR><BR><BR>tnx,<BR><BR>shaz<BR><BR><BR>
  <DIV 
  style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman,new york,times,serif">----- 
  Original Message ----<BR>From: "Anstis, Michael (M.)" 
  &lt;manstis1@ford.com&gt;<BR>To: Rules Users List 
  &lt;rules-users@lists.jboss.org&gt;<BR>Sent: Friday, November 2, 2007 12:17:51 
  AM<BR>Subject: RE: [rules-users] Accessing maps (hashmaps) keys and values in 
  rules<BR><BR>
  <DIV dir=ltr align=left><SPAN class=886131616-01112007><FONT face=Arial 
  color=#0000ff size=2>By way of example (if you misunderstand how the rule 
  engine should be used):-</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN class=886131616-01112007><FONT face=Arial 
  color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
  <DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New">rule 
  chkobj<BR>when<BR><SPAN class=886131616-01112007>&nbsp;&nbsp;&nbsp; $o : 
  </SPAN>MyClass(<SPAN class=886131616-01112007> </SPAN>id == "1"<SPAN 
  class=886131616-01112007>,&nbsp;</SPAN><SPAN 
  class=886131616-01112007>n</SPAN>ame == "name"<SPAN class=886131616-01112007> 
  )</SPAN></FONT></FONT></FONT></DIV>
  <DIV><SPAN class=886131616-01112007></SPAN><SPAN 
  class=886131616-01112007></SPAN><FONT color=#0000ff size=2><FONT 
  face="Courier New">t<SPAN 
  class=886131616-01112007>hen</SPAN></FONT></FONT></DIV>
  <DIV><FONT size=+0><SPAN class=886131616-01112007></SPAN><FONT 
  color=#0000ff><FONT face="Courier New" size=2><SPAN 
  class=886131616-01112007>&nbsp;&nbsp;&nbsp; //Do something 
  else</SPAN></FONT></FONT></FONT></DIV>
  <DIV><FONT size=+0><FONT size=+0><SPAN class=886131616-01112007></SPAN><FONT 
  color=#0000ff><FONT face="Courier New" size=2><SPAN 
  class=886131616-01112007>&nbsp;&nbsp;&nbsp; 
  $o.doSomething();</SPAN></FONT></FONT></FONT></FONT></DIV>
  <DIV><FONT size=+0><FONT size=+0><FONT size=+0><FONT size=+0><FONT 
  size=+0><FONT size=+0><SPAN class=886131616-01112007></SPAN><SPAN 
  class=886131616-01112007></SPAN><FONT face="Courier New" color=#0000ff 
  size=2>e<SPAN 
  class=886131616-01112007>nd</SPAN></FONT></FONT></FONT></FONT></FONT></FONT></FONT></DIV><BR>
  <BLOCKQUOTE style="MARGIN-RIGHT: 0px">
    <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
    <HR tabIndex=-1>
    <FONT face=Tahoma size=2><B>From:</B> rules-users-bounces@lists.jboss.org 
    [mailto:rules-users-bounces@lists.jboss.org] <B>On Behalf Of </B>Edson 
    Tirelli<BR><B>Sent:</B> 01 November 2007 15:48<BR><B>To:</B> Rules Users 
    List<BR><B>Subject:</B> Re: [rules-users] Accessing maps (hashmaps) keys and 
    values in rules<BR></FONT><BR></DIV>
    <DIV></DIV><BR>&nbsp;&nbsp; Shaz,<BR><BR>&nbsp;&nbsp; We strongly advise you 
    to move to 4.0.3, but this is not related to your problem. <BR>&nbsp;&nbsp; 
    I think you are misunderstanding something. Why are you using the global map 
    to store your fact? Simply insert it into the working memory and it will 
    work fine. <BR><BR>&nbsp;&nbsp; []s<BR>&nbsp;&nbsp; Edson<BR><BR><BR>
    <DIV><SPAN class=gmail_quote>2007/11/1, Shaz Tumulak &lt;<A 
    href="mailto:shauii@yahoo.com" target=_blank rel=nofollow 
    ymailto="mailto:shauii@yahoo.com">shauii@yahoo.com</A>&gt;:</SPAN> 
    <BLOCKQUOTE class=gmail_quote 
    style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid"><BR>Hi,<BR><BR>I 
      can't seem to make this syntax work in Drools 4.0.2. Pls. see my 
      sample<BR>code below.<BR>________________________________________<BR>class 
      MyClass {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String 
      id;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String 
      name;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyClass(String 
      id, String 
      name){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://this.id" target=_blank rel=nofollow>this.id</A> = 
      id;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://this.name" target=_blank rel=nofollow>this.name</A> = 
      name;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getter, 
      setter methods 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<BR>}<BR><BR>MyClass 
      obj = new MyClass("1"", "name");<BR><BR>TreeMap&lt;String, MyClass&gt; 
      mapOfObj = new TreeMap&lt;String, 
      MyClass&gt;();<BR>mapOfObj.put("keyOfObj", obj); 
      <BR>________________________________________<BR><BR>DRL 
      file<BR>-------<BR><BR>global java.util.TreeMap mapOfObj;<BR><BR>rule 
      chkobj<BR>when<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;obj : 
      MyClass(mapOfObj["keyOfObj"].id == 
      "1");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eval(obj.getName() 
      == "name");<BR>________________________________________<BR><BR>I'm getting 
      this error: 
      org.drools.RuntimeDroolsException:<BR>java.lang.NullPointerException<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at 
      <BR>org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:76)<BR><BR>Is 
      my syntax correct and has someone used this in 4.0.2 or should I move 
      on<BR>to Drools 4.0.3? Thanks in 
      advance.<BR><BR>Regards,<BR><BR>shaz<BR><BR><BR>Edson Tirelli-3 
      wrote:<BR>&gt;<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;Denis,<BR>&gt;<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;If 
      you are using latest build from trunk (I'm not sure it already 
      works<BR>&gt; in MR3), you can use a simplified MVEL 
      syntax:<BR>&gt;<BR>&gt; when <BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Person( 
      address["business"].phone == "99999999" )<BR>&gt; 
      then<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; ...<BR>&gt; 
      end<BR>&gt;<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;Although, the above will be 
      converted into an inline-eval. Not as bad<BR>&gt; as <BR>&gt; a top level 
      eval, but still more costly then using regular 
      fields.<BR>&gt;<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;[]s<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;Edson<BR>&gt;<BR>&gt; 
      2007/7/19, Ryan, Dennis (Dennis) &lt;<A href="mailto:dennisryan@avaya.com" 
      target=_blank rel=nofollow 
      ymailto="mailto:dennisryan@avaya.com">dennisryan@avaya.com 
      </A>&gt;:<BR>&gt;&gt;<BR>&gt;&gt;&nbsp;&nbsp;We are using Maps (HashMaps) 
      in our rules and the only way we have found<BR>&gt;&gt; to access keys and 
      values in the Map in the "when" clauses is thru use on<BR>&gt;&gt; eval() 
      which I know is a big no-no by rules purists. Is there a better 
      <BR>&gt;&gt; way,<BR>&gt;&gt; maybe some shorthand I'm not familiar with 
      to deal with Maps in the when<BR>&gt;&gt; 
      clause?<BR>&gt;&gt;<BR>&gt;&gt;<BR>&gt;&gt;<BR>&gt;&gt; 
      Thanks,<BR>&gt;&gt;<BR>&gt;&gt; Dennis<BR>&gt;&gt; <BR>&gt;&gt; 
      _______________________________________________<BR>&gt;&gt; rules-users 
      mailing list<BR>&gt;&gt; <A href="mailto:rules-users@lists.jboss.org" 
      target=_blank rel=nofollow 
      ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR>&gt;&gt; 
      <A href="https://lists.jboss.org/mailman/listinfo/rules-users" 
      target=_blank 
      rel=nofollow>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR>&gt;&gt;<BR>&gt;&gt;<BR>&gt;<BR>&gt;<BR>&gt; 
      --<BR>&gt;&nbsp;&nbsp; Edson Tirelli<BR>&gt;&nbsp;&nbsp; Software Engineer 
      - JBoss Rules Core Developer<BR>&gt;&nbsp;&nbsp; Office: +55 11 3529-6000 
      <BR>&gt;&nbsp;&nbsp; Mobile: +55 11 9287-5646<BR>&gt;&nbsp;&nbsp; JBoss, a 
      division of Red Hat @ <A href="http://www.jboss.com" target=_blank 
      rel=nofollow>www.jboss.com</A><BR>&gt;<BR>&gt; 
      _______________________________________________<BR>&gt; rules-users 
      mailing list <BR>&gt; <A href="mailto:rules-users@lists.jboss.org" 
      target=_blank rel=nofollow 
      ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR>&gt; 
      <A href="https://lists.jboss.org/mailman/listinfo/rules-users" 
      target=_blank 
      rel=nofollow>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR>&gt; 
      <BR>&gt;<BR><A href="mailto:shauii@yahoo.com" target=_blank rel=nofollow 
      ymailto="mailto:shauii@yahoo.com">shauii@yahoo.com</A><BR>--<BR>View this 
      message in context: <A 
      href="http://www.nabble.com/Accessing-maps-%28hashmaps%29-keys-and-values-in-rules-tf4112197.html#a13524477" 
      target=_blank 
      rel=nofollow>http://www.nabble.com/Accessing-maps-%28hashmaps%29-keys-and-values-in-rules-tf4112197.html#a13524477 
      </A><BR>Sent from the drools - user mailing list archive at <A 
      href="http://Nabble.com" target=_blank 
      rel=nofollow>Nabble.com</A>.<BR><BR>_______________________________________________<BR>rules-users 
      mailing list<BR><A href="mailto:rules-users@lists.jboss.org" target=_blank 
      rel=nofollow 
      ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR><A 
      href="https://lists.jboss.org/mailman/listinfo/rules-users" target=_blank 
      rel=nofollow>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR></BLOCKQUOTE></DIV><BR><BR 
    clear=all><BR>-- <BR>&nbsp;&nbsp;Edson Tirelli <BR>&nbsp;&nbsp;Software 
    Engineer - JBoss Rules Core Developer<BR>&nbsp;&nbsp;Office: +55 11 
    3529-6000<BR>&nbsp;&nbsp;Mobile: +55 11 9287-5646<BR>&nbsp;&nbsp;JBoss, a 
    division of Red Hat @ <A href="http://www.jboss.com" target=_blank 
    rel=nofollow>www.jboss.com</A> </BLOCKQUOTE></DIV><BR></DIV></DIV><BR>
  <HR SIZE=1>
  <FONT face=Arial size=-1>Platonic friends of the opposite sex - the real 
  deal?<BR>Be a better buddy<BR><A 
  href="http://ph.answers.yahoo.com/dir/index;_ylt=AsCq4OcgSoQ9qZZdke2cnGhL5Qt.;_ylv=3?link=over&amp;sid=396545433">Find 
  out at Yahoo! Answers</A></FONT> </BLOCKQUOTE></BODY></HTML>