jadex.rules.state.javaimpl.OAVObjectModifiedEvent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-rules Show documentation
Show all versions of jadex-rules Show documentation
Jadex Rules is a small lightweight rule engine, which currently
employs the well-known Rete algorithm for highly efficient rule
matching. Jadex rules is therefore similar to other rule engines
like JESS and Drools. Despite the similarities there are also
important differences between these systems:
* Jadex Rules is very small and
intended to be used as component
of other software. Even though rules can be specified in a Java
dialect as well as (a small variation of) the CLIPS language
its primary usage is on the API level. Jadex Rules is currently
the core component of the Jadex BDI reasoning engine.
* Jadex Rules cleanly separates between state and rule representation.
This allows the state implementation as well as the matcher to be
flexibly exchanged. Some experiments have e.g. been conducted with
a Jena representation. Regarding the matcher, it is planned to
support also the Treat algorithm, which has a lower memory footprint
than Rete.
* Jadex Rules pays close attention to rule debugging. The state as
well as the rete engine can be observed at runtime. The rule debugger
provides functionalities to execute a rule program stepwise and also
use rule breakpoints to stop the execution at those points.
package jadex.rules.state.javaimpl;
import jadex.commons.SUtil;
import jadex.rules.state.IOAVState;
import jadex.rules.state.OAVAttributeType;
import jadex.rules.state.OAVObjectType;
/**
* Internal object modified event.
*/
class OAVObjectModifiedEvent
{
//-------- attributes --------
/** The state. */
protected IOAVState state;
/** The object id. */
protected Object id;
/** The object type. */
protected OAVObjectType type;
/** The attribute. */
protected OAVAttributeType attribute;
/** The old value. */
protected Object oldvalue;
/** The new value. */
protected Object newvalue;
//-------- constructors --------
/**
* Create a new object modified event.
*/
public OAVObjectModifiedEvent(IOAVState state, Object id, OAVObjectType type,
OAVAttributeType attribute, Object oldvalue, Object newvalue)
{
this.state = state;
this.id = id;
this.type = type;
this.attribute = attribute;
this.oldvalue = oldvalue;
this.newvalue = newvalue;
}
//-------- methods --------
/**
* Compute the hascode.
* @return The hashcode.
*/
public int hashCode()
{
int ret;
if(!attribute.getMultiplicity().equals(OAVAttributeType.NONE))
{
ret = super.hashCode();
}
else
{
final int prime = 31;
ret = prime * id.hashCode();
ret = prime * ret + type.hashCode();
ret = prime * ret + attribute.hashCode();
}
return ret;
}
/**
* Test for equality.
* @param obj The object to test.
* @return True, if equal.
*/
public boolean equals(Object obj)
{
boolean ret = obj==this;
if(!ret && attribute.getMultiplicity().equals(OAVAttributeType.NONE)
&& obj instanceof OAVObjectModifiedEvent)
{
// Problem multi attributes:
// a) add/remove to a list (2x same object would be different)
// -> keep both events
// b) add/remove to a set (2x same object would not be different)
// -> last add/remove should not have worked! no event should have been created
// For a single attribute only the last event should occur
OAVObjectModifiedEvent evt = (OAVObjectModifiedEvent)obj;
if(state.equals(id, evt.id) && SUtil.equals(type, evt.type)
&& SUtil.equals(attribute, evt.attribute)
)
{
ret = true;
}
}
return ret;
}
/**
* Get the string representation.
* @return The string representation.
*/
public String toString()
{
return "OAVObjectModifiedEvent(id="+id+", type="+type+", attribute="+attribute+", oldval="+oldvalue+", newval="+newvalue+")";
}
}