Package com.alibaba.toolkit.util.collection

Examples of com.alibaba.toolkit.util.collection.Predicate


     * @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;
            }
        }

View Full Code Here


     *
     * @param context 匹配上下文
     * @return 如果匹配成功, 则返回<code>true</code>
     */
    public boolean matches(MatchContext context) {
        Predicate predicate = context.getPredicate();

        // 如果没有predicate, 则选择使用更高效的策略
        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;
            }
        }

View Full Code Here

     * @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;
            }
        }

View Full Code Here

TOP

Related Classes of com.alibaba.toolkit.util.collection.Predicate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.