<!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> </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> </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> </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> </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> </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> </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() > 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.)"
<manstis1@ford.com><BR>To: Rules Users List
<rules-users@lists.jboss.org><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> </DIV>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New">rule
chkobj<BR>when<BR><SPAN class=886131616-01112007> $o :
</SPAN>MyClass(<SPAN class=886131616-01112007> </SPAN>id == "1"<SPAN
class=886131616-01112007>, </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> //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>
$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> Shaz,<BR><BR> We strongly advise you
to move to 4.0.3, but this is not related to your problem. <BR>
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> []s<BR> Edson<BR><BR><BR>
<DIV><SPAN class=gmail_quote>2007/11/1, Shaz Tumulak <<A
href="mailto:shauii@yahoo.com" target=_blank rel=nofollow
ymailto="mailto:shauii@yahoo.com">shauii@yahoo.com</A>>:</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> String
id;<BR> String
name;<BR><BR> MyClass(String
id, String
name){<BR> <A
href="http://this.id" target=_blank rel=nofollow>this.id</A> =
id;<BR> <A
href="http://this.name" target=_blank rel=nofollow>this.name</A> =
name;<BR> }<BR> :<BR> getter,
setter methods
<BR> :<BR>}<BR><BR>MyClass
obj = new MyClass("1"", "name");<BR><BR>TreeMap<String, MyClass>
mapOfObj = new TreeMap<String,
MyClass>();<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> obj :
MyClass(mapOfObj["keyOfObj"].id ==
"1");<BR> eval(obj.getName()
== "name");<BR>________________________________________<BR><BR>I'm getting
this error:
org.drools.RuntimeDroolsException:<BR>java.lang.NullPointerException<BR> 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>><BR>> Denis,<BR>><BR>> If
you are using latest build from trunk (I'm not sure it already
works<BR>> in MR3), you can use a simplified MVEL
syntax:<BR>><BR>> when <BR>> Person(
address["business"].phone == "99999999" )<BR>>
then<BR>> ...<BR>>
end<BR>><BR>> Although, the above will be
converted into an inline-eval. Not as bad<BR>> as <BR>> a top level
eval, but still more costly then using regular
fields.<BR>><BR>> []s<BR>> Edson<BR>><BR>>
2007/7/19, Ryan, Dennis (Dennis) <<A href="mailto:dennisryan@avaya.com"
target=_blank rel=nofollow
ymailto="mailto:dennisryan@avaya.com">dennisryan@avaya.com
</A>>:<BR>>><BR>>> We are using Maps (HashMaps)
in our rules and the only way we have found<BR>>> to access keys and
values in the Map in the "when" clauses is thru use on<BR>>> eval()
which I know is a big no-no by rules purists. Is there a better
<BR>>> way,<BR>>> maybe some shorthand I'm not familiar with
to deal with Maps in the when<BR>>>
clause?<BR>>><BR>>><BR>>><BR>>>
Thanks,<BR>>><BR>>> Dennis<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>>><BR>>><BR>><BR>><BR>>
--<BR>> Edson Tirelli<BR>> Software Engineer
- JBoss Rules Core Developer<BR>> Office: +55 11 3529-6000
<BR>> Mobile: +55 11 9287-5646<BR>> JBoss, a
division of Red Hat @ <A href="http://www.jboss.com" target=_blank
rel=nofollow>www.jboss.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>>
<BR>><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> Edson Tirelli <BR> Software
Engineer - JBoss Rules Core Developer<BR> Office: +55 11
3529-6000<BR> Mobile: +55 11 9287-5646<BR> 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&sid=396545433">Find
out at Yahoo! Answers</A></FONT> </BLOCKQUOTE></BODY></HTML>