if((factName == null) || (!templateName.equalsIgnoreCase(factName)))
return false;
}
// Match the address sequence. See 'FIPA Agent Management Specification, Sect. 6.4.2.1'
Iterator itTemplate = template.getAllAddresses();
Iterator itFact = fact.getAllAddresses();
// All the elements in the template sequence must appear in the
// fact sequence, in the same order
while(itTemplate.hasNext()) {
String templateAddr = (String)itTemplate.next();
// Search 'templateAddr' into the remaining part of the fact sequence
boolean found = false;
while(!found && itFact.hasNext()) {
String factAddr = (String)itFact.next();
found = templateAddr.equalsIgnoreCase(factAddr);
}
if(!found) // An element of the template does not appear in the fact sequence
return false;
}
// Match the resolvers sequence. See 'FIPA Agent Management Specification, Sect. 6.4.2.1'
itTemplate = template.getAllResolvers();
itFact = fact.getAllResolvers();
while(itTemplate.hasNext()) {
AID templateRes = (AID)itTemplate.next();
// Search 'templateRes' into the remaining part of the fact sequence
boolean found = false;
while(!found && itFact.hasNext()) {
AID factRes = (AID)itFact.next();
found = matchAID(templateRes, factRes); // Recursive call
}
if(!found) // An element of the template does not appear in the fact sequence
return false;
}