[rules-users] Question about Object.equals and modifyRetract/Insert
Edson Tirelli
tirelli at post.com
Mon Oct 13 18:23:55 EDT 2008
It is fine to do that.
2008/10/13 Michal Bali <michalbali at gmail.com>
> Hello,
>
> Let's say we have a simple BeanA with one property that is part of
> equal/hashCode method e.g.:
> ----------------------------------------
> public class BeanA {
> int someProperty;
>
> public int getSomeProperty() {
> return someProperty;
> }
> public void setSomeProperty(int someProperty) {
> this.someProperty = someProperty;
> }
>
> @Override
> public boolean equals(final Object other) {
> if (this == other)
> return true;
> if (!(other instanceof BeanA))
> return false;
> BeanA castOther = (BeanA) other;
> return new EqualsBuilder().append(someProperty,
> castOther.someProperty).isEquals();
> }
>
> @Override
> public int hashCode() {
> return new HashCodeBuilder(228431015, 1383549405).append(
> someProperty).toHashCode();
> }
> }
> ------------------------------------
> This bean is inserted into the working memory. Is it something wrong with
> doing?:
> wm.modifyRetract(beanA);
> beanA.setSomeProperty(22); //this is changing the object equality key
> wm.modifyInsert(beanAHandle, beanA);
>
> I know that simple update is not allowed:
> beanA.SetSomeProperty(22);
> update(beanAHandle, beanA); //this is wrong
>
> I guess there is no difference if this code is outside the rule engine or
> inside (e.g. in a rule consequence).
>
> Thank you,
> Best Regards,
> Michal
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
--
Edson Tirelli
JBoss Drools Core Development
JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20081013/7aa742cf/attachment.html
More information about the rules-users
mailing list