|
List Info
Thread: Casting an Object value in the LHS
|
|
| Casting an Object value in the LHS |
  United States |
2008-04-28 11:38:52 |
|
| Suppose I have a
"Measurement" class, with a getName() method that returns a String
and with a getValue() method that returns an Object. Sometimes the
Object is a String, sometimes a Integer, sometimes a Double. I know that a "Foo"
Measurement must be an integer, so I could cast (or otherwise coerce) into
a form that can be compared with a constant integer (or other
"Foo" Measurement).
How do I handle this
type of value in the LHS of the rule?
when
$m : Measurement(name == "Foo", value < 10)
then
System.out.println("It's less than ten!");
end
I'd also like to be
able to test for the Objects type (instanceof). I'm using java as my dialect, if
that makes a difference. For other reasons I'd like to avoid having
to either subclass Measurement or add type-specific value
accessors.
-Russ |
| Re: Casting an Object value in the LHS |

|
2008-04-29 04:16:24 |
|
You can use inline eval
$m : Measurement(
name == "Foo",
eval(value instanceof Number),
value < 10)
2008/4/28 < rrogers  us.imsheal th.com">rrogers us.imshealth.com>:
Suppose I have a
"Measurement" class, with a getName() method that returns a String
and with a getValue() method that returns an Object. Sometimes the
Object is a String, sometimes a Integer, sometimes a Double. I know that a "Foo"
Measurement must be an integer, so I could cast (or otherwise coerce) into
a form that can be compared with a constant integer (or other
"Foo" Measurement).
How do I handle this
type of value in the LHS of the rule?
when
$m : Measurement(name == "Foo", value < 10)
then
System.out.println("It's less than ten!");
end
I'd also like to be
able to test for the Objects type (instanceof). I'm using java as my dialect, if
that makes a difference. For other reasons I'd like to avoid having
to either subclass Measurement or add type-specific value
accessors.
-Russ
_______________________________________________
rules-users mailing list
rules-users lists.jboss.org">rules-users lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
|
[1-2]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|