final Rule rule = new Rule( "findSeating" );
// ---------------
// context : Context( state == Context.ASSIGN_SEATS )
// ---------------
final Pattern contextPattern = new Pattern( 0,
this.contextType,
"context" );
contextPattern.addConstraint( getLiteralConstraint( contextPattern,
"state",
Context.ASSIGN_SEATS,
this.integerEqualEvaluator ) );
rule.addPattern( contextPattern );
final Declaration contextDeclaration = rule.getDeclaration( "context" );
// -------------------------------
// Seating( seatingId:id, seatingPid:pid, pathDone == true
// seatingRightSeat:rightSeat seatingRightGuestName:rightGuestName )
// -------------------------------
final Pattern seatingPattern = new Pattern( 1,
this.seatingType );
setFieldDeclaration( seatingPattern,
"id",
"seatingId" );
setFieldDeclaration( seatingPattern,
"pid",
"seatingPid" );
seatingPattern.addConstraint( getLiteralConstraint( seatingPattern,
"pathDone",
true,
this.booleanEqualEvaluator ) );
setFieldDeclaration( seatingPattern,
"rightSeat",
"seatingRightSeat" );
setFieldDeclaration( seatingPattern,
"rightGuestName",
"seatingRightGuestName" );
rule.addPattern( seatingPattern );
final Declaration seatingIdDeclaration = rule.getDeclaration( "seatingId" );
final Declaration seatingPidDeclaration = rule.getDeclaration( "seatingPid" );
final Declaration seatingRightGuestNameDeclaration = rule.getDeclaration( "seatingRightGuestName" );
final Declaration seatingRightSeatDeclaration = rule.getDeclaration( "seatingRightSeat" );
// --------------
// Guest( name == seatingRightGuestName, rightGuestSex:sex,
// rightGuestHobby:hobby )
// ---------------
final Pattern rightGuestPattern = new Pattern( 2,
this.guestType );
rightGuestPattern.addConstraint( getBoundVariableConstraint( rightGuestPattern,
"name",
seatingRightGuestNameDeclaration,
this.objectEqualEvaluator ) );
setFieldDeclaration( rightGuestPattern,
"sex",
"rightGuestSex" );
setFieldDeclaration( rightGuestPattern,
"hobby",
"rightGuestHobby" );
rule.addPattern( rightGuestPattern );
final Declaration rightGuestSexDeclaration = rule.getDeclaration( "rightGuestSex" );
final Declaration rightGuestHobbyDeclaration = rule.getDeclaration( "rightGuestHobby" );
// ----------------
// Guest( leftGuestName:name , sex != rightGuestSex, hobby ==
// rightGuestHobby )
// ----------------
final Pattern leftGuestPattern = new Pattern( 3,
this.guestType );
setFieldDeclaration( leftGuestPattern,
"name",
"leftGuestName" );
leftGuestPattern.addConstraint( getBoundVariableConstraint( rightGuestPattern,
"hobby",
rightGuestHobbyDeclaration,
this.objectEqualEvaluator ) );
leftGuestPattern.addConstraint( getBoundVariableConstraint( leftGuestPattern,
"sex",
rightGuestSexDeclaration,
this.objectNotEqualEvaluator ) );
rule.addPattern( leftGuestPattern );
final Declaration leftGuestNameDeclaration = rule.getDeclaration( "leftGuestName" );
// ---------------
// count : Count()
// ---------------
final Pattern count = new Pattern( 4,
this.countType,
"count" );
rule.addPattern( count );
final Declaration countDeclaration = rule.getDeclaration( "count" );
// --------------
// not ( Path( id == seatingId, guestName == leftGuestName) )
// --------------
final Pattern notPathPattern = new Pattern( 5,
this.pathType );
notPathPattern.addConstraint( getBoundVariableConstraint( notPathPattern,
"id",
seatingIdDeclaration,
this.integerEqualEvaluator ) );
notPathPattern.addConstraint( getBoundVariableConstraint( notPathPattern,
"guestName",
leftGuestNameDeclaration,
this.objectEqualEvaluator ) );
final GroupElement notPath = GroupElementFactory.newNotInstance();
notPath.addChild( notPathPattern );
rule.addPattern( notPath );
// ------------
// not ( Chosen( id == seatingId, guestName == leftGuestName, hobby ==
// rightGuestHobby ) )
// ------------
final Pattern notChosenPattern = new Pattern( 6,
this.chosenType );
notChosenPattern.addConstraint( getBoundVariableConstraint( notChosenPattern,
"id",
seatingIdDeclaration,
this.integerEqualEvaluator ) );
notChosenPattern.addConstraint( getBoundVariableConstraint( notChosenPattern,
"guestName",
leftGuestNameDeclaration,
this.objectEqualEvaluator ) );
notChosenPattern.addConstraint( getBoundVariableConstraint( notChosenPattern,
"hobby",
rightGuestHobbyDeclaration,
this.objectEqualEvaluator ) );
final GroupElement notChosen = GroupElementFactory.newNotInstance();