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 
            
package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.*;
import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.visitors.FizzBuzzOutputGenerationContext;
import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.printers.StringPrinter;
import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.OutputGenerationStrategy;
import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.SingleStepOutputGenerationParameter;
import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.visitors.OutputGenerationContext;
import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.visitors.OutputGenerationContextVisitor;

@Service
public class SingleStepOutputGenerationStrategy implements OutputGenerationStrategy
{

    private final List<OutputGenerationContext> contexts;
    private final OutputGenerationContextVisitor contextVisitor;
    private final StringPrinter myNewLinePrinter;

    @Autowired
    public SingleStepOutputGenerationStrategy(
        final FizzBuzzOutputGenerationContextVisitorFactory fizzBuzzOutputGenerationContextVisitorFactory,
        final FizzStrategyFactory fizzStrategyFactory,
        final FizzStringPrinterFactory fizzStringPrinterFactory,
        final BuzzStrategyFactory buzzStrategyFactory,
        final BuzzStringPrinterFactory buzzStringPrinterFactory,
        final NoFizzNoBuzzStrategyFactory noFizzNoBuzzStrategyFactory,
        final IntegerIntegerPrinterFactory integerIntegerPrinterFactory,
        final NewLineStringPrinterFactory newLineStringPrinterFactory)
    {
        super();
        this.contextVisitor = fizzBuzzOutputGenerationContextVisitorFactory.createVisitor();
        this.contexts = new ArrayList<OutputGenerationContext>();
        this.contexts.add(new FizzBuzzOutputGenerationContext(fizzStrategyFactory.createIsEvenlyDivisibleStrategy(),
                            fizzStringPrinterFactory.createStringPrinter()));
        this.contexts.add(new FizzBuzzOutputGenerationContext(buzzStrategyFactory.createIsEvenlyDivisibleStrategy(),
                            buzzStringPrinterFactory.createStringPrinter()));
        this.contexts.add(new FizzBuzzOutputGenerationContext(
                                noFizzNoBuzzStrategyFactory.createIsEvenlyDivisibleStrategy(),
                                integerIntegerPrinterFactory.createPrinter()));

        this.myNewLinePrinter = newLineStringPrinterFactory.createStringPrinter();
    }

    public void performGenerationForCurrentStep(final SingleStepOutputGenerationParameter generationParameter)
    {
        final int nGenerationParameter = generationParameter.retrieveIntegerValue();
        final Iterator<OutputGenerationContext> iterator = this.contexts.iterator();
        while (iterator.hasNext())
        {
            final OutputGenerationContext context = iterator.next();
            this.contextVisitor.visit(context, nGenerationParameter);
        }
        this.myNewLinePrinter.print();
    }

}
            
¡Vaya!
Esto compilaba ayer...
¡La nueva página estará lista en cuanto
encontremos el ';' que falta!