package edu.wright.hendrix11.conway.logic;

import java.util.Arrays;
import java.util.List;

/**
 * @author Joe Hendrix
 */
public class Pattern {

    public static final Pattern block = new Pattern("block", new String[]{"XX", "XX"});
    public static final Pattern single = new Pattern("single", new String[]{"X"});

    private final String name;
    private final List<String> pattern;

    public Pattern(String name, List<String> pattern) {
        this.name = name;
        this.pattern = pattern;
        assert classInv();
    }

    public Pattern(String name, String[] pattern) {
        this(name, Arrays.asList(pattern));
    }

    private boolean classInv() {
        boolean invarient = true;

        invarient = name != null && pattern != null;

        if (pattern != null) {
            for (String string : pattern) {
                if (string == null) {
                    invarient = false;
                }
            }
        }

        return invarient;
    }

    public void generate(Cell seed) {
        Cell outterCell = seed;

        for (String row : pattern) {

            Cell innerCell = outterCell;

            for (char letter : row.toCharArray()) {
                if (letter == 'X') {
                    innerCell.toggle();
                }

                innerCell = innerCell.getEasternCell();
            }

            outterCell = outterCell.getSouthernCell();
        }

        assert classInv();
    }

    @Override
    public String toString() {
        return name;
    }
}


@@ -632,24 +632,151 @@
 n));%0A    %7D%0A%0A
+    /**%0A     * The name is not null, the pattern list is not null, and no element in the pattern%0A     * list is null.%0A     */ %0A
     private 
@@ -1121,41 +1121,228 @@
     
-public void generate(Cell seed) %7B
+/**%0A     * Generates the pattern specified in pattern.%0A     * %0A     * precondition:    seed is not null%0A     * postcondition:   %0A     * %0A     */%0A    public void generate(Cell seed) %7B%0A        assert seed != null;%0A        
 %0A   

Update Pattern.java