// Path: src/main/java/uk/co/compendiumdev/javafortesters/domain/counterstrings/Creators/CounterStringCreator.java
// public interface CounterStringCreator {
//     void append(String nextPart);
//     void finished();
// }
// 
// Path: src/main/java/uk/co/compendiumdev/javafortesters/domain/counterstrings/Creators/StringCounterStringCreator.java
// public class StringCounterStringCreator implements CounterStringCreator {
// 
//     private final StringBuilder string;
// 
//     public StringCounterStringCreator(){
//         string = new StringBuilder();
// 
//     }
// 
//     @Override
//     public void append(String nextPart) {
//         string.append(nextPart);
//     }
// 
//     @Override
//     public void finished() {
//         // string is ready to output now
//     }
// 
//     @Override
//     public String toString() {
//         return string.toString();
//     }
// }


import uk.co.compendiumdev.javafortesters.domain.counterstrings.Creators.CounterStringCreator;
import uk.co.compendiumdev.javafortesters.domain.counterstrings.Creators.StringCounterStringCreator;
import java.util.List;
package uk.co.compendiumdev.javafortesters.domain.counterstrings;



/**
 * Created by alan on 08/12/2014.
 */
public class CounterString {

    /*
        forward counterstring algorithm
        assumptions - blocks of numbers are lengths of strings
            35*  is length 3
                so 2 digit numbers are represented as 3 chars
            2*   is length 2
                so 1 digit numbers are represented as 2 chars


        if 35* then how many 3 digit strings are there?
                9
            why?
2*4*6*8*11*14*17*20*23*26*29*32*35*
            35 - 10 = 25
            25/3 = 8.33

            int(8.3) = 8 + 1 = 9 * 3 char numbers

            9 * 3 = 27
            35-27 = 8

            7 is not a 3 char number so lowest 3 char number is 8 + 3 = 11

            lowest 3 char number is 11
            so highest 2 char number is
            8 (11 - 3)

            with 1-9, when odd start with 1
                    , when even start with 2


        if 34* then
*3*5*7*10*13*16*19*22*25*28*31*34*
            9 3 chars
            34-10 - 24
            24/3 = 8

            int(8) = 8 + 1 = 9 * 3 char numbers
            3*9 = 27
            34-27 = 7
            7 is not a 3 char number so lowest 3 char number is 7 + 3 = 10


            lowest 3 char number is 10
            so highest 2 char number is
            7 (10 - 3)

            with 1-9, when odd start with 1
                    , when even start with 2


        if 33* then
*3*5*7*9*12*15*18*21*24*27*30*33*
            8 3 chars
            33-10 - 23
            23/3 = 7.

            int(7.) = 7 + 1 = 8 * 3 char numbers

            lowest 3 char number is 12
            3*8 - 24
            33 - 24 = 9
            9 is not a 3 char number so next 3 char number is 9+3 = 12


        if 10* then
            1 3 chars
            10-10 = 0
            0/3 = 0

        how many 2 chars?

        lowest 3 char number is 10
            so highest 2 char number is
            7 (10 - 3)

            with 1-9, when odd start with 1
                    , when even start with 2



     */

    public String create(int length) throws CounterStringCreationError {
        return create(length,"*");
    }

    public String create(int lengthOfCounterString, String limiter) throws CounterStringCreationError {

        return createWith(lengthOfCounterString, limiter, new StringCounterStringCreator()).toString();

    }

// Path: src/main/java/uk/co/compendiumdev/javafortesters/domain/counterstrings/Creators/CounterStringCreator.java
// public interface CounterStringCreator {
//     void append(String nextPart);
//     void finished();
// }
// 
// Path: src/main/java/uk/co/compendiumdev/javafortesters/domain/counterstrings/Creators/StringCounterStringCreator.java
// public class StringCounterStringCreator implements CounterStringCreator {
// 
//     private final StringBuilder string;
// 
//     public StringCounterStringCreator(){
//         string = new StringBuilder();
// 
//     }
// 
//     @Override
//     public void append(String nextPart) {
//         string.append(nextPart);
//     }
// 
//     @Override
//     public void finished() {
//         // string is ready to output now
//     }
// 
//     @Override
//     public String toString() {
//         return string.toString();
//     }
// }


// Path: src/main/java/uk/co/compendiumdev/javafortesters/domain/counterstrings/CounterString.java
import uk.co.compendiumdev.javafortesters.domain.counterstrings.Creators.CounterStringCreator;
import uk.co.compendiumdev.javafortesters.domain.counterstrings.Creators.StringCounterStringCreator;
import java.util.List;

package uk.co.compendiumdev.javafortesters.domain.counterstrings;



/**
 * Created by alan on 08/12/2014.
 */
public class CounterString {

    /*
        forward counterstring algorithm
        assumptions - blocks of numbers are lengths of strings
            35*  is length 3
                so 2 digit numbers are represented as 3 chars
            2*   is length 2
                so 1 digit numbers are represented as 2 chars


        if 35* then how many 3 digit strings are there?
                9
            why?
2*4*6*8*11*14*17*20*23*26*29*32*35*
            35 - 10 = 25
            25/3 = 8.33

            int(8.3) = 8 + 1 = 9 * 3 char numbers

            9 * 3 = 27
            35-27 = 8

            7 is not a 3 char number so lowest 3 char number is 8 + 3 = 11

            lowest 3 char number is 11
            so highest 2 char number is
            8 (11 - 3)

            with 1-9, when odd start with 1
                    , when even start with 2


        if 34* then
*3*5*7*10*13*16*19*22*25*28*31*34*
            9 3 chars
            34-10 - 24
            24/3 = 8

            int(8) = 8 + 1 = 9 * 3 char numbers
            3*9 = 27
            34-27 = 7
            7 is not a 3 char number so lowest 3 char number is 7 + 3 = 10


            lowest 3 char number is 10
            so highest 2 char number is
            7 (10 - 3)

            with 1-9, when odd start with 1
                    , when even start with 2


        if 33* then
*3*5*7*9*12*15*18*21*24*27*30*33*
            8 3 chars
            33-10 - 23
            23/3 = 7.

            int(7.) = 7 + 1 = 8 * 3 char numbers

            lowest 3 char number is 12
            3*8 - 24
            33 - 24 = 9
            9 is not a 3 char number so next 3 char number is 9+3 = 12


        if 10* then
            1 3 chars
            10-10 = 0
            0/3 = 0

        how many 2 chars?

        lowest 3 char number is 10
            so highest 2 char number is
            7 (10 - 3)

            with 1-9, when odd start with 1
                    , when even start with 2



     */

    public String create(int length) throws CounterStringCreationError {
        return create(length,"*");
    }

    public String create(int lengthOfCounterString, String limiter) throws CounterStringCreationError {

        return createWith(lengthOfCounterString, limiter, new StringCounterStringCreator()).toString();

    }

    public CounterStringCreator createWith(int lengthOfCounterString, String limiter, CounterStringCreator creator) throws CounterStringCreationError {