* @param context ƥ��������
*
* @return ���ƥ��ɹ�, ��<code>true</code>
*/
public boolean matches(MatchContext context) {
Predicate predicate = context.getPredicate();
// ���û��predicate, ��ѡ��ʹ�ø���Ч�IJ���
if (predicate == null) {
return matchWithoutPredicate(context);
}
Collection patterns = context.getPatterns();
List matchItemList = new ArrayList(patterns.size());
for (Iterator i = patterns.iterator(); i.hasNext();) {
MatchPattern pattern = (MatchPattern) i.next();
if (pattern.matches(context)) {
matchItemList.add(context.getLastMatchItem());
}
}
// ��ƥ��, ��ֱ�ӷ���null
if (matchItemList.size() == 0) {
return false;
}
// ��ƥ�䳤���ɴ�С����(�ȶ�)
Collections.sort(matchItemList, MATCH_LENGTH_COMPARATOR);
// ͨ��ָ����predicate��������ƥ����
for (Iterator i = matchItemList.iterator(); i.hasNext();) {
MatchItem item = (MatchItem) i.next();
if (predicate.evaluate(item)) {
context.setLastMatchItem(item);
return true;
}
}