One other thing, something that most "old timers" even forget.  :-)  If you re-write equals for a class that already exists or one that you inherit then you have to re-write the hash map table.  There are some examples in Bruce Eckles book.  I've forgotten the title and someone "borrowed" my copy, but it's available at most book stores and, to my knowledge, is one of the FEW books in Java where you can actually find an example and explanation of rewriting equals and hash map.  (Actually, I think, it's the Hashtable, not the Hashmap - although things may have changed with the newer versions of Java Collections.  :-)

SDG
jco

Jason Morris wrote:
I think that Camillo wrote:
  
How I use "eq" to compare generic objects?
      

Well, first off a bit of listserv etiquette... let's not do an end-run
around Ernest here.  So if you have a question personally for me, then send
it to me at my address below.  But every day that Ernest has to answer FAQs
is one day that I don't get to play with Charlemagne (Jess 7.0), so whatever
I can do (humbly) to help I will.  :-D

Seriously, this is more of a Java question.  Let me quote now from the Jess
function link for "eq"
http://herzberg.ca.sandia.gov/jess/docs/61/function_index.html

"...Uses the Java Object.equals() function, so can be redefined for external
types. "

There's your answer.  You have to roll your own.

When you write Java classes that will be compared at some point, it is
standard practice to override the equals() method to suit your need.  Again,
quoting from "Practical Java" by Peter Haggar, "...An equals method should
be provided by a class if equality of an object of that class requires more
than a comparison of its object reference."

Hope that helps.
Cheers,

-Jason
------------------------

Jason Morris
Morris Technical Solutions
[EMAIL PROTECTED]
www.morristechnicalsolutions.com
fax/phone: 503.692.1088



  
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Camillo
Sent: Tuesday, August 03, 2004 8:06 AM
To: [EMAIL PROTECTED]
Subject: R: JESS: new to jess


Hi Jason,
I'm also a new to using jess and I have a trouble... You say to use "eq"
to compare objects,symbols and references. I have this problem:

(defrule myRule (myPattern (mySlot slotValue))=>...)

where slotValue isn't a primitive type but a generic java object bounded
to jess variable

How I use "eq" to compare generic objects?

I have used this:

(defrule myRule (myPattern (myslot ?slotValue&:(eq (call ?slotValue
getValue) myPrimitiveValue)))=>...)

but don't works and I think is incorrect however. Can you help me?
Thanks

Camillo

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED].
--------------------------------------------------------------------

    

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED].
--------------------------------------------------------------------

  




Reply via email to