Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8eda48879979fa79e2c0b95c02d9e7074f0352a6 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*******************************************************************************
 * Copyright (c) 2010, 2019 IBM Corporation and others.
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.common.internal.strategy;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

/**
 * A simple concrete implementation that uses a constructor provided values
 * to implement abstract methods.
 * 
 * @author cbateman
 *
 * @param <INPUT>
 * @param <OUTPUT>
 * @param <RESULTTYPE> 
 * @param <IDTYPE>
 * @param <STRATEGYTYPE>
 */
public class SimpleStrategyComposite<INPUT, OUTPUT, RESULTTYPE, IDTYPE, STRATEGYTYPE extends IIdentifiableStrategy<INPUT,OUTPUT,IDTYPE>> extends
StrategyComposite<INPUT, OUTPUT, RESULTTYPE, IDTYPE, STRATEGYTYPE>
{

    private final RESULTTYPE _noResultValue;
    private final Collection<STRATEGYTYPE> _strategies;

    /**
     * Use the list of strategies and null as the no result value.
     * @param strategies
     */
    public SimpleStrategyComposite(final Collection<STRATEGYTYPE> strategies)
    {
        this(strategies, (RESULTTYPE) null);
    }
    /**
     * Use the list of strategies and the provided no result value.
     * @param strategies
     * @param noResultValue
     */
    public SimpleStrategyComposite(final Collection<STRATEGYTYPE> strategies, final RESULTTYPE noResultValue)
    {
        super();
        _strategies = strategies;
        _noResultValue = noResultValue;
    }

    /**
     * Use the provided strategies, composition strategy and null for the no result value
     * @param strategies
     * @param compositionStrategy
     */
    public SimpleStrategyComposite(final Collection<STRATEGYTYPE> strategies,
            final AbstractCompositionStrategy<INPUT, OUTPUT, RESULTTYPE, STRATEGYTYPE> compositionStrategy)
    {
        this(strategies, null, compositionStrategy);
    }

    /**
     * Use the provided strategies, composition strategy and null for the no result value
     * @param strategies
     * @param noResultValue
     * @param compositionStrategy
     */
    public SimpleStrategyComposite(final Collection<STRATEGYTYPE> strategies, final RESULTTYPE noResultValue,
            final AbstractCompositionStrategy<INPUT, OUTPUT, RESULTTYPE, STRATEGYTYPE> compositionStrategy)
    {
        super(compositionStrategy);
        _strategies = strategies;
        _noResultValue = noResultValue;
    }

    @Override
    public RESULTTYPE getNoResult()
    {
        return _noResultValue;
    }

    @Override
    public Iterator<STRATEGYTYPE> getIterator()
    {
        return Collections.unmodifiableCollection(_strategies).iterator();
    }

}

Back to the top