ReturnValueExpressionConstraint isCheddar = new ReturnValueExpressionConstraint() {
public boolean isAllowed(Object object,
ConstraintComparator comparator)
{
Cheese cheese = (Cheese) object;
return comparator.compare( cheese.getType(),
"cheddar" );
}
/* everything is ignored - except object */
public boolean isAllowed(Object object,
FactHandle handle,
Declaration[] declarations,
Tuple tuple,
ConstraintComparator comparator)
{
Cheese cheese = (Cheese) object;
return comparator.compare( cheese.getType(),
"cheddar" );
}
};
/*
* Creates a constraint with the given expression
*/
ReturnValueConstraint constraint0 = new ReturnValueConstraint( isCheddar,
null, // alpha nodes cannot have required declarations
new StringConstraintComparator( ConstraintComparator.EQUAL ) );
AlphaNode alphaNode = new AlphaNode( 2,
constraint0,
true,
source );
MockObjectSink sink = new MockObjectSink();
alphaNode.addObjectSink( sink );
Cheese cheddar = new Cheese( "cheddar",
5 );
FactHandleImpl f0 = new FactHandleImpl( 0 );
workingMemory.putObject( f0,
cheddar );
assertLength( 0,
sink.getAsserted() );
/* object should assert as it passes text */
alphaNode.assertObject( cheddar,
f0,
context,
workingMemory );
assertLength( 1,
sink.getAsserted() );
Object[] list = (Object[]) sink.getAsserted().get( 0 );
assertSame( cheddar,
list[0] );
Cheese stilton = new Cheese( "stilton",
6 );
/* object should not assert as it does not pass text */
alphaNode.assertObject( stilton,
f0,