public class DiamondAsteriskPrinter {

    protected final int n;
    private final int diamondHeight;
    private final int diamondWidth;

    public DiamondAsteriskPrinter(int n) {
        this.n = n;
        this.diamondHeight = getDiamondHeight(n);
        this.diamondWidth = getDiamondWidth(n);
    }

    private static int getDiamondHeight(int lines) {
        return lines*2 - 1;
    }

    private static int getDiamondWidth(int lines) {
        return 1 + (lines - 1)*2;
    }

    public String printValue() {
        StringBuilder builder = new StringBuilder();
        buildDiamond(builder, 0);
        return builder.toString();
    }

    private void buildDiamond(StringBuilder builder, int currentLine) {
        if (n <= 0) {
            return;
        }

        buildLine(builder, currentLine);

        if (currentLine == diamondHeight - 1) {
            return;
        }

        buildDiamond(builder, currentLine + 1);
    }

    protected void buildLine(StringBuilder builder, int currentLine) {
        fillLine(builder, currentLine);
        addLineBreaker(builder, currentLine);
    }

    protected void fillLine(StringBuilder builder, int currentLine) {
        for (int j = 0; j < diamondWidth; ++j) {
            if (j >= getFirstAsteriskIndex(currentLine) && j <= getLastAsteriskIndex(currentLine)) {
                builder.append("*");
            } else {
                builder.append(" ");
            }
        }
    }

    protected void addLineBreaker(StringBuilder builder, int currentLine) {
        if (currentLine < diamondHeight - 1) {
            builder.append("\n");
        }
    }

    private int getFirstAsteriskIndex(int currentLine) {
        return (diamondWidth - getNumberOfAsterisksOnLine(currentLine))/2;
    }

    private int getNumberOfAsterisksOnLine(int currentLine) {
        if (currentLine >= n) {
            currentLine = (diamondHeight - 1) - currentLine;
        }

        return currentLine*2 + 1;
    }

    private int getLastAsteriskIndex(int currentLine) {
        return (diamondWidth - 1) - getFirstAsteriskIndex(currentLine);
    }
}

@@ -1248,71 +1248,25 @@
 if (
-j %3E= getFirstAsteriskIndex(currentLine) && j %3C= getLast
+canAppend
 Asterisk
 Inde
@@ -1253,38 +1253,36 @@
 anAppendAsterisk
-Index(
+(j, 
 currentLine)) %7B%0A
@@ -1417,57 +1417,49 @@
   pr
-otected void addLineBreaker(StringBuilder builder
+ivate boolean canAppendAsterisk(int index
 , in
@@ -1487,90 +1487,105 @@
     
-if (currentLine %3C diamondHeight - 1) %7B%0A            builder.append(%22%5Cn%22);%0A        %7D
+return index %3E= getFirstAsteriskIndex(currentLine) && index %3C= getLastAsteriskIndex(currentLine);
 %0A   
@@ -1982,32 +1982,32 @@
  currentLine) %7B%0A
-
         return (
@@ -2067,11 +2067,185 @@
 );%0A    %7D
+%0A%0A    protected void addLineBreaker(StringBuilder builder, int currentLine) %7B%0A        if (currentLine %3C diamondHeight - 1) %7B%0A            builder.append(%22%5Cn%22);%0A        %7D%0A    %7D
 %0A%7D%0A

Extracting a boolean statement to a method.