Hi Erich,

First, let me mention that I'm happy to see someone using the
brand-new "static imports" feature -- the thing that lets you use
(CarClass.MINI) as a constant.

Second, your code looks fine except that the defclass defines a short
template tag RentalCarReservation, but the rules are using the long
com.... form; I'll assume this is a transcription error, because the
rules won't compile unless you're consistent here.

Third, let me mention, as I often do on this list (I really need to
make this point more strongly in the manual) that direct matching
should always be preferred to function calls, and anything else should
be preferred to the "test" CE; this is not only a style issue but a
performance issue. Although your rules are both correct, it's better
style and will perform better to write them as

(defrule car_class_is_compact
    
    (RentalCarReservation (carClass ~=(CarClass.COMPACT)))
    =>
    (printout t "Car Class is not COMPACT" crlf)
    )

(defrule one_hundred_miles
    
    (RentalCarReservation (freeMiles 100))
    =>
    (printout t "100 free miles" crlf)
    )

Finally, I can't say for sure what the problem is, but I'll guess
(since you've mentioned equals()) that you've written a class whose
hashCode() is not consistent with its equals() method (perhaps simply
by  not overriding hashCode().) Jess is rather sensitive to this
error, as are many of the java.util container classes.

I think erich.oliphant wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> 
> 
> Hi I am a new jess user and I'm running into a problem trying to match an java
> object value in a rule.  Here are 2 rules and their setup, the first is the
> one with the problem.  The other I added to verify that it would match on a
> primitive type and it seems to work fine:
> (import CarClass)
> 
> (defclass RentalCarReservation 
>      RentalCarReservation nil)
> (bind ?tmpRentalCarRes (new RentalCarReservation))
> (definstance  RentalCarReservation 
>     ?tmpRentalCarRes
>     static)
> (call ?tmpRentalCarRes setCarClass (CarClass.MINI))
> (call ?tmpRentalCarRes setFreeMiles 100)
> (reset)
> 
> (facts)
> 
> 
> (defrule car_class_is_compact
>     
>     (com.ngc.dts.domain.reservation.car.RentalCarReservation (carClass ?x))
>     (test (neq ?x (CarClass.COMPACT)))
>     =>
>     (printout t "Car Class is not COMPACT" crlf)
>     )
> 
> (defrule one_hundred_miles
>     
>     (com.ngc.dts.domain.reservation.car.RentalCarReservation (freeMiles ?x))
>     (test (eq ?x 100))
>     =>
>     (printout t "100 free miles" crlf)
>     )
> 
> --
> 
> CarClass is an enum type i.e.:
> 
> class CarClass
> {
> ...
>    static public MINI = new CarClass("MINI");
> ...
> }
> 
> --
> 
> equals() has been overridden in CarClass as well.  The one_hundred_miles rule
> works fine so I know there's a specific problem using the object.  Any help
> would be greatly appreciated.
> 
> --------------------------------------------------------------------
> 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]
> --------------------------------------------------------------------
> 



---------------------------------------------------------
Ernest Friedman-Hill  
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550         http://herzberg.ca.sandia.gov

--------------------------------------------------------------------
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