Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4cd661b058b6349f50a5446bb524afc18bcb8e00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package org.eclipse.jst.jsf.common.internal.finder;

import java.util.Collections;
import java.util.List;

/**
 * A finder that finds it's OUTPUT in INPUT by using a matching strategy.
 * @author cbateman
 * @param <INPUT> 
 * @param <OUTPUT> 
 * @param <IDTYPE> 
 *
 */
public abstract class AbstractMatcher<INPUT, OUTPUT, IDTYPE> extends AbstractFinder<INPUT, OUTPUT, IDTYPE>
{
    private final List<? extends IMatcher> _matchers;

    /**
     * An interface that defines a match.
     *
     */
    public interface IMatcher
    {
        /**
         * @param matchThis
         * @return true if T matches the expected critieria
         */
        boolean matches(Object matchThis);
    }
    
    /**
     * A matcher that matches always.
     * @author cbateman
     *
     */
    public static final class AlwaysMatcher implements IMatcher
    {
        public boolean matches(Object matchThis)
        {
            return true;
        }
    }

    /**
     * @param id
     * @param displayName
     * @param noResultValue
     * @param matchers
     */
    public AbstractMatcher(final IDTYPE id, final String displayName, final OUTPUT noResultValue, final List<? extends IMatcher>  matchers)
    {
        super(id, displayName, noResultValue);
        _matchers = matchers;
    }

    @Override
    public abstract OUTPUT perform(INPUT input) throws Exception;

    /**
     * @return the matchers
     */
    protected final List<IMatcher> getMatchers()
    {
        return Collections.unmodifiableList(_matchers);
    }
}

Back to the top